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


Python Org.list_catalog_items方法代码示例

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


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

示例1: upload_media

# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import list_catalog_items [as 别名]
    def upload_media(cls):
        """Uploads the test media to the test catalog.

        If media already exists in the catalog then skips uploading it.

        :raises: Exception: if the class variable _org_href is not populated.
        """
        cls._basic_check()
        if cls._org_href is None:
            raise Exception('Org ' + cls._config['vcd']['default_org_name'] +
                            ' doesn\'t exist.')

        try:
            catalog_author_client = Environment.get_client_in_default_org(
                CommonRoles.CATALOG_AUTHOR)
            org = Org(catalog_author_client, href=cls._org_href)

            catalog_name = cls._config['vcd']['default_catalog_name']
            catalog_items = org.list_catalog_items(catalog_name)
            media_name = cls._config['vcd']['default_media_name']
            for item in catalog_items:
                if item.get('name').lower() == media_name.lower():
                    cls._logger.debug('Reusing existing media ' +
                                      media_name)
                    cls._media_resource = org.get_catalog_item(catalog_name,media_name)
                    return

            cls._logger.debug('Uploading media ' + media_name +
                              ' to catalog ' + catalog_name + '.')
            org.upload_media(catalog_name=catalog_name, file_name=media_name)

            # wait for the template import to finish in vCD.
            catalog_item = org.get_catalog_item(
                name=catalog_name, item_name=media_name)
            media = catalog_author_client.get_resource(
                catalog_item.Entity.get('href'))
            catalog_author_client.get_task_monitor().wait_for_success(
                task=media.Tasks.Task[0])

            cls._media_resource = org.get_catalog_item(catalog_name,media_name)

        finally:
            catalog_author_client.logout()
开发者ID:vmware,项目名称:pyvcloud,代码行数:45,代码来源:environment.py

示例2: Catalog

# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import list_catalog_items [as 别名]

#.........这里部分代码省略.........

    def manage_operations(self):
        operation = self.params.get('operation')
        if operation == "shared":
            return self.shared()

        if operation == "read":
            return self.read()

        if operation == "list_items":
            return self.list_items()

    def create(self):
        catalog_name = self.params.get('catalog_name')
        description = self.params.get('description')
        response = dict()
        response['changed'] = False

        try:
            self.org.get_catalog(name=catalog_name)
        except EntityNotFoundException:
            self.org.create_catalog(name=catalog_name, description=description)
            response['msg'] = 'Catalog {} has been created.'.format(catalog_name)
            response['changed'] = True
        else:
            response['warnings'] = 'Catalog {} is already present.'.format(catalog_name)

        return response

    def delete(self):
        catalog_name = self.params.get('catalog_name')
        response = dict()
        response['changed'] = False

        try:
            self.org.get_catalog(name=catalog_name)
        except EntityNotFoundException:
            response['warnings'] = 'Catalog {} is not present.'.format(catalog_name)
        else:
            self.org.delete_catalog(catalog_name)
            response['msg'] = 'Catalog {} has been deleted.'.format(catalog_name)
            response['changed'] = True

        return response

    def update(self):
        catalog_name = self.params.get('catalog_name')
        new_catalog_name = self.params.get('new_catalog_name')
        description = self.params.get('description')
        response = dict()
        response['changed'] = False

        if not new_catalog_name:
            new_catalog_name = catalog_name

        self.org.update_catalog(old_catalog_name=catalog_name,
                                new_catalog_name=new_catalog_name,
                                description=description)
        response['msg'] = 'Catalog {} has been updated.'.format(catalog_name)
        response['changed'] = True

        return response

    def shared(self):
        catalog_name = self.params.get('catalog_name')
        shared = self.params.get('shared')
        response = dict()
        response['changed'] = False

        self.org.share_catalog(name=catalog_name, share=shared)
        response['msg'] = 'Catalog {} shared state has been updated to [shared={}].'.format(catalog_name, shared)
        response['changed'] = True

        return response

    def read(self):
        catalog_name = self.params.get('catalog_name')
        response = dict()
        result = dict()
        response['changed'] = False

        catalog = self.org.get_catalog(catalog_name)
        result['name'] = str(catalog.get("name"))
        result['description'] = str(catalog.Description)
        result['shared'] = str(catalog.IsPublished)
        response['msg'] = result
        response['changed'] = False

        return response

    def list_items(self):
        catalog_name = self.params.get('catalog_name')
        response = dict()
        response['changed'] = False

        catalog_items = self.org.list_catalog_items(catalog_name)
        response['msg'] = [catalog_item['name'] for catalog_item in catalog_items]
        response['changed'] = False

        return response
开发者ID:equinix-ms,项目名称:ansible-module-vcloud-director,代码行数:104,代码来源:vcd_catalog.py


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