mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-11-22 23:20:24 +00:00
Merge "feat: add support for live_migrate action"
This commit is contained in:
@@ -17,9 +17,10 @@ options:
|
|||||||
- Action to perform.
|
- Action to perform.
|
||||||
- By default, only server owners and administrators are allowed to
|
- By default, only server owners and administrators are allowed to
|
||||||
perform actions C(pause), C(unpause), C(suspend), C(resume), C(lock),
|
perform actions C(pause), C(unpause), C(suspend), C(resume), C(lock),
|
||||||
C(unlock) and C(shelve_offload).
|
C(unlock), C(shelve_offload) and C(live_migrate).
|
||||||
choices: [lock, pause, reboot_hard, reboot_soft, rebuild, resume, shelve,
|
choices: [lock, pause, reboot_hard, reboot_soft, rebuild, resume, shelve,
|
||||||
shelve_offload, start, stop, suspend, unlock, unpause, unshelve]
|
shelve_offload, start, stop, suspend, unlock, unpause, unshelve,
|
||||||
|
live_migrate]
|
||||||
type: str
|
type: str
|
||||||
required: true
|
required: true
|
||||||
admin_password:
|
admin_password:
|
||||||
@@ -42,6 +43,12 @@ options:
|
|||||||
required: true
|
required: true
|
||||||
type: str
|
type: str
|
||||||
aliases: ['server']
|
aliases: ['server']
|
||||||
|
host:
|
||||||
|
description:
|
||||||
|
- Target hypervisor host for C(live_migrate) action. If not specified, the server will be
|
||||||
|
live migrated to a suitable host automatically selected by Nova scheduler.
|
||||||
|
type: str
|
||||||
|
required: false
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- openstack.cloud.openstack
|
- openstack.cloud.openstack
|
||||||
'''
|
'''
|
||||||
@@ -53,6 +60,20 @@ EXAMPLES = r'''
|
|||||||
action: pause
|
action: pause
|
||||||
server: vm1
|
server: vm1
|
||||||
timeout: 200
|
timeout: 200
|
||||||
|
|
||||||
|
- name: Live migrate compute instance to an auto-selected hypervisor
|
||||||
|
openstack.cloud.server_action:
|
||||||
|
cloud: devstack-admin
|
||||||
|
action: live_migrate
|
||||||
|
server: vm1
|
||||||
|
timeout: 200
|
||||||
|
|
||||||
|
- name: Live migrate compute instance to a specified hypervisor
|
||||||
|
openstack.cloud.server_action:
|
||||||
|
cloud: devstack-admin
|
||||||
|
action: live_migrate
|
||||||
|
server: vm1
|
||||||
|
host: compute1
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||||
@@ -64,9 +85,10 @@ class ServerActionModule(OpenStackModule):
|
|||||||
choices=['stop', 'start', 'pause', 'unpause',
|
choices=['stop', 'start', 'pause', 'unpause',
|
||||||
'lock', 'unlock', 'suspend', 'reboot_soft',
|
'lock', 'unlock', 'suspend', 'reboot_soft',
|
||||||
'reboot_hard', 'resume', 'rebuild', 'shelve',
|
'reboot_hard', 'resume', 'rebuild', 'shelve',
|
||||||
'shelve_offload', 'unshelve']),
|
'shelve_offload', 'unshelve', 'live_migrate']),
|
||||||
admin_password=dict(no_log=True),
|
admin_password=dict(no_log=True),
|
||||||
all_projects=dict(type='bool', default=False),
|
all_projects=dict(type='bool', default=False),
|
||||||
|
host=dict(type='str', default=None),
|
||||||
image=dict(),
|
image=dict(),
|
||||||
name=dict(required=True, aliases=['server']),
|
name=dict(required=True, aliases=['server']),
|
||||||
)
|
)
|
||||||
@@ -116,7 +138,9 @@ class ServerActionModule(OpenStackModule):
|
|||||||
'rebuild': ['ACTIVE'],
|
'rebuild': ['ACTIVE'],
|
||||||
'shelve': ['SHELVED_OFFLOADED', 'SHELVED'],
|
'shelve': ['SHELVED_OFFLOADED', 'SHELVED'],
|
||||||
'shelve_offload': ['SHELVED_OFFLOADED'],
|
'shelve_offload': ['SHELVED_OFFLOADED'],
|
||||||
'unshelve': ['ACTIVE']}
|
'unshelve': ['ACTIVE'],
|
||||||
|
'live_migrate': ['ACTIVE'],
|
||||||
|
}
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# TODO: Replace with self.conn.compute.find_server(
|
# TODO: Replace with self.conn.compute.find_server(
|
||||||
@@ -141,10 +165,17 @@ class ServerActionModule(OpenStackModule):
|
|||||||
or (action == 'reboot_soft')
|
or (action == 'reboot_soft')
|
||||||
or (action == 'lock' and not server['is_locked'])
|
or (action == 'lock' and not server['is_locked'])
|
||||||
or (action == 'unlock' and server['is_locked'])
|
or (action == 'unlock' and server['is_locked'])
|
||||||
|
or (action == 'live_migrate' and not server.status.lower() == 'migrating')
|
||||||
or server.status.lower() not in [a.lower()
|
or server.status.lower() not in [a.lower()
|
||||||
for a
|
for a
|
||||||
in self._action_map[action]])
|
in self._action_map[action]])
|
||||||
|
|
||||||
|
# If live_migrate targets the same host the VM is already on, skip it
|
||||||
|
if action == 'live_migrate' and self.params['host'] is not None:
|
||||||
|
current_host = server.get('OS-EXT-SRV-ATTR:host') or server.get('hypervisor_hostname')
|
||||||
|
if current_host and current_host == self.params['host']:
|
||||||
|
self.exit_json(changed=False, msg='VM is already on target host {0}, skipping migration.'.format(self.params['host']))
|
||||||
|
|
||||||
if not will_change:
|
if not will_change:
|
||||||
self.exit_json(changed=False)
|
self.exit_json(changed=False)
|
||||||
elif self.ansible.check_mode:
|
elif self.ansible.check_mode:
|
||||||
@@ -189,6 +220,11 @@ class ServerActionModule(OpenStackModule):
|
|||||||
func_name(server, 'SOFT')
|
func_name(server, 'SOFT')
|
||||||
elif action == 'reboot_hard':
|
elif action == 'reboot_hard':
|
||||||
func_name(server, 'HARD')
|
func_name(server, 'HARD')
|
||||||
|
elif action == 'live_migrate':
|
||||||
|
kwargs = {}
|
||||||
|
if self.params['host'] is not None:
|
||||||
|
kwargs['host'] = self.params['host']
|
||||||
|
func_name(server, **kwargs)
|
||||||
else:
|
else:
|
||||||
func_name(server)
|
func_name(server)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user