コード例 #1
0
ファイル: service.py プロジェクト: j2sol/melange
 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)
コード例 #2
0
ファイル: service.py プロジェクト: pombredanne/melange
 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)
コード例 #3
0
ファイル: service.py プロジェクト: OpenStack-Kha/melange
 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)
コード例 #4
0
ファイル: service.py プロジェクト: pombredanne/melange
 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)
コード例 #5
0
ファイル: service.py プロジェクト: blackantcloud/melange
    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)
コード例 #6
0
ファイル: service.py プロジェクト: j2sol/melange
    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)
コード例 #7
0
ファイル: service.py プロジェクト: j2sol/melange
 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)
コード例 #8
0
ファイル: service.py プロジェクト: j2sol/melange
 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)
コード例 #9
0
ファイル: service.py プロジェクト: blackantcloud/melange
 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)
コード例 #10
0
ファイル: test_utils.py プロジェクト: AsherBond/melange
 def test_returns_none_if_dict_is_none(self):
     self.assertIsNone(utils.filter_dict(None, 'key1'))
コード例 #11
0
ファイル: test_utils.py プロジェクト: pombredanne/melange
 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"})
コード例 #12
0
ファイル: test_utils.py プロジェクト: AsherBond/melange
 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"})
コード例 #13
0
ファイル: service.py プロジェクト: markmc/melange
 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)
コード例 #14
0
ファイル: service.py プロジェクト: Cerberus98/melange
 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)
コード例 #15
0
ファイル: service.py プロジェクト: Cerberus98/melange
 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)
コード例 #16
0
ファイル: test_utils.py プロジェクト: pombredanne/melange
 def test_returns_none_if_dict_is_none(self):
     self.assertIsNone(utils.filter_dict(None, 'key1'))
コード例 #17
0
ファイル: test_utils.py プロジェクト: AsherBond/melange
 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"})
コード例 #18
0
ファイル: test_utils.py プロジェクト: pombredanne/melange
 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"
     })