Ejemplo n.º 1
0
    def delete_network(self, tenant_id, net_id):
        """
        Deletes the network with the specified network identifier
        belonging to the specified tenant.
        """
        LOG.debug("LinuxBridgePlugin.delete_network() called")
        net = db.network_get(net_id)
        if net:
            ports_on_net = db.port_list(net_id)
            if len(ports_on_net) > 0:
                for port in ports_on_net:
                    if port[const.INTERFACEID]:
                        raise exc.NetworkInUse(net_id=net_id)
                for port in ports_on_net:
                    self.delete_port(tenant_id, net_id, port[const.UUID])

            net_dict = cutil.make_net_dict(net[const.UUID],
                                           net[const.NETWORKNAME],
                                           [], net[const.OPSTATUS])
            try:
                self._release_vlan_for_tenant(tenant_id, net_id)
                cdb.remove_vlan_binding(net_id)
            except Exception as excp:
                LOG.warning("Exception: %s" % excp)
                db.network_update(net_id, tenant_id, {const.OPSTATUS:
                                                      OperationalStatus.DOWN})
            db.network_destroy(net_id)
            return net_dict
        # Network not found
        raise exc.NetworkNotFound(net_id=net_id)
Ejemplo n.º 2
0
    def delete_network(self, tenant_id, net_id):
        """
        Deletes the network with the specified network identifier
        belonging to the specified tenant.

        :returns: a sequence of mappings with the following signature:
                    {'net-id': uuid that uniquely identifies the
                                 particular quantum network
                    }
        :raises: exception.NetworkInUse
        :raises: exception.NetworkNotFound
        """
        LOG.debug("QuantumRestProxy: delete_network() called")
        net = self.get_network(tenant_id, net_id)
        for port in db.port_list(net_id):
            if port['interface_id']:
                raise exc.NetworkInUse(net_id=net_id)

        # Delete from DB
        db.network_destroy(net_id)

        # delete from network ctrl. Remote error on delete is ignored
        try:
            resource = '/tenants/%s/networks/%s' % (tenant_id, net_id)
            ret = self.servers.delete(resource)
            if not self.servers.action_success(ret):
                raise RemoteRestError(ret[2])
        except RemoteRestError as e:
            LOG.error(
                'QuantumRestProxy: Unable to update remote network: %s' %
                e.message)

        # return deleted network
        return net
Ejemplo n.º 3
0
    def delete_network(self, tenant_id, net_id):
        """
        Deletes the network with the specified network identifier
        belonging to the specified tenant.
        """
        LOG.debug("LinuxBridgePlugin.delete_network() called")
        db.validate_network_ownership(tenant_id, net_id)
        net = db.network_get(net_id)
        if net:
            ports_on_net = db.port_list(net_id)
            if len(ports_on_net) > 0:
                for port in ports_on_net:
                    if port[const.INTERFACEID]:
                        raise exc.NetworkInUse(net_id=net_id)
                for port in ports_on_net:
                    self.delete_port(tenant_id, net_id, port[const.UUID])

            net_dict = cutil.make_net_dict(net[const.UUID],
                                           net[const.NETWORKNAME], [],
                                           net[const.OPSTATUS])
            try:
                self._release_vlan_for_tenant(tenant_id, net_id)
                cdb.remove_vlan_binding(net_id)
            except Exception as excp:
                LOG.warning("Exception: %s" % excp)
                db.network_update(net_id, tenant_id,
                                  {const.OPSTATUS: OperationalStatus.DOWN})
            db.network_destroy(net_id)
            return net_dict
        # Network not found
        raise exc.NetworkNotFound(net_id=net_id)
    def _verify_show_network_details(self):
            # Verification - get raw result from db
            nw = db.network_list(self.tenant_id)[0]
            network = {'id': nw.uuid,
                       'name': nw.name,
                       'op-status': nw.op_status}
            port_list = db.port_list(nw.uuid)
            if not port_list:
                network['ports'] = [{'id': '<none>',
                                     'state': '<none>',
                                     'attachment': {'id': '<none>'}}]
            else:
                network['ports'] = []
                for port in port_list:
                    network['ports'].append({'id': port.uuid,
                                             'state': port.state,
                                             'attachment': {'id':
                                                            port.interface_id
                                                            or '<none>'}})

            # Fill CLI template
            output = cli.prepare_output('show_net_detail',
                                        self.tenant_id,
                                        dict(network=network),
                                        self.version)
            # Verify!
            # Must add newline at the end to match effect of print call
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
Ejemplo n.º 5
0
 def _validate_attachment(self, tenant_id, network_id, port_id,
                          remote_interface_id):
     for port in db.port_list(network_id):
         if port['interface_id'] == remote_interface_id:
             raise exc.AlreadyAttached(net_id=network_id,
                                       port_id=port_id,
                                       att_id=port['interface_id'],
                                       att_port_id=port['uuid'])
