Esempio n. 1
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        neutron_client = self.app.client_manager.network

        trunk_name = parsed_args.name
        network = neutron_client.find_network(parsed_args.native_network)
        tagged_networks = parsed_args.tagged_networks

        trunk_port_name = utils.get_port_name(
            network.name, prefix=trunk_name, suffix='trunk-port')
        trunk_port = utils.get_or_create_port(
            trunk_port_name, network, neutron_client)

        sub_ports = []
        for tagged_network_name in tagged_networks:
            tagged_network = neutron_client.find_network(
                tagged_network_name)
            sub_port_name = utils.get_port_name(
                tagged_network.name, prefix=trunk_name, suffix='sub-port')
            sub_port = utils.get_or_create_port(
                sub_port_name, tagged_network, neutron_client)
            sub_ports.append({
                'port_id': sub_port.id,
                'segmentation_type': 'vlan',
                'segmentation_id': tagged_network.provider_segmentation_id
            })

        trunk = neutron_client.create_trunk(
            name=trunk_name,
            port_id=trunk_port.id,
            sub_ports=sub_ports
        )

        return ["Trunk", "Port", "Sub Ports"], \
            [trunk.name,
             trunk_port.name,
             trunk.sub_ports]
Esempio n. 2
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        tagged_networks = parsed_args.tagged_networks

        if len(tagged_networks) == 0:
            raise exceptions.CommandError(
                "ERROR: no networks specified")

        neutron_client = self.app.client_manager.network
        trunk = neutron_client.find_trunk(parsed_args.name)

        if trunk is None:
            raise exceptions.CommandError(
                "ERROR: no trunk named {0}".format(parsed_args.name))

        sub_ports = []
        for tagged_network_name in tagged_networks:
            tagged_network = neutron_client.find_network(
                tagged_network_name)

            if tagged_network is None:
                raise exceptions.CommandError(
                    "ERROR: no network named {0}".format(tagged_network_name))

            sub_port_name = utils.get_port_name(
                tagged_network.name, prefix=trunk.name, suffix='sub-port')
            sub_port = utils.get_or_create_port(
                sub_port_name, tagged_network, neutron_client)
            sub_ports.append({
                'port_id': sub_port.id,
                'segmentation_type': 'vlan',
                'segmentation_id': tagged_network.provider_segmentation_id
            })

        trunk = neutron_client.add_trunk_subports(
            trunk.id,
            sub_ports
        )

        return ["Trunk", "Sub Ports"], \
            [trunk.name,
             trunk.sub_ports]
Esempio n. 3
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        tagged_networks = parsed_args.tagged_networks

        if len(tagged_networks) == 0:
            raise exceptions.CommandError(
                "ERROR: no networks specified")

        neutron_client = self.app.client_manager.network
        trunk = neutron_client.find_trunk(parsed_args.name)

        if trunk is None:
            raise exceptions.CommandError(
                "ERROR: no trunk named {0}".format(parsed_args.name))

        sub_ports = []
        for tagged_network_name in tagged_networks:
            sub_port_name = utils.get_port_name(
                tagged_network_name, prefix=trunk.name, suffix='sub-port')

            sub_port = neutron_client.find_port(sub_port_name)
            if not sub_port:
                raise exceptions.CommandError(
                    "ERROR: {1} is not attached to {0}".format(
                        trunk.name, tagged_network_name))
            sub_ports.append({
                'port_id': sub_port.id,
            })

        trunk = neutron_client.delete_trunk_subports(
            trunk.id,
            sub_ports
        )
        for sub_port in sub_ports:
            neutron_client.delete_port(sub_port['port_id'])

        return ["Trunk", "Sub Ports"], \
            [trunk.name,
             trunk.sub_ports]
