本文整理汇总了Python中hm.model.load_balancer.LoadBalancer.find方法的典型用法代码示例。如果您正苦于以下问题:Python LoadBalancer.find方法的具体用法?Python LoadBalancer.find怎么用?Python LoadBalancer.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hm.model.load_balancer.LoadBalancer
的用法示例。
在下文中一共展示了LoadBalancer.find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_destroy
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [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 find [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: delete_block
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
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)
示例4: add_block
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
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)
示例5: new_instance
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
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)
示例6: activate_ssl
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
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: info
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
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),
},
]
示例8: generate_crt
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
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')
示例9: update_certificate
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
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: activate_ssl
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
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 ''
示例11: update_certificate
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
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)
示例12: swap
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
def swap(self, src_instance, dst_instance):
self.task_manager.ensure_ready(src_instance)
self.task_manager.ensure_ready(dst_instance)
for instance in [src_instance, dst_instance]:
lb = LoadBalancer.find(instance)
if lb is None:
raise storage.InstanceNotFoundError(instance)
self.consul_manager.swap_instances(src_instance, dst_instance)
示例13: add_route
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
def add_route(self, name, path, destination, content):
self._ensure_ready(name)
path = path.strip()
lb = LoadBalancer.find(name)
if lb is None:
raise storage.InstanceNotFoundError()
self.storage.replace_binding_path(name, path, destination, content)
for host in lb.hosts:
self.nginx_manager.update_binding(host.dns_name, path, destination, content)
示例14: add_route
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
def add_route(self, name, path, destination, content):
self.task_manager.ensure_ready(name)
path = path.strip()
lb = LoadBalancer.find(name)
if lb is None:
raise storage.InstanceNotFoundError()
self.storage.replace_binding_path(name, path, destination, content)
self.consul_manager.write_location(name, path, destination=destination,
content=content)
示例15: run
# 需要导入模块: from hm.model.load_balancer import LoadBalancer [as 别名]
# 或者: from hm.model.load_balancer.LoadBalancer import find [as 别名]
def run(self, config, name):
self.init_config(config)
lb = LoadBalancer.find(name, self.config)
if lb is None:
raise storage.InstanceNotFoundError()
for host in lb.hosts:
host.destroy()
lb.destroy()
self.hc.destroy(name)