def index(self, request, tenant_id=None): filter_conditions = utils.filter_dict(request.params, 'used_by_device', 'address') if tenant_id: filter_conditions['used_by_tenant'] = tenant_id ips = models.IpAddress.find_all_allocated_ips(**filter_conditions) return self._paginated_response('ip_addresses', ips, request)
def create(self, request, ip_block_id, tenant_id, body=None): ip_block = self._find_block(id=ip_block_id, tenant_id=tenant_id) params = self._extract_required_params(body, 'subnet') subnet = ip_block.subnet(**utils.filter_dict(params, 'cidr', 'network_id', 'tenant_id')) return wsgi.Result(dict(subnet=subnet.data()), 201)
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 index(self, request): filters = utils.filter_dict(request.params, 'network_id', 'device_id', 'tenant_id') network_id = filters.pop('network_id', None) page_filter = None if network_id: # NOTE(jkoelker) network_id is a synthetic filter (aka # not a database condition). Prevent # really really bad runtime by requiring # a true filter so we arn't iterating # over every interface. This will have to # be reworked when/if we allow leasing ports # on a network. if not filters: msg = ("Filter network_id must be accompanied with " "another filter (device_id, tenant_id)") return wsgi.Result(msg, 422) page_filter = {'network_id': network_id} LOG.info("Listing all interfaces with filter: %s" % filters) interfaces = self._model.find_all(**filters) return self._paginated_response('interfaces', interfaces, request, filter=page_filter)
def index(self, request, tenant_id): LOG.info("Listing all IP blocks for tenant '%s'" % tenant_id) filters = utils.filter_dict(request.params, 'type', 'network_id') all_blocks = models.IpBlock.find_all(tenant_id=tenant_id, **filters) return self._paginated_response('ip_blocks', all_blocks, request)
def index(self, request, tenant_id): LOG.info("Listing all IP blocks for tenant '%s'" % tenant_id) type_dict = utils.filter_dict(request.params, 'type') all_blocks = models.IpBlock.find_all(tenant_id=tenant_id, **type_dict) return self._paginated_response('ip_blocks', all_blocks, request)
def test_returns_none_if_dict_is_none(self): self.assertIsNone(utils.filter_dict(None, 'key1'))
def test_filter_ignore_non_exsistant_keys(self): dictionary = {'key1': "value1", 'key2': "value2", 'key3': "value3"} self.assertEqual(utils.filter_dict(dictionary, 'key2', 'nonexistant'), {'key2': "value2"})
def test_filters_given_keys(self): dictionary = {'key1': "value1", 'key2': "value2", 'key3': "value3"} self.assertEqual(utils.filter_dict(dictionary, 'key2', 'key3'), {'key2': "value2", 'key3': "value3"})
def index(self, request, tenant_id): type_dict = utils.filter_dict(request.params, 'type') all_blocks = models.IpBlock.find_all(tenant_id=tenant_id, **type_dict) return self._paginated_response('ip_blocks', all_blocks, request)
def index(self, request, tenant_id=None): filter_conditions = utils.filter_dict(request.params, "used_by_device", "address") if tenant_id: filter_conditions["used_by_tenant"] = tenant_id ips = models.IpAddress.find_all_allocated_ips(**filter_conditions) return self._paginated_response("ip_addresses", ips, request)
def create(self, request, ip_block_id, tenant_id, body=None): ip_block = self._find_block(id=ip_block_id, tenant_id=tenant_id) params = self._extract_required_params(body, "subnet") subnet = ip_block.subnet(**utils.filter_dict(params, "cidr", "network_id", "network_name", "tenant_id")) return wsgi.Result(dict(subnet=subnet.data()), 201)
def test_filters_given_keys(self): dictionary = {'key1': "value1", 'key2': "value2", 'key3': "value3"} self.assertEqual(utils.filter_dict(dictionary, 'key2', 'key3'), { 'key2': "value2", 'key3': "value3" })