Skip to content

Commit 18ec478

Browse files
committed
Adds support for cold migration to drain script
1 parent e8c8113 commit 18ec478

File tree

6 files changed

+131
-57
lines changed

6 files changed

+131
-57
lines changed

etc/kayobe/ansible/nova-compute-drain.yml

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,39 @@
55
tags:
66
- nova-compute-drain
77
vars:
8-
venv: "{{ virtualenv_path }}/openstack"
9-
live_migration_fatal: true
8+
nova_compute_migration_fatal: true
109
tasks:
11-
- name: Set up openstack cli virtualenv
12-
pip:
13-
virtualenv: "{{ venv }}"
14-
name:
15-
- python-openstackclient
16-
state: latest
17-
extra_args: "{% if pip_upper_constraints_file %}-c {{ pip_upper_constraints_file }}{% endif %}"
10+
- include_role:
11+
name: nova-compute-drain
12+
tasks_from: setup.yml
1813
run_once: true
19-
delegate_to: "{{ groups['controllers'][0] }}"
2014

21-
- block:
22-
- name: Query instances
23-
command: >
24-
{{ venv }}/bin/openstack
25-
server list --host {{ ansible_facts.nodename }}
26-
--all-projects
27-
--status ACTIVE
28-
--format json
29-
register: instances
15+
- include_role:
16+
name: nova-compute-drain
17+
tasks_from: instance-info.yml
3018

31-
- name: Live migrate instances
32-
command: >
33-
{{ venv }}/bin/openstack
34-
--os-compute-api-version 2.25
35-
server migrate
36-
{{ instance_uuid }}
37-
--live-migration
38-
--wait
39-
loop: "{{ instances.stdout | from_json }}"
40-
loop_control:
41-
label: "{{ instance_uuid }}"
42-
vars:
43-
instance_uuid: "{{ item.ID | default }}"
44-
register: result
45-
failed_when:
46-
- live_migration_fatal | bool
47-
- result is failed
19+
- include_role:
20+
name: nova-compute-drain
21+
tasks_from: live-migrate.yml
22+
loop: "{{ nova_compute_drain_instance_info | selectattr('Status', 'equalto', 'ACTIVE') | list }}"
23+
loop_control:
24+
label: "{{ item.ID | default }}"
4825

49-
- name: Query instances
50-
command: >
51-
{{ venv }}/bin/openstack
52-
server list --host {{ ansible_facts.nodename }}
53-
--all-projects
54-
--status ACTIVE
55-
--format json
56-
register: instances
26+
- include_role:
27+
name: nova-compute-drain
28+
tasks_from: cold-migrate.yml
29+
loop: "{{ nova_compute_drain_instance_info | selectattr('Status', 'equalto', 'SHUTOFF') | list }}"
30+
loop_control:
31+
label: "{{ item.ID | default }}"
5732

58-
- name: Fail if there are instances still on the host
59-
fail:
60-
msg: >
61-
Instances still on {{ inventory_hostname }}: {{ instances.stdout | from_json }}
62-
when:
63-
- live_migration_fatal | bool
64-
- instances.stdout | from_json | length > 0
33+
- include_role:
34+
name: nova-compute-drain
35+
tasks_from: instance-info.yml
6536

