diff options
author | Vasyl Saienko <vsaienko@mirantis.com> | 2016-05-17 13:59:39 +0300 |
---|---|---|
committer | Vladyslav Drok <vdrok@mirantis.com> | 2016-07-12 19:08:07 +0300 |
commit | cde11611d93946a1c79e406dc429aa5e742da729 (patch) | |
tree | 9eb33e34012373f15f5076c0562c7bc05fde79a4 /ironic/dhcp | |
parent | 1825267b3a47ea9f82008a40dd90f0f4946bfd52 (diff) | |
download | ironic-cde11611d93946a1c79e406dc429aa5e742da729.tar.gz |
Add network interface to base driver class
This change also introduces two network interfaces:
* flat: Copies current neutron DHCP provider logic to work with
cleaning ports;
* noop: noop interface.
The default value of the network_interface is None, meaning that the
node will be using the default network interface. The default network
interface is determined the following way:
* if [DEFAULT]default_network_interface configuration option is set
(the default for it is None), the specified interface becomes the
default for all nodes;
* if it is not set, 'flat' interface will be used if the deployment
currently uses 'neutron' DHCP provider, otherwise 'noop' interface
will be used.
create_cleaning_ports and delete_cleaning_ports methods of the DHCP
providers are still being called in case of out-of-tree DHCP
providers, but this possibility will be removed completely in the
next release. If the DHCP provider logic is rewritten into a custom
network interface, please remove those methods from the provider, so
that network interface is called instead.
Partial-bug: #1526403
Co-Authored-By: Om Kumar <om.kumar@hp.com>
Co-Authored-By: Vasyl Saienko <vsaienko@mirantis.com>
Co-Authored-By: Sivaramakrishna Garimella <sivaramakrishna.garimella@hp.com>
Co-Authored-By: Vladyslav Drok <vdrok@mirantis.com>
Co-Authored-By: Zhenguo Niu <Niu.ZGlinux@gmail.com>
Change-Id: I0c26582b6b6e9d32650ff3e2b9a3269c3c2d5454
Diffstat (limited to 'ironic/dhcp')
-rw-r--r-- | ironic/dhcp/neutron.py | 105 |
1 files changed, 25 insertions, 80 deletions
diff --git a/ironic/dhcp/neutron.py b/ironic/dhcp/neutron.py index 15935a491..084300d1a 100644 --- a/ironic/dhcp/neutron.py +++ b/ironic/dhcp/neutron.py @@ -34,6 +34,9 @@ from ironic import objects CONF = cfg.CONF LOG = logging.getLogger(__name__) +create_cleaning_ports_deprecation = False +delete_cleaning_ports_deprecation = False + class NeutronDHCPApi(base.BaseDHCP): """API for communicating to neutron 2.x API.""" @@ -271,95 +274,37 @@ class NeutronDHCPApi(base.BaseDHCP): return port_ip_addresses + portgroup_ip_addresses + # TODO(vsaienko) Remove this method when deprecation period is passed + # in Ocata. def create_cleaning_ports(self, task): """Create neutron ports for each port on task.node to boot the ramdisk. :param task: a TaskManager instance. - :raises: InvalidParameterValue if the cleaning network is None + :raises: NetworkError, InvalidParameterValue :returns: a dictionary in the form {port.uuid: neutron_port['id']} """ - if not CONF.neutron.cleaning_network_uuid: - raise exception.InvalidParameterValue(_('Valid cleaning network ' - 'UUID not provided')) - neutron_client = neutron.get_client(task.context.auth_token) - body = { - 'port': { - 'network_id': CONF.neutron.cleaning_network_uuid, - 'admin_state_up': True, - } - } - ports = {} - for ironic_port in task.ports: - body['port']['mac_address'] = ironic_port.address - try: - port = neutron_client.create_port(body) - except neutron_client_exc.ConnectionFailed as e: - self._rollback_cleaning_ports(task) - msg = (_('Could not create cleaning port on network %(net)s ' - 'from %(node)s. %(exc)s') % - {'net': CONF.neutron.cleaning_network_uuid, - 'node': task.node.uuid, - 'exc': e}) - LOG.exception(msg) - raise exception.NodeCleaningFailure(msg) - if not port.get('port') or not port['port'].get('id'): - self._rollback_cleaning_ports(task) - msg = (_('Failed to create cleaning ports for node ' - '%(node)s') % {'node': task.node.uuid}) - LOG.error(msg) - raise exception.NodeCleaningFailure(msg) - # Match return value of get_node_vif_ids() - ports[ironic_port.uuid] = port['port']['id'] - return ports + global create_cleaning_ports_deprecation + if not create_cleaning_ports_deprecation: + LOG.warning(_LW('create_cleaning_ports via dhcp provider is ' + 'deprecated. The node.network_interface setting ' + 'should be used instead.')) + create_cleaning_ports_deprecation = True + return task.driver.network.add_cleaning_network(task) + + # TODO(vsaienko) Remove this method when deprecation period is passed + # in Ocata. def delete_cleaning_ports(self, task): """Deletes the neutron port created for booting the ramdisk. :param task: a TaskManager instance. + :raises: NetworkError, InvalidParameterValue """ - neutron_client = neutron.get_client(task.context.auth_token) - macs = [p.address for p in task.ports] - params = { - 'network_id': CONF.neutron.cleaning_network_uuid - } - try: - ports = neutron_client.list_ports(**params) - except neutron_client_exc.ConnectionFailed as e: - msg = (_('Could not get cleaning network vif for %(node)s ' - 'from Neutron, possible network issue. %(exc)s') % - {'node': task.node.uuid, - 'exc': e}) - LOG.exception(msg) - raise exception.NodeCleaningFailure(msg) - - # Iterate the list of Neutron port dicts, remove the ones we added - for neutron_port in ports.get('ports', []): - # Only delete ports using the node's mac addresses - if neutron_port.get('mac_address') in macs: - try: - neutron_client.delete_port(neutron_port.get('id')) - except neutron_client_exc.ConnectionFailed as e: - msg = (_('Could not remove cleaning ports on network ' - '%(net)s from %(node)s, possible network issue. ' - '%(exc)s') % - {'net': CONF.neutron.cleaning_network_uuid, - 'node': task.node.uuid, - 'exc': e}) - LOG.exception(msg) - raise exception.NodeCleaningFailure(msg) - - def _rollback_cleaning_ports(self, task): - """Attempts to delete any ports created by cleaning - - Purposefully will not raise any exceptions so error handling can - continue. - - :param task: a TaskManager instance. - """ - try: - self.delete_cleaning_ports(task) - except Exception: - # Log the error, but let the caller invoke the - # manager.cleaning_error_handler(). - LOG.exception(_LE('Failed to rollback cleaning port ' - 'changes for node %s') % task.node.uuid) + global delete_cleaning_ports_deprecation + if not delete_cleaning_ports_deprecation: + LOG.warning(_LW('delete_cleaning_ports via dhcp provider is ' + 'deprecated. The node.network_interface setting ' + 'should be used instead.')) + delete_cleaning_ports_deprecation = True + + task.driver.network.remove_cleaning_network(task) |