本文整理汇总了Python中vnc_api.vnc_api.ServiceInstance类的典型用法代码示例。如果您正苦于以下问题:Python ServiceInstance类的具体用法?Python ServiceInstance怎么用?Python ServiceInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceInstance类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update_loadbalancer_instance_v2
def _update_loadbalancer_instance_v2(self, lb_id):
lb = LoadbalancerSM.get(lb_id)
if lb is None:
msg = ('Unable to retrieve loadbalancer %s' % lb_id)
self._svc_manager.logger.error(msg)
return
fq_name = lb.fq_name[:-1]
fq_name.append(lb_id)
si_refs = lb.service_instance
si_obj = ServiceInstanceSM.get(si_refs)
vip_vmi = VirtualMachineInterfaceSM.get(lb.virtual_machine_interface)
props = self._calculate_instance_properties(None, vip_vmi, lb_id)
if props is None:
try:
self._api.service_instance_delete(id=si_refs)
ServiceInstanceSM.delete(si_refs)
except RefsExistError as ex:
self._svc_manager.logger.error(str(ex))
return
if si_obj:
self._service_instance_update_props(si_obj, props)
else:
self._get_template()
si_obj = ServiceInstance(name=fq_name[-1], parent_type='project',
fq_name=fq_name, service_instance_properties=props)
si_obj.set_service_template(self.get_lb_template())
self._api.service_instance_create(si_obj)
ServiceInstanceSM.locate(si_obj.uuid)
if si_refs is None or si_refs != si_obj.uuid:
self._api.ref_update('loadbalancer', lb.uuid,
'service-instance', si_obj.uuid, None, 'ADD')
示例2: _update_loadbalancer_instance
def _update_loadbalancer_instance(self, pool_id, vip_id):
""" Update the loadbalancer service instance.
Prerequisites:
pool and vip must be known.
"""
try:
pool = self._api.loadbalancer_pool_read(id=pool_id)
except NoIdError:
msg = ('Unable to retrieve pool %s' % pool_id)
self._svc_manager.logger.log_error(msg)
return
try:
vip = self._api.virtual_ip_read(id=vip_id)
except NoIdError:
msg = ('Unable to retrieve virtual-ip %s' % vip_id)
self._svc_manager.logger.log_error(msg)
return
fq_name = pool.get_fq_name()[:-1]
fq_name.append(pool_id)
props = self._calculate_instance_properties(pool, vip)
if props is None:
try:
self._api.service_instance_delete(fq_name=fq_name)
except RefsExistError as ex:
self._svc_manager.logger.log_error(str(ex))
return
self._get_template()
try:
si_obj = self._api.service_instance_read(fq_name=fq_name)
update = self._service_instance_update_props(si_obj, props)
if update:
self._api.service_instance_update(si_obj)
except NoIdError:
proj_obj = self._api.project_read(fq_name=fq_name[:-1])
si_obj = ServiceInstance(name=fq_name[-1], parent_obj=proj_obj,
service_instance_properties=props)
si_obj.set_service_template(self._lb_template)
self._api.service_instance_create(si_obj)
si_refs = pool.get_service_instance_refs()
if si_refs is None or si_refs[0]['uuid'] != si_obj.uuid:
pool.set_service_instance(si_obj)
self._api.loadbalancer_pool_update(pool)
self.db.pool_driver_info_insert(pool_id, {'service_instance': si_obj.uuid})
示例3: test_vm_instance
def test_vm_instance(self, cassandra_init_mock):
logging.debug("init")
self._api_client = mock.Mock()
arguments = Arguments()
with patch.object(logging.handlers, 'RotatingFileHandler'):
self._svc_monitor = SvcMonitor(arguments)
self._svc_monitor.post_init(self._api_client, arguments)
self._svc_monitor.db._svc_si_cf = {}
self._svc_monitor.db._svc_vm_cf = mock.Mock()
self._svc_monitor._novaclient_get = mock.Mock()
identities = {
'service-template': 'default-domain:test:template1',
'service-instance': 'default-domain:test:service1'
}
tmpl_attr = ServiceTemplateType()
tmpl_attr.service_mode = 'in-network-nat'
tmpl_attr.service_type = 'firewall'
tmpl_attr.image_name = 'test-template'
tmpl_attr.service_virtualization_type = 'virtual-machine'
template = ServiceTemplate(service_template_properties=tmpl_attr)
template.uuid = 'aaa'
svc_attr = ServiceInstanceType()
svc_attr.left_virtual_network = 'default-project:demo:test'
svc_attr.right_virtual_network = 'default-project:admin:public'
svc_attr.scale_out = ServiceScaleOutType()
service = ServiceInstance('test-instance',
service_instance_properties=svc_attr)
service.uuid = 'bbb'
self._api_client.service_template_read.return_value = template
self._api_client.service_instance_read.return_value = service
with contextlib.nested(
patch.object(self._svc_monitor.vm_manager,
'_create_svc_vm'),
patch.object(self._svc_monitor.db,
'service_instance_insert')) as (create_svc_vm, svc_insert):
class Vm(object):
@property
def id(self):
return 'ccc'
create_svc_vm.return_value = Vm()
self._svc_monitor.\
_addmsg_service_instance_service_template(identities)
svc_insert.assert_called_with(
'default-domain:default-project:test-instance',
{'vm0-state': 'pending', 'vm0-preference': '0',
'vm0-uuid': 'ccc', 'vm0-vrouter': 'None',
'vm0-name': 'default-domain__default-project__bbb__1'})
示例4: _update_loadbalancer_instance
def _update_loadbalancer_instance(self, pool_id, vip_id):
""" Update the loadbalancer service instance.
Prerequisites:
pool and vip must be known.
"""
try:
pool = self._api.loadbalancer_pool_read(id=pool_id)
except NoIdError:
msg = ('Unable to retrieve pool %s' % pool_id)
raise n_exc.BadRequest(resource='pool', msg=msg)
try:
vip = self._api.virtual_ip_read(id=vip_id)
except NoIdError:
msg = ('Unable to retrieve virtual-ip %s' % vip_id)
raise n_exc.BadRequest(resource='vip', msg=msg)
fq_name = pool.get_fq_name()[:-1]
fq_name.append(pool_id)
props = self._calculate_instance_properties(pool, vip)
if props is None:
try:
self._api.service_instance_delete(fq_name=fq_name)
except RefsExistError as ex:
LOG.error(ex)
return
self._get_template()
try:
si_obj = self._api.service_instance_read(fq_name=fq_name)
update = self._service_instance_update_props(si_obj, props)
# TODO: update template if necessary
if update:
self._api.service_instance_update(si_obj)
except NoIdError:
proj_obj = self._api.project_read(fq_name=fq_name[:-1])
si_obj = ServiceInstance(name=fq_name[-1], parent_obj=proj_obj,
service_instance_properties=props)
si_obj.set_service_template(self._lb_template)
self._api.service_instance_create(si_obj)
si_refs = pool.get_service_instance_refs()
if si_refs is None or si_refs[0]['uuid'] != si_obj.uuid:
pool.set_service_instance(si_obj)
self._api.loadbalancer_pool_update(pool)
示例5: _update_loadbalancer_instance
def _update_loadbalancer_instance(self, pool_id, vip_id):
""" Update the loadbalancer service instance.
Prerequisites:
pool and vip must be known.
"""
pool = LoadbalancerPoolSM.get(pool_id)
if pool is None:
msg = ('Unable to retrieve pool %s' % pool_id)
self._svc_manager.logger.log_error(msg)
return
vip = VirtualIpSM.get(vip_id)
if vip is None:
msg = ('Unable to retrieve virtual ip %s' % vip_id)
self._svc_manager.logger.log_error(msg)
return
fq_name = pool.fq_name[:-1]
fq_name.append(pool_id)
si_refs = pool.service_instance
si_obj = ServiceInstanceSM.get(si_refs)
props = self._calculate_instance_properties(pool, vip)
if props is None:
try:
self._api.service_instance_delete(id=si_refs)
ServiceInstanceSM.delete(si_refs)
except RefsExistError as ex:
self._svc_manager.logger.log_error(str(ex))
return
if si_obj:
update_obj = self._service_instance_update_props(si_obj, props)
if update_obj:
self._api.service_instance_update(update_obj)
else:
si_obj = ServiceInstance(name=fq_name[-1], parent_type='project',
fq_name=fq_name, service_instance_properties=props)
si_obj.set_service_template(self.get_lb_template())
self._api.service_instance_create(si_obj)
ServiceInstanceSM.locate(si_obj.uuid)
if si_refs is None or si_refs != si_obj.uuid:
self._api.ref_update('loadbalancer-pool', pool.uuid,
'service_instance_refs', si_obj.uuid, None, 'ADD')
self.db.pool_driver_info_insert(pool_id,
{'service_instance': si_obj.uuid})
示例6: _service_instance_update_props
def _service_instance_update_props(self, si, nprops):
old_ifs = si.params.get('interface_list', [])
new_ifs = nprops.get_interface_list()
update = False
if len(new_ifs) != len(old_ifs):
update = True
else:
for index, new_if in enumerate(new_ifs):
if new_if.get_ip_address() != old_ifs[index]['ip_address']:
update = True
break
if new_if.get_virtual_network() != \
old_ifs[index]['virtual_network']:
update = True
break
if update:
si_obj = ServiceInstance(name=si.name, parent_type='project')
si_obj.uuid = si.uuid
si_obj.set_service_instance_properties(nprops)
self._api.service_instance_update(si_obj)
si.update()
示例7: set_haproxy_config
def set_haproxy_config(self, si_id, lb_version, lb_uuid, conf):
si = ServiceInstanceSM.get(si_id)
if not si:
return
for kv in si.kvps or []:
if kv['key'] == 'haproxy_config':
if kv['value'] == conf:
return
si_obj = ServiceInstance()
si_obj.uuid = si.uuid
si_obj.fq_name = si.fq_name
kvp = KeyValuePair('lb_version', lb_version)
si_obj.add_service_instance_bindings(kvp)
kvp = KeyValuePair('lb_uuid', lb_uuid)
si_obj.add_service_instance_bindings(kvp)
kvp = KeyValuePair('haproxy_config', conf)
si_obj.add_service_instance_bindings(kvp)
try:
self._api.service_instance_update(si_obj)
except NoIdError:
return
示例8: set_haproxy_config
def set_haproxy_config(self, si_id, lb_version, lb_uuid, conf, device_owner=None):
si = ServiceInstanceSM.get(si_id)
if not si:
return
for kv in si.kvps or []:
if kv['key'] == 'haproxy_config':
if kv['value'] == conf:
return
si_obj = ServiceInstance()
si_obj.uuid = si.uuid
si_obj.fq_name = si.fq_name
kvp = KeyValuePair('lb_version', lb_version)
si_obj.add_service_instance_bindings(kvp)
kvp = KeyValuePair('lb_uuid', lb_uuid)
si_obj.add_service_instance_bindings(kvp)
kvp = KeyValuePair('haproxy_config', conf)
si_obj.add_service_instance_bindings(kvp)
if device_owner and device_owner == 'K8S:LOADBALANCER':
kvp = KeyValuePair('orchestrator', 'kubernetes')
si_obj.add_service_instance_bindings(kvp)
try:
self._api.service_instance_update(si_obj)
except NoIdError:
return