本文整理汇总了Python中shinken.http_client.HTTPClient.post方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPClient.post方法的具体用法?Python HTTPClient.post怎么用?Python HTTPClient.post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shinken.http_client.HTTPClient
的用法示例。
在下文中一共展示了HTTPClient.post方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SatelliteLink
# 需要导入模块: from shinken.http_client import HTTPClient [as 别名]
# 或者: from shinken.http_client.HTTPClient import post [as 别名]
class SatelliteLink(Item):
"""SatelliteLink is a common Class for link to satellite for
Arbiter with Conf Dispatcher.
"""
# id = 0 each Class will have it's own id
properties = Item.properties.copy()
properties.update({
'address': StringProp(fill_brok=['full_status']),
'timeout': IntegerProp(default='3', fill_brok=['full_status']),
'data_timeout': IntegerProp(default='120', fill_brok=['full_status']),
'check_interval': IntegerProp(default='60', fill_brok=['full_status']),
'max_check_attempts': IntegerProp(default='3', fill_brok=['full_status']),
'spare': BoolProp(default='0', fill_brok=['full_status']),
'manage_sub_realms': BoolProp(default='1', fill_brok=['full_status']),
'manage_arbiters': BoolProp(default='0', fill_brok=['full_status'], to_send=True),
'modules': ListProp(default='', to_send=True),
'polling_interval': IntegerProp(default='1', fill_brok=['full_status'], to_send=True),
'use_timezone': StringProp(default='NOTSET', to_send=True),
'realm': StringProp(default='', fill_brok=['full_status'], brok_transformation=get_obj_name_two_args_and_void),
'satellitemap': DictProp(default=None, elts_prop=AddrProp, to_send=True, override=True),
'use_ssl': BoolProp(default='0', fill_brok=['full_status']),
})
running_properties = Item.running_properties.copy()
running_properties.update({
'con': StringProp(default=None),
'alive': StringProp(default=True, fill_brok=['full_status']),
'broks': StringProp(default=[]),
'attempt': StringProp(default=0, fill_brok=['full_status']), # the number of failed attempt
'reachable': StringProp(default=False, fill_brok=['full_status']), # can be network ask or not (dead or check in timeout or error)
'last_check': IntegerProp(default=0, fill_brok=['full_status']),
'managed_confs': StringProp(default={}),
})
def __init__(self, *args, **kwargs):
super(SatelliteLink, self).__init__(*args, **kwargs)
self.arb_satmap = {'address': '0.0.0.0', 'port': 0}
if hasattr(self, 'address'):
self.arb_satmap['address'] = self.address
if hasattr(self, 'port'):
try:
self.arb_satmap['port'] = int(self.port)
except:
pass
def set_arbiter_satellitemap(self, satellitemap):
"""
arb_satmap is the satellitemap in current context:
- A SatelliteLink is owned by an Arbiter
- satellitemap attribute of SatelliteLink is the map defined IN THE satellite configuration
but for creating connections, we need the have the satellitemap of the Arbiter
"""
self.arb_satmap = {'address': self.address, 'port': self.port}
self.arb_satmap.update(satellitemap)
def create_connection(self):
self.con = HTTPClient(address=self.arb_satmap['address'], port=self.arb_satmap['port'],
timeout=self.timeout, data_timeout=self.data_timeout, use_ssl=self.use_ssl
)
self.uri = self.con.uri
def put_conf(self, conf):
if self.con is None:
self.create_connection()
# Maybe the connexion was not ok, bail out
if not self.con:
return False
try:
#pyro.set_timeout(self.con, self.data_timeout)
self.con.post('put_conf', {'conf':conf}, wait='long')
#pyro.set_timeout(self.con, self.timeout)
print "PUT CONF SUCESS", self.get_name()
return True
except HTTPExceptions, exp:
self.con = None
logger.error("Failed sending configuration for %s: %s" % (self.get_name(), str(exp)))
return False
示例2: SatelliteLink
# 需要导入模块: from shinken.http_client import HTTPClient [as 别名]
# 或者: from shinken.http_client.HTTPClient import post [as 别名]
class SatelliteLink(Item):
"""SatelliteLink is a common Class for link to satellite for
Arbiter with Conf Dispatcher.
"""
# id = 0 each Class will have it's own id
properties = Item.properties.copy()
properties.update(
{
"address": StringProp(fill_brok=["full_status"]),
"timeout": IntegerProp(default="3", fill_brok=["full_status"]),
"data_timeout": IntegerProp(default="120", fill_brok=["full_status"]),
"check_interval": IntegerProp(default="60", fill_brok=["full_status"]),
"max_check_attempts": IntegerProp(default="3", fill_brok=["full_status"]),
"spare": BoolProp(default="0", fill_brok=["full_status"]),
"manage_sub_realms": BoolProp(default="1", fill_brok=["full_status"]),
"manage_arbiters": BoolProp(default="0", fill_brok=["full_status"], to_send=True),
"modules": ListProp(default="", to_send=True),
"polling_interval": IntegerProp(default="1", fill_brok=["full_status"], to_send=True),
"use_timezone": StringProp(default="NOTSET", to_send=True),
"realm": StringProp(
default="", fill_brok=["full_status"], brok_transformation=get_obj_name_two_args_and_void
),
"satellitemap": DictProp(default=None, elts_prop=AddrProp, to_send=True, override=True),
"use_ssl": BoolProp(default="0", fill_brok=["full_status"]),
"hard_ssl_name_check": BoolProp(default="0", fill_brok=["full_status"]),
"passive": BoolProp(default="0", fill_brok=["full_status"], to_send=True),
}
)
running_properties = Item.running_properties.copy()
running_properties.update(
{
"con": StringProp(default=None),
"alive": StringProp(default=True, fill_brok=["full_status"]),
"broks": StringProp(default=[]),
"attempt": StringProp(default=0, fill_brok=["full_status"]), # the number of failed attempt
"reachable": StringProp(
default=False, fill_brok=["full_status"]
), # can be network ask or not (dead or check in timeout or error)
"last_check": IntegerProp(default=0, fill_brok=["full_status"]),
"managed_confs": StringProp(default={}),
}
)
def __init__(self, *args, **kwargs):
super(SatelliteLink, self).__init__(*args, **kwargs)
self.arb_satmap = {"address": "0.0.0.0", "port": 0}
if hasattr(self, "address"):
self.arb_satmap["address"] = self.address
if hasattr(self, "port"):
try:
self.arb_satmap["port"] = int(self.port)
except:
pass
def set_arbiter_satellitemap(self, satellitemap):
"""
arb_satmap is the satellitemap in current context:
- A SatelliteLink is owned by an Arbiter
- satellitemap attribute of SatelliteLink is the map defined IN THE satellite configuration
but for creating connections, we need the have the satellitemap of the Arbiter
"""
self.arb_satmap = {
"address": self.address,
"port": self.port,
"use_ssl": self.use_ssl,
"hard_ssl_name_check": self.hard_ssl_name_check,
}
self.arb_satmap.update(satellitemap)
def create_connection(self):
self.con = HTTPClient(
address=self.arb_satmap["address"],
port=self.arb_satmap["port"],
timeout=self.timeout,
data_timeout=self.data_timeout,
use_ssl=self.use_ssl,
strong_ssl=self.hard_ssl_name_check,
)
self.uri = self.con.uri
def put_conf(self, conf):
if self.con is None:
self.create_connection()
# Maybe the connexion was not ok, bail out
if not self.con:
return False
try:
# pyro.set_timeout(self.con, self.data_timeout)
self.con.get("ping")
self.con.post("put_conf", {"conf": conf}, wait="long")
# pyro.set_timeout(self.con, self.timeout)
print "PUT CONF SUCESS", self.get_name()
return True
#.........这里部分代码省略.........