Ejemplo n.º 6
0
 def validate_attachment(self, tenant_id, network_id, port_id,
                          remote_interface_id):
     for port in db.port_list(network_id):
         if port['interface_id'] == remote_interface_id:
             raise exc.AlreadyAttached(net_id=network_id,
                                       port_id=port_id,
                                       att_id=port['interface_id'],
                                       att_port_id=port['uuid'])
Ejemplo n.º 7
0
 def get_all_ports(self, tenant_id, net_id):
     ids = []
     ports = db.port_list(net_id)
     for p in ports:
         LOG.debug("Appending port: %s" % p.uuid)
         d = self._make_port_dict(str(p.uuid), p.state, p.network_id,
                                                 p.interface_id)
         ids.append(d)
     return ids
Ejemplo n.º 8
0
 def _verify_list_ports(self, network_id):
     # Verification - get raw result from db
     port_list = db.port_list(network_id)
     ports = [dict(id=port.uuid, state=port.state) for port in port_list]
     # Fill CLI template
     output = cli.prepare_output('list_ports', self.tenant_id,
                                 dict(network_id=network_id, ports=ports))
     # Verify!
     # Must add newline at the end to match effect of print call
     self.assertEquals(self.fake_stdout.make_string(), output + '\n')
Ejemplo n.º 9
0
    def delete_network(self, tenant_id, net_id):
        net = db.network_get(net_id)

        # Verify that no attachments are plugged into the network
        for port in db.port_list(net_id):
            if port.interface_id:
                raise q_exc.NetworkInUse(net_id=net_id)
        net = db.network_destroy(net_id)
        ovs_db.remove_vlan_binding(net_id)
        self.vmap.release(net_id)
        return self._make_net_dict(str(net.uuid), net.name, [])
Ejemplo n.º 10
0
    def delete_network(self, tenant_id, net_id):
        net = db.network_get(net_id)

        # Verify that no attachments are plugged into the network
        for port in db.port_list(net_id):
            if port.interface_id:
                raise q_exc.NetworkInUse(net_id=net_id)
        net = db.network_destroy(net_id)
        ovs_db.remove_vlan_binding(net_id)
        self.vmap.release(net_id)
        return self._make_net_dict(str(net.uuid), net.name, [], net.op_status)
Ejemplo n.º 11
0
    def delete_network(self, tenant_id, net_id):
        db.validate_network_ownership(tenant_id, net_id)
        net = db.network_get(net_id)

        # Verify that no attachments are plugged into the network
        for port in db.port_list(net_id):
            if port.interface_id:
                raise q_exc.NetworkInUse(net_id=net_id)
        net = db.network_destroy(net_id)
        self.driver.delete_network(net)
        return self._make_net_dict(str(net.uuid), net.name, [], net.op_status)
Ejemplo n.º 12
0
    def delete_network(self, tenant_id, net_id):
        db.validate_network_ownership(tenant_id, net_id)
        net = db.network_get(net_id)

        # Verify that no attachments are plugged into the network
        for port in db.port_list(net_id):
            if port.interface_id:
                raise q_exc.NetworkInUse(net_id=net_id)
        net = db.network_destroy(net_id)
        self.driver.delete_network(net)
        return self._make_net_dict(str(net.uuid), net.name, [], net.op_status)