66-
delegate_to: "{{ groups['controllers'][0] }}"
67-
environment: "{{ openstack_auth_env }}"
37+
- name: Fail if there are instances still on the host
38+
fail:
39+
msg: >
40+
Instances still on {{ inventory_hostname }}: {{ instances.stdout | from_json }}
6841
when:
69-
- "'compute' in group_names"
70-
- groups['compute'] | length > 1
71-
vars:
72-
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
42+
- nova_compute_migration_fatal | bool
43+
- nova_compute_drain_instance_info | length > 0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
nova_compute_drain_venv: "{{ virtualenv_path }}/openstack"
4+
nova_compute_drain_delegate_host: "{{ groups['controllers'][0] }}"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
3+
- block:
4+
- name: "Cold migrate instance: {{ instance_uuid }}"
5+
command: >
6+
{{ nova_compute_drain_venv }}/bin/openstack
7+
--os-compute-api-version 2.25
8+
server migrate
9+
{{ instance_uuid }}
10+
--wait
11+
register: result
12+
13+
- name: "Wait for VERIFY_RESIZE: {{ instance_uuid }}"
14+
command: >
15+
{{ nova_compute_drain_venv }}/bin/openstack server show {{ instance_uuid }} -f value -c status
16+
register: result
17+
until: result.stdout == 'VERIFY_RESIZE' or result.stdout == 'SHUTOFF'
18+
retries: 10
19+
delay: 30
20+
21+
- name: "Confirm resize: {{ instance_uuid }}"
22+
command: >
23+
{{ nova_compute_drain_venv }}/bin/openstack server migrate confirm {{ instance_uuid }}
24+
when: result.stdout == 'VERIFY_RESIZE'
25+
26+
- name: "Wait for SHUTOFF: {{ instance_uuid }}"
27+
command: >
28+
{{ nova_compute_drain_venv }}/bin/openstack server show {{ instance_uuid }} -f value -c status
29+
register: result
30+
until: result.stdout == 'SHUTOFF'
31+
retries: 10
32+
delay: 30
33+
environment: "{{ openstack_auth_env }}"
34+
vars:
35+
ansible_host: "{{ hostvars[nova_compute_drain_delegate_host].ansible_host }}"
36+
instance_uuid: "{{ item.ID | default }}"
37+
rescue:
38+
- meta: noop
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
- name: Query instances
3+
command: >
4+
{{ nova_compute_drain_venv }}/bin/openstack
5+
server list --host {{ ansible_facts.fqdn }}
6+
--all-projects
7+
--format json
8+
register: instances
9+
environment: "{{ openstack_auth_env }}"
10+
vars:
11+
ansible_host: "{{ hostvars[nova_compute_drain_delegate_host].ansible_host }}"
12+
13+
- name: Set fact containing list of instances
14+
set_fact:
15+
nova_compute_drain_instance_info: "{{ instances.stdout | from_json }}"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
3+
- name: "Live migrate instance: {{ instance_uuid }}"
4+
command: >
5+
{{ nova_compute_drain_venv }}/bin/openstack
6+
--os-compute-api-version 2.25
7+
server migrate
8+
{{ instance_uuid }}
9+
--live-migration
10+
--wait
11+
environment: "{{ openstack_auth_env }}"
12+
vars:
13+
instance_uuid: "{{ item.ID | default }}"
14+
ansible_host: "{{ hostvars[nova_compute_drain_delegate_host].ansible_host }}"
15+
register: result
16+
failed_when:
17+
- result is failed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
3+
- name: Initiate openstack cli virtualenv
4+
pip:
5+
virtualenv: "{{ nova_compute_drain_venv }}"
6+
name:
7+
- pip
8+
- setuptools
9+
state: latest
10+
virtualenv_command: /usr/bin/python3.6 -m venv
11+
run_once: true
12+
delegate_to: "{{ nova_compute_drain_delegate_host }}"
13+
vars:
14+
# NOTE: Without this, the delegate ansible_host variable will not
15+
# be respected when using delegate_to.
16+
ansible_host: "{{ hostvars[nova_compute_drain_delegate_host].ansible_host | default(nova_compute_drain_delegate_host) }}"
17+
18+
- name: Install openstack CLI tools in virtualenv
19+
pip:
20+
virtualenv: "{{ nova_compute_drain_venv }}"
21+
name:
22+
- python-openstackclient
23+
24+
run_once: true
25+
delegate_to: "{{ nova_compute_drain_delegate_host }}"
26+
vars:
27+
# NOTE: Without this, the delegate's ansible_host variable will not
28+
# be respected when using delegate_to.
29+
ansible_host: "{{ hostvars[nova_compute_drain_delegate_host].ansible_host | default(nova_compute_drain_delegate_host) }}"

0 commit comments

Comments
 (0)