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


Python Org.upload_media方法代码示例

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


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

示例1: upload_media

# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import upload_media [as 别名]
def upload_media(client, catalog_name, file_name, item_name):
    logging.debug("===== upload_media to ++catalog called === \n")
    result = pyvcloudprovider_pb2.CatalogUploadMediaResult()
    result.created = False

    try:
        logged_in_org = client.get_org()
        org = Org(client, resource=logged_in_org)
        org.upload_media(
            catalog_name=catalog_name,
            file_name=file_name,
            item_name=item_name)
        result.created = True
        return result
    except Exception as e:
        logging.warn("error occured", e)
        return result
开发者ID:gefeng24,项目名称:terraform-provider-vcloud-director,代码行数:19,代码来源:catalog.py

示例2: upload_media

# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import upload_media [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

示例3: upload_media

# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import upload_media [as 别名]
def upload_media(client, context, catalog_name, file_name, item_name):
    logging.basicConfig(level=logging.DEBUG)
    logging.debug("===== upload_media to  catalog called === \n")
    result = catalog_item_pb2.CatalogUploadMediaResult()
    result.created = False

    try:
        logged_in_org = client.get_org()
        org = Org(client, resource=logged_in_org)
        org.upload_media(
            catalog_name=catalog_name,
            file_name=file_name,
            item_name=item_name)
        result.created = True
        logging.debug("===== return created true  ")
        return result
    except Exception as e:
        error_message = 'ERROR........ Upload Media..... {0}'.format(str(e))
        logging.warn(error_message, e)
        context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
        context.set_details(error_message)
        return result
开发者ID:gefeng24,项目名称:terraform-provider-vcloud-director,代码行数:24,代码来源:catalog_item.py

示例4: upload

# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import upload_media [as 别名]
def upload(ctx, catalog_name, file_name, item_name, progress):
    try:
        restore_session(ctx)
        client = ctx.obj['client']
        in_use_org_href = ctx.obj['profiles'].get('org_href')
        org = Org(client, in_use_org_href)
        cb = upload_callback if progress else None
        filename, file_extension = os.path.splitext(file_name)
        if file_extension == '.ova':
            bytes_written = org.upload_ovf(
                catalog_name, file_name, item_name, callback=cb)
        else:
            bytes_written = org.upload_media(
                catalog_name, file_name, item_name, callback=cb)
        result = {'file': file_name, 'size': bytes_written}
        stdout(result, ctx)
    except Exception as e:
        stderr(e, ctx)
开发者ID:vmware,项目名称:vca-cli,代码行数:20,代码来源:catalog.py

示例5: CatalogItem

# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import upload_media [as 别名]
class CatalogItem(VcdAnsibleModule):
    def __init__(self, **kwargs):
        super(CatalogItem, self).__init__(**kwargs)
        logged_in_org = self.client.get_org()
        self.org = Org(self.client, resource=logged_in_org)

    def manage_states(self):
        state = self.params.get('state')
        if state == "present":
            return self.upload()

        if state == "absent":
            return self.delete()

    def manage_operations(self):
        operation = self.params.get('operation')
        if operation == "capturevapp":
            return self.capture_vapp()
        if operation == "list_vms":
            return self.list_vms()

    def is_present(self):
        params = self.params
        catalog_name = params.get('catalog_name')
        item_name = params.get('item_name')

        try:
            self.org.get_catalog_item(catalog_name, item_name)
        except EntityNotFoundException:
            return False

        return True

    def upload(self):
        params = self.params
        catalog_name = params.get('catalog_name')
        item_name = params.get('item_name')
        file_name = params.get('file_name')
        chunk_size = params.get('chunk_size')
        response = dict()
        response['changed'] = False
        item_details = {
            "catalog_name": catalog_name,
            "item_name": item_name,
            "file_name": file_name,
            "chunk_size": chunk_size
        }

        if self.is_present():
            response['warnings'] = "Catalog Item {} is already present.".format(item_name)
            return response

        if file_name.endswith(".ova") or file_name.endswith(".ovf"):
            self.org.upload_ovf(**item_details)
            self.ova_check_resolved()

        if not file_name.endswith(".ova"):
            self.org.upload_media(**item_details)

        response['msg'] = "Catalog item {} is uploaded.".format(item_name)
        response['changed'] = True

        return response

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

        if not self.is_present():
            response['warnings'] = "Catalog Item {} is not present.".format(item_name)
            return response

        self.org.delete_catalog_item(name=catalog_name, item_name=item_name)
        response['msg'] = "Catalog Item {} has been deleted.".format(item_name)
        response['changed'] = True

        return response

    def capture_vapp(self):
        params = self.params
        vapp_name = params.get('vapp_name')
        vdc_name = params.get('vdc_name')
        catalog_name = params.get('catalog_name')
        item_name = params.get('item_name')
        desc = params.get('description')
        customize_on_instantiate = params.get('customize_on_instantiate')
        overwrite = params.get('overwrite')
        client = self.client
        response = dict()
        response['changed'] = False

        v = self.org.get_vdc(vdc_name)
        vdc = VDC(client, href=v.get('href'))
        vapp = vdc.get_vapp(vapp_name)
        catalog = self.org.get_catalog(catalog_name)
        self.org.capture_vapp(
            catalog_resource=catalog,
#.........这里部分代码省略.........
开发者ID:equinix-ms,项目名称:ansible-module-vcloud-director,代码行数:103,代码来源:vcd_catalog_item.py


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