示例#1
0
 def create(self, request, tenant_id, source_block_id, body=None):
     source_block = models.IpBlock.find_by(id=source_block_id,
                                           tenant_id=tenant_id)
     params = self._extract_required_params(body, 'ip_route')
     ip_route = models.IpRoute.create(source_block_id=source_block.id,
                                      **params)
     return wsgi.Result(dict(ip_route=ip_route.data()), 201)
示例#2
0
 def update(self, request, id, tenant_id, body=None):
     LOG.info("Updating IP block %(id)s for %(tenant_id)s" % locals())
     ip_block = self._find_block(id=id, tenant_id=tenant_id)
     params = self._extract_required_params(body, 'ip_block')
     ip_block.update(**utils.exclude(params, 'cidr', 'type'))
     LOG.debug("Updated IP block %(id)s parameters: %(params)s" % locals())
     return wsgi.Result(dict(ip_block=ip_block.data()), 200)
示例#3
0
    def _paginated_response(self, collection_type, collection_query, request):
        elements, next_marker = collection_query.paginated_collection(
            **self._extract_limits(request.params))
        collection = [element.data() for element in elements]

        return wsgi.Result(
            pagination.PaginatedDataView(collection_type, collection,
                                         request.url, next_marker))
示例#4
0
 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
 def create(self, request, interface_id, tenant_id, body=None):
     params = self._extract_required_params(body, 'allowed_ip')
     interface = models.Interface.find_by(vif_id_on_device=interface_id,
                                          tenant_id=tenant_id)
     network = models.Network.find_by(id=params['network_id'])
     ip = network.find_allocated_ip(address=params['ip_address'],
                                    used_by_tenant_id=tenant_id)
     interface.allow_ip(ip)
     return wsgi.Result(dict(ip_address=ip.data()), 201)
示例#6
0
 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)
示例#7
0
    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, 'ip_address')

        interface = models.Interface.find_or_configure(
            virtual_interface_id=params.pop('interface_id', None),
            device_id=params.pop('used_by_device', None),
            tenant_id=params.pop('tenant_id', tenant_id),
            mac_address=params.pop('mac_address', None))

        ip_address = ip_block.allocate_ip(interface=interface, **params)
        return wsgi.Result(dict(ip_address=ip_address.data()), 201)
示例#8
0
    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)
示例#9
0
    def create(self, request, body=None):
        params = self._extract_required_params(body, 'interface')
        params['virtual_interface_id'] = params.pop('id', None)
        network_params = utils.stringify_keys(params.pop('network', None))
        LOG.debug("Creating interface with parameters: %s" % params)
        interface = models.Interface.create_and_configure(**params)

        if network_params:
            network = models.Network.find_or_create_by(
                network_params.pop('id'), network_params.pop('tenant_id'))
            network.allocate_ips(interface=interface, **network_params)

        view_data = views.InterfaceConfigurationView(interface).data()
        return wsgi.Result(dict(interface=view_data), 201)
示例#10
0
 def index(self, request):
     """Respond to a request for all OpenStack API versions."""
     versions = [Version("v0.1", "CURRENT", request.application_url)]
     return wsgi.Result(VersionsDataView(versions))
示例#11
0
 def test_data_returns_json_specific_input_data(self):
     self.assertEqual(wsgi.Result(self.TestData()).data("application/json"),
                      {'foo': "bar", 'foo2': "bar2"})
示例#12
0
 def test_data_returns_xml_specific_input_data(self):
     self.assertEqual(wsgi.Result(self.TestData()).data("application/xml"),
                      {'foos': [{'foo': "bar"}, {'foo2': "bar2"}]})
示例#13
0
 def test_data_returns_back_input_data(self):
     self.assertEqual(wsgi.Result("blah").data("application/json"), "blah")
     self.assertEqual(wsgi.Result({'x': "blah"}).data("application/json"),
                      {'x': "blah"})
     self.assertEqual(wsgi.Result(["x", "blah"]).data("application/xml"),
                      ["x", "blah"])
示例#14
0
 def create(self, request, policy_id, tenant_id, body=None):
     policy = models.Policy.find_by(id=policy_id, tenant_id=tenant_id)
     params = self._extract_required_params(body, 'ip_octet')
     ip_octet = policy.create_unusable_ip_octet(**params)
     return wsgi.Result(dict(ip_octet=ip_octet.data()), 201)
示例#15
0
 def create(self, request, tenant_id, body=None):
     params = self._extract_required_params(body, 'policy')
     policy = models.Policy.create(tenant_id=tenant_id, **params)
     return wsgi.Result(dict(policy=policy.data()), 201)
示例#16
0
 def create(self, request, body=None):
     params = self._extract_required_params(body, 'mac_address_range')
     LOG.info("Creating MAC address range: %s" % params)
     mac_range = models.MacAddressRange.create(**params)
     return wsgi.Result(dict(mac_address_range=mac_range.data()), 201)
示例#17
0
 def create(self, request, tenant_id, body=None):
     LOG.info("Creating an IP block for tenant '%s'" % tenant_id)
     params = self._extract_required_params(body, 'ip_block')
     block = models.IpBlock.create(tenant_id=tenant_id, **params)
     LOG.debug("New IP block parameters: %s" % params)
     return wsgi.Result(dict(ip_block=block.data()), 201)