Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_0015_list_external_network_config_ip_allocations(self):
"""List external network configure ip allocations.
Invoke the list_gateways_configure_ip_settings of the gateway.
"""
for client in (TestGateway._client, TestGateway._org_client):
gateway_obj = Gateway(client, self._name,
TestGateway._gateway.get('href'))
ip_allocations = gateway_obj.list_configure_ip_settings()
platform = Platform(TestGateway._client)
external_networks = platform.list_external_networks()
self.assertTrue(bool(ip_allocations))
exnet = ip_allocations[0].get('external_network')
self.assertEqual(external_networks[0].get('name'), exnet)
def test_0050_enable_vc(self):
"""Platform.enable_vcenter enables a vcenter.
Wait for async command to complete before checking result.
"""
platform = Platform(TestVC._client)
task = platform.enable_disable_vcenter(
vc_name=TestVC._vcServerName, enable_flag=True)
TestVC._client.get_task_monitor().wait_for_success(task=task)
vc = platform.get_vcenter(name=TestVC._vcServerName)
self.assertTrue(vc.IsEnabled)
query_result_format=QueryResultFormat.RECORDS,
equality_filter=name_filter)
port_group = None
for record in list(query.execute()):
if record.get('networkName') == '--':
if not record.get('name').startswith('vxw-'):
port_group = record.get('name')
break
if port_group is None:
raise Exception(
'None of the port groups are free for new network.')
name = 'external_network_' + str(uuid1())
platform = Platform(TestGateway._client)
ext_net = platform.create_external_network(
name=name,
vim_server_name=vc_name,
port_group_names=[port_group],
gateway_ip='10.10.30.1',
netmask='255.255.255.0',
ip_ranges=['10.10.30.101-10.10.30.150'],
description=name,
primary_dns_ip='8.8.8.8',
secondary_dns_ip='8.8.8.9',
dns_suffix='example.com')
task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0]
TestGateway._client.get_task_monitor().wait_for_success(task=task)
TestGateway._external_network2 = ext_net
return ext_net
def test_0050_migrate_vms_back(self):
"""Migrate VM(s) from one resource pool to another."""
platform = Platform(TestPVDC._sys_admin_client)
task = platform.pvdc_migrate_vms(
TestPVDC._pvdc_name,
TestPVDC._vms_to_migrate,
TestPVDC._target_resource_pool)
res = TestPVDC._sys_admin_client.get_task_monitor().wait_for_success(
task=task)
self.assertEqual(res.get('status'), TaskStatus.SUCCESS.value)
def info(ctx, name):
try:
restore_session(ctx)
platform = Platform(ctx.obj['client'])
stdout(platform.get_vcenter(name=name), ctx)
except Exception as e:
stderr(e, ctx)
def _pvdc_helper(ctx):
client = ctx.obj['client']
platform = Platform(client)
return client, platform
def __init__(self, **kwargs):
super(VcdExternalNetwork, self).__init__(**kwargs)
self.platform = Platform(self.client)
:return: VSphere object for a specific VM inside a VApp
:rtype: vsphere_guest_run.vsphere.VSphere
"""
global cache
global vsphere_list
# get vm id from vm resource
vm_id = vapp.get_vm(vm_name).get('id')
if vm_id not in cache:
# recreate vapp with sys admin client
vapp = VApp(sys_admin_client, href=vapp.href)
vm_resource = vapp.get_vm(vm_name)
vm_sys = VM(sys_admin_client, resource=vm_resource)
vcenter_name = vm_sys.get_vc()
platform = Platform(sys_admin_client)
vcenter = platform.get_vcenter(vcenter_name)
vcenter_url = urlparse(vcenter.Url.text)
cache_item = {
'hostname': vcenter_url.hostname,
'port': vcenter_url.port
}
if not vsphere_list:
raise Exception("Global list of vSphere info not set.")
for vc in vsphere_list:
if vc['name'] == vcenter_name:
cache_item['username'] = vc['username']
cache_item['password'] = vc['password']
break
cache[vm_id] = cache_item
def _get_platform(ctx):
"""Returns Platform object"""
restore_session(ctx)
client = ctx.obj['client']
return Platform(client)
def detach(ctx, name):
try:
restore_session(ctx)
platform = Platform(ctx.obj['client'])
stdout(platform.detach_vcenter(vc_name=name), ctx)
except Exception as e:
stderr(e, ctx)