本文整理汇总了Python中pyvcloud.vcd.org.Org.get_catalog_item方法的典型用法代码示例。如果您正苦于以下问题:Python Org.get_catalog_item方法的具体用法?Python Org.get_catalog_item怎么用?Python Org.get_catalog_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvcloud.vcd.org.Org
的用法示例。
在下文中一共展示了Org.get_catalog_item方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_0002_add_vm
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [as 别名]
def test_0002_add_vm(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
vdc = VDC(self.client, href=vdc_resource.get('href'))
assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
assert vapp_resource.get('name') == self.config['vcd']['vapp']
vapp = VApp(self.client, resource=vapp_resource)
catalog_item = org.get_catalog_item(self.config['vcd']['catalog'],
self.config['vcd']['template'])
source_vapp_resource = self.client.get_resource(
catalog_item.Entity.get('href'))
spec = {'source_vm_name': self.config['vcd']['vm'],
'vapp': source_vapp_resource}
spec['target_vm_name'] = self.config['vcd']['hostname']
spec['hostname'] = self.config['vcd']['hostname']
spec['network'] = self.config['vcd']['network']
spec['ip_allocation_mode'] = self.config['vcd']['ip_allocation_mode']
spec['storage_profile'] = vdc.get_storage_profile(
self.config['vcd']['storage_profile'])
vms = [spec]
result = vapp.add_vms(vms)
task = self.client.get_task_monitor().wait_for_status(
task=result,
timeout=60,
poll_frequency=2,
fail_on_statuses=None,
expected_target_statuses=[
TaskStatus.SUCCESS,
TaskStatus.ABORTED,
TaskStatus.ERROR,
TaskStatus.CANCELED],
callback=None)
assert task.get('status') == TaskStatus.SUCCESS.value
示例2: info
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [as 别名]
def info(ctx, catalog_name, item_name):
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)
if item_name is None:
catalog = org.get_catalog(catalog_name)
result = to_dict(catalog)
# We don't have a way to know in advance if a user has access to a
# catalog's ACL or not. So we try to retrieve it always. If the
# call fails due to permission issues, we silently eat the
# exception and exclude ACL settings from the output of the current
# command. Users who have access to ACL of the catalog will remain
# unaffected. Also any other errors/exceptions will bubble up as
# usual.
try:
access_control_settings = access_settings_to_dict(
org.get_catalog_access_settings(catalog_name))
result.update(access_control_settings)
except AccessForbiddenException as e:
pass
else:
catalog_item = org.get_catalog_item(catalog_name, item_name)
result = to_dict(catalog_item)
vapp = VApp(client, href=catalog_item.Entity.get('href'))
vapp.reload()
template = vapp_to_dict(vapp.resource)
for k, v in template.items():
result['template-%s' % k] = v
stdout(result, ctx)
except Exception as e:
stderr(e, ctx)
示例3: ova_check_resolved
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [as 别名]
def ova_check_resolved(client, context, ovaInfo):
logging.debug("===== INIT ova_check_resolved %s called === \n",
ovaInfo.item_name)
cresult = pyvcloudprovider_pb2.CheckResolvedResult()
cresult.resolved = False
try:
logged_in_org = client.get_org()
org = Org(client, resource=logged_in_org)
source_ova_item = org.get_catalog_item(ovaInfo.catalog_name,
ovaInfo.item_name)
if source_ova_item is None: #TODO WRITE A TEST CASE
raise error.ItemFoundError('Item = {0}'.format(ovaInfo.item_name))
check_resolved(client, source_ova_item)
cresult.resolved = True
logging.debug(
"===== DONE upload/capture ova to catalog %s %s === \n",
ovaInfo.catalog_name, ovaInfo.item_name)
return cresult
except Exception as e:
error_message = 'ERROR.. ova_check_resolved {0} '.format(
ovaInfo.item_name)
logging.warn(error_message, e)
context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
context.set_details(error_message)
raise
示例4: upload_media
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [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()
示例5: is_present
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [as 别名]
def is_present(client, catalog_name, item_name):
logging.basicConfig(level=logging.DEBUG)
logging.debug("=== isPresent catalog item called === \n")
try:
logged_in_org = client.get_org()
org = Org(client, resource=logged_in_org)
result = catalog_item_pb2.IsPresentCatalogItemResult()
result.present = False
try:
catalog = org.get_catalog_item(catalog_name, item_name)
result.present = True
except Exception as e:
logging.info("catalog item is not present")
return result
except Exception as e:
logging.warn("__ERROR__ occured", e)
示例6: get_source_resource
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [as 别名]
def get_source_resource(self):
source_catalog_name = self.params.get('source_catalog_name')
source_template_name = self.params.get('source_template_name')
source_vdc = self.params.get('source_vdc')
source_vapp = self.params.get('source_vapp')
org_resource = Org(self.client, resource=self.client.get_org())
source_vapp_resource = None
if source_vapp:
source_vdc_resource = VDC(
self.client, resource=org_resource.get_vdc(source_vdc))
source_vapp_resource_href = source_vdc_resource.get_resource_href(
name=source_vapp, entity_type=EntityType.VAPP)
source_vapp_resource = self.client.get_resource(
source_vapp_resource_href)
if source_catalog_name:
catalog_item = org_resource.get_catalog_item(
source_catalog_name, source_template_name)
source_vapp_resource = self.client.get_resource(
catalog_item.Entity.get('href'))
return source_vapp_resource
示例7: add_vm
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [as 别名]
def add_vm(ctx, name, source_vapp, source_vm, catalog, target_vm, hostname,
network, ip_allocation_mode, storage_profile, password_auto,
accept_all_eulas):
try:
restore_session(ctx, vdc_required=True)
client = ctx.obj['client']
in_use_org_href = ctx.obj['profiles'].get('org_href')
org = Org(client, in_use_org_href)
vdc_href = ctx.obj['profiles'].get('vdc_href')
vdc = VDC(client, href=vdc_href)
source_vapp_resource = None
if catalog is None:
source_vapp_resource = vdc.get_vapp(source_vapp)
else:
catalog_item = org.get_catalog_item(catalog, source_vapp)
source_vapp_resource = client.get_resource(
catalog_item.Entity.get('href'))
assert source_vapp_resource is not None
vapp_resource = vdc.get_vapp(name)
vapp = VApp(client, resource=vapp_resource)
spec = {'source_vm_name': source_vm, 'vapp': source_vapp_resource}
if target_vm is not None:
spec['target_vm_name'] = target_vm
if hostname is not None:
spec['hostname'] = hostname
if network is not None:
spec['network'] = network
spec['ip_allocation_mode'] = ip_allocation_mode
if storage_profile is not None:
spec['storage_profile'] = vdc.get_storage_profile(storage_profile)
if password_auto is not None:
spec['password_auto'] = password_auto
task = vapp.add_vms([spec], all_eulas_accepted=accept_all_eulas)
stdout(task, ctx)
except Exception as e:
stderr(e, ctx)
示例8: create_from_catalog
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [as 别名]
def create_from_catalog(self, request):
logging.info("__INIT__create[VappVm] source_catalog_name[%s]",
request.source_catalog_name)
res = vapp_vm_pb2.CreateVappVmResult()
res.created = False
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
try:
vdc_resource = org.get_vdc(request.target_vdc)
vdc = VDC(
self.client, name=request.target_vdc, resource=vdc_resource)
vapp_resource = vdc.get_vapp(request.target_vapp)
vapp = VApp(
self.client, name=request.target_vapp, resource=vapp_resource)
catalog_item = org.get_catalog_item(request.source_catalog_name,
request.source_template_name)
source_vapp_resource = self.client.get_resource(
catalog_item.Entity.get('href'))
specs = [{
'source_vm_name': request.source_vm_name,
'vapp': source_vapp_resource,
'target_vm_name': request.target_vm_name,
'hostname': request.hostname,
'network': request.network,
'ip_allocation_mode': request.ip_allocation_mode,
# 'storage_profile': request.storage_profile
}]
create_vapp_vm_resp = vapp.add_vms(
specs,
power_on=request.power_on,
all_eulas_accepted=request.all_eulas_accepted)
task_monitor = self.client.get_task_monitor()
task = task_monitor.wait_for_status(
task=create_vapp_vm_resp,
timeout=60,
poll_frequency=2,
fail_on_statuses=None,
expected_target_statuses=[
TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
TaskStatus.CANCELED
],
callback=None)
st = task.get('status')
if st != TaskStatus.SUCCESS.value:
raise errors.VappVmCreateError(
etree.tostring(task, pretty_print=True))
message = 'status : {0} '.format(st)
logging.info(message)
res.created = True
except Exception as e:
errmsg = '''__ERROR_create[VappVm] failed for vm {0}. __ErrorMessage__ {1}'''
logging.warn(errmsg.format(request.target_vm_name, str(e)))
self.context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
self.context.set_details(errmsg)
return res
logging.info("__DONE__create[VappVm]")
return res
示例9: CatalogItem
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [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,
#.........这里部分代码省略.........
示例10: print
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [as 别名]
# 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(
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")
示例11: test_validate_ova
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [as 别名]
def test_validate_ova(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
template = org.get_catalog_item(self.config['vcd']['catalog'],
self.config['vcd']['template'])
assert self.config['vcd']['template'] == template.get('name')
示例12: instantiate_vapp
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [as 别名]
def instantiate_vapp(self,
name,
catalog,
template,
network=None,
fence_mode='bridged',
ip_allocation_mode='dhcp',
deploy=True,
power_on=True,
accept_all_eulas=False,
memory=None,
cpu=None,
disk_size=None,
password=None,
cust_script=None,
vm_name=None,
hostname=None,
storage_profile=None):
"""Instantiate a vApp from a vApp template in a catalog.
If customization parameters are provided, it will customize the VM and
guest OS, taking some assumptions.
See each parameter for details.
:param name: (str): The name of the new vApp.
:param catalog: (str): The name of the catalog.
:param template: (str): The name of the vApp template.
:param network: (str): The name of a vdc network.
When provided, connects the VM to the network.
It assumes one VM in the vApp and one NIC in the VM.
:param fence_mode: (str): Fence mode.
Possible values are `bridged` and `natRouted`
:param ip_allocation_mode: (str): IP allocation mode.
Possible values are `pool`, `dhcp` and `static`
:param deploy: (bool):
:param power_on: (bool):
:param accept_all_eulas: (bool): True confirms acceptance of all EULAs
in a vApp template.
:param memory: (int):
:param cpu: (int):
:param disk_size: (int):
:param password: (str):
:param cust_script: (str):
:param vm_name: (str): When provided, set the name of the VM.
It assumes one VM in the vApp.
:param hostname: (str): When provided, set the hostname of the guest
OS. It assumes one VM in the vApp.
:param storage_profile: (str):
:return: A :class:`lxml.objectify.StringElement` object describing the
new vApp.
"""
if self.resource is None:
self.resource = self.client.get_resource(self.href)
# Get hold of the template
org_href = find_link(self.resource, RelationType.UP,
EntityType.ORG.value).href
org = Org(self.client, href=org_href)
catalog_item = org.get_catalog_item(catalog, template)
template_resource = self.client.get_resource(
catalog_item.Entity.get('href'))
# If network is not specified by user then default to
# vApp network name specified in the template
template_networks = template_resource.xpath(
'//ovf:NetworkSection/ovf:Network',
namespaces={
'ovf': NSMAP['ovf']
})
assert len(template_networks) > 0
network_name_from_template = template_networks[0].get(
'{' + NSMAP['ovf'] + '}name')
if ((network is None) and (network_name_from_template != 'none')):
network = network_name_from_template
# Find the network in vdc referred to by user, using
# name of the network
network_href = network_name = None
if network is not None:
if hasattr(self.resource, 'AvailableNetworks') and \
hasattr(self.resource.AvailableNetworks, 'Network'):
for n in self.resource.AvailableNetworks.Network:
if network == n.get('name'):
network_href = n.get('href')
network_name = n.get('name')
break
if network_href is None:
raise Exception(
'Network \'%s\' not found in the Virtual Datacenter.' %
network)
# Configure the network of the vApp
vapp_instantiation_param = None
if network_name is not None:
network_configuration = E.Configuration(
E.ParentNetwork(href=network_href), E.FenceMode(fence_mode))
if fence_mode == 'natRouted':
# TODO(need to find the vm_id)
#.........这里部分代码省略.........
示例13: create
# 需要导入模块: from pyvcloud.vcd.org import Org [as 别名]
# 或者: from pyvcloud.vcd.org.Org import get_catalog_item [as 别名]
def create(client):
print("=============== __LOG__Create_VDC =======================\n\n")
vdc_name = "ACME_PAYG"
vapp_name = "test2"
org_resource = client.get_org()
org = Org(client, resource=org_resource)
print("Org name: ", org.get_name())
print("Vdc name: ", vdc_name)
try:
vdc_resource = org.get_vdc(vdc_name)
vdc = VDC(client, name=vdc_name, resource=vdc_resource)
vapp_resource = vdc.get_vapp(vapp_name)
vapp = VApp(client, name=vapp_name, resource=vapp_resource)
print("vapp : ", vapp)
catalog_item = org.get_catalog_item('ACME', 'tinyova')
source_vapp_resource = client.get_resource(
catalog_item.Entity.get('href'))
print("source_vapp_resource: ", source_vapp_resource)
spec = {
'source_vm_name': 'Tiny Linux template',
'vapp': source_vapp_resource
}
storage_profiles = [{
'name': 'Performance',
'enabled': True,
'units': 'MB',
'limit': 0,
'default': True
}]
spec['target_vm_name'] = 'ubuntu_pcp_11'
spec['hostname'] = 'ubuntu'
spec['network'] = 'global'
spec['ip_allocation_mode'] = 'dhcp'
#spec['storage_profile'] = storage_profiles
vms = [spec]
result = vapp.add_vms(vms)
print("result: ", result)
#task = client.get_task_monitor().wait_for_status(
# task=result,
# timeout=60,
# poll_frequency=2,
# fail_on_statuses=None,
# expected_target_statuses=[
# TaskStatus.SUCCESS,
# TaskStatus.ABORTED,
# TaskStatus.ERROR,
# TaskStatus.CANCELED],
# callback=None)
#st = task.get('status')
#if st == TaskStatus.SUCCESS.value:
# message = 'status : {0} '.format(st)
# logging.info(message)
#else:
# print("st : ", st)
# raise Exception(task)
print("=============================================\n\n")
return True
except Exception as e:
error_message = '__ERROR_ [create_vdc] failed for vdc {0} '.format(
vdc_name)
logging.warn(error_message, e)
return False