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


Python Org.upload_ovf方法代码示例

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


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

示例1: upload_ova

# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import upload_ovf [as 别名]
def upload_ova(client, context, catalog_name, file_name, item_name):
    logging.debug(
        "===== INIT upload ova to catalog %s  called === %s item %s \n",
        catalog_name, file_name, item_name)
    cresult = catalog_item_pb2.CatalogUploadOvaResult()
    cresult.created = False

    try:
        logged_in_org = client.get_org()
        org = Org(client, resource=logged_in_org)
        result = org.upload_ovf(
            catalog_name=catalog_name,
            file_name=file_name,
            item_name=item_name)

        logging.info("result ---- " + str(result))
        cresult.created = True

        logging.debug("===== DONE upload ova to  catalog %s   === \n",
                      catalog_name)
        return cresult
    except Exception as e:
        error_message = 'ERROR.. upload_ova failed  {0} '.format(catalog_name)
        logging.warn(error_message, e)
        context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
        context.set_details(error_message)
开发者ID:gefeng24,项目名称:terraform-provider-vcloud-director,代码行数:28,代码来源:catalog_item.py

示例2: upload_template

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

        If template 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)
            template_name = cls._config['vcd']['default_template_file_name']
            for item in catalog_items:
                if item.get('name').lower() == template_name.lower():
                    cls._logger.debug('Reusing existing template ' +
                                      template_name)
                    return

            cls._logger.debug('Uploading template ' + template_name +
                              ' to catalog ' + catalog_name + '.')
            org.upload_ovf(catalog_name=catalog_name, file_name=template_name)

            # wait for the template import to finish in vCD.
            catalog_item = org.get_catalog_item(
                name=catalog_name, item_name=template_name)
            template = catalog_author_client.get_resource(
                catalog_item.Entity.get('href'))
            catalog_author_client.get_task_monitor().wait_for_success(
                task=template.Tasks.Task[0])
        finally:
            catalog_author_client.logout()
开发者ID:vmware,项目名称:pyvcloud,代码行数:41,代码来源:environment.py

示例3: upload

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

示例4: CatalogItem

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

示例5: print

# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import upload_ovf [as 别名]
        catalog_item_resource = org.get_catalog_item(
            catalog_item['catalog_name'], catalog_item['item_name'])
        print("Catalog item exists: {0}".format(catalog_item['item_name']))
    except Exception:
        # Define a progress reporter to track upload, since it takes
        # a while.
        def progress_reporter(transferred, total):
            print("{:,} of {:,} bytes, {:.0%}".format(
                transferred, total, transferred / total))

        print("Loading catalog item: catalog={0}, item={1}, file={2}".format(
            catalog_item['catalog_name'],
            catalog_item['item_name'],
            catalog_item['file_name']))
        catalog_item['callback'] = progress_reporter
        org.upload_ovf(**catalog_item)
        print("Upload completed")

# Just because OVF templates are loaded does not mean they are usable yet.
# We check to ensure they are in the resolved state; otherwise, we cannot
# use them for vApps.  The following code loops until catalog items are
# in the right state.
print("Checking for unresolved templates")
find_unresolved = True
while find_unresolved:
    find_unresolved = False
    # Iterate over all the desired templates from the config file.
    for catalog_item in cfg.catalog_items:
        # Run a report query on this catalog item to find its state.
        catalog_item_resource = org.get_catalog_item(
            catalog_item['catalog_name'], catalog_item['item_name'])
开发者ID:vmware,项目名称:pyvcloud,代码行数:33,代码来源:tenant-onboard.py

示例6: test_upload_ova

# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import upload_ovf [as 别名]
 def test_upload_ova(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     template = org.upload_ovf(self.config['vcd']['catalog'],
                               self.config['vcd']['local_template'])
开发者ID:vmware,项目名称:pyvcloud,代码行数:7,代码来源:vcd_catalog_setup.py


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