本文整理汇总了Python中hm.model.load_balancer.LoadBalancer.create方法的典型用法代码示例。如果您正苦于以下问题:Python LoadBalancer.create方法的具体用法?Python LoadBalancer.create怎么用?Python LoadBalancer.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hm.model.load_balancer.LoadBalancer
的用法示例。
在下文中一共展示了LoadBalancer.create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_destroy
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import create [as 别名]
def test_destroy(self):
LoadBalancer.create('fake', 'my-lb', {'LB_ID': 'xxx'})
db_lb = LoadBalancer.find('my-lb')
self.assertEqual(db_lb.id, 'xxx')
db_lb.destroy()
db_lb = LoadBalancer.find('my-lb')
self.assertIsNone(db_lb)
示例2: test_destroy_ignores_manager_exception
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import create [as 别名]
def test_destroy_ignores_manager_exception(self, log):
LoadBalancer.create('fake', 'my-lb', {'LB_ID': 'explode'})
db_lb = LoadBalancer.find('my-lb')
self.assertEqual(db_lb.id, 'explode')
db_lb.destroy()
self.assertEqual(log.call_args, call("Error trying to destroy load balancer name: 'my-lb' "
"id: 'explode' in 'fake': failure to destroy"))
db_lb = LoadBalancer.find('my-lb')
self.assertIsNone(db_lb)
示例3: run
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import create [as 别名]
def run(self, config, name):
self.init_config(config)
healthcheck_timeout = int(self._get_conf("RPAAS_HEALTHCHECK_TIMEOUT", 600))
host = Host.create(self.host_manager_name, name, self.config)
lb = None
try:
lb = LoadBalancer.create(self.lb_manager_name, name, self.config)
lb.add_host(host)
self.nginx_manager.wait_healthcheck(host.dns_name, timeout=healthcheck_timeout)
self.hc.create(name)
self.hc.add_url(name, host.dns_name)
self.storage.remove_task(name)
except:
exc_info = sys.exc_info()
rollback = self._get_conf("RPAAS_ROLLBACK_ON_ERROR", "0") in ("True", "true", "1")
if not rollback:
raise
try:
if lb is not None:
lb.destroy()
except Exception as e:
logging.error("Error in rollback trying to destroy load balancer: {}".format(e))
try:
host.destroy()
except Exception as e:
logging.error("Error in rollback trying to destroy host: {}".format(e))
try:
self.hc.destroy(name)
except Exception as e:
logging.error("Error in rollback trying to remove healthcheck: {}".format(e))
raise exc_info[0], exc_info[1], exc_info[2]
示例4: test_remove_host
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import create [as 别名]
def test_remove_host(self):
h1 = Host('x', 'x.me.com')
h2 = Host('y', 'y.me.com')
lb = LoadBalancer.create('fake', 'my-lb', {'LB_ID': 'explode'})
lb.add_host(h1)
lb.add_host(h2)
lb.remove_host(h1)
self.assertItemsEqual(lb.hosts, [h2])
db_lb = LoadBalancer.find('my-lb')
self.assertItemsEqual([h.to_json() for h in db_lb.hosts], [h2.to_json()])
示例5: test_add_host
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import create [as 别名]
def test_add_host(self):
h1 = Host('x', 'x.me.com')
h2 = Host('y', 'y.me.com')
conf = {'LB_ID': 'explode'}
lb = LoadBalancer.create('fake', 'my-lb', conf)
lb.add_host(h1)
lb.add_host(h2)
self.assertItemsEqual(lb.hosts, [h1, h2])
db_lb = LoadBalancer.find('my-lb', conf)
self.assertEqual(db_lb.hosts[0].config, conf)
self.assertEqual(db_lb.hosts[1].config, conf)
self.assertItemsEqual([h.to_json() for h in db_lb.hosts], [h1.to_json(), h2.to_json()])
示例6: test_create
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import create [as 别名]
def test_create(self):
conf = {'LB_ID': 'xxx'}
lb = LoadBalancer.create('fake', 'my-lb', conf=conf)
self.assertEqual(lb.id, 'xxx')
self.assertEqual(lb.name, 'my-lb')
self.assertEqual(lb.manager, 'fake')
self.assertEqual(lb.extra, 'something')
self.assertEqual(lb.config, conf)
db_lb = LoadBalancer.find('my-lb', conf=conf)
self.assertEqual(db_lb.id, 'xxx')
self.assertEqual(db_lb.name, 'my-lb')
self.assertEqual(db_lb.manager, 'fake')
self.assertEqual(db_lb.extra, 'something')
self.assertEqual(db_lb.config, conf)
示例7: _add_host
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import create [as 别名]
def _add_host(self, name, lb=None):
healthcheck_timeout = int(self._get_conf("RPAAS_HEALTHCHECK_TIMEOUT", 600))
created_lb = None
try:
if not lb:
lb = created_lb = LoadBalancer.create(self.lb_manager_name, name, self.config)
self.hc.create(name)
config = copy.deepcopy(self.config)
if hasattr(lb, 'dsr') and lb.dsr:
config["HOST_TAGS"] = config["HOST_TAGS"] + ",dsr_ip:{}".format(lb.address)
host = Host.create(self.host_manager_name, name, config)
lb.add_host(host)
self.nginx_manager.wait_healthcheck(host.dns_name, timeout=healthcheck_timeout)
acls = self.consul_manager.find_acl_network(name)
if acls:
acl_host = acls.pop()
for dst in acl_host['destination']:
self.acl_manager.add_acl(name, host.dns_name, dst)
self.hc.add_url(name, host.dns_name)
except:
exc_info = sys.exc_info()
rollback = self._get_conf("RPAAS_ROLLBACK_ON_ERROR", "0") in ("True", "true", "1")
if not rollback:
raise
try:
if created_lb is not None:
created_lb.destroy()
except Exception as e:
logging.error("Error in rollback trying to destroy load balancer: {}".format(e))
try:
if created_lb is not None:
self._delete_host(name, host)
else:
self._delete_host(name, host, lb)
except Exception as e:
logging.error("Error in rollback trying to destroy host: {}".format(e))
try:
if lb and len(lb.hosts) == 0:
self.hc.destroy(name)
except Exception as e:
logging.error("Error in rollback trying to remove healthcheck: {}".format(e))
raise exc_info[0], exc_info[1], exc_info[2]
finally:
self.storage.remove_task(name)
示例8: test_create_duplicated
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import create [as 别名]
def test_create_duplicated(self):
lb = LoadBalancer.create('fake', 'my-lb', {'LB_ID': 'xxx'})
self.assertEqual(lb.id, 'xxx')
self.assertEqual(lb.name, 'my-lb')
with self.assertRaises(pymongo.errors.DuplicateKeyError):
LoadBalancer.create('fake', 'my-lb', {'LB_ID': 'xxx'})