Example #1
0
 def create(self, request, device_id, body=None):
     iface_params = self._extract_required_params(body, "interface")
     network_params = utils.stringify_keys(iface_params.pop("network", None))
     interface = models.Interface.create_and_allocate_ips(
         device_id=device_id, network_params=network_params, **iface_params
     )
     view_data = views.InterfaceConfigurationView(interface).data()
     return dict(interface=view_data)
Example #2
0
 def create(self, request, device_id, body=None):
     iface_params = self._extract_required_params(body, 'interface')
     network_params = utils.stringify_keys(iface_params.pop(
         'network', None))
     interface = models.Interface.create_and_allocate_ips(
         device_id=device_id, network_params=network_params, **iface_params)
     view_data = views.InterfaceConfigurationView(interface).data()
     return dict(interface=view_data)
Example #3
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)
Example #4
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)
Example #5
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))
        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)
Example #6
0
    def create(self, request, device_id, body=None):
        iface_params = self._extract_required_params(body, 'interface')
        network_params = utils.stringify_keys(iface_params.pop('network',
                                                               None))
        try:
            interface = models.Interface.create_and_allocate_ips(
                device_id=device_id,
                network_params=network_params,
                **iface_params)
        except models.NetworkOverQuotaError as exc:
            return wsgi.Result("Network %s Over Quota" % exc, 413)

        view_data = views.InterfaceConfigurationView(interface).data()
        return dict(interface=view_data)
Example #7
0
    def update_all(self, request, device_id, body=None):
        models.Interface.delete_by(device_id=device_id)

        params = self._extract_required_params(body, "instance")
        tenant_id = params["tenant_id"]
        created_interfaces = []
        for iface in params["interfaces"]:

            network_params = utils.stringify_keys(iface.pop("network", None))
            interface = models.Interface.create_and_allocate_ips(
                device_id=device_id, network_params=network_params, tenant_id=tenant_id, **iface
            )

            view_data = views.InterfaceConfigurationView(interface).data()
            created_interfaces.append(view_data)

        return {"instance": {"interfaces": created_interfaces}}
Example #8
0
    def update_all(self, request, device_id, body=None):
        models.Interface.delete_by(device_id=device_id)

        params = self._extract_required_params(body, 'instance')
        tenant_id = params['tenant_id']
        created_interfaces = []
        for iface in params['interfaces']:

            network_params = utils.stringify_keys(iface.pop('network', None))
            interface = models.Interface.create_and_allocate_ips(
                device_id=device_id,
                network_params=network_params,
                tenant_id=tenant_id,
                **iface)

            view_data = views.InterfaceConfigurationView(interface).data()
            created_interfaces.append(view_data)

        return {'instance': {'interfaces': created_interfaces}}
Example #9
0
    def update(self, request, device_id, body=None):
        models.Interface.delete_by(device_id=device_id)

        params = self._extract_required_params(body, 'instance')
        tenant_id = params['tenant_id']
        created_interfaces = []
        for iface in params['interfaces']:

            network_params = utils.stringify_keys(iface.pop('network', None))
            interface = models.Interface.create_and_configure(
                    device_id=device_id, tenant_id=tenant_id, **iface)

            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()
            created_interfaces.append(view_data)

        return {'instance': {'interfaces': created_interfaces}}
Example #10
0
    def update_all(self, request, device_id, body=None):
        models.Interface.delete_by(device_id=device_id)

        params = self._extract_required_params(body, 'instance')
        tenant_id = params['tenant_id']
        created_interfaces = []
        try:
            for iface in params['interfaces']:

                network_params = utils.stringify_keys(iface.pop('network',
                                                                None))
                interface = models.Interface.create_and_allocate_ips(
                    device_id=device_id,
                    network_params=network_params,
                    tenant_id=tenant_id,
                    **iface)

                view_data = views.InterfaceConfigurationView(interface).data()
                created_interfaces.append(view_data)
        except models.NetworkOverQuotaError as exc:
            return wsgi.Result("Network %s Over Quota" % exc, 413)

        return {'instance': {'interfaces': created_interfaces}}
Example #11
0
 def params(self):
     return utils.stringify_keys(super(Request, self).params)
Example #12
0
 def params(self):
     return utils.stringify_keys(super(Request, self).params)
Example #13
0
 def _extract_required_params(self, params, model_name):
     params = params or {}
     model_params = params.get(model_name, {})
     return utils.stringify_keys(
         utils.exclude(model_params, *self.exclude_attr))
Example #14
0
 def test_returns_none_if_dict_is_none(self):
     self.assertIsNone(utils.stringify_keys(None))
Example #15
0
 def test_returns_none_if_dict_is_none(self):
     self.assertIsNone(utils.stringify_keys(None))
Example #16
0
    def test_converts_keys_to_string(self):
        dictionary = {u'key1': "value1", 'key2': u"value2"}
        converted_dictionary = utils.stringify_keys(dictionary)

        for key in converted_dictionary:
            self.assertEqual(type(key), str)
Example #17
0
 def _extract_required_params(self, params, model_name):
     params = params or {}
     model_params = params.get(model_name, {})
     return utils.stringify_keys(utils.exclude(model_params,
                                               *self.exclude_attr))
Example #18
0
    def test_converts_keys_to_string(self):
        dictionary = {u'key1': "value1", 'key2': u"value2"}
        converted_dictionary = utils.stringify_keys(dictionary)

        for key in converted_dictionary:
            self.assertEqual(type(key), str)