Ejemplo n.º 13
0
 def _verify_delete_port(self, network_id, port_id):
     # Verification - get raw result from db
     port_list = db.port_list(network_id)
     if len(port_list) != 0:
         self.fail("DB should not contain any port")
     # Fill CLI template
     output = cli.prepare_output(
         'delete_port', self.tenant_id,
         dict(network_id=network_id, port_id=port_id))
     # Verify!
     # Must add newline at the end to match effect of print call
     self.assertEquals(self.fake_stdout.make_string(), output + '\n')
Ejemplo n.º 14
0
 def get_all_ports(self, tenant_id, net_id):
     """
     Retrieves all port identifiers belonging to the
     specified Virtual Network.
     """
     LOG.debug("FakePlugin.get_all_ports() called")
     port_ids = []
     ports = db.port_list(net_id)
     for x in ports:
         d = {'port-id': str(x.uuid)}
         port_ids.append(d)
     return port_ids
Ejemplo n.º 15
0
 def _verify_list_ports(self, network_id):
         # Verification - get raw result from db
         port_list = db.port_list(network_id)
         ports = [dict(id=port.uuid, state=port.state)
                  for port in port_list]
         # Fill CLI template
         output = cli.prepare_output('list_ports', self.tenant_id,
                                     dict(network_id=network_id,
                                          ports=ports))
         # Verify!
         # Must add newline at the end to match effect of print call
         self.assertEquals(self.fake_stdout.make_string(), output + '\n')
Ejemplo n.º 16
0
 def _verify_delete_port(self, network_id, port_id):
         # Verification - get raw result from db
         port_list = db.port_list(network_id)
         if len(port_list) != 0:
             self.fail("DB should not contain any port")
         # Fill CLI template
         output = cli.prepare_output('delete_port', self.tenant_id,
                                     dict(network_id=network_id,
                                          port_id=port_id))
         # Verify!
         # Must add newline at the end to match effect of print call
         self.assertEquals(self.fake_stdout.make_string(), output + '\n')
Ejemplo n.º 17
0
 def get_all_ports(self, tenant_id, net_id):
     """
     Retrieves all port identifiers belonging to the
     specified Virtual Network.
     """
     LOG.debug("FakePlugin.get_all_ports() called")
     port_ids = []
     ports = db.port_list(net_id)
     for x in ports:
         d = {'port-id': str(x.uuid)}
         port_ids.append(d)
     return port_ids
Ejemplo n.º 18
0
 def _verify_create_port(self, network_id):
     # Verification - get raw result from db
     port_list = db.port_list(network_id)
     if len(port_list) != 1:
         self.fail("No port created")
     port_id = port_list[0].uuid
     # Fill CLI template
     output = cli.prepare_output(
         'create_port', self.tenant_id,
         dict(network_id=network_id, port_id=port_id))
     # Verify!
     # Must add newline at the end to match effect of print call
     self.assertEquals(self.fake_stdout.make_string(), output + '\n')
Ejemplo n.º 19
0
 def _verify_create_port(self, network_id):
         # Verification - get raw result from db
         port_list = db.port_list(network_id)
         if len(port_list) != 1:
             self.fail("No port created")
         port_id = port_list[0].uuid
         # Fill CLI template
         output = cli.prepare_output('create_port', self.tenant_id,
                                     dict(network_id=network_id,
                                          port_id=port_id))
         # Verify!
         # Must add newline at the end to match effect of print call
         self.assertEquals(self.fake_stdout.make_string(), output + '\n')
Ejemplo n.º 20
0
 def get_all_ports(self, tenant_id, network_id):
     """
     Retrieves all port identifiers belonging to the
     specified Virtual Network.
     """
     LOG.debug("get_all_ports() called")
     # verify network_id
     self._get_network(tenant_id, network_id)
     ports = db.port_list(network_id)
     port_ids = []
     for x in ports:
         port_id = {'port-id': x.uuid}
         port_ids.append(port_id)
     return port_ids
Ejemplo n.º 21
0
    def get_all_ports(self, tenant_id, net_id, **kwargs):
        """
        Retrieves all port identifiers belonging to the
        specified Virtual Network.
        """
        LOG.debug("LinuxBridgePlugin.get_all_ports() called")
        network = db.network_get(net_id)
        ports_list = db.port_list(net_id)
        ports_on_net = []
        for port in ports_list:
            new_port = cutil.make_port_dict(port)
            ports_on_net.append(new_port)

        # This plugin does not perform filtering at the moment
        return ports_on_net
