本文整理汇总了Python中quantumclient.quantum.v2_0.find_resourceid_by_name_or_id函数的典型用法代码示例。如果您正苦于以下问题:Python find_resourceid_by_name_or_id函数的具体用法?Python find_resourceid_by_name_or_id怎么用?Python find_resourceid_by_name_or_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_resourceid_by_name_or_id函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: args2body
def args2body(self, parsed_args):
_network_id = quantumv20.find_resourceid_by_name_or_id(
self.get_client(), 'network', parsed_args.network_id)
body = {'port': {'admin_state_up': parsed_args.admin_state_down,
'network_id': _network_id, }, }
if parsed_args.mac_address:
body['port'].update({'mac_address': parsed_args.mac_address})
if parsed_args.device_id:
body['port'].update({'device_id': parsed_args.device_id})
if parsed_args.tenant_id:
body['port'].update({'tenant_id': parsed_args.tenant_id})
if parsed_args.name:
body['port'].update({'name': parsed_args.name})
ips = []
if parsed_args.fixed_ip:
for ip_spec in parsed_args.fixed_ip:
ip_dict = utils.str2dict(ip_spec)
if 'subnet_id' in ip_dict:
subnet_name_id = ip_dict['subnet_id']
_subnet_id = quantumv20.find_resourceid_by_name_or_id(
self.get_client(), 'subnet', subnet_name_id)
ip_dict['subnet_id'] = _subnet_id
ips.append(ip_dict)
if ips:
body['port'].update({'fixed_ips': ips})
return body
开发者ID:vbannai,项目名称:python-quantumclient,代码行数:26,代码来源:port.py
示例2: args2body
def args2body(self, parsed_args):
_security_group_id = quantumv20.find_resourceid_by_name_or_id(
self.get_client(), 'security_group', parsed_args.security_group_id)
body = {'security_group_rule': {
'security_group_id': _security_group_id,
'direction': parsed_args.direction,
'ethertype': parsed_args.ethertype}}
if parsed_args.protocol:
body['security_group_rule'].update(
{'protocol': parsed_args.protocol})
if parsed_args.port_range_min:
body['security_group_rule'].update(
{'port_range_min': parsed_args.port_range_min})
if parsed_args.port_range_max:
body['security_group_rule'].update(
{'port_range_max': parsed_args.port_range_max})
if parsed_args.source_ip_prefix:
body['security_group_rule'].update(
{'source_ip_prefix': parsed_args.source_ip_prefix})
if parsed_args.source_group_id:
_source_group_id = quantumv20.find_resourceid_by_name_or_id(
self.get_client(), 'security_group',
parsed_args.source_group_id)
body['security_group_rule'].update(
{'source_group_id': _source_group_id})
if parsed_args.tenant_id:
body['security_group_rule'].update(
{'tenant_id': parsed_args.tenant_id})
return body
开发者ID:StackOps,项目名称:python-quantumclient,代码行数:29,代码来源:securitygroup.py
示例3: run
def run(self, parsed_args):
self.log.debug("run(%s)" % parsed_args)
quantum_client = self.get_client()
quantum_client.format = parsed_args.request_format
# TODO(danwent): handle passing in port-id
_router_id = quantumv20.find_resourceid_by_name_or_id(quantum_client, self.resource, parsed_args.router_id)
_subnet_id = quantumv20.find_resourceid_by_name_or_id(quantum_client, "subnet", parsed_args.subnet_id)
quantum_client.remove_interface_router(_router_id, {"subnet_id": _subnet_id})
print >>self.app.stdout, (_("Removed interface from router %s") % parsed_args.router_id)
开发者ID:usc-isi,项目名称:python-quantumclient,代码行数:9,代码来源:router.py
示例4: run
def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
quantum_client = self.get_client()
quantum_client.format = parsed_args.request_format
#TODO(danwent): handle passing in port-id
_router_id = quantumv20.find_resourceid_by_name_or_id(
quantum_client, self.resource, parsed_args.router_id)
_subnet_id = quantumv20.find_resourceid_by_name_or_id(
quantum_client, 'subnet', parsed_args.subnet_id)
quantum_client.add_interface_router(_router_id,
{'subnet_id': _subnet_id})
#TODO(danwent): print port ID that is added
print >>self.app.stdout, (
_('Added interface to router %s') % parsed_args.router_id)
开发者ID:wallnerryan,项目名称:quantum_migrate,代码行数:14,代码来源:router.py
示例5: call_server
def call_server(self, quantum_client, search_opts, parsed_args):
_id = quantumV20.find_resourceid_by_name_or_id(quantum_client,
'router',
parsed_args.router)
search_opts['router'] = _id
data = quantum_client.list_l3_agent_hosting_routers(**search_opts)
return data
开发者ID:CiscoSystems,项目名称:python-quantumclient,代码行数:7,代码来源:agentscheduler.py
示例6: args2body
def args2body(self, parsed_args):
_network_id = quantumv20.find_resourceid_by_name_or_id(
self.get_client(), 'network', parsed_args.network_id)
body = {'subnet': {'cidr': parsed_args.cidr,
'network_id': _network_id,
'ip_version': parsed_args.ip_version, }, }
if parsed_args.gateway and parsed_args.no_gateway:
raise exceptions.CommandError("--gateway option and "
"--no-gateway option can "
"not be used same time")
if parsed_args.no_gateway:
body['subnet'].update({'gateway_ip': None})
if parsed_args.gateway:
body['subnet'].update({'gateway_ip': parsed_args.gateway})
if parsed_args.tenant_id:
body['subnet'].update({'tenant_id': parsed_args.tenant_id})
if parsed_args.name:
body['subnet'].update({'name': parsed_args.name})
ips = []
if parsed_args.allocation_pool:
for ip_spec in parsed_args.allocation_pool:
ips.append(utils.str2dict(ip_spec))
if ips:
body['subnet'].update({'allocation_pools': ips})
return body
开发者ID:kumarcv,项目名称:openstack-nf,代码行数:27,代码来源:subnet.py
示例7: args2body
def args2body(self, parsed_args):
_network_id = quantumv20.find_resourceid_by_name_or_id(
self.get_client(), 'network', parsed_args.network_id)
body = {'subnet': {'cidr': parsed_args.cidr,
'network_id': _network_id,
'ip_version': parsed_args.ip_version, }, }
if parsed_args.gateway and parsed_args.no_gateway:
raise exceptions.CommandError("--gateway option and "
"--no-gateway option can "
"not be used same time")
if parsed_args.no_gateway:
body['subnet'].update({'gateway_ip': None})
if parsed_args.gateway:
body['subnet'].update({'gateway_ip': parsed_args.gateway})
if parsed_args.tenant_id:
body['subnet'].update({'tenant_id': parsed_args.tenant_id})
if parsed_args.name:
body['subnet'].update({'name': parsed_args.name})
if parsed_args.disable_dhcp:
body['subnet'].update({'enable_dhcp': False})
if parsed_args.allocation_pools:
body['subnet']['allocation_pools'] = parsed_args.allocation_pools
if parsed_args.host_routes:
body['subnet']['host_routes'] = parsed_args.host_routes
if parsed_args.dns_nameservers:
body['subnet']['dns_nameservers'] = parsed_args.dns_nameservers
return body
开发者ID:StackOps,项目名称:python-quantumclient,代码行数:29,代码来源:subnet.py
示例8: get_data
def get_data(self, parsed_args):
quantum_client = self.get_client()
quantum_client.format = parsed_args.request_format
_id = quantumv20.find_resourceid_by_name_or_id(
quantum_client, 'router', parsed_args.id)
self.values_specs.append('--device_id=%s' % _id)
return super(ListRouterPort, self).get_data(parsed_args)
开发者ID:CiscoSystems,项目名称:python-quantumclient,代码行数:7,代码来源:port.py
示例9: run
def run(self, parsed_args):
quantum_client = self.get_client()
quantum_client.format = parsed_args.request_format
body = {'health_monitor': {'id': parsed_args.health_monitor_id}}
pool_id = quantumv20.find_resourceid_by_name_or_id(
quantum_client, 'pool', parsed_args.pool_id)
quantum_client.associate_health_monitor(pool_id, body)
print >>self.app.stdout, (_('Associated health monitor '
'%s') % parsed_args.health_monitor_id)
开发者ID:dodai-compute-v2,项目名称:python-quantumclient,代码行数:9,代码来源:healthmonitor.py
示例10: test_get_id_from_name_multiple
def test_get_id_from_name_multiple(self):
name = 'myname'
reses = {'networks': [{'id': str(uuid.uuid4())},
{'id': str(uuid.uuid4())}]}
resstr = self.client.serialize(reses)
self.mox.StubOutWithMock(self.client.httpclient, "request")
path = getattr(self.client, "networks_path")
self.client.httpclient.request(
test_cli20.end_url(path, "fields=id&name=" + name), 'GET',
body=None,
headers=mox.ContainsKeyValue('X-Auth-Token', test_cli20.TOKEN)
).AndReturn((test_cli20.MyResp(200), resstr))
self.mox.ReplayAll()
try:
quantumv20.find_resourceid_by_name_or_id(
self.client, 'network', name)
except exceptions.QuantumClientException as ex:
self.assertTrue('Multiple' in ex.message)
开发者ID:CiscoSystems,项目名称:python-quantumclient,代码行数:18,代码来源:test_name_or_id.py
示例11: remove_from_instance
def remove_from_instance(self, context, instance, security_group_name):
"""Remove the security group associated with the instance."""
quantum = quantumv2.get_client(context)
try:
security_group_id = quantumv20.find_resourceid_by_name_or_id(
quantum, 'security_group', security_group_name)
except q_exc.QuantumClientException as e:
exc_info = sys.exc_info()
if e.status_code == 404:
msg = ("Security group %s is not found for project %s" %
(security_group_name, context.project_id))
self.raise_not_found(msg)
else:
LOG.exception(_("Quantum Error:"))
raise exc_info[0], exc_info[1], exc_info[2]
params = {'device_id': instance['uuid']}
try:
ports = quantum.list_ports(**params).get('ports')
except q_exc.QuantumClientException:
with excutils.save_and_reraise_exception():
LOG.exception(_("Quantum Error:"))
if not ports:
msg = ("instance_id %s could not be found as device id on"
" any ports" % instance['uuid'])
self.raise_not_found(msg)
found_security_group = False
for port in ports:
try:
port.get('security_groups', []).remove(security_group_id)
except ValueError:
# When removing a security group from an instance the security
# group should be on both ports since it was added this way if
# done through the nova api. In case it is not a 404 is only
# raised if the security group is not found on any of the
# ports on the instance.
continue
updated_port = {'security_groups': port['security_groups']}
try:
LOG.info(_("Adding security group %(security_group_id)s to "
"port %(port_id)s"),
{'security_group_id': security_group_id,
'port_id': port['id']})
quantum.update_port(port['id'], {'port': updated_port})
found_security_group = True
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(_("Quantum Error:"))
if not found_security_group:
msg = (_("Security group %(security_group_name)s not assocaited "
"with the instance %(instance)s"),
{'security_group_name': security_group_name,
'instance': instance['uuid']})
self.raise_not_found(msg)
开发者ID:DavidYan,项目名称:nova,代码行数:56,代码来源:quantum_driver.py
示例12: run
def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
quantum_client = self.get_client()
quantum_client.format = parsed_args.request_format
_net_id = quantumV20.find_resourceid_by_name_or_id(
quantum_client, 'network', parsed_args.network)
quantum_client.remove_network_from_dhcp_agent(
parsed_args.dhcp_agent, _net_id)
print >>self.app.stdout, (
_('Removed network %s to DHCP agent') % parsed_args.network)
开发者ID:CiscoSystems,项目名称:python-quantumclient,代码行数:10,代码来源:agentscheduler.py
示例13: args2body
def args2body(self, parsed_args):
_pool_id = quantumv20.find_resourceid_by_name_or_id(
self.get_client(), 'pool', parsed_args.pool_id)
body = {
self.resource: {
'pool_id': _pool_id,
'admin_state_up': parsed_args.admin_state_down,
},
}
quantumv20.update_dict(parsed_args, body[self.resource],
['address', 'port', 'weight', 'tenant_id'])
return body
开发者ID:StackOps,项目名称:python-quantumclient,代码行数:12,代码来源:member.py
示例14: args2body
def args2body(self, parsed_args):
_network_id = quantumv20.find_resourceid_by_name_or_id(
self.get_client(), 'network', parsed_args.floating_network_id)
body = {self.resource: {'floating_network_id': _network_id}}
if parsed_args.port_id:
body[self.resource].update({'port_id': parsed_args.port_id})
if parsed_args.tenant_id:
body[self.resource].update({'tenant_id': parsed_args.tenant_id})
if parsed_args.fixed_ip_address:
body[self.resource].update({'fixed_ip_address':
parsed_args.fixed_ip_address})
return body
开发者ID:kumarcv,项目名称:openstack-nf,代码行数:12,代码来源:floatingip.py
示例15: remove_from_instance
def remove_from_instance(self, context, instance, security_group_name):
"""Remove the security group associated with the instance."""
quantum = quantumv2.get_client(context)
try:
security_group_id = quantumv20.find_resourceid_by_name_or_id(quantum, "security_group", security_group_name)
except q_exc.QuantumClientException as e:
if e.status_code == 404:
msg = "Security group %s is not found for project %s" % (security_group_name, context.project_id)
self.raise_not_found(msg)
else:
LOG.exception(_("Quantum Error:"))
raise e
params = {"device_id": instance["uuid"]}
try:
ports = quantum.list_ports(**params).get("ports")
except q_exc.QuantumClientException as e:
LOG.exception(_("Quantum Error:"))
raise e
if not ports:
msg = "instance_id %s could not be found as device id on" " any ports" % instance["uuid"]
self.raise_not_found(msg)
found_security_group = False
for port in ports:
try:
port.get("security_groups", []).remove(security_group_id)
except ValueError:
# When removing a security group from an instance the security
# group should be on both ports since it was added this way if
# done through the nova api. In case it is not a 404 is only
# raised if the security group is not found on any of the
# ports on the instance.
continue
updated_port = {"security_groups": port["security_groups"]}
try:
LOG.info(
_("Adding security group %(security_group_id)s to " "port %(port_id)s"),
{"security_group_id": security_group_id, "port_id": port["id"]},
)
quantum.update_port(port["id"], {"port": updated_port})
found_security_group = True
except Exception:
LOG.exception(_("Quantum Error:"))
raise e
if not found_security_group:
msg = (
_("Security group %(security_group_name)s not assocaited " "with the instance %(instance)s"),
{"security_group_name": security_group_name, "instance": instance["uuid"]},
)
self.raise_not_found(msg)
开发者ID:mygoda,项目名称:openstack,代码行数:52,代码来源:quantum_driver.py
示例16: args2body
def args2body(self, parsed_args):
_subnet_id = quantumv20.find_resourceid_by_name_or_id(
self.get_client(), 'subnet', parsed_args.subnet_id)
body = {
self.resource: {
'admin_state_up': parsed_args.admin_state,
'subnet_id': _subnet_id,
},
}
quantumv20.update_dict(parsed_args, body[self.resource],
['description', 'lb_method', 'name',
'protocol', 'tenant_id'])
return body
开发者ID:dodai-compute-v2,项目名称:python-quantumclient,代码行数:13,代码来源:pool.py
示例17: args2body
def args2body(self, parsed_args):
_pool_id = quantumv20.find_resourceid_by_name_or_id(
self.get_client(), 'pool', parsed_args.pool_id)
body = {
self.resource: {
'pool_id': _pool_id,
'admin_state_up': parsed_args.admin_state_down,
},
}
quantumv20.update_dict(parsed_args, body[self.resource],
['address', 'connection_limit', 'description',
'name', 'port', 'protocol', 'subnet_id',
'tenant_id'])
return body
开发者ID:StackOps,项目名称:python-quantumclient,代码行数:14,代码来源:vip.py
示例18: get
def get(self, context, name=None, id=None, map_exception=False):
quantum = quantumv2.get_client(context)
try:
if not id and name:
id = quantumv20.find_resourceid_by_name_or_id(quantum, "security_group", name)
group = quantum.show_security_group(id).get("security_group")
except q_exc.QuantumClientException as e:
if e.status_code == 404:
LOG.debug(_("Quantum security group %s not found"), name)
self.raise_not_found(e.message)
else:
LOG.error(_("Quantum Error: %s"), e)
raise e
return self._convert_to_nova_security_group_format(group)
开发者ID:mygoda,项目名称:openstack,代码行数:15,代码来源:quantum_driver.py
示例19: run
def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
quantum_client = self.get_client()
quantum_client.format = parsed_args.request_format
if '=' in parsed_args.interface:
resource, value = parsed_args.interface.split('=', 1)
if resource not in ['subnet', 'port']:
exceptions.CommandError('You must specify either subnet or '
'port for INTERFACE parameter.')
else:
resource = 'subnet'
value = parsed_args.interface
_router_id = quantumv20.find_resourceid_by_name_or_id(
quantum_client, self.resource, parsed_args.router_id)
_interface_id = quantumv20.find_resourceid_by_name_or_id(
quantum_client, resource, value)
body = {'%s_id' % resource: _interface_id}
portinfo = self.call_api(quantum_client, _router_id, body)
print >>self.app.stdout, self.success_message(parsed_args.router_id,
portinfo)
开发者ID:dodai-compute-v2,项目名称:python-quantumclient,代码行数:24,代码来源:router.py
示例20: test_get_id_from_id
def test_get_id_from_id(self):
_id = str(uuid.uuid4())
reses = {'networks': [{'id': _id, }, ], }
resstr = self.client.serialize(reses)
self.mox.StubOutWithMock(self.client.httpclient, "request")
path = getattr(self.client, "networks_path")
self.client.httpclient.request(
test_cli20.end_url(path, "fields=id&id=" + _id), 'GET',
body=None,
headers=mox.ContainsKeyValue('X-Auth-Token', test_cli20.TOKEN)
).AndReturn((test_cli20.MyResp(200), resstr))
self.mox.ReplayAll()
returned_id = quantumv20.find_resourceid_by_name_or_id(
self.client, 'network', _id)
self.assertEqual(_id, returned_id)
开发者ID:CiscoSystems,项目名称:python-quantumclient,代码行数:15,代码来源:test_name_or_id.py
注:本文中的quantumclient.quantum.v2_0.find_resourceid_by_name_or_id函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论