本文整理汇总了Python中pyvcloud.vcd.vapp.VApp类的典型用法代码示例。如果您正苦于以下问题:Python VApp类的具体用法?Python VApp怎么用?Python VApp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VApp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_060_attach_disk_to_vm_in_vapp
def test_060_attach_disk_to_vm_in_vapp(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, resource=vdc_resource)
assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
assert self.config['vcd']['vapp'] == vapp_resource.get('name')
vapp = VApp(self.client, resource=vapp_resource)
disk = vdc.get_disk(self.config['vcd']['idisk_name'])
result = vapp.attach_disk_to_vm(disk_href=disk.get('href'),
vm_name=self.config['vcd']['vm'])
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: test_0010_vm_setup
def test_0010_vm_setup(self):
"""Setup the vms required for the other tests in this module.
Create a vApp with just one vm as per the configuration stated above.
This test passes if the vApp and vm hrefs are not None.
"""
logger = Environment.get_default_logger()
TestPVDC._org_client = Environment.get_client_in_default_org(
TestPVDC._test_runner_role)
vdc = Environment.get_test_vdc(TestPVDC._org_client)
logger.debug('Creating vApp ' + TestPVDC._test_vapp_name + '.')
TestPVDC._test_vapp_href = create_customized_vapp_from_template(
client=TestPVDC._org_client,
vdc=vdc,
name=TestPVDC._test_vapp_name,
catalog_name=Environment.get_default_catalog_name(),
template_name=Environment.get_default_template_name(),
memory_size=TestPVDC._test_vapp_first_vm_memory_size,
num_cpu=TestPVDC._test_vapp_first_vm_num_cpu,
disk_size=TestPVDC._test_vapp_first_vm_first_disk_size,
vm_name=TestPVDC._test_vapp_first_vm_name,
nw_adapter_type=TestPVDC._test_vapp_first_vm_network_adapter_type)
self.assertIsNotNone(TestPVDC._test_vapp_href)
vapp = VApp(TestPVDC._org_client, href=TestPVDC._test_vapp_href)
vm_resource = vapp.get_vm(TestPVDC._test_vapp_first_vm_name)
TestPVDC._test_vapp_first_vm_href = vm_resource.get('href')
self.assertIsNotNone(TestPVDC._test_vapp_first_vm_href)
示例3: read
def read(self, request):
logging.info("__INIT__read[VappVm]")
res = vapp_vm_pb2.ReadVappVmResult()
res.present = False
org_resource = self.client.get_org()
org = Org(self.client, resource=org_resource)
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)
read_vapp_vm_resp = vapp.get_vm(request.target_vm_name)
vm = VM(client=self.client, href=None, resource=read_vapp_vm_resp)
res.present = True
except Exception as e:
errmsg = '__ERROR_read[VappVm] failed for VappVm {0}. __ErrorMessage__ {1}'
logging.warn(errmsg.format(request.target_vm_name, str(e)))
return res
logging.info("__DONE__read[VappVm]")
return res
示例4: test_1006_snapshot_create
def test_1006_snapshot_create(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, resource=vdc_resource)
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)
vm_resource = vapp.get_vm(self.config['vcd']['vm'])
assert vm_resource.get('name') == self.config['vcd']['vm']
vm = VM(self.client, resource=vm_resource)
task = vm.snapshot_create(memory=False, quiesce=False)
task = self.client.get_task_monitor().wait_for_status(
task=task,
timeout=120,
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
示例5: delete_vm
def delete_vm(client):
print("================= Vdc delete request ===================")
vdc_name = "pcp_vdc_02"
target_vm_name = "pcp_vm"
org_resource = client.get_org()
org = Org(client, resource=org_resource)
print("Org name: ", org.get_name())
print("Vdc name: ", vdc_name)
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)
delete_vapp_vm_resp = vapp.delete_vms(target_vm_name)
task = client.get_task_monitor().wait_for_status(
task=delete_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:
message = 'delete vdc status : {0} '.format(st)
logging.info(message)
else:
raise errors.VCDVdcDeleteError(etree.tostring(task, pretty_print=True))
示例6: test_1002_deploy_vm
def test_1002_deploy_vm(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')
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)
vm_resource = vapp.get_vm(self.config['vcd']['vm'])
vm = VM(self.client, resource=vm_resource)
result = vm.deploy()
# result = vm.shutdown()
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
示例7: test_0002_add_vm
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
示例8: info
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)
示例9: get_test_vapp_with_network
def get_test_vapp_with_network(cls, client):
"""Gets the vapp for testing in current vDC.
:param pyvcloud.vcd.client.Client client: client which will be used to
create the VDC object.
:return: the vdc that is backing the organization in which all tests
will run.
:rtype: pyvcloud.vcd.vdc.VDC
"""
if not cls._vapp_href:
vdc = Environment.get_test_vdc(client)
try:
vapp = vdc.get_vapp(VAppConstants.name)
cls._vapp_href = vapp.get('href')
except EntityNotFoundException:
cls._vapp_href = create_vapp_from_template(
client,
vdc,
VAppConstants.name,
cls._config['vcd']['default_catalog_name'],
cls._config['vcd']['default_template_file_name'],
power_on=False,
deploy=False)
vapp = VApp(client, href=cls._vapp_href)
task = vapp.create_vapp_network(
VAppConstants.network1_name,
VAppConstants.network1_cidr,
ip_ranges=VAppConstants.network1_ip_ranges)
client.get_task_monitor().wait_for_success(task=task)
return VApp(client, href=cls._vapp_href)
示例10: create_from_vapp
def create_from_vapp(self, request):
logging.info("__INIT__create[VappVm] source_catalog_name[%s]",
request.source_vapp)
res = vapp_vm_pb2.CreateVappVmResult()
res.created = False
source_vapp_resource = self.get_vapp_resource(
request.target_vdc, vapp_name=request.source_vapp)
target_vapp_resource = self.get_vapp_resource(
request.target_vdc, vapp_name=request.target_vapp)
specs = [{
'vapp': source_vapp_resource,
'source_vm_name': request.source_vm_name,
'target_vm_name': request.target_vm_name,
'hostname': request.hostname,
'password': request.password,
'password_auto': request.password_auto,
'password_reset': request.password_reset,
'cust_script': request.cust_script,
'network': request.network,
# 'storage_profile': request.storage_profile
}]
try:
vapp = VApp(self.client, resource=target_vapp_resource)
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
示例11: test_0002_modify_memory
def test_0002_modify_memory(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, resource=vdc_resource)
assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
vapp = VApp(self.client, resource=vapp_resource)
vm_resource = vapp.get_vm(self.config['vcd']['vm'])
vm = VM(self.client, resource=vm_resource)
task = vm.modify_memory(self.config['vcd']['memory'])
task = self.client.get_task_monitor().wait_for_status(
task=task,
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
vm.reload()
assert vm.get_memory() == self.config['vcd']['memory']
示例12: test_1003_get_vapp_access
def test_1003_get_vapp_access(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, resource=vdc_resource)
vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
vapp = VApp(self.client, resource=vapp_resource)
control_access = vapp.get_access_settings()
assert len(control_access.AccessSettings.AccessSetting) == 2
示例13: test_1001_remove_all_vapp_access
def test_1001_remove_all_vapp_access(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, resource=vdc_resource)
vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
vapp = VApp(self.client, resource=vapp_resource)
control_access = vapp.remove_access_settings(remove_all=True)
self.assertFalse(hasattr(control_access, 'AccessSettings'))
示例14: list_networks
def list_networks(self):
vapp_name = self.params.get('vapp_name')
vapp_resource = self.vdc.get_vapp(vapp_name)
vapp = VApp(self.client, name=vapp_name, resource=vapp_resource)
response = dict()
response['msg'] = []
for network in vapp.get_all_networks():
response['msg'].append(network.get('{'+NSMAP['ovf']+'}name'))
return response
示例15: test_1006_unshare_vapp_access
def test_1006_unshare_vapp_access(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, resource=vdc_resource)
vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
vapp = VApp(self.client, resource=vapp_resource)
control_access = vapp.unshare_from_org_members()
assert control_access.IsSharedToEveryone.text == 'false'