增强软关机和NMI的电源接口

https://bugs.launchpad.net/ironic/+bug/1526226

本提案介绍了增强电源接口以支持软重启和软关机所需的工作,以及管理接口以支持诊断中断(NMI [1])。

问题描述

当前驱动程序接口存在一个问题,即使 ipmitool [2] 和大多数 BMC 支持这些功能,它也不提供软关机和诊断中断(NMI [1])功能。

以下是 ipmitool 手册页的一部分,其中描述了软关机和诊断中断(NMI [1])。

$ man ipmitool

...
power

       Performs a chassis control command to view and change the
       power state.

       ...

       diag

              Pulse a diagnostic interrupt (NMI) directly to the
              processor(s).

       soft

              Initiate a soft-shutdown of OS via ACPI. This can be
              done in a number of ways, commonly by simulating an
              overtemperature or by simulating a power button press.
              It is necessary for there to be Operating System
              support for ACPI and some sort of daemon watching for
              events for this soft power to work.

从客户的角度来看,无论是租户管理员还是租户用户,缺乏软关机和诊断中断(NMI [1])都会导致以下不便。

  1. 客户无法在不登录的情况下安全地关闭或软关机他们的实例。

  2. 客户无法自行获取 NMI 转储来调查与操作系统相关的问题。

从部署者的角度来看,即云提供商,缺乏这两种功能会导致以下不便。

  1. 云提供商支持人员无法为了硬件维护或其他原因在不登录的情况下安全地关闭客户的实例。

  2. 云提供商支持人员无法要求客户获取 NMI 转储作为调查材料之一。

提议的变更

为了解决上一节中描述的问题,本规范建议增强电源状态、PowerInterface 基类和 ManagementInterface 基类,以便每个驱动程序可以实现启动软重启、软关机和注入 NMI。

这种增强功能可以通过 Ironic CLI 和 REST API 为租户管理员和云提供商启用软重启、软关机和注入 NMI。 此外,当 Nova 的蓝图 [3] 实施时,它还可以通过 Nova CLI 和 REST API 为租户用户启用这些功能。

作为参考实现,本规范还建议将增强的 PowerInterface 基类实现到 IPMIPower 具体类中,并将增强的 ManagementInterface 基类实现到 IPMIManagement 具体类中。

  1. 将以下新的电源状态添加到 ironic.common.states

    SOFT_REBOOT = 'soft rebooting'
    SOFT_POWER_OFF = 'soft power off'
    
  2. 将“get_supported_power_states”方法及其默认实现添加到 ironic/drivers/base.py 中的 PowerInterface 基类

    def get_supported_power_states(self, task):
        """Get a list of the supported power states.
    
        :param task: A TaskManager instance containing the node to act on.
        :returns: A list of the supported power states defined
                  in :mod:`ironic.common.states`.
        """
        return [states.POWER_ON, states.POWER_OFF, states.REBOOT]
    
    • 注意:WakeOnLanPower 驱动程序仅支持 states.POWER_ON。

  3. 将默认参数 timeout 添加到 ironic/drivers/base.py 中 PowerInterface 基类的“set_power_state”方法中

    @abc.abstractmethod
    def set_power_state(self, task, power_state, timeout=None):
        """Set the power state of the task's node.
    
        :param task: a TaskManager instance containing the node to act on.
        :param power_state: Any power state from :mod:`ironic.common.states`.
        :param timeout: timeout positive integer (> 0) for any power state.
           ``None`` indicates to use default timeout which depends on
           ``power_state``[*]_ and driver.
        :raises: MissingParameterValue if a required parameter is missing.
        """
    
  4. 增强 IPMIPower 类中的“set_power_state”方法,以便可以将新的状态作为“power_state”参数接受。

    IPMIPower 参考实现支持 SOFT_REBOOT 和 SOFT_POWER_OFF。

    SOFT_REBOOT 的实现方式是先 SOFT_POWER_OFF,然后再进行普通的 POWER_ON,从而 Ironic 实现 REBOOT。 这种实现方式使通用的 BMC 可以检测到重启完成,即电源状态从 ON -> OFF -> ON 的变化,这种电源转换称为 power cycle

    下表显示了每个状态变量的电源状态值。 new_state 是 set_power_state() 函数的第二个参数的值。 power_state 是节点属性的值。 target_power_state 是节点属性的值。

    new_state

    power_state(起始状态)

    target_power_state(分配值)

    power_state(结束状态)

    SOFT_REBOOT

    SOFT_REBOOT SOFT_POWER_OFF SOFT_POWER_OFF

    POWER_ON POWER_OFF[*]_ POWER_OFF POWER_ON POWER_OFF

    SOFT_POWER_OFF POWER_ON POWER_ON SOFT_POWER_OFF NONE

    POWER_OFF[*]_ POWER_ON POWER_ON POWER_OFF POWER_OFF

    new_state

    power_state(起始状态)

    target_power_state(分配值)

    power_state(结束状态)

    SOFT_REBOOT SOFT_POWER_OFF

    POWER_ON POWER_ON

    SOFT_POWER_OFF SOFT_POWER_OFF

    ERROR[*]_ ERROR[*]_

  5. 将“get_supported_power_states”方法和实现添加到 IPMIPower

    def get_supported_power_states(self, task):
        """Get a list of the supported power states.
    
        :param task: A TaskManager instance containing the node to act on.
           currently not used.
        :returns: A list of the supported power states defined
                  in :mod:`ironic.common.states`.
        """
    
        return [states.POWER_ON, states.POWER_OFF, states.REBOOT,
                states.SOFT_REBOOT, states.SOFT_POWER_OFF]
    
  6. 将“inject_nmi”抽象方法添加到 ironic/drivers/base.py 中的 ManagementInterface 基类

    @abc.abstractmethod
    def inject_nmi(self, task):
        """Inject NMI, Non Maskable Interrupt.
    
        :param task: A TaskManager instance containing the node to act on.
        :returns: None
        """
    
  7. 将“inject_nmi”具体方法实现添加到 IPMIManagement 类。

