-
Notifications
You must be signed in to change notification settings - Fork 23
Adds support for cold migration to drain script #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
18ec478
969de52
e99b6e4
3bb5911
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,68 +5,39 @@ | |
tags: | ||
- nova-compute-drain | ||
vars: | ||
venv: "{{ virtualenv_path }}/openstack" | ||
live_migration_fatal: true | ||
nova_compute_migration_fatal: true | ||
tasks: | ||
- name: Set up openstack cli virtualenv | ||
pip: | ||
virtualenv: "{{ venv }}" | ||
name: | ||
- python-openstackclient | ||
state: latest | ||
extra_args: "{% if pip_upper_constraints_file %}-c {{ pip_upper_constraints_file }}{% endif %}" | ||
- include_role: | ||
name: nova-compute-drain | ||
tasks_from: setup.yml | ||
run_once: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: not required |
||
delegate_to: "{{ groups['controllers'][0] }}" | ||
|
||
- block: | ||
- name: Query instances | ||
command: > | ||
{{ venv }}/bin/openstack | ||
server list --host {{ ansible_facts.nodename }} | ||
--all-projects | ||
--status ACTIVE | ||
--format json | ||
register: instances | ||
- include_role: | ||
name: nova-compute-drain | ||
tasks_from: instance-info.yml | ||
|
||
- name: Live migrate instances | ||
command: > | ||
{{ venv }}/bin/openstack | ||
--os-compute-api-version 2.25 | ||
server migrate | ||
{{ instance_uuid }} | ||
--live-migration | ||
--wait | ||
loop: "{{ instances.stdout | from_json }}" | ||
loop_control: | ||
label: "{{ instance_uuid }}" | ||
vars: | ||
instance_uuid: "{{ item.ID | default }}" | ||
register: result | ||
failed_when: | ||
- live_migration_fatal | bool | ||
- result is failed | ||
- include_role: | ||
name: nova-compute-drain | ||
tasks_from: live-migrate.yml | ||
loop: "{{ nova_compute_drain_instance_info | selectattr('Status', 'equalto', 'ACTIVE') | list }}" | ||
loop_control: | ||
label: "{{ item.ID | default }}" | ||
|
||
- name: Query instances | ||
command: > | ||
{{ venv }}/bin/openstack | ||
server list --host {{ ansible_facts.nodename }} | ||
--all-projects | ||
--status ACTIVE | ||
--format json | ||
register: instances | ||
- include_role: | ||
name: nova-compute-drain | ||
tasks_from: cold-migrate.yml | ||
loop: "{{ nova_compute_drain_instance_info | selectattr('Status', 'equalto', 'SHUTOFF') | list }}" | ||
loop_control: | ||
label: "{{ item.ID | default }}" | ||
|
||
- name: Fail if there are instances still on the host | ||
fail: | ||
msg: > | ||
Instances still on {{ inventory_hostname }}: {{ instances.stdout | from_json }} | ||
when: | ||
- live_migration_fatal | bool | ||
- instances.stdout | from_json | length > 0 | ||
- include_role: | ||
name: nova-compute-drain | ||
tasks_from: instance-info.yml | ||
|
||
delegate_to: "{{ groups['controllers'][0] }}" | ||
environment: "{{ openstack_auth_env }}" | ||
- name: Fail if there are instances still on the host | ||
fail: | ||
msg: > | ||
Instances still on {{ inventory_hostname }}: {{ instances.stdout | from_json }} | ||
when: | ||
- "'compute' in group_names" | ||
- groups['compute'] | length > 1 | ||
vars: | ||
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}" | ||
- nova_compute_migration_fatal | bool | ||
- nova_compute_drain_instance_info | length > 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
|
||
nova_compute_drain_venv: "{{ virtualenv_path }}/openstack" | ||
nova_compute_drain_delegate_host: "{{ groups['controllers'][0] }}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
|
||
- block: | ||
- name: "Cold migrate instance: {{ instance_uuid }}" | ||
command: > | ||
{{ nova_compute_drain_venv }}/bin/openstack | ||
--os-compute-api-version 2.25 | ||
server migrate | ||
{{ instance_uuid }} | ||
--wait | ||
register: result | ||
|
||
- name: "Wait for VERIFY_RESIZE: {{ instance_uuid }}" | ||
command: > | ||
{{ nova_compute_drain_venv }}/bin/openstack server show {{ instance_uuid }} -f value -c status | ||
register: result | ||
until: result.stdout == 'VERIFY_RESIZE' or result.stdout == 'SHUTOFF' | ||
retries: 10 | ||
delay: 30 | ||
|
||
- name: "Confirm resize: {{ instance_uuid }}" | ||
command: > | ||
{{ nova_compute_drain_venv }}/bin/openstack server migrate confirm {{ instance_uuid }} | ||
when: result.stdout == 'VERIFY_RESIZE' | ||
|
||
- name: "Wait for SHUTOFF: {{ instance_uuid }}" | ||
command: > | ||
{{ nova_compute_drain_venv }}/bin/openstack server show {{ instance_uuid }} -f value -c status | ||
register: result | ||
until: result.stdout == 'SHUTOFF' | ||
retries: 10 | ||
delay: 30 | ||
environment: "{{ openstack_auth_env }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it need delegate_to? |
||
vars: | ||
ansible_host: "{{ hostvars[nova_compute_drain_delegate_host].ansible_host }}" | ||
instance_uuid: "{{ item.ID | default }}" | ||
|
||
rescue: | ||
- meta: noop |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||||
--- | ||||||
- name: Query instances | ||||||
command: > | ||||||
{{ nova_compute_drain_venv }}/bin/openstack | ||||||
server list --host {{ ansible_facts.fqdn }} | ||||||
|
server list --host {{ ansible_facts.fqdn }} | |
server list --host {{ ansible_facts.nodename }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the cloud I was testing on their was some funkiness around the compute host names. nodenmae
is the correct value to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need delegate_to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yep looks like it. Not sure, how that got lost! I'll re-add.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
|
||
- name: "Live migrate instance: {{ instance_uuid }}" | ||
command: > | ||
{{ nova_compute_drain_venv }}/bin/openstack | ||
--os-compute-api-version 2.25 | ||
server migrate | ||
{{ instance_uuid }} | ||
--live-migration | ||
--wait | ||
environment: "{{ openstack_auth_env }}" | ||
vars: | ||
instance_uuid: "{{ item.ID | default }}" | ||
ansible_host: "{{ hostvars[nova_compute_drain_delegate_host].ansible_host }}" | ||
register: result | ||
failed_when: | ||
- result is failed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it need delegate_to? |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||
--- | ||||
|
||||
- name: Initiate openstack cli virtualenv | ||||
pip: | ||||
virtualenv: "{{ nova_compute_drain_venv }}" | ||||
name: | ||||
- pip | ||||
- setuptools | ||||
state: latest | ||||
virtualenv_command: /usr/bin/python3.6 -m venv | ||||
run_once: true | ||||
delegate_to: "{{ nova_compute_drain_delegate_host }}" | ||||
vars: | ||||
# NOTE: Without this, the delegate ansible_host variable will not | ||||
# be respected when using delegate_to. | ||||
ansible_host: "{{ hostvars[nova_compute_drain_delegate_host].ansible_host | default(nova_compute_drain_delegate_host) }}" | ||||
|
||||
- name: Install openstack CLI tools in virtualenv | ||||
pip: | ||||
virtualenv: "{{ nova_compute_drain_venv }}" | ||||
name: | ||||
- python-openstackclient | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we pin it, or use upper constraints? (as was done before) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, In train where I was testing this we couldn't use: |
||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to put this in a main.yml, using include_tasks instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call.