本文整理汇总了Python中vnc_api.vnc_api.VncApi.physical_router_read方法的典型用法代码示例。如果您正苦于以下问题:Python VncApi.physical_router_read方法的具体用法?Python VncApi.physical_router_read怎么用?Python VncApi.physical_router_read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vnc_api.vnc_api.VncApi
的用法示例。
在下文中一共展示了VncApi.physical_router_read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_ztp_dhcp_config
# 需要导入模块: from vnc_api.vnc_api import VncApi [as 别名]
# 或者: from vnc_api.vnc_api.VncApi import physical_router_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 physical_router_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: SanityBase
# 需要导入模块: from vnc_api.vnc_api import VncApi [as 别名]
# 或者: from vnc_api.vnc_api.VncApi import physical_router_read [as 别名]
#.........这里部分代码省略.........
fab_namespaces = self._api.fabric_namespaces_list(
parent_id=fab.uuid)
for namespace in fab_namespaces.get('fabric-namespaces') or []:
self._logger.debug(
"Delete namespace: %s", namespace.get('fq_name'))
self._api.fabric_namespace_delete(namespace.get('fq_name'))
# delete fabric
self._logger.debug("Delete fabric: %s", fab_fqname)
self._api.fabric_delete(fab_fqname)
# delete all prouters in this fabric
for prouter in fab.get_physical_router_back_refs() or []:
self._delete_prouter(prouter.get('uuid'))
except NoIdError:
self._logger.warn('Fabric "%s" not found', fab_name)
# end cleanup_fabric
def cleanup_image(self, img_name,):
# image cleanup
self._logger.info("Clean up image and prouter from db")
try:
img_fqname = ['default-global-system-config', img_name]
img = self._api.device_image_read(fq_name=img_fqname)
self._logger.debug(
"Delete Image: %s", img_fqname)
self._api.device_image_delete(img_fqname)
except NoIdError:
self._logger.warn('Image "%s" not found', img_name)
def _delete_prouter(self, uuid):
prouter = self._api.physical_router_read(id=uuid)
# delete all physical and logical interfaces
ifds = self._api.physical_interfaces_list(parent_id=uuid)
for ifd in ifds.get('physical-interfaces') or []:
# delete all child logical interfaces
ifls = self._api.logical_interfaces_list(parent_id=ifd.get('uuid'))
for ifl in ifls.get('logical-interfaces') or []:
self._logger.debug(
"Delete logical interface: %s", ifl.get('fq_name'))
self._api.logical_interface_delete(ifl.get('fq_name'))
# delete the physical interface
self._logger.debug(
"Delete physical interface: %s", ifd.get('fq_name'))
self._api.physical_interface_delete(ifd.get('fq_name'))
# delete the prouter
self._logger.debug(
"Delete physical router: %s", prouter.get_fq_name())
self._api.physical_router_delete(prouter.get_fq_name())
# delete corresponding bgp routers
for bgp_router_ref in prouter.get_bgp_router_refs() or []:
self._logger.debug(
"Delete bgp router: %s", bgp_router_ref.get('to'))
self._api.bgp_router_delete(bgp_router_ref.get('to'))
# end _delete_prouter
@staticmethod
def _get_job_status_query_payload(job_execution_id, status):
return {
'start_time': 'now-5m',
示例4: DeviceInfo
# 需要导入模块: from vnc_api.vnc_api import VncApi [as 别名]
# 或者: from vnc_api.vnc_api.VncApi import physical_router_read [as 别名]
#.........这里部分代码省略.........
break
return hostname
def device_info_processing(self, host, oid_mapped):
valid_creds = False
return_code = True
if not oid_mapped.get('family') or not oid_mapped.get('vendor'):
self.logger.info("Could not retrieve family/vendor info for "
"the host: {}, not creating PR "
"object".format(host))
self.logger.info("vendor: {}, family: {}".format(
oid_mapped.get('vendor'), oid_mapped.get('family')))
oid_mapped = {}
if oid_mapped.get('host'):
valid_creds = self._detailed_cred_check(host, oid_mapped,
self.credentials)
if not valid_creds and oid_mapped:
self.logger.info("No credentials matched for host: {}, nothing "
"to update in DB".format(host))
oid_mapped = {}
if oid_mapped:
if self.serial_num_flag:
if oid_mapped.get('serial-number') not in \
self.all_serial_num:
self.logger.info(
"Serial number {} for host {} not present "
"in fabric_namespace, nothing to update "
"in DB".format(
oid_mapped.get('serial-number'), host))
return
# use the user input hostname is there. If its none check
# for hostname derived from the device system info. If
# that is also missing then set the hostname to the serial num
user_input_hostname = None
if self.job_ctx.get('job_input').get('device_to_ztp') is not None:
user_input_hostname = \
self.get_hostname_from_job_input(oid_mapped.get(
'serial-number'))
if user_input_hostname is not None:
oid_mapped['hostname'] = user_input_hostname
elif oid_mapped.get('hostname') is None:
oid_mapped['hostname'] = oid_mapped.get('serial-number')
fq_name = [
'default-global-system-config',
oid_mapped.get('hostname')]
return_code, pr_uuid = self._pr_object_create_update(
oid_mapped, fq_name, False)
if return_code == REF_EXISTS_ERROR:
physicalrouter = self.vncapi.physical_router_read(
fq_name=fq_name)
phy_router = self.vncapi.obj_to_dict(physicalrouter)
if (phy_router.get('physical_router_management_ip')
== oid_mapped.get('host')):
self.logger.info(
"Device with same mgmt ip already exists {}".format(
phy_router.get('physical_router_management_ip')))
return_code, pr_uuid = self._pr_object_create_update(
oid_mapped, fq_name, True)
else:
fq_name = [
'default-global-system-config',
oid_mapped.get('hostname') +
'_' +
oid_mapped.get('host')]
return_code, pr_uuid = self._pr_object_create_update(
oid_mapped, fq_name, False)
if return_code == REF_EXISTS_ERROR:
self.logger.debug("Object already exists")
if return_code is True:
self.vncapi.ref_update(
"physical_router", pr_uuid, "fabric", self.fabric_uuid,
None, "ADD")
self.logger.info(
"Fabric updated with physical router info for "
"host: {}".format(host))
temp = {}
temp['device_management_ip'] = oid_mapped.get('host')
temp['device_fqname'] = fq_name
temp['device_username'] = oid_mapped.get('username')
temp['device_password'] = oid_mapped.get('password')
temp['device_family'] = oid_mapped.get('family')
temp['device_vendor'] = oid_mapped.get('vendor')
temp['device_product'] = oid_mapped.get('product')
temp['device_serial_number'] = oid_mapped.get('serial-number')
DeviceInfo.output.update({pr_uuid: temp})
def discovery_percentage_write(self):
if self.module.results.get('percentage_completed'):
exec_id = self.job_ctx.get('job_execution_id')
pb_id = self.job_ctx.get('unique_pb_id')
self._job_file_write.write_to_file(
exec_id, pb_id, JobFileWrite.JOB_PROGRESS,
str(self.module.results.get('percentage_completed'))
)