Exemplo n.º 1
0
    def test_create_network(self):
        """Test brocade specific network db."""

        net_id = str(uuid.uuid4())

        # Create a network
        self.context = context.get_admin_context()
        brocade_db.create_network(self.context, net_id, TEST_VLAN)

        # Get the network and verify
        net = brocade_db.get_network(self.context, net_id)
        self.assertEqual(net['id'], net_id)
        self.assertEqual(int(net['vlan']), TEST_VLAN)

        # Delete the network
        brocade_db.delete_network(self.context, net['id'])
Exemplo n.º 2
0
    def test_create_network(self):
        """Test brocade specific network db."""

        net_id = str(uuid.uuid4())

        # Create a network
        self.context = context.get_admin_context()
        brocade_db.create_network(self.context, net_id, TEST_VLAN)

        # Get the network and verify
        net = brocade_db.get_network(self.context, net_id)
        self.assertEqual(net['id'], net_id)
        self.assertEqual(int(net['vlan']), TEST_VLAN)

        # Delete the network
        brocade_db.delete_network(self.context, net['id'])
Exemplo n.º 3
0
    def create_port(self, context, port):
        """Create logical port on the switch."""

        tenant_id = port['port']['tenant_id']
        network_id = port['port']['network_id']
        admin_state_up = port['port']['admin_state_up']

        physical_interface = self.physical_interface

        with context.session.begin(subtransactions=True):
            bnet = brocade_db.get_network(context, network_id)
            vlan_id = bnet['vlan']

            quantum_port = super(BrocadePluginV2, self).create_port(context,
                                                                    port)
            interface_mac = quantum_port['mac_address']
            port_id = quantum_port['id']

            switch = self._switch

            # convert mac format: xx:xx:xx:xx:xx:xx -> xxxx.xxxx.xxxx
            mac = self.mac_reformat_62to34(interface_mac)
            try:
                self._driver.associate_mac_to_network(switch['address'],
                                                      switch['username'],
                                                      switch['password'],
                                                      vlan_id,
                                                      mac)
            except Exception as e:
                # Proper formatting
                LOG.warning(_("Brocade NOS driver:"))
                LOG.warning(_("%s"), e)
                raise Exception("Brocade plugin raised exception, check logs")

            # save to brocade persistent db
            brocade_db.create_port(context, port_id, network_id,
                                   physical_interface,
                                   vlan_id, tenant_id, admin_state_up)

        # apply any extensions
        return self._extend_port_dict_binding(context, quantum_port)
Exemplo n.º 4
0
    def create_port(self, context, port):
        """Create logical port on the switch."""

        tenant_id = port['port']['tenant_id']
        network_id = port['port']['network_id']
        admin_state_up = port['port']['admin_state_up']

        physical_interface = self.physical_interface

        with context.session.begin(subtransactions=True):
            bnet = brocade_db.get_network(context, network_id)
            vlan_id = bnet['vlan']

            quantum_port = super(BrocadePluginV2, self).create_port(context,
                                                                    port)
            interface_mac = quantum_port['mac_address']
            port_id = quantum_port['id']

            switch = self._switch

            # convert mac format: xx:xx:xx:xx:xx:xx -> xxxx.xxxx.xxxx
            mac = self.mac_reformat_62to34(interface_mac)
            try:
                self._driver.associate_mac_to_network(switch['address'],
                                                      switch['username'],
                                                      switch['password'],
                                                      vlan_id,
                                                      mac)
            except Exception as e:
                # Proper formatting
                LOG.warning(_("Brocade NOS driver:"))
                LOG.warning(_("%s"), e)
                raise Exception("Brocade plugin raised exception, check logs")

            # save to brocade persistent db
            brocade_db.create_port(context, port_id, network_id,
                                   physical_interface,
                                   vlan_id, tenant_id, admin_state_up)

        # apply any extensions
        return self._extend_port_dict_binding(context, quantum_port)
Exemplo n.º 5
0
    def delete_network(self, context, net_id):
        """Delete network.

        This call to delete the network translates to removing the
        port-profile on the physical switch.
        """

        with context.session.begin(subtransactions=True):
            result = super(BrocadePluginV2, self).delete_network(context,
                                                                 net_id)
            # we must delete all ports in db first (foreign key constraint)
            # there is no need to delete port in the driver (its a no-op)
            # (actually: note there is no such call to the driver)
            bports = brocade_db.get_ports(context, net_id)
            for bport in bports:
                brocade_db.delete_port(context, bport['port_id'])

            # find the vlan for this network
            net = brocade_db.get_network(context, net_id)
            vlan_id = net['vlan']

            # Tell hw to do remove PP
            switch = self._switch
            try:
                self._driver.delete_network(switch['address'],
                                            switch['username'],
                                            switch['password'],
                                            net_id)
            except Exception as e:
                # Proper formatting
                LOG.warning(_("Brocade NOS driver:"))
                LOG.warning(_("%s"), e)
                raise Exception("Brocade plugin raised exception, check logs")

            # now ok to delete the network
            brocade_db.delete_network(context, net_id)

        # relinquish vlan in bitmap
        self._vlan_bitmap.release_vlan(int(vlan_id))
        return result
Exemplo n.º 6
0
    def delete_network(self, context, net_id):
        """Delete network.

        This call to delete the network translates to removing the
        port-profile on the physical switch.
        """

        with context.session.begin(subtransactions=True):
            result = super(BrocadePluginV2, self).delete_network(context,
                                                                 net_id)
            # we must delete all ports in db first (foreign key constraint)
            # there is no need to delete port in the driver (its a no-op)
            # (actually: note there is no such call to the driver)
            bports = brocade_db.get_ports(context, net_id)
            for bport in bports:
                brocade_db.delete_port(context, bport['port_id'])

            # find the vlan for this network
            net = brocade_db.get_network(context, net_id)
            vlan_id = net['vlan']

            # Tell hw to do remove PP
            switch = self._switch
            try:
                self._driver.delete_network(switch['address'],
                                            switch['username'],
                                            switch['password'],
                                            net_id)
            except Exception as e:
                # Proper formatting
                LOG.warning(_("Brocade NOS driver:"))
                LOG.warning(_("%s"), e)
                raise Exception("Brocade plugin raised exception, check logs")

            # now ok to delete the network
            brocade_db.delete_network(context, net_id)

        # relinquish vlan in bitmap
        self._vlan_bitmap.release_vlan(int(vlan_id))
        return result