Add reboot and reboot_hard actions on server

Reboot actions (both SOFT and HARD) were missing in ansible actions.
Reboot is different than stop and start, because reboot (HARD) is asking
openstack nova to recreate the libvirt XML, which is sometimes needed.

Signed-off-by: Arnaud Morin <arnaud.morin@ovhcloud.com>
Change-Id: I43a42010e7474f47020c8df2839f8584157c97a4
This commit is contained in:
Arnaud Morin 2022-12-05 09:23:48 +01:00 committed by Jakob Meng
parent 3b0ae6c43f
commit 852d971d50
2 changed files with 62 additions and 6 deletions

View File

@ -536,6 +536,46 @@
- info24.servers.0.status == 'ACTIVE'
- server is not changed
- name: Reboot server (SOFT)
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: "{{ server_name }}"
action: reboot_soft
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: "{{ server_name }}"
register: info25
- name: Ensure status for server is ACTIVE
assert:
that:
- info25.servers.0.status == 'ACTIVE'
- server is not changed
- name: Reboot server (HARD)
openstack.cloud.server_action:
cloud: "{{ cloud }}"
server: "{{ server_name }}"
action: reboot_hard
wait: true
register: server
- name: Get info about server
openstack.cloud.server_info:
cloud: "{{ cloud }}"
server: "{{ server_name }}"
register: info26
- name: Ensure status for server is ACTIVE
assert:
that:
- info26.servers.0.status == 'ACTIVE'
- server is not changed
- name: Delete server
openstack.cloud.server:
cloud: "{{ cloud }}"
@ -573,12 +613,12 @@
openstack.cloud.server_info:
cloud: "{{ cloud_alt }}"
server: "{{ server_alt_name }}"
register: info25
register: info27
- name: Ensure status for server in alternate project is ACTIVE
assert:
that:
- info25.servers.0.status == 'ACTIVE'
- info27.servers.0.status == 'ACTIVE'
- name: Try to stop server in alternate project
openstack.cloud.server_action:

View File

@ -34,8 +34,9 @@ options:
description:
- Perform the given action. The lock and unlock actions always return
changed as the servers API does not provide lock status.
choices: [stop, start, pause, unpause, lock, unlock, suspend, resume,
rebuild, shelve, shelve_offload, unshelve]
choices: [stop, start, pause, unpause, lock, unlock, suspend,
reboot_soft, reboot_hard, resume, rebuild, shelve,
shelve_offload, unshelve]
type: str
required: true
image:
@ -106,6 +107,8 @@ _action_map = {'stop': ['SHUTOFF'],
'lock': ['ACTIVE'], # API doesn't show lock/unlock status
'unlock': ['ACTIVE'],
'suspend': ['SUSPENDED'],
'reboot_soft': ['ACTIVE'],
'reboot_hard': ['ACTIVE'],
'resume': ['ACTIVE'],
'rebuild': ['ACTIVE'],
'shelve': ['SHELVED_OFFLOADED', 'SHELVED'],
@ -120,7 +123,7 @@ class ServerActionModule(OpenStackModule):
server=dict(required=True),
action=dict(required=True,
choices=['stop', 'start', 'pause', 'unpause',
'lock', 'unlock', 'suspend', 'resume',
'lock', 'unlock', 'suspend', 'reboot_soft', 'reboot_hard', 'resume',
'rebuild', 'shelve', 'shelve_offload', 'unshelve']),
image=dict(),
admin_password=dict(no_log=True),
@ -165,12 +168,25 @@ class ServerActionModule(OpenStackModule):
# shelve_offload is not supported in OpenstackSDK
return self._action(os_server, json={'shelveOffload': None})
action_name = self.params['action'] + "_server"
# reboot_* actions are using reboot_server method with an extra param
if self.params['action'] == 'reboot_soft' or self.params['action'] == 'reboot_hard':
action_name = 'reboot_server'
# Try to grab method from OpenstackSDK
try:
func_name = getattr(self.conn.compute, action_name)
except AttributeError:
self.fail_json(
msg="Method %s wasn't found in OpenstackSDK compute" % action_name)
func_name(os_server)
# Do the action
if self.params['action'] == 'reboot_soft':
func_name(os_server, 'SOFT')
elif self.params['action'] == 'reboot_hard':
func_name(os_server, 'HARD')
else:
func_name(os_server)
def _rebuild_server(self, os_server):
# rebuild should ensure images exists