def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) ironic_client = self.app.client_manager.baremetal neutron_client = self.app.client_manager.network if parsed_args.node: ports = ironic_client.port.list(node=parsed_args.node, detail=True) else: ports = ironic_client.port.list(detail=True) if parsed_args.network: filter_network = neutron_client.find_network(parsed_args.network) data = [] for port in ports: node = ironic_client.node.get(port.node_uuid) neutron_port_id = port.internal_info.get('tenant_vif_port_id') if neutron_port_id: neutron_port = neutron_client.get_port(neutron_port_id) network_id = neutron_port.network_id if not parsed_args.network or filter_network.id == network_id: network_names, _, fixed_ips \ = utils.get_full_network_info_from_port( neutron_port, neutron_client) data.append([ node.name, port.address, neutron_port.name, "\n".join(network_names), "\n".join(fixed_ips) ]) elif not parsed_args.network: data.append([node.name, port.address, None, None, None]) return ["Node", "MAC Address", "Port", "Network", "Fixed IP"], data
def test_get_full_network_info_from_port(self): port = test_utils.create_mock_object({ "id": "port_uuid", "name": "test_port", "network_id": "network_uuid_1", "fixed_ips": [{ "ip_address": '77.77.77.77' }], "trunk_details": { "trunk_id": "trunk_uuid", "sub_ports": [ { "segmentation_id": "777", "port_id": "subport_uuid_1" }, { "segmentation_id": "888", "port_id": "subport_uuid_2" }, ] } }) results = utils.get_full_network_info_from_port( port, self.neutron_client) self.assertEqual(([ 'test_network (777)', 'test_network (777)', 'test_network_2 (888)' ], ['test_port', 'test_subport_1', 'test_subport_2' ], ['77.77.77.77', '11.22.33.44', '55.66.77.88']), results)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) neutron_client = self.app.client_manager.network trunks = neutron_client.trunks() data = [] for trunk in trunks: trunk_port = neutron_client.get_port(trunk.port_id) network_names, port_names, _ \ = utils.get_full_network_info_from_port( trunk_port, neutron_client) data.append( [trunk.name, "\n".join(port_names), "\n".join(network_names)]) return ["Trunk", "Port", "Network"], data
def test_get_full_network_info_from_port_no_trunk(self): port = test_utils.create_mock_object({ "id": "port_uuid", "name": "test_port", "network_id": "network_uuid_1", "fixed_ips": [{ "ip_address": '77.77.77.77' }], "trunk_details": None }) results = utils.get_full_network_info_from_port( port, self.neutron_client) self.assertEqual( (['test_network (777)'], ['test_port'], ['77.77.77.77']), results)
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 node.provision_state == MANAGEABLE: # adopt the node node_update = [] node_revert = [] if 'image_source' not in node.instance_info: temp_image = node.driver_info['deploy_ramdisk'] node_update.append({ 'path': '/instance_info/image_source', 'value': temp_image, 'op': 'add' }) node_revert.append({ 'path': '/instance_info/image_source', 'op': 'remove' }) if 'capabilities' not in node.instance_info: node_update.append({ 'path': '/instance_info/capabilities', 'value': "{\"boot_option\": \"local\"}", 'op': 'add' }) node_revert.append({ 'path': '/instance_info/capabilities', 'op': 'remove' }) try: if len(node_update) > 0: ironic_client.node.update(node_uuid, node_update) ironic_client.node.set_provision_state(node_uuid, ADOPT) finally: if len(node_revert) > 0: ironic_client.node.update(node_uuid, node_revert) # reload node information node = ironic_client.node.get(node_uuid) if node.provision_state != ACTIVE: raise exceptions.CommandError( "ERROR: Node {0} must be in the active state".format( node.name)) 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) network = neutron_client.get_network(port.network_id) else: print("Attaching network {1} to node {0}{2}".format( node.name, network.name, mac_string)) port = neutron_client.create_port(name=node.name, network_id=network.id, device_owner='baremetal:none') 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)]
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)]