当前位置: 首页>>代码示例>>Python>>正文


Python VncApi.fabric_namespaces_list方法代码示例

本文整理汇总了Python中vnc_api.vnc_api.VncApi.fabric_namespaces_list方法的典型用法代码示例。如果您正苦于以下问题:Python VncApi.fabric_namespaces_list方法的具体用法?Python VncApi.fabric_namespaces_list怎么用?Python VncApi.fabric_namespaces_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vnc_api.vnc_api.VncApi的用法示例。


在下文中一共展示了VncApi.fabric_namespaces_list方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DeviceInfo

# 需要导入模块: from vnc_api.vnc_api import VncApi [as 别名]
# 或者: from vnc_api.vnc_api.VncApi import fabric_namespaces_list [as 别名]
class DeviceInfo(object):
    output = {}

    def __init__(self, module):
        self.module = module
        self.logger = module.logger
        self.job_ctx = module.job_ctx
        self.fabric_uuid = module.params['fabric_uuid']
        self.total_retry_timeout = float(module.params['total_retry_timeout'])
        self._job_file_write = JobFileWrite(self.logger)

    def initial_processing(self, concurrent):
        self.serial_num_flag = False
        self.all_serial_num = []
        serial_num = []
        self.per_greenlet_percentage = None

        self.job_ctx['current_task_index'] = 2

        try:
            total_percent = self.job_ctx.get('playbook_job_percentage')
            if total_percent:
                total_percent = float(total_percent)

            # Calculate the total percentage of this entire greenlet based task
            # This will be equal to the percentage alloted to this task in the
            # weightage array off the total job percentage. For example:
            # if the task weightage array is [10, 85, 5] and total job %
            # is 95. Then the 2nd task's effective total percentage is 85% of
            # 95%
            total_task_percentage = self.module.calculate_job_percentage(
                self.job_ctx.get('total_task_count'),
                task_seq_number=self.job_ctx.get('current_task_index'),
                total_percent=total_percent,
                task_weightage_array=self.job_ctx.get(
                    'task_weightage_array'))[0]

            # Based on the number of greenlets spawned (i.e num of sub tasks)
            # split the total_task_percentage equally amongst the greenlets.
            self.logger.info("Number of greenlets: {} and total_percent: "
                             "{}".format(concurrent, total_task_percentage))
            self.per_greenlet_percentage = \
                self.module.calculate_job_percentage(
                    concurrent, total_percent=total_task_percentage)[0]
            self.logger.info("Per greenlet percent: "
                             "{}".format(self.per_greenlet_percentage))

            self.vncapi = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
                                 auth_token=self.job_ctx.get('auth_token'))
        except Exception as ex:
            self.logger.info("Percentage calculation failed with error "
                             "{}".format(str(ex)))

        try:
            self.vncapi = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
                                 auth_token=self.job_ctx.get('auth_token'))
        except Exception as ex:
            self.module.results['failed'] = True
            self.module.results['msg'] = "Failed to connect to API server " \
                "due to error: %s"\
                % str(ex)
            self.module.exit_json(**self.module.results)

        # get credentials and serial number if greenfield
        if self.total_retry_timeout:
            # get device credentials
            fabric = self.vncapi.fabric_read(id=self.fabric_uuid)
            fabric_object = self.vncapi.obj_to_dict(fabric)
            self.credentials = fabric_object.get('fabric_credentials').get(
                'device_credential')

            # get serial numbers
            fabric_namespace_obj_list = self.vncapi.fabric_namespaces_list(
                parent_id=self.fabric_uuid, detail=True)
            fabric_namespace_list = self.vncapi.obj_to_dict(
                fabric_namespace_obj_list)

            for namespace in fabric_namespace_list:
                if namespace.get('fabric_namespace_type') == "SERIAL_NUM":
                    self.serial_num_flag = True
                    serial_num.append(namespace.get(
                        'fabric_namespace_value').get('serial_num'))

            if len(serial_num) > 1:
                for outer_list in serial_num:
                    for sn in outer_list:
                        self.all_serial_num.append(sn)

        else:
            self.credentials = self.module.params['credentials']

        for cred in self.credentials:
            if cred.get('credential', {}).get('password'):
                cred['credential']['password'] = JobVncApi.decrypt_password(
                    encrypted_password=cred.get('credential', {}).get('password'),
                    admin_password=self.job_ctx.get('vnc_api_init_params').get(
                        'admin_password'))

    def ping_sweep(self, host):
        try:
#.........这里部分代码省略.........
开发者ID:Juniper,项目名称:contrail-controller,代码行数:103,代码来源:device_info.py

示例2: SanityBase

# 需要导入模块: from vnc_api.vnc_api import VncApi [as 别名]
# 或者: from vnc_api.vnc_api.VncApi import fabric_namespaces_list [as 别名]

#.........这里部分代码省略.........
            self._logger.info('Creating image: %s', img_name)
            img_fqname = ['default-global-system-config', img_name]
            image = DeviceImage(
                name=img_name,
                fq_name=img_fqname,
                parent_type='global-system-config',
                device_image_file_uri=img_uri,
                device_image_os_version=img_version,
                device_image_device_family=img_family,
                device_image_vendor_name=img_vendor
            )
            img_uuid = self._api.device_image_create(image)
            image = self._api.device_image_read(id=img_uuid)

        except RefsExistError:
            self._logger.warn("Image '%s' already exists", img_name)
            image = self._api.device_image_read(fq_name=img_fqname)

        self._logger.debug(
            "Image created:\n%s",
            pprint.pformat(self._api.obj_to_dict(image), indent=4))
        return image

    # end create_image_and_device

    def cleanup_fabric(self, fab_name):
        """delete fabric including all prouters in the fabric"""
        try:
            self._logger.info('Deleting fabric "%s" ...', fab_name)
            fab_fqname = ['default-global-system-config', fab_name]
            fab = self._api.fabric_read(fq_name=fab_fqname)

            # delete all namespaces in this fabric
            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):
开发者ID:Juniper,项目名称:contrail-controller,代码行数:70,代码来源:sanity_base.py

示例3: import

# 需要导入模块: from vnc_api.vnc_api import VncApi [as 别名]
# 或者: from vnc_api.vnc_api.VncApi import fabric_namespaces_list [as 别名]
from vnc_api.vnc_api import VncApi
from vnc_api.gen.resource_client import (
    Fabric,
    FabricNamespace,
    VirtualNetwork,
    NetworkIpam
)

    
vnc_api = VncApi()

#import pdb; pdb.set_trace()
namespaces = vnc_api.fabric_namespaces_list(detail=True)
for ns in namespaces:
    vnc_api.fabric_namespace_delete(id=ns.uuid)

fabs = vnc_api.fabrics_list(detail=True)
for fab in fabs:
    # remove fabric->vn refs
    fab.set_virtual_network_list([])
    vnc_api.fabric_update(fab)
    
    # remove fabric->node_profile refs     
    fab.set_node_profile_list([])
    vnc_api.fabric_update(fab)
   
    # remove fabric
    vnc_api.fabric_delete(id=fab.uuid)

role_configs = vnc_api.role_configs_list(detail=True)
for role_config in role_configs:
开发者ID:Juniper,项目名称:contrail-controller,代码行数:33,代码来源:cleanup.py


注:本文中的vnc_api.vnc_api.VncApi.fabric_namespaces_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。