本文整理汇总了Python中pyvcloud.vcd.vdc.VDC.instantiate_vapp方法的典型用法代码示例。如果您正苦于以下问题:Python VDC.instantiate_vapp方法的具体用法?Python VDC.instantiate_vapp怎么用?Python VDC.instantiate_vapp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvcloud.vcd.vdc.VDC
的用法示例。
在下文中一共展示了VDC.instantiate_vapp方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_001_instantiate_vapp
# 需要导入模块: from pyvcloud.vcd.vdc import VDC [as 别名]
# 或者: from pyvcloud.vcd.vdc.VDC import instantiate_vapp [as 别名]
def test_001_instantiate_vapp(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
v = org.get_vdc(self.config['vcd']['vdc'])
vdc = VDC(self.client, href=v.get('href'))
assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
result = vdc.instantiate_vapp(
self.config['vcd']['vapp'],
self.config['vcd']['catalog'],
self.config['vcd']['template'],
network='net2',
fence_mode='natRouted',
deploy=False,
power_on=False)
task = self.client.get_task_monitor().wait_for_status(
task=result.Tasks.Task[0],
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: test_100_instantiate_vapp_identical
# 需要导入模块: from pyvcloud.vcd.vdc import VDC [as 别名]
# 或者: from pyvcloud.vcd.vdc.VDC import instantiate_vapp [as 别名]
def test_100_instantiate_vapp_identical(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
v = org.get_vdc(self.config['vcd']['vdc'])
vdc = VDC(self.client, href=v.get('href'))
assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
result = vdc.instantiate_vapp(
self.config['vcd']['vapp'],
self.config['vcd']['catalog'],
self.config['vcd']['template'],
network=self.config['vcd']['network'],
fence_mode='bridged',
deploy=True,
power_on=False,
identical=True)
task = self.client.get_task_monitor().wait_for_status(
task=result.Tasks.Task[0],
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
vdc.reload()
vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
vm = vapp_resource.xpath(
'//vcloud:VApp/vcloud:Children/vcloud:Vm', namespaces=NSMAP)
assert len(vm) > 0
assert vm[0].get('name') == self.config['vcd']['vm']
示例3: create
# 需要导入模块: from pyvcloud.vcd.vdc import VDC [as 别名]
# 或者: from pyvcloud.vcd.vdc.VDC import instantiate_vapp [as 别名]
def create(ctx, name, description, catalog, template, network, memory, cpu,
disk_size, ip_allocation_mode, vm_name, hostname, storage_profile,
accept_all_eulas):
try:
restore_session(ctx, vdc_required=True)
client = ctx.obj['client']
vdc_href = ctx.obj['profiles'].get('vdc_href')
vdc = VDC(client, href=vdc_href)
if catalog is None and template is None:
vapp_resource = vdc.create_vapp(
name,
description=description,
network=network,
accept_all_eulas=accept_all_eulas)
else:
vapp_resource = vdc.instantiate_vapp(
name,
catalog,
template,
description=description,
network=network,
memory=memory,
cpu=cpu,
disk_size=disk_size,
deploy=True,
power_on=True,
accept_all_eulas=accept_all_eulas,
cust_script=None,
ip_allocation_mode=ip_allocation_mode,
vm_name=vm_name,
hostname=hostname,
storage_profile=storage_profile)
stdout(vapp_resource.Tasks.Task[0], ctx)
except Exception as e:
stderr(e, ctx)
示例4: test_110_instantiate_vapp_custom_disk_size
# 需要导入模块: from pyvcloud.vcd.vdc import VDC [as 别名]
# 或者: from pyvcloud.vcd.vdc.VDC import instantiate_vapp [as 别名]
def test_110_instantiate_vapp_custom_disk_size(self):
logged_in_org = self.client.get_org()
org = Org(self.client, resource=logged_in_org)
v = org.get_vdc(self.config['vcd']['vdc'])
vdc = VDC(self.client, href=v.get('href'))
assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
result = vdc.instantiate_vapp(
self.config['vcd']['vapp'],
self.config['vcd']['catalog'],
self.config['vcd']['template'],
network=self.config['vcd']['network'],
fence_mode='bridged',
deploy=True,
power_on=False,
disk_size=self.config['vcd']['disk_size_new'])
task = self.client.get_task_monitor().wait_for_status(
task=result.Tasks.Task[0],
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
vdc.resource = vdc.client.get_resource(vdc.href)
vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
vms = vapp_resource.xpath(
'//vcloud:VApp/vcloud:Children/vcloud:Vm', namespaces=NSMAP)
assert len(vms) > 0
items = vms[0].xpath(
'//ovf:VirtualHardwareSection/ovf:Item',
namespaces={
'ovf': NSMAP['ovf']
})
assert len(items) > 0
found_disk = False
for item in items:
if item['{' + NSMAP['rasd'] + '}ResourceType'] == 17: # NOQA
found_disk = True
assert item['{' + NSMAP['rasd'] + '}VirtualQuantity'] == \
(self.config['vcd']['disk_size_new'] * 1024 * 1024)
break
# this check makes sure that the vm isn't disk-less
assert found_disk
# cleanup
self.test_100_delete_vapp()
示例5: len
# 需要导入模块: from pyvcloud.vcd.vdc import VDC [as 别名]
# 或者: from pyvcloud.vcd.vdc.VDC import instantiate_vapp [as 别名]
name=network['network_name'],
type=FenceMode.ISOLATED.value)
if len(new_network_list) > 0:
print("Isolated network is visible in VDC: {0}".format(
network['network_name']))
network_exists = True
else:
print("Isolated network is not visible yet: {0}".format(
network['network_name']))
time.sleep(3)
# Check for vApps and create them if they don't exist. We have to
# reload the VDC object so it has all the links to current vApps.
vdc.reload()
for vapp_cfg in cfg.vapps:
try:
vapp = vdc.get_vapp(vapp_cfg['name'])
print("vApp exists: {0}".format(vapp_cfg['name']))
except Exception:
print("vApp does not exist: name={0}".format(vapp_cfg['name']))
vapp_resource = vdc.instantiate_vapp(**vapp_cfg)
print("vApp instantiated")
# We don't track the task as instantiating a vApp takes a while.
# Uncomment below if you want to ensure the vApps are available.
# handle_task(client, vapp_resource.Tasks.Task[0])
# Log out.
print("All done!")
client.logout()
示例6: create
# 需要导入模块: from pyvcloud.vcd.vdc import VDC [as 别名]
# 或者: from pyvcloud.vcd.vdc.VDC import instantiate_vapp [as 别名]
def create(client, context, vappInfo):
logging.debug('__INIT__vapp_create [ {0} ]'.format(vappInfo))
cresult = vapp_pb2.CreateVAppResult()
cresult.created = False
#cresult.in_vapp_info=vapp_pb2.CreateVAppInfo()
cresult.in_vapp_info.CopyFrom(vappInfo)
try:
logged_in_org = client.get_org()
org = Org(client, resource=logged_in_org)
v = org.get_vdc(vappInfo.vdc)
if v is None:
raise errors.VDCNotFoundError(vappInfo.vdc)
vdc = VDC(client, href=v.get('href'))
logging.info("__LOG__vapp_create_calling instantiate_vapp............")
network = None
memory = None
storage_profile = None
accept_all_eulas = False
power_on = False
if vappInfo.network:
network = vappInfo.network
if vappInfo.memory:
memory = vappInfo.memory
if vappInfo.storage_profile:
storage_profile = vappInfo.storage_profile
if vappInfo.accept_all_eulas:
accept_all_eulas = vappInfo.accept_all_eulas
if vappInfo.power_on:
power_on = vappInfo.power_on
logging.info(
"__LOG__ CREATE VAPP Params - MEMORY = [%s] NETWORK = [%s] storage_profile =[%s] ",
memory, network, storage_profile)
result = vdc.instantiate_vapp(
name=vappInfo.name,
catalog=vappInfo.catalog_name,
template=vappInfo.template_name,
network=network,
memory=memory,
cpu=vappInfo.cpu,
power_on=power_on,
storage_profile=storage_profile,
accept_all_eulas=accept_all_eulas)
task = client.get_task_monitor().wait_for_status(
task=result.Tasks.Task[0],
timeout=60,
poll_frequency=2,
fail_on_statuses=None,
expected_target_statuses=[
TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
TaskStatus.CANCELED
],
callback=task_callback)
st = task.get('status')
if st == TaskStatus.SUCCESS.value:
cresult.created = True
else:
raise errors.VCDVappCreationError(
etree.tostring(task, pretty_print=True))
vapp = vdc.get_vapp(vappInfo.name)
if vappInfo.power_on is True:
logging.info("Powering on [Vapp %v]".format(vappInfo.name))
vapp.power_on()
else:
logging.info("Powering off [Vapp %v]".format(vappInfo.name))
vapp.undeploy()
except Exception as e:
error_message = 'ERROR.. Not Created VApp {0} {1}'.format(
vappInfo.name, str(e))
logging.warn(error_message, e)
context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
context.set_details(error_message)
return cresult
示例7: Vapp
# 需要导入模块: from pyvcloud.vcd.vdc import VDC [as 别名]
# 或者: from pyvcloud.vcd.vdc.VDC import instantiate_vapp [as 别名]
class Vapp(VcdAnsibleModule):
def __init__(self, **kwargs):
super(Vapp, self).__init__(**kwargs)
logged_in_org = self.client.get_org()
self.org = Org(self.client, resource=logged_in_org)
vdc_resource = self.org.get_vdc(self.params.get('vdc'))
self.vdc = VDC(self.client, href=vdc_resource.get('href'))
def manage_states(self):
state = self.params.get('state')
if state == "present":
catalog_name = self.params.get('catalog_name')
if catalog_name:
return self.instantiate()
else:
return self.create()
if state == "absent":
return self.delete()
def manage_operations(self):
state = self.params.get('operation')
if state == "poweron":
return self.power_on()
if state == "poweroff":
return self.power_off()
if state == "deploy":
return self.deploy()
if state == "undeploy":
return self.undeploy()
if state == "list_vms":
return self.list_vms()
if state == "list_networks":
return self.list_networks()
def instantiate(self):
params = self.params
vapp_name = params.get('vapp_name')
catalog_name = params.get('catalog_name')
template_name = params.get('template_name')
description = params.get('description')
network = params.get('network')
fence_mode = params.get('fence_mode')
ip_allocation_mode = params.get('ip_allocation_mode')
deploy = params.get('deploy')
power_on = params.get('power_on')
accept_all_eulas = params.get('accept_all_eulas')
memory = params.get('memory')
cpu = params.get('cpu')
disk_size = params.get('disk_size')
vmpassword = params.get('vmpassword')
cust_script = params.get('cust_script')
vm_name = params.get('vm_name')
hostname = params.get('hostname')
ip_address = params.get('ip_address')
storage_profile = params.get('storage_profile')
network_adapter_type = params.get('network_adapter_type')
response = dict()
response['changed'] = False
try:
self.vdc.get_vapp(vapp_name)
except EntityNotFoundException:
create_vapp_task = self.vdc.instantiate_vapp(
name=vapp_name,
catalog=catalog_name,
template=template_name,
description=description,
network=network,
fence_mode=fence_mode,
ip_allocation_mode=ip_allocation_mode,
deploy=deploy,
power_on=power_on,
accept_all_eulas=accept_all_eulas,
memory=memory,
cpu=cpu,
disk_size=disk_size,
password=vmpassword,
cust_script=cust_script,
vm_name=vm_name,
hostname=hostname,
ip_address=ip_address,
storage_profile=storage_profile,
network_adapter_type=network_adapter_type)
self.execute_task(create_vapp_task.Tasks.Task[0])
response['msg'] = 'Vapp {} has been created.'.format(vapp_name)
response['changed'] = True
else:
response['warnings'] = "Vapp {} is already present.".format(vapp_name)
return response
def create(self):
params = self.params
vapp_name = params.get('vapp_name')
#.........这里部分代码省略.........