本文整理汇总了Python中vnc_api.vnc_api.VncApi.virtual_network_read方法的典型用法代码示例。如果您正苦于以下问题:Python VncApi.virtual_network_read方法的具体用法?Python VncApi.virtual_network_read怎么用?Python VncApi.virtual_network_read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vnc_api.vnc_api.VncApi
的用法示例。
在下文中一共展示了VncApi.virtual_network_read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_ztp_dhcp_config
# 需要导入模块: from vnc_api.vnc_api import VncApi [as 别名]
# 或者: from vnc_api.vnc_api.VncApi import virtual_network_read [as 别名]
def get_ztp_dhcp_config(cls, job_ctx, fabric_uuid):
dhcp_config = {}
try:
vncapi = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
auth_token=job_ctx.get('auth_token'))
fabric = vncapi.fabric_read(id=fabric_uuid)
fabric_dict = vncapi.obj_to_dict(fabric)
# From here we get the 'management' type virtual network
vn_uuid = None
virtual_network_refs = fabric_dict.get('virtual_network_refs') or []
for virtual_net_ref in virtual_network_refs:
if 'management' in virtual_net_ref['attr']['network_type']:
vn_uuid = virtual_net_ref['uuid']
break
if vn_uuid is None:
raise NoIdError("Cannot find mgmt virtual network on fabric")
virtual_net = vncapi.virtual_network_read(id=vn_uuid)
virtual_net_dict = vncapi.obj_to_dict(virtual_net)
# Get the IPAM attached to the virtual network
ipam_refs = virtual_net_dict.get('network_ipam_refs')
if ipam_refs:
ipam_ref = ipam_refs[0]
ipam = vncapi.network_ipam_read(id=ipam_ref['uuid'])
ipam_dict = vncapi.obj_to_dict(ipam)
ipam_subnets = ipam_dict.get('ipam_subnets')
if ipam_subnets:
dhcp_config['ipam_subnets'] = ipam_subnets.get('subnets')
# Get static ip configuration for physical routers
pr_refs = fabric.get_physical_router_back_refs()
pr_uuids = [ref['uuid'] for ref in pr_refs]
static_ips = {}
for pr_uuid in pr_uuids:
pr = vncapi.physical_router_read(id=pr_uuid)
pr_dict = vncapi.obj_to_dict(pr)
mac = pr_dict.get('physical_router_management_mac')
ip = pr_dict.get('physical_router_management_ip')
if mac and ip:
static_ips[ip] = mac
if static_ips:
dhcp_config['static_ips'] = static_ips
except Exception as ex:
logging.error("Error getting ZTP DHCP configuration: {}".format(ex))
return dhcp_config
示例2: get_pr_subnet
# 需要导入模块: from vnc_api.vnc_api import VncApi [as 别名]
# 或者: from vnc_api.vnc_api.VncApi import virtual_network_read [as 别名]
def get_pr_subnet(cls, job_ctx, fabric_uuid, device_fq_name):
api = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
auth_token=job_ctx.get('auth_token'))
fabric = api.fabric_read(id=fabric_uuid)
fabric_dict = api.obj_to_dict(fabric)
vn_uuid = None
virtual_network_refs = fabric_dict.get('virtual_network_refs') or []
for virtual_net_ref in virtual_network_refs:
if 'management' in virtual_net_ref['attr']['network_type']:
vn_uuid = virtual_net_ref['uuid']
break
if vn_uuid is None:
raise NoIdError("Cannot find mgmt virtual network on fabric")
virtual_net = api.virtual_network_read(id=vn_uuid)
virtual_net_dict = api.obj_to_dict(virtual_net)
subnets = None
ipam_refs = virtual_net_dict.get('network_ipam_refs')
if ipam_refs:
ipam_ref = ipam_refs[0]
ipam = api.network_ipam_read(id=ipam_ref['uuid'])
ipam_dict = api.obj_to_dict(ipam)
ipam_subnets = ipam_dict.get('ipam_subnets')
if ipam_subnets:
subnets = ipam_subnets.get('subnets')
gateway = None
cidr = None
if subnets:
pr = api.physical_router_read(fq_name=device_fq_name)
pr_dict = api.obj_to_dict(pr)
ip = pr_dict.get('physical_router_management_ip')
ip_addr = IPAddress(ip)
for subnet in subnets:
inner_subnet = subnet.get('subnet')
cidr = inner_subnet.get('ip_prefix') + '/' + str(inner_subnet.get('ip_prefix_len'))
if ip_addr in IPNetwork(cidr) and subnet.get('default_gateway'):
gateway = subnet.get('default_gateway')
break
if cidr and gateway:
return { 'cidr': cidr, 'gateway': gateway }
raise Error("Cannot find cidr and gateway for device: %s" % str(device_fq_name))
示例3: get_ztp_config
# 需要导入模块: from vnc_api.vnc_api import VncApi [as 别名]
# 或者: from vnc_api.vnc_api.VncApi import virtual_network_read [as 别名]
def get_ztp_config(cls, job_ctx, fabric_uuid):
ztp_config = {}
try:
vncapi = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
auth_token=job_ctx.get('auth_token'))
fabric = vncapi.fabric_read(id=fabric_uuid)
fabric_dict = vncapi.obj_to_dict(fabric)
fabric_creds = fabric_dict.get('fabric_credentials')
if fabric_creds:
device_creds = fabric_creds.get('device_credential')
if device_creds:
dev_cred = device_creds[0]
ztp_config['password'] = dev_cred['credential']['password']
# From here we get the 'management' type virtual network
vn_uuid = None
virtual_network_refs = fabric_dict.get('virtual_network_refs') or []
for virtual_net_ref in virtual_network_refs:
if "management" in virtual_net_ref['attr']['network_type']:
vn_uuid = virtual_net_ref['uuid']
break
if vn_uuid is None:
raise NoIdError("Cannot find mgmt virtual network on fabric")
virtual_net = vncapi.virtual_network_read(id=vn_uuid)
virtual_net_dict = vncapi.obj_to_dict(virtual_net)
# Get the IPAM attached to the virtual network
ipam_refs = virtual_net_dict.get('network_ipam_refs')
if ipam_refs:
ipam_ref = ipam_refs[0]
ipam = vncapi.network_ipam_read(id=ipam_ref['uuid'])
ipam_dict = vncapi.obj_to_dict(ipam)
ipam_subnets = ipam_dict.get('ipam_subnets')
if ipam_subnets:
ztp_config['ipam_subnets'] = ipam_subnets.get('subnets')
except NoIdError:
logging.error("Cannot find mgmt virtual network")
except Exception as ex:
logging.error("Error getting ZTP configuration: {}".format(ex))
return ztp_config