def create(self, request, body, device_id, interface_id): params = self._extract_required_params(body, 'network') interface = models.Interface.find_by(id=interface_id, device_id=device_id) network = models.Network.find_by(params.pop('id'), tenant_id=params.pop('tenant_id')) ips = network.allocate_ips(interface=interface, **params) ip_config_view = views.IpConfigurationView(*ips) return wsgi.Result(dict(ip_addresses=ip_config_view.data()), 201)
def test_data_returns_deallocated_ip_info(self): block = factory_models.IpBlockFactory() interface = factory_models.InterfaceFactory(vif_id_on_device="123") ip = factory_models.IpAddressFactory(ip_block_id=block.id, interface_id=interface.id) ip.deallocate() deallocated_ip = models.IpAddress.find(ip.id) expected_ip_config = _ip_data(deallocated_ip, block) ip_configuration_view = views.IpConfigurationView(deallocated_ip) self.assertEqual(expected_ip_config, ip_configuration_view.data()[0])
def test_data_returns_ip_address_configuration_information(self): interface = factory_models.InterfaceFactory() ip1 = factory_models.IpAddressFactory(interface_id=interface.id) ip2 = factory_models.IpAddressFactory(interface_id=interface.id) data = views.InterfaceConfigurationView(interface).data() self.assertEqual(len(data['ip_addresses']), 2) self.assertItemsEqual(data['ip_addresses'], views.IpConfigurationView(ip1, ip2).data())
def test_data_returns_route_info(self): block = factory_models.IpBlockFactory() interface = factory_models.InterfaceFactory(vif_id_on_device="123") route1 = factory_models.IpRouteFactory(source_block_id=block.id) route2 = factory_models.IpRouteFactory(source_block_id=block.id) ip = factory_models.IpAddressFactory(ip_block_id=block.id, interface_id=interface.id) expected_ip_config_routes = [_route_data(route1), _route_data(route2)] ip_configuration_view = views.IpConfigurationView(ip).data()[0] ip1_config_routes = ip_configuration_view['ip_block'].pop('ip_routes') self.assertItemsEqual(expected_ip_config_routes, ip1_config_routes)
def create(self, request, network_id, interface_id, tenant_id, body=None): network = models.Network.find_or_create_by(network_id, tenant_id) params = self._extract_required_params(body, 'network') network_params = utils.filter_dict(params, "addresses") interface = models.Interface.find_or_configure( virtual_interface_id=interface_id, tenant_id=params.get('tenant_id', tenant_id), device_id=params.get('used_by_device', None), mac_address=params.get('mac_address', None)) ips = network.allocate_ips(interface=interface, **network_params) ip_config_view = views.IpConfigurationView(*ips) return wsgi.Result(dict(ip_addresses=ip_config_view.data()), 201)
def test_data_returns_block_ip_info(self): block1 = factory_models.IpBlockFactory() block2 = factory_models.IpBlockFactory() interface = factory_models.InterfaceFactory(vif_id_on_device="123") ip1 = factory_models.IpAddressFactory(ip_block_id=block1.id, interface_id=interface.id) ip2 = factory_models.IpAddressFactory(ip_block_id=block2.id, interface_id=interface.id) expected_ip1_config = _ip_data(ip1, block1) expected_ip2_config = _ip_data(ip2, block2) ip_configuration_view = views.IpConfigurationView(ip1, ip2) self.assertEqual(expected_ip1_config, ip_configuration_view.data()[0]) self.assertEqual(expected_ip2_config, ip_configuration_view.data()[1])
def index(self, request, network_id, interface_id, tenant_id): network = models.Network.find_by(id=network_id, tenant_id=tenant_id) interface = models.Interface.find_by(vif_id_on_device=interface_id) ips_on_interface = network.allocated_ips(interface_id=interface.id) ip_configuration_view = views.IpConfigurationView(*ips_on_interface) return dict(ip_addresses=ip_configuration_view.data())