Ejemplo n.º 22
0
 def get_all_ports(self, net_id):
     """Get all ports."""
     ports = []
     try:
         for port in db.port_list(net_id):
             LOG.debug("Getting port: %s", port.uuid)
             port_dict = {}
             port_dict["id"] = str(port.uuid)
             port_dict["net-id"] = str(port.network_id)
             port_dict["attachment"] = port.interface_id
             port_dict["state"] = port.state
             ports.append(port_dict)
         return ports
     except Exception as exc:
         LOG.error("Failed to get all ports: %s", str(exc))
 def get_all_ports(self, net_id):
     """Get all ports"""
     ports = []
     try:
         for port in db.port_list(net_id):
             LOG.debug("Getting port: %s", port.uuid)
             port_dict = {}
             port_dict["id"] = str(port.uuid)
             port_dict["net-id"] = str(port.network_id)
             port_dict["attachment"] = port.interface_id
             port_dict["state"] = port.state
             ports.append(port_dict)
         return ports
     except Exception, exc:
         LOG.error("Failed to get all ports: %s", str(exc))
Ejemplo n.º 24
0
    def get_all_ports(self, tenant_id, net_id, **kwargs):
        """
        Retrieves all port identifiers belonging to the
        specified Virtual Network.
        """
        LOG.debug("LinuxBridgePlugin.get_all_ports() called")
        db.validate_network_ownership(tenant_id, net_id)
        ports_list = db.port_list(net_id)
        ports_on_net = []
        for port in ports_list:
            new_port = cutil.make_port_dict(port)
            ports_on_net.append(new_port)

        # This plugin does not perform filtering at the moment
        return ports_on_net
Ejemplo n.º 25
0
 def get_all_ports(self, tenant_id, net_id, **kwargs):
     """
     Retrieves all port identifiers belonging to the
     specified Virtual Network.
     """
     LOG.debug("FakePlugin.get_all_ports() called")
     filter_opts = kwargs.get('filter_opts', None)
     if not filter_opts is None and len(filter_opts) > 0:
         LOG.debug("filtering options were passed to the plugin"
                   "but the Fake plugin does not support them")
     port_ids = []
     ports = db.port_list(net_id)
     for x in ports:
         d = {'port-id': str(x.uuid)}
         port_ids.append(d)
     return port_ids
Ejemplo n.º 26
0
 def delete_network(self, tenant_id, net_id):
     """
     Deletes the network with the specified network identifier
     belonging to the specified tenant.
     """
     LOG.debug("FakePlugin.delete_network() called")
     net = self._get_network(tenant_id, net_id)
     # Verify that no attachments are plugged into the network
     if net:
         for port in db.port_list(net_id):
             if port['interface_id']:
                 raise exc.NetworkInUse(net_id=net_id)
         db.network_destroy(net_id)
         return net
     # Network not found
     raise exc.NetworkNotFound(net_id=net_id)
Ejemplo n.º 27
0
 def delete_network(self, tenant_id, net_id):
     """
     Deletes the network with the specified network identifier
     belonging to the specified tenant.
     """
     LOG.debug("FakePlugin.delete_network() called")
     net = self._get_network(tenant_id, net_id)
     # Verify that no attachments are plugged into the network
     if net:
         for port in db.port_list(net_id):
             if port['interface_id']:
                 raise exc.NetworkInUse(net_id=net_id)
         db.network_destroy(net_id)
         return net
     # Network not found
     raise exc.NetworkNotFound(net_id=net_id)
Ejemplo n.º 28
0
    def delete_network(self, tenant_id, network_id):
        """
        Deletes the network with the specified network identifier
        belonging to the specified tenant.
        """
        LOG.debug("delete_network() called")
        network = self._get_network(tenant_id, network_id)
        # Verify that the network has no port
        for port in db.port_list(network_id):
            if port:
                raise exc.NetworkInUse(network_id=network_id)

        ofn_tenant_id = self._get_ofn_tenant_id(tenant_id)
        ofn_network_id = self._get_ofn_network_id(network_id)
        self.ofn.ofn_delete_network(ofn_tenant_id, ofn_network_id)
        ndb.del_ofn_network(network_id)
        db.network_destroy(network_id)
        return {'net-id': network.uuid}