备选方案

  • 软关机和诊断中断(NMI [1])都可以通过供应商直通来实现。 但是,所提出的更改优于供应商直通,因为 Ironic API 或 Ironic CLI 的用户可以统一编写脚本或程序。

数据模型影响

状态机影响

REST API 影响

  • 将 SOFT_REBOOT 和 SOFT_POWER_OFF 的支持添加到以下 API 的 target 参数中

    PUT /v1/nodes/(node_ident)/states/power
    
    The target parameter supports the following JSON data respectively.
    ``timeout`` is an optional parameter for any ``target`` parameter.
    In case of "soft reboot" and "soft power off", ``timeout`` overrides
    ``soft_power_off_timeout`` in the in the Ironic configuration file,
    typically /etc/ironic/ironic.conf.
    
    Examples
    
      {"target": "soft reboot",
       "timeout": 900}
    
      {"target": "soft power off",
       "timeout": 600}
    
  • 添加一个新的管理 API 以支持注入 NMI

    PUT /v1/nodes/(node_ident)/management/inject_nmi
    
    Request doesn't take any parameter.
    

客户端 (CLI) 影响

  • 增强 Ironic CLI “ironic node-set-power-state” 以支持通过添加可选参数进行优雅关机/重启。 此 CLI 是异步的。 为了获取最新状态,请调用“ironic node-show-states”并检查返回值。

    usage: ironic node-set-power-state <node> <power-state>
           [--soft] [--timeout <timeout>]
    
    Power a node on/off/reboot, power graceful off/reboot to a node.
    
    Positional arguments
    
    <node>
    
        Name or UUID of the node.
    
    <power-state>
    
        'on', 'off', 'reboot'
    
    Optional arguments:
       --soft
         power graceful off/reboot.
    
       --timeout <timeout>
         timeout positive integer value(> 0) for any ``power-state``.
         If ``--soft`` option is also specified, it overrides
         ``soft_power_off_timeout`` in the in the Ironic configuration
         file, typically /etc/ironic/ironic.conf.
    
  • 添加一个新的 Ironic CLI “ironic node-inject-nmi” 以支持注入 nmi。 此 CLI 是异步的。 为了获取最新状态,需要串行控制台访问权限。

    usage: ironic node-inject-nmi <node>
    
    Inject NMI, Non Maskable Interrupt.
    
    Positional arguments
    
    <node>
    
        Name or UUID of the node.
    
  • 增强 OSC 插件“openstack baremetal node”,以便该参数可以接受 ‘reboot [–soft] [–timeout <timeout>]’、’power [on|off [–soft] [–timeout <timeout>]’ 和 ‘inject nmi’。 此 CLI 是异步的。 为了获取最新状态,请调用“openstack baremetal node show”并检查返回值。

    usage: openstack baremetal node reboot [--soft] [--timeout <timeout>] <uuid>
    
    usage: openstack baremetal node power off [--soft] [--timeout <timeout>] <uuid>
    
    usage: openstack baremetal node inject nmi <uuid>
    

RPC API 影响

驱动程序 API 影响

PowerInterface 基类和 ManagementInterface 基类通过添加一个新方法得到增强,如“Proposed change”部分所述。 这些增强功能保持 API 向后兼容。 因此,它没有破坏树外驱动程序的风险。

Nova 驱动程序影响

“nova reboot”命令对 KVM 等虚拟机实例的默认行为是软重启。 “nova reboot”命令有一个 ‘–hard’ 选项来指示硬重启。

但是,“nova reboot”命令对 Ironic 实例的默认行为是硬重启,并且 –hard 选项对 Ironic 实例没有意义。

因此,Ironic Nova 驱动程序需要更新,以统一虚拟机实例和裸机实例之间的行为。

此问题报告为错误 [6]。 如何解决此问题在 nova 蓝图 [10] 和规范 [11] 中指定。

“nova reboot”命令的默认行为更改是通过遵循标准的弃用策略 [12] 来完成的。 如何弃用 nova 命令也在 nova 蓝图 [10] 和规范 [11] 中指定。

Ramdisk 影响

安全影响

其他最终用户影响

可扩展性影响

性能影响

其他部署者影响

  • 部署者、云提供商需要在云环境中设置支持 ACPI [7] 和 NMI [1] 的裸机服务器。

  • 如果需要,更改 Ironic 配置文件中(通常为 /etc/ironic/ironic.conf)中的默认超时值(秒)。

开发人员影响

  • 每个驱动程序开发人员需要遵循此接口来实现此提议的功能。

实现

负责人

主要负责人

玉田直弘 (naohirot)

其他贡献者

工作项

  • 增强 PowerInterface 类和 ManagementInterface 类以支持软关机和注入 nmi [1],如“Proposed change”中所述。

  • 增强 Ironic API,如“REST API impact”中所述。

  • 增强 Ironic CLI,如“Client (CLI) impact”中所述。

  • 将增强的 PowerInterface 类实现到具体类 IPMIPower 中,并将增强的 ManagementInterface 类实现到具体类 IPMIManagement 中。 实现供应商的具体类由每个供应商决定。

  • 如果需要,与 Nova NMI 支持“Inject NMI to an instance” [3] 协调工作。

  • 从 Ironic 的角度更新部署者文档。

依赖项

  • 软关机控制取决于 ACPI [7]。 对于 Linux 系统,必须安装 acpid [8]。 对于 Windows 系统,必须按照“Shutdown: Allow system to be shut down without having to log on” [9] 中所述的方式设置本地安全策略。

  • NMI [1] 反应取决于内核崩溃转储配置。 可以找到 Linux 系统的内核转储设置方法,请参见 [13]、[14],Windows 系统的设置方法,请参见 [15]。

测试

  • 单元测试。

  • Tempest 测试,至少软重启/软关机。

  • 如果已实现,每个供应商计划进行第三方 CI 测试。

升级和向后兼容性

无(向前兼容性不在范围内)

  • 注意 “nova reboot”命令的默认行为更改的向后兼容性问题通过遵循标准的弃用策略 [12] 解决。

文档影响

  • 需要更新部署者文档和 REST API 参考手册。(CLI 手册从源代码自动生成)

参考资料

[1] http://en.wikipedia.org/wiki/Non-maskable_interrupt

[2] http://linux.die.net/man/1/ipmitool

[3] https://review.opendev.org/#/c/187176/

[4] https://en.wikipedia.org/wiki/Communicating_sequential_processes

[5] http://linux.die.net/man/1/virsh

[6] https://bugs.launchpad.net/nova/+bug/1485416

[7] http://en.wikipedia.org/wiki/Advanced_Configuration_and_Power_Interface

[8] http://linux.die.net/man/8/acpid

[9] https://technet.microsoft.com/en-us/library/jj852274%28v=ws.10%29.aspx

[10] https://blueprints.launchpad.net/nova/+spec/soft-reboot-poweroff

[11] https://review.opendev.org/#/c/229282/

[12] http://governance.openstack.org/reference/tags/assert_follows-standard-deprecation.html

[13] https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Kernel_Crash_Dump_Guide/

[14] https://help.ubuntu.com/lts/serverguide/kernel-crash-dump.html

[15] https://support.microsoft.com/en-us/kb/927069