Esempio n. 4
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        node_uuid = parsed_args.node
        volume_uuid = parsed_args.volume

        if parsed_args.network and parsed_args.port:
            raise exceptions.CommandError(
                "ERROR: Specify only one of network or port")
        if not parsed_args.network and not parsed_args.port:
            raise exceptions.CommandError(
                "ERROR: You must specify either network or port")

        ironic_client = self.app.client_manager.baremetal
        neutron_client = self.app.client_manager.network
        cinder_client = self.app.client_manager.volume

        if parsed_args.network:
            network = neutron_client.find_network(parsed_args.network)
            port = None
        elif parsed_args.port:
            port = neutron_client.find_port(parsed_args.port)

        node = ironic_client.node.get(node_uuid)
        if uuidutils.is_uuid_like(volume_uuid):
            volume = cinder_client.volumes.get(volume_uuid)
        else:
            volume = cinder_client.volumes.find(name=volume_uuid)

        # check node state
        if node.provision_state != AVAILABLE:
            raise exceptions.CommandError(
                "ERROR: Node {0} must be in the available state".format(
                    node.name))

        # check volume state
        if volume.status != AVAILABLE:
            raise exceptions.CommandError(
                "ERROR: Volume {0} must be in the available state".format(
                    volume.name))

        # check node ports
        baremetal_ports = ironic_client.port.list(node=node_uuid, detail=True)
        has_free_port = False
        for bp in baremetal_ports:
            if 'tenant_vif_port_id' not in bp.internal_info:
                has_free_port = True
                break

        if not has_free_port:
            raise exceptions.CommandError(
                "ERROR: Node {0} has no free ports".format(node.name))

        # set baremetal node storage interface and capabilities
        node_update = [{
            'path': '/instance_info/storage_interface',
            'value': 'cinder',
            'op': 'add'
        }, {
            'path': '/instance_info/capabilities',
            'value': "{\"iscsi_boot\": \"True\"}",
            'op': 'add'
        }]
        ironic_client.node.update(node_uuid, node_update)

        # delete old volume connectors; create new one
        vcs = ironic_client.volume_connector.list(node=node_uuid, )
        for vc in vcs:
            ironic_client.volume_connector.delete(vc.uuid)
        connector_id = 'iqn.%s.org.openstack.%s' % (
            datetime.now().strftime('%Y-%m'), uuidutils.generate_uuid())
        ironic_client.volume_connector.create(
            node_uuid=node.uuid,
            type='iqn',
            connector_id=connector_id,
        )

        # create volume target if needed
        vts = [
            vt.volume_id
            for vt in ironic_client.volume_target.list(node=node_uuid,
                                                       fields=['volume_id'])
        ]
        if volume.id not in vts:
            ironic_client.volume_target.create(
                node_uuid=node.uuid,
                volume_id=volume.id,
                volume_type='iscsi',
                boot_index=0,
            )

        # attach node to storage network
        if not port:
            # create port if needed
            port_name = utils.get_port_name(network.name,
                                            prefix=node.name,
                                            suffix='volume')
            port = utils.get_or_create_port(port_name, network, neutron_client)

        ironic_client.node.vif_attach(node_uuid, port.id)

        # deploy
        ironic_client.node.set_provision_state(node_uuid, ACTIVE)

        return ["Node", "Volume"], [node.name, volume.name]
Esempio n. 5
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        node_uuid = parsed_args.node
        if parsed_args.network and parsed_args.port:
            raise exceptions.CommandError(
                "ERROR: Specify only one of network or port")
        if not parsed_args.network and not parsed_args.port:
            raise exceptions.CommandError(
                "ERROR: You must specify either network or port")

        ironic_client = self.app.client_manager.baremetal
        neutron_client = self.app.client_manager.network

        if parsed_args.network:
            network = neutron_client.find_network(parsed_args.network)
            port = None
        elif parsed_args.port:
            port = neutron_client.find_port(parsed_args.port)

        node = ironic_client.node.get(node_uuid)

        if parsed_args.mac_address:
            bp = ironic_client.port.get_by_address(parsed_args.mac_address)
            vif_info = {'port_uuid': bp.uuid}
            mac_string = " on {0}".format(parsed_args.mac_address)
        else:
            vif_info = {}
            mac_string = ""

            baremetal_ports = ironic_client.port.list(node=node_uuid,
                                                      detail=True)
            has_free_port = False
            for bp in baremetal_ports:
                if 'tenant_vif_port_id' not in bp.internal_info:
                    has_free_port = True
                    break

            if not has_free_port:
                raise exceptions.CommandError(
                    "ERROR: Node {0} has no free ports".format(node.name))

        if port:
            print("Attaching port {1} to node {0}{2}".format(
                node.name, port.name, mac_string))
            ironic_client.node.vif_attach(node_uuid, port.id, **vif_info)
        else:
            print("Attaching network {1} to node {0}{2}".format(
                node.name, network.name, mac_string))
            port_name = utils.get_port_name(network.name, prefix=node.name)
            port = utils.get_or_create_port(port_name, network, neutron_client)
            ironic_client.node.vif_attach(node_uuid, port.id, **vif_info)
            port = neutron_client.get_port(port.id)

        network_names, _, fixed_ips \
            = utils.get_full_network_info_from_port(
                port, neutron_client)

        return ["Node", "MAC Address", "Port", "Network", "Fixed IP"], \
            [node.name, port.mac_address, port.name,
             "\n".join(network_names),
             "\n".join(fixed_ips)]
Esempio n. 6
0
 def test_get_port_name_prefix_and_suffix(self):
     name = utils.get_port_name(self.network.name,
                                prefix='foo',
                                suffix='bar')
     self.assertEqual('esi-foo-test_network-bar', name)
Esempio n. 7
0
 def test_get_port_name_suffix(self):
     name = utils.get_port_name(self.network.name, suffix='bar')
     self.assertEqual('esi-test_network-bar', name)
Esempio n. 8
0
 def test_get_port_name_prefix(self):
     name = utils.get_port_name(self.network.name, prefix='foo')
     self.assertEqual('esi-foo-test_network', name)
Esempio n. 9
0
 def test_get_port_name(self):
     name = utils.get_port_name(self.network.name)
     self.assertEqual('esi-test_network', name)