Ejemplo n.º 29
0
    def get_network_details(self, tenant_id, net_id):
        """
        retrieved a list of all the remote vifs that
        are attached to the network
        """
        LOG.debug("LinuxBridgePlugin.get_network_details() called")
        network = db.network_get(net_id)
        ports_list = db.port_list(net_id)
        ports_on_net = []
        for port in ports_list:
            new_port = cutil.make_port_dict(port)
            ports_on_net.append(new_port)

        new_network = cutil.make_net_dict(network[const.UUID],
                                          network[const.NETWORKNAME],
                                          ports_on_net,
                                          network[const.OPSTATUS])

        return new_network
Ejemplo n.º 30
0
    def get_all_ports(self, tenant_id, net_id, **kwargs):
        """
        Retrieves all port identifiers belonging to the
        specified Virtual Network.
        :param tenant_id: unique identifier for the tenant for which this
            method is going to retrieve ports
        :param net_id: unique identifiers for the network whose ports are
            about to be retrieved
        :param **kwargs: options to be passed to the plugin. The following
            keywork based-options can be specified:
            filter_opts - options for filtering network list
        :returns: a list of mapping sequences with the following signature:
                     [ {'port-id': uuid representing a particular port
                                    on the specified quantum network
                       },
                       ....
                       {'port-id': uuid representing a particular port
                                     on the specified quantum network
                       }
                    ]
        :raises: exception.NetworkNotFound
        """
        LOG.debug("QuantumRestProxy: get_all_ports() called")
        db.validate_network_ownership(tenant_id, net_id)

        filter_fn = None
        filter_opts = kwargs.get('filter_opts', None)
        if filter_opts is not None and len(filter_opts) > 0:
            filter_fn = self.filter_port
            LOG.debug("QuantumRestProxy: filter_opts ignored: %s" %
                      filter_opts)

        port_ids = []
        ports = db.port_list(net_id)
        for port in ports:
            if filter_fn is not None and \
               filter_fn(filter_opts, port) is None:
                continue
            d = {
                'port-id': str(port.uuid),
            }
            port_ids.append(d)
        return port_ids
Ejemplo n.º 31
0
    def get_network_details(self, tenant_id, net_id):
        """
        retrieved a list of all the remote vifs that
        are attached to the network
        """
        LOG.debug("LinuxBridgePlugin.get_network_details() called")
        db.validate_network_ownership(tenant_id, net_id)
        network = db.network_get(net_id)
        ports_list = db.port_list(net_id)
        ports_on_net = []
        for port in ports_list:
            new_port = cutil.make_port_dict(port)
            ports_on_net.append(new_port)

        new_network = cutil.make_net_dict(network[const.UUID],
                                          network[const.NETWORKNAME],
                                          ports_on_net,
                                          network[const.OPSTATUS])

        return new_network
Ejemplo n.º 32
0
 def get_all_ports(self, tenant_id, net_id, **kwargs):
     ids = []
     db.validate_network_ownership(tenant_id, net_id)
     ports = db.port_list(net_id)
     # This plugin does not perform filtering at the moment
     return [{'port-id': str(p.uuid)} for p in ports]
Ejemplo n.º 33
0
 def get_all_ports(self, tenant_id, net_id):
     ids = []
     ports = db.port_list(net_id)
     return [{'port-id': str(p.uuid)} for p in ports]
 def get_all_ports(self, tenant_id, net_id, **kwargs):
     ports = db.port_list(net_id)
     # This plugin does not perform filtering at the moment
     return [{'port-id': str(p.uuid)} for p in ports]
Ejemplo n.º 35
0
 def get_all_ports(self, tenant_id, net_id):
     ids = []
     ports = db.port_list(net_id)
     return [{'port-id': str(p.uuid)} for p in ports]
Ejemplo n.º 36
0
 def get_all_ports(self, tenant_id, net_id, **kwargs):
     ids = []
     db.validate_network_ownership(tenant_id, net_id)
     ports = db.port_list(net_id)
     # This plugin does not perform filtering at the moment
     return [{'port-id': str(p.uuid)} for p in ports]