本文整理汇总了Python中hm.model.load_balancer.LoadBalancer类的典型用法代码示例。如果您正苦于以下问题:Python LoadBalancer类的具体用法?Python LoadBalancer怎么用?Python LoadBalancer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LoadBalancer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_destroy
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
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: test_remove_host
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()])
示例4: test_add_host
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()])
示例5: test_create
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)
示例6: activate_ssl
def activate_ssl(self, name, domain, plugin='default'):
lb = LoadBalancer.find(name)
if lb is None:
raise storage.InstanceNotFoundError()
if not self._check_dns(name, domain):
raise SslError('rpaas IP is not registered for this DNS name')
key = ssl.generate_key()
csr = ssl.generate_csr(key, domain)
if plugin == 'le':
try:
self.task_manager.create(name)
task = tasks.DownloadCertTask().delay(self.config, name, plugin, csr, key, domain)
self.task_manager.update(name, task.task_id)
return ''
except Exception:
raise SslError('rpaas IP is not registered for this DNS name')
else:
p_ssl = ssl_plugins.default.Default(domain)
cert = p_ssl.download_crt(key=key)
self.update_certificate(name, cert, key)
return ''
示例7: activate_ssl
def activate_ssl(self, name, domain, plugin='default'):
lb = LoadBalancer.find(name)
if lb is None:
raise storage.InstanceNotFoundError()
# Check if DNS is registered for rpaas ip
if not self._check_dns(name, domain):
raise SslError('rpaas IP is not registered for this DNS name')
# Key and CSR generated to request a certificate
key = self._generate_key()
csr = self._generate_csr(key, domain)
# load plugin if get it as an arg
if plugin.isalpha() and plugin in rpaas.ssl_plugins.__all__ and \
plugin not in ['default', '__init__']:
try:
self.storage.store_task(name)
task = tasks.DownloadCertTask().delay(self.config, name, plugin, csr, key, domain)
self.storage.update_task(name, task.task_id)
return ''
except Exception:
raise SslError('rpaas IP is not registered for this DNS name')
else:
# default
p_ssl = rpaas.ssl_plugins.default.Default(domain)
cert = p_ssl.download_crt(key=key)
self.update_certificate(name, cert, key)
return ''
示例8: new_instance
def new_instance(self, name, team=None, plan_name=None, flavor_name=None):
plan = None
flavor = None
if plan_name:
plan = self.storage.find_plan(plan_name)
if flavor_name:
flavor = self.storage.find_flavor(flavor_name)
used, quota = self.storage.find_team_quota(team)
if len(used) >= quota:
raise QuotaExceededError(len(used), quota)
if not self.storage.increment_quota(team, used, name):
raise Exception("concurrent operations updating team quota")
lb = LoadBalancer.find(name)
if lb is not None:
raise storage.DuplicateError(name)
self.task_manager.create(name)
config = copy.deepcopy(self.config)
metadata = {}
if plan:
config.update(plan.config)
metadata["plan_name"] = plan_name
if flavor:
config.update(flavor.config)
metadata["flavor_name"] = flavor_name
metadata["consul_token"] = consul_token = self.consul_manager.generate_token(name)
self.consul_manager.write_healthcheck(name)
self.storage.store_instance_metadata(name, **metadata)
self._add_tags(name, config, consul_token)
task = tasks.NewInstanceTask().delay(config, name)
self.task_manager.update(name, task.task_id)
示例9: update_certificate
def update_certificate(self, name, cert, key):
self.task_manager.ensure_ready(name)
lb = LoadBalancer.find(name)
if lb is None:
raise storage.InstanceNotFoundError()
self.storage.update_binding_certificate(name, cert, key)
self.consul_manager.set_certificate(name, cert, key)
示例10: run
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]
示例11: delete_block
def delete_block(self, name, block_name):
self.task_manager.ensure_ready(name)
block_name = block_name.strip()
lb = LoadBalancer.find(name)
if lb is None:
raise storage.InstanceNotFoundError()
self.consul_manager.remove_block(name, block_name)
示例12: add_block
def add_block(self, name, block_name, content):
self._ensure_ready(name)
block_name = block_name.strip()
lb = LoadBalancer.find(name)
if lb is None:
raise storage.InstanceNotFoundError()
self.consul_manager.write_block(name, block_name, content)
示例13: info
def info(self, name):
addr = self._get_address(name)
routes_data = []
binding_data = self.storage.find_binding(name)
if binding_data:
paths = binding_data.get('paths') or []
for path_data in paths:
routes_data.append("path = {}".format(path_data['path']))
dst = path_data.get('destination')
content = path_data.get('content')
if dst:
routes_data.append("destination = {}".format(dst))
if content:
routes_data.append("content = {}".format(content))
lb = LoadBalancer.find(name)
host_count = 0
if lb:
host_count = len(lb.hosts)
return [
{
"label": "Address",
"value": addr,
},
{
"label": "Instances",
"value": str(host_count),
},
{
"label": "Routes",
"value": "\n".join(routes_data),
},
]
示例14: generate_crt
def generate_crt(config, name, plugin, csr, key, domain):
lb = LoadBalancer.find(name, config)
if lb is None:
raise storage.InstanceNotFoundError()
strg = storage.MongoDBStorage(config)
consul_mngr = consul_manager.ConsulManager(config)
crt = None
plugin_class = ssl_plugins.get(plugin)
if not plugin_class:
raise Exception("Invalid plugin {}".format(plugin))
plugin_obj = plugin_class(domain, os.environ.get('RPAAS_PLUGIN_LE_EMAIL', '[email protected]'+domain),
name, consul_manager=consul_mngr)
# Upload csr and get an Id
plugin_id = plugin_obj.upload_csr(csr)
crt = plugin_obj.download_crt(id=str(plugin_id))
# Download the certificate and update nginx with it
if crt:
try:
js_crt = json.loads(crt)
cert = js_crt['crt']
cert = cert+js_crt['chain'] if 'chain' in js_crt else cert
key = js_crt['key'] if 'key' in js_crt else key
except:
cert = crt
consul_mngr.set_certificate(name, cert, key)
strg.store_le_certificate(name, domain)
else:
raise Exception('Could not download certificate')
示例15: update_certificate
def update_certificate(self, name, cert, key):
self._ensure_ready(name)
lb = LoadBalancer.find(name)
if lb is None:
raise storage.InstanceNotFoundError()
self.storage.update_binding_certificate(name, cert, key)
for host in lb.hosts:
self.nginx_manager.update_certificate(host.dns_name, cert, key)