"Fossies" - the Fresh Open Source Software Archive

Member "ironic-16.0.3/ironic/drivers/modules/pxe.py" (18 Jan 2021, 4880 Bytes) of package /linux/misc/openstack/ironic-16.0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "pxe.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 16.0.2_vs_16.0.3.

    1 # Copyright 2013 Hewlett-Packard Development Company, L.P.
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 # not use this file except in compliance with the License. You may obtain
    5 # a copy of the License at
    6 #
    7 #      http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 # License for the specific language governing permissions and limitations
   13 # under the License.
   14 """
   15 PXE Boot Interface
   16 """
   17 
   18 from ironic_lib import metrics_utils
   19 from oslo_log import log as logging
   20 
   21 from ironic.common import exception
   22 from ironic.common.i18n import _
   23 from ironic.common import states
   24 from ironic.conductor import task_manager
   25 from ironic.conductor import utils as manager_utils
   26 from ironic.drivers import base
   27 from ironic.drivers.modules import agent_base
   28 from ironic.drivers.modules import deploy_utils
   29 from ironic.drivers.modules import pxe_base
   30 LOG = logging.getLogger(__name__)
   31 
   32 METRICS = metrics_utils.get_metrics_logger(__name__)
   33 
   34 
   35 class PXEBoot(pxe_base.PXEBaseMixin, base.BootInterface):
   36 
   37     capabilities = ['ramdisk_boot', 'pxe_boot']
   38 
   39 
   40 class PXERamdiskDeploy(agent_base.AgentBaseMixin, agent_base.HeartbeatMixin,
   41                        base.DeployInterface):
   42 
   43     def get_properties(self, task):
   44         return {}
   45 
   46     def validate(self, task):
   47         if 'ramdisk_boot' not in task.driver.boot.capabilities:
   48             raise exception.InvalidParameterValue(
   49                 message=_('Invalid configuration: The boot interface '
   50                           'must have the `ramdisk_boot` capability. '
   51                           'You are using an incompatible boot interface.'))
   52         task.driver.boot.validate(task)
   53 
   54         # Validate node capabilities
   55         deploy_utils.validate_capabilities(task.node)
   56 
   57     @METRICS.timer('RamdiskDeploy.deploy')
   58     @base.deploy_step(priority=100)
   59     @task_manager.require_exclusive_lock
   60     def deploy(self, task):
   61         if 'configdrive' in task.node.instance_info:
   62             LOG.warning('A configuration drive is present with '
   63                         'in the deployment request of node %(node)s. '
   64                         'The configuration drive will be ignored for '
   65                         'this deployment.',
   66                         {'node': task.node})
   67         manager_utils.node_power_action(task, states.POWER_OFF)
   68         # Tenant neworks must enable connectivity to the boot
   69         # location, as reboot() can otherwise be very problematic.
   70         # IDEA(TheJulia): Maybe a "trusted environment" mode flag
   71         # that we otherwise fail validation on for drivers that
   72         # require explicit security postures.
   73         with manager_utils.power_state_for_network_configuration(task):
   74             task.driver.network.configure_tenant_networks(task)
   75 
   76         # calling boot.prepare_instance will also set the node
   77         # to PXE boot, and update PXE templates accordingly
   78         task.driver.boot.prepare_instance(task)
   79 
   80         # Power-on the instance, with PXE prepared, we're done.
   81         manager_utils.node_power_action(task, states.POWER_ON)
   82         LOG.info('Deployment setup for node %s done', task.node.uuid)
   83         return None
   84 
   85     @METRICS.timer('RamdiskDeploy.prepare')
   86     @task_manager.require_exclusive_lock
   87     def prepare(self, task):
   88         node = task.node
   89         # Log a warning if the boot_option is wrong... and
   90         # otherwise reset it.
   91         boot_option = deploy_utils.get_boot_option(node)
   92         if boot_option != 'ramdisk':
   93             LOG.warning('Incorrect "boot_option" set for node %(node)s '
   94                         'and will be overridden to "ramdisk" as to '
   95                         'match the deploy interface. Found: %(boot_opt)s.',
   96                         {'node': node.uuid,
   97                          'boot_opt': boot_option})
   98             i_info = task.node.instance_info
   99             i_info.update({'capabilities': {'boot_option': 'ramdisk'}})
  100             node.instance_info = i_info
  101             node.save()
  102 
  103         deploy_utils.populate_storage_driver_internal_info(task)
  104         if node.provision_state == states.DEPLOYING:
  105             # Ask the network interface to validate itself so
  106             # we can ensure we are able to proceed.
  107             task.driver.network.validate(task)
  108 
  109             manager_utils.node_power_action(task, states.POWER_OFF)
  110             # NOTE(TheJulia): If this was any other interface, we would
  111             # unconfigure tenant networks, add provisioning networks, etc.
  112             task.driver.storage.attach_volumes(task)
  113         if node.provision_state in (states.ACTIVE, states.UNRESCUING):
  114             # In the event of takeover or unrescue.
  115             task.driver.boot.prepare_instance(task)