-
Notifications
You must be signed in to change notification settings - Fork 0
Adds nova-compute drain role #6
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
|
||
nova_compute_drain_venv: "{{ virtualenv_path }}/openstack" | ||
nova_compute_drain_delegate_host: "{{ groups['controllers'][0] }}" | ||
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. Default doesn't make sense outside kayobe 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. localhost as a reasonable default? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
|
||
- block: | ||
- name: "Cold migrate instance: {{ instance_uuid }}" # noqa no-changed-when | ||
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. Add |
||
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' | ||
changed_when: false | ||
retries: 10 | ||
delay: 30 | ||
|
||
- name: "Confirm resize: {{ instance_uuid }}" # noqa no-changed-when | ||
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. Add |
||
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 | ||
changed_when: false | ||
environment: "{{ openstack_auth_env }}" | ||
delegate_to: "{{ nova_compute_drain_delegate_host }}" | ||
vars: | ||
ansible_host: "{{ hostvars[nova_compute_drain_delegate_host].ansible_host }}" | ||
rescue: | ||
- meta: noop # noqa unnamed-task | ||
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. Could use a comment to explain why we're ignoring errors here. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||
--- | ||||||
- name: Query instances | ||||||
command: > | ||||||
{{ nova_compute_drain_venv }}/bin/openstack | ||||||
server list --host {{ ansible_facts.nodename }} | ||||||
--all-projects | ||||||
--format json | ||||||
register: instances | ||||||
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.
Suggested change
|
||||||
delegate_to: "{{ nova_compute_drain_delegate_host }}" | ||||||
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.
Suggested change
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. and add to defaults |
||||||
changed_when: false | ||||||
vars: | ||||||
ansible_host: "{{ hostvars[nova_compute_drain_delegate_host].ansible_host }}" | ||||||
|
||||||
- name: Set fact containing list of instances | ||||||
set_fact: | ||||||
nova_compute_drain_instance_info: "{{ instances.stdout | from_json }}" | ||||||
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.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
|
||
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. Do we need to ignore errors here, or is it an async API that does not generally fail? |
||
- name: "Live migrate instance: {{ instance_uuid }}" # noqa no-changed-when | ||
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. Add |
||
command: > | ||
{{ nova_compute_drain_venv }}/bin/openstack | ||
--os-compute-api-version 2.25 | ||
server migrate | ||
{{ instance_uuid }} | ||
--live-migration | ||
--wait | ||
delegate_to: "{{ nova_compute_drain_delegate_host }}" | ||
environment: "{{ openstack_auth_env }}" | ||
vars: | ||
ansible_host: "{{ hostvars[nova_compute_drain_delegate_host].ansible_host }}" | ||
register: result | ||
failed_when: | ||
- result is failed |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,28 @@ | ||||||
--- | ||||||
- include_tasks: setup.yml | ||||||
|
||||||
- include_tasks: instance-info.yml | ||||||
|
||||||
- include_tasks: live-migrate.yml | ||||||
loop: "{{ nova_compute_drain_instance_info | selectattr('Status', 'equalto', 'ACTIVE') | list }}" | ||||||
loop_control: | ||||||
label: "{{ item.ID | default }}" | ||||||
vars: | ||||||
instance_uuid: "{{ item.ID | default }}" | ||||||
|
||||||
- include_tasks: cold-migrate.yml | ||||||
loop: "{{ nova_compute_drain_instance_info | selectattr('Status', 'equalto', 'SHUTOFF') | list }}" | ||||||
loop_control: | ||||||
label: "{{ item.ID | default }}" | ||||||
vars: | ||||||
instance_uuid: "{{ item.ID | default }}" | ||||||
|
||||||
- include_tasks: instance-info.yml | ||||||
|
||||||
- name: Fail if there are instances still on the host | ||||||
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. What can we do about instances in states other than ACTIVE or SHUTOFF? |
||||||
fail: | ||||||
msg: > | ||||||
Instances still on {{ inventory_hostname }}: {{ instances.stdout | from_json }} | ||||||
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.
Suggested change
|
||||||
when: | ||||||
- nova_compute_migration_fatal | bool | ||||||
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. Add to defaults |
||||||
- nova_compute_drain_instance_info | length > 0 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||
--- | ||||||
|
||||||
- name: Initiate openstack cli virtualenv # noqa package-latest | ||||||
pip: | ||||||
virtualenv: "{{ nova_compute_drain_venv }}" | ||||||
name: | ||||||
- pip | ||||||
- setuptools | ||||||
state: latest | ||||||
virtualenv_command: /usr/bin/python3.6 -m venv | ||||||
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.
Suggested change
|
||||||
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) }}" | ||||||
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. run_once: true? |
||||||
|
||||||
- name: Install openstack CLI tools in virtualenv | ||||||
pip: | ||||||
virtualenv: "{{ nova_compute_drain_venv }}" | ||||||
name: | ||||||
- python-openstackclient | ||||||
extra_args: "{% if pip_upper_constraints_file %}-c {{ pip_upper_constraints_file }}{% endif %}" | ||||||
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.
Suggested change
And add to defaults? |
||||||
delegate_to: "{{ nova_compute_drain_delegate_host }}" | ||||||
vars: | ||||||
# NOTE: Without this, the delegate's 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) }}" | ||||||
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. run_once: true? |
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.
virtualenv_path is defined by kayobe. Should I add some default here? Something in the home directory maybe?
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.
Yeah that would be a better default