本文整理汇总了Python中pyvcloud.vcd.org.Org.create_catalog方法的典型用法代码示例。如果您正苦于以下问题:Python Org.create_catalog方法的具体用法?Python Org.create_catalog怎么用?Python Org.create_catalog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvcloud.vcd.org.Org
的用法示例。
在下文中一共展示了Org.create_catalog方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_catalog
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_catalog [as 别名]
def create_catalog(cls):
"""Creates a catalog by the name specified in the configuration file.
Skips creating one, if such a catalog already exists.
: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_records = org.list_catalogs()
for catalog_record in catalog_records:
if catalog_record.get('name') == catalog_name:
cls._logger.debug('Reusing existing catalog ' +
catalog_name)
return
cls._logger.debug('Creating new catalog ' + catalog_name)
catalog_resource = org.create_catalog(
name=catalog_name, description='')
catalog_author_client.get_task_monitor().wait_for_success(
task=catalog_resource.Tasks.Task[0])
finally:
catalog_author_client.logout()
示例2: create
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_catalog [as 别名]
def create(client, context, name, description):
logging.debug("_INIT_create_catalog__")
logging.debug("name = [%s] desc = [%s] ", name, description)
result = pyvcloudprovider_pb2.CreateCatalogResult()
result.created = False
try:
logged_in_org = client.get_org()
org = Org(client, resource=logged_in_org)
try:
catalog = org.create_catalog(name=name, description=description)
result.created = True
except Exception as e:
error_message = "__ ERROR Creating catalog [{0}] __ERROR_MESSAGE__ [{1}]".format(
name, str(e))
logging.warn(error_message)
context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
context.set_details(error_message)
except Exception as e:
error_message = "__ ERROR Creating catalog [{0}] __ERROR_MESSAGE__ [{1}]".format(
name, str(e))
logging.warn(error_message)
context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
context.set_details(error_message)
logging.debug("_DONE_create_catalog__")
return result
示例3: create
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_catalog [as 别名]
def create(ctx, catalog_name, description):
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)
c = org.create_catalog(catalog_name, description)
stdout(c.Tasks.Task[0], ctx, show_id=True)
except Exception as e:
stderr(e, ctx)
示例4: handle_task
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_catalog [as 别名]
handle_task(client, admin_vdc_resource.Tasks.Task[0])
org.reload()
vdc_resource = org.get_vdc(cfg.vdc['vdc_name'])
vdc = VDC(client, resource=vdc_resource)
print("VDC now exists: {0}".format(vdc.name))
# Ensure the catalog exists. For now we don't do anything special with
# permissions. As with VDC's we reload the org if we create a catalog
# so that it's visible in future calls.
try:
catalog_resource = org.get_catalog_resource(cfg.catalog['name'])
print("Catalog already exists: {0}".format(cfg.catalog['name']))
except Exception:
print("Catalog does not exist, creating: {0}".format(cfg.catalog['name']))
catalog_kwargs = cfg.catalog
catalog_resource = org.create_catalog(**catalog_kwargs)
org.reload()
print("Catalog now exists: {0}".format(catalog_resource.get('name')))
# Check for catalog_items containing OVF templates in the catalog and
# upload them if they are missing.
for catalog_item in cfg.catalog_items:
try:
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(
示例5: test_create_catalog
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_catalog [as 别名]
def test_create_catalog(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
catalog = org.create_catalog(self.config['vcd']['catalog'], 'test catalog')
assert self.config['vcd']['catalog'] == catalog.get('name')
示例6: Catalog
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import create_catalog [as 别名]
class Catalog(VcdAnsibleModule):
def __init__(self, **kwargs):
super(Catalog, 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.create()
if state == "absent":
return self.delete()
if state == "update":
return self.update()
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)
#.........这里部分代码省略.........