def convert_to_distributed_interface(ctx, name): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) vdcNetwork = VdcNetwork(client, resource=routed_network) task = vdcNetwork.convert_to_distributed_interface() stdout(task, ctx) except Exception as e: stderr(e, ctx)
def list_allocated_ip_address(ctx, name): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) vdcNetwork = VdcNetwork(client, resource=routed_network) allocated_ip_addresses = vdcNetwork.list_allocated_ip_address() stdout(allocated_ip_addresses, ctx) except Exception as e: stderr(e, ctx)
def list_connected_vapps(ctx, name): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) vdcNetwork = VdcNetwork(client, resource=routed_network) connected_vapps = vdcNetwork.list_connected_vapps() stdout(connected_vapps, ctx) except Exception as e: stderr(e, ctx)
def test_0090_list_routed_vdc_network_allocated_ip(self): vdc = Environment.get_test_vdc(TestNetwork._client) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdc_network = VdcNetwork( TestNetwork._client, resource=org_vdc_routed_nw) allocated_ip_addresses = vdc_network.list_allocated_ip_address() self.assertEqual(len(allocated_ip_addresses), 1) ip_address = TestNetwork._routed_orgvdc_network_gateway_ip.split( '/')[0] self.assertEqual(allocated_ip_addresses[0]['IP Address'], ip_address)
def test_0090_list_routed_vdc_network_allocated_ip(self): vdc = Environment.get_test_vdc(TestNetwork._client) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdc_network = VdcNetwork(TestNetwork._client, resource=org_vdc_routed_nw) allocated_ip_addresses = vdc_network.list_allocated_ip_address() self.assertEqual(len(allocated_ip_addresses), 1) ip_address = TestNetwork._routed_orgvdc_network_gateway_ip.split( '/')[0] self.assertEqual(allocated_ip_addresses[0]['IP Address'], ip_address)
def modify_ip_range_of_routed_vdc_network(ctx, name, ip_range, new_ip_range): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) vdcNetwork = VdcNetwork(client, resource=routed_network) task = vdcNetwork.modify_static_ip_pool(ip_range, new_ip_range) stdout(task, ctx) stdout('Modify IP range of routed org vdc network is ' 'successfull.', ctx) except Exception as e: stderr(e, ctx)
def add_ip_ranges_of_routed_vdc_network(ctx, name, ip_ranges): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) vdcNetwork = VdcNetwork(client, resource=routed_network) task = vdcNetwork.add_static_ip_pool(ip_ranges) stdout(task, ctx) stdout('Add of ip ranges for routed org vdc network is successfull.', ctx) except Exception as e: stderr(e, ctx)
def set_metadata(ctx, name, key, value, domain, visibility, value_type): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) vdcNetwork = VdcNetwork(client, resource=routed_network) task = vdcNetwork.set_metadata(key, value, domain, visibility, value_type) stdout(task, ctx) stdout('Metadata is set to routed org vdc network successfully.', ctx) except Exception as e: stderr(e, ctx)
def remove_metadata(ctx, name, key, domain): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) vdcNetwork = VdcNetwork(client, resource=routed_network) task = vdcNetwork.remove_metadata(key, domain) stdout(task, ctx) stdout('Metadata is removed from vdc routed network successfully.', ctx) except Exception as e: stderr(e, ctx)
def remove_ip_range(ctx, name, ip_range): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) vdcNetwork = VdcNetwork(client, resource=routed_network) task = vdcNetwork.remove_static_ip_pool(ip_range) stdout(task, ctx) stdout('IP range of routed org vdc network is removed successfully.', ctx) except Exception as e: stderr(e, ctx)
def add_ip_ranges_of_routed_vdc_network(ctx, name, ip_ranges): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) vdcNetwork = VdcNetwork(client, resource=routed_network) task = vdcNetwork.add_static_ip_pool_and_dns(ip_ranges) stdout(task, ctx) stdout('IP ranges are added to routed org vdc network successfully.', ctx) except Exception as e: stderr(e, ctx)
def _list_connected_vapps(self, client): vdc = Environment.get_test_vdc(client) vapp_name = 'test-connected-vapp' + str(uuid1()) vdc.create_vapp( vapp_name, network=TestNetwork._routed_org_vdc_network_name) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdc_network = VdcNetwork(client, resource=org_vdc_routed_nw) connected_vapps = vdc_network.list_connected_vapps() self.assertEqual(len(connected_vapps), 1) self.assertEqual(connected_vapps[0].get('Name'), vapp_name) # Delete test vApp after test vdc.reload() vdc.delete_vapp(vapp_name)
def _list_connected_vapps(self, client): vdc = Environment.get_test_vdc(client) vapp_name = 'test-connected-vapp' + str(uuid1()) vdc.create_vapp(vapp_name, network=TestNetwork._routed_org_vdc_network_name) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdc_network = VdcNetwork(client, resource=org_vdc_routed_nw) connected_vapps = vdc_network.list_connected_vapps() self.assertEqual(len(connected_vapps), 1) self.assertEqual(connected_vapps[0].get('Name'), vapp_name) # Delete test vApp after test vdc.reload() vdc.delete_vapp(vapp_name)
def __convert_to_subinterface(self, client): vdc = Environment.get_test_vdc(client) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdc_network = VdcNetwork(client, resource=org_vdc_routed_nw) result = vdc_network.convert_to_sub_interface() task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value) # Verify vdc_network.reload_admin() reloaded_vdc_network = vdc_network.admin_resource self.assertTrue(reloaded_vdc_network.Configuration.SubInterface) # Revert to Internal Interface result = vdc_network.convert_to_internal_interface() task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value) # Verify vdc_network.reload_admin() reloaded_vdc_network = vdc_network.admin_resource self.assertFalse(reloaded_vdc_network.Configuration.SubInterface)
def edit_routed_vdc_network(ctx, name, new_vdc_routed_nw_name, description=None, is_shared=None): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) is_shared if is_shared is not None else routed_network.IsShared vdcNetwork = VdcNetwork(client, resource=routed_network) task = vdcNetwork.edit_name_description_and_shared_state( new_vdc_routed_nw_name, description, is_shared) stdout(task, ctx) stdout('Edit of routed org vdc network successfull.', ctx) except Exception as e: stderr(e, ctx)
def add_dns_of_routed_vdc_network(ctx, name, primary_dns_ip, secondary_dns_ip, dns_suffix): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) vdcNetwork = VdcNetwork(client, resource=routed_network) task = vdcNetwork.add_static_ip_pool_and_dns( primary_dns_ip=primary_dns_ip, secondary_dns_ip=secondary_dns_ip, dns_suffix=dns_suffix) stdout(task, ctx) stdout('DNS are added to routed org vdc network successfully.', ctx) except Exception as e: stderr(e, ctx)
def get_network(self, network_name=None, network_type=None): if network_name and not network_type: raise VCloudSDKException( 'The method get_network requires both network_name and ' 'network_type parameters.') elif not network_name and not self.network_name: raise VCloudSDKException( 'The method get_network requires a network_name parameter if ' 'self.network_name is not set.') if not network_name: network_name = self.network_name if not network_type: network_type = self.network_type if network_type == 'routed_vdc_network': network_resource = self.vdc.get_routed_orgvdc_network( name=network_name) elif network_type == 'isolated_vdc_network': network_resource = self.vdc.get_isolated_orgvdc_network( name=network_name) elif network_type == 'directly_connected_vdc_network': network_resource = self.vdc.get_direct_orgvdc_network( name=network_name) else: raise VCloudSDKException( 'The property network_type {network_type} is not one of ' '[\'routed_vdc_network\', ' '\'isolated_vdc_network\', ' '\'directly_connected_vdc_network\', ' '\'vapp_network\]'.format(network_type=self.network_type)) return VdcNetwork(self.client, resource=network_resource)
def test_0076_add_static_ip_pool(self): vdc = Environment.get_test_vdc(TestNetwork._client) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdcNetwork = VdcNetwork(TestNetwork._client, resource=org_vdc_routed_nw) result = vdcNetwork.add_static_ip_pool_and_dns([TestNetwork._ip_range], TestNetwork._dns1, TestNetwork._dns2, TestNetwork._dns_suffix) task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value) result = vdcNetwork.add_static_ip_pool_and_dns(None, TestNetwork._dns1, TestNetwork._dns2, TestNetwork._dns_suffix) task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value) result = vdcNetwork.add_static_ip_pool_and_dns(None, TestNetwork._dns1) task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value) result = vdcNetwork.add_static_ip_pool_and_dns(None, None, None, TestNetwork._dns_suffix) task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value) # Verify vdcNetwork.reload() vdc_routed_nw = vdcNetwork.get_resource() ip_scope = vdc_routed_nw.Configuration.IpScopes.IpScope ip_ranges = ip_scope.IpRanges.IpRange match_found = False for ip_range in ip_ranges: if (ip_range.StartAddress + '-' + ip_range.EndAddress) == \ TestNetwork._ip_range: match_found = True self.assertTrue(match_found) self.assertTrue(ip_scope.Dns1, TestNetwork._dns1) self.assertTrue(ip_scope.Dns2, TestNetwork._dns2) self.assertTrue(ip_scope.DnsSuffix, TestNetwork._dns_suffix)
def test_0075_edit_name_description_and_shared_state_for_routed_network( self): vdc = Environment.get_test_vdc(TestNetwork._client) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdcNetwork = VdcNetwork(TestNetwork._client, resource=org_vdc_routed_nw) result = vdcNetwork.edit_name_description_and_shared_state( TestNetwork._routed_org_vdc_network_new_name, 'Test ' 'Description', True) task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value) # Resetting to original name result = vdcNetwork.edit_name_description_and_shared_state( TestNetwork._routed_org_vdc_network_name, None, False) task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value)
def test_0075_edit_name_description_and_shared_state_for_routed_network( self): vdc = Environment.get_test_vdc(TestNetwork._client) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdcNetwork = VdcNetwork( TestNetwork._client, resource=org_vdc_routed_nw) result = vdcNetwork.edit_name_description_and_shared_state( TestNetwork._routed_org_vdc_network_new_name, 'Test ' 'Description', True) task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value) # Resetting to original name result = vdcNetwork.edit_name_description_and_shared_state( TestNetwork._routed_org_vdc_network_name, None, False) task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value)
def test_0077_modify_static_ip_pool(self): vdc = Environment.get_test_vdc(TestNetwork._client) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdcNetwork = VdcNetwork( TestNetwork._client, resource=org_vdc_routed_nw) result = vdcNetwork.modify_static_ip_pool(TestNetwork._ip_range, TestNetwork._new_ip_range) task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value) # Verify vdcNetwork.reload() vdc_routed_nw = vdcNetwork.get_resource() ip_scope = vdc_routed_nw.Configuration.IpScopes.IpScope ip_ranges = ip_scope.IpRanges.IpRange match_found = False for ip_range in ip_ranges: if (ip_range.StartAddress + '-' + ip_range.EndAddress) == \ TestNetwork._new_ip_range: match_found = True self.assertTrue(match_found)
def list_metadata(ctx, name): try: vdc = _get_vdc_ref(ctx) client = ctx.obj['client'] routed_network = vdc.get_routed_orgvdc_network(name) vdcNetwork = VdcNetwork(client, resource=routed_network) metadata = vdcNetwork.get_all_metadata() result = [] for metadata_entry in metadata.MetadataEntry: visibility = MetadataVisibility.READ_WRITE.value if hasattr(metadata_entry, 'Domain'): visibility = metadata_entry.Domain.get('visibility') type = metadata_entry.TypedValue.get('{' + NSMAP['xsi'] + '}type') result.append({ 'Name': metadata_entry.Key, 'Value': metadata_entry.TypedValue.Value, 'Type': type, 'User access': visibility }) stdout(result, ctx) except Exception as e: stderr(e, ctx)
def __convert_to_distributed_interface(self, client): self.__convert_enable_dr_in_gateway_using_sys_client(True) vdc = Environment.get_test_vdc(client) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdc_network = VdcNetwork(client, resource=org_vdc_routed_nw) result = vdc_network.convert_to_distributed_interface() self.__wait_for_success(client, result) # Verify vdc_network.reload_admin() reloaded_vdc_network = vdc_network.admin_resource self.assertTrue( reloaded_vdc_network.Configuration.DistributedInterface) # Revert result = vdc_network.convert_to_internal_interface() self.__wait_for_success(client, result) # Disable the distributed routing on gateway self.__convert_enable_dr_in_gateway_using_sys_client(False)
def test_0078_remove_static_ip_pool(self): vdc = Environment.get_test_vdc(TestNetwork._client) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdcNetwork = VdcNetwork( TestNetwork._client, resource=org_vdc_routed_nw) result = vdcNetwork.remove_static_ip_pool(TestNetwork._new_ip_range) task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value) # Verification vdcNetwork.reload() vdc_routed_nw = vdcNetwork.get_resource() ip_scope = vdc_routed_nw.Configuration.IpScopes.IpScope # IPRanges element will be missing if there was only one IP range if not hasattr(ip_scope, 'IpRanges'): return ip_ranges = ip_scope.IpRanges.IpRange match_found = False for ip_range in ip_ranges: if (ip_range.StartAddress + '-' + ip_range.EndAddress) == \ TestNetwork._new_ip_range: match_found = True self.assertFalse(match_found)
def __create_routed_ovdc_network(self): """Creates a routed org vdc network. :raises: Exception: if the class variable _ovdc_href is not populated. """ vdc_reource = TestIpSecVpn._vdc_resource vdc = VDC(TestIpSecVpn._client, resource=vdc_reource) routednet = vdc.create_routed_vdc_network( network_name=TestIpSecVpn._routed_network_name, gateway_name=TestIpSecVpn._gateway_name, network_cidr=TestIpSecVpn._routed_orgvdc_network_gateway_ip, description='org vdc network description') TestIpSecVpn._client.get_task_monitor() \ .wait_for_success(task=routednet.Tasks.Task[0]) TestIpSecVpn._routednet_href = routednet.get('href') TestIpSecVpn._routednet_obj = VdcNetwork( TestIpSecVpn._client, href=TestIpSecVpn._routednet_href) TestIpSecVpn._routednet_resource = TestIpSecVpn.\ _routednet_obj.get_resource()
def test_0080_routed_vdc_network_metadata(self): vdc = Environment.get_test_vdc(TestNetwork._client) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdc_network = VdcNetwork(TestNetwork._client, resource=org_vdc_routed_nw) # Test data metadata_key = "test-key1" metadata_value = "test-value1" updated_metadata_value = "updated-" + metadata_value # Testing add, update and delete metadata TestNetwork._add_routed_vdc_network_metadata(self, vdc_network, metadata_key, metadata_value) TestNetwork._update_routed_vdc_network_metadata( self, vdc_network, metadata_key, updated_metadata_value) TestNetwork._delete_routed_vcd_network_metadata( self, vdc_network, metadata_key)
def test_0078_remove_static_ip_pool(self): vdc = Environment.get_test_vdc(TestNetwork._client) org_vdc_routed_nw = vdc.get_routed_orgvdc_network( TestNetwork._routed_org_vdc_network_name) vdcNetwork = VdcNetwork(TestNetwork._client, resource=org_vdc_routed_nw) result = vdcNetwork.remove_static_ip_pool(TestNetwork._new_ip_range) task = TestNetwork._client.get_task_monitor().wait_for_success( task=result) self.assertEqual(task.get('status'), TaskStatus.SUCCESS.value) # Verification vdcNetwork.reload() vdc_routed_nw = vdcNetwork.get_resource() ip_scope = vdc_routed_nw.Configuration.IpScopes.IpScope # IPRanges element will be missing if there was only one IP range if not hasattr(ip_scope, 'IpRanges'): return ip_ranges = ip_scope.IpRanges.IpRange match_found = False for ip_range in ip_ranges: if (ip_range.StartAddress + '-' + ip_range.EndAddress) == \ TestNetwork._new_ip_range: match_found = True self.assertFalse(match_found)