Add a playbook to register nova flavors for baremetal nodes

Currently fairly simplistic - registers a flavor for each unique combination of
scheduling properties.
This commit is contained in:
Mark Goddard 2017-04-06 10:59:55 +01:00
parent 7920568796
commit 47cef3085d
5 changed files with 158 additions and 0 deletions
ansible

@ -0,0 +1,58 @@
---
# This playbook queries the bare metal compute node inventory in ironic and
# creates flavors in nova for each unique combination of scheduling properties
# (ram, disk, cpus). More complex flavor registration must currently be
# performed manually.
- name: Determine a list of baremetal flavors to register in nova
hosts: controllers[0]
vars:
venv: "{{ ansible_env.PWD }}/shade-venv"
flavor_base_name: baremetal-
roles:
- role: openstackclient
openstackclient_venv: "{{ venv }}"
tasks:
- name: Get a list of ironic nodes
shell: >
source {{ venv }}/bin/activate &&
openstack baremetal node list --fields name extra properties -f json
register: ironic_node_list
changed_when: False
environment: "{{ openstack_auth_env }}"
- name: Set facts containing the ironic nodes and initialise lists
set_fact:
ironic_nodes: "{{ ironic_node_list.stdout | from_json }}"
ironic_node_flavor_properties: []
nova_flavors: []
- name: Set a fact containing the ironic node properties
set_fact:
# Extra_specs required for CPU archiecture but not currently supported
# by ansible. Will be added in 2.3.
# At that point, add "'cpu_arch': item.Properties.cpu_arch,".
ironic_node_flavor_properties: >
{{ ironic_node_flavor_properties +
[{'vcpus': item.Properties.cpus,
'ram': item.Properties.memory_mb,
'disk': item.Properties.local_gb}] }}
with_items: "{{ ironic_nodes }}"
- name: Set a fact containing a list of flavors to register in nova
set_fact:
nova_flavors: >
{{ nova_flavors +
[item.1 | combine({'name': flavor_base_name ~ item.0})] }}
with_indexed_items: "{{ ironic_node_flavor_properties | unique | sort }}"
- name: Ensure baremetal compute node flavors are registered
hosts: controllers[0]
vars:
venv: "{{ ansible_env.PWD }}/shade-venv"
roles:
- role: nova-flavors
nova_flavors_venv: "{{ venv }}"
nova_flavors_auth_type: "{{ openstack_auth_type }}"
nova_flavors_auth: "{{ openstack_auth }}"

@ -0,0 +1,59 @@
Nova Flavors
============
This role can be used to register flavors in nova using the
os\_nova\_flavor module.
Requirements
------------
The OpenStack nova API should be accessible from the target host.
Role Variables
--------------
`nova_flavors_venv` is a path to a directory in which to create a
virtualenv.
`nova_flavors_auth_type` is an authentication type compatible with
the `auth_type` argument of `os_*` Ansible modules.
`nova_flavors_auth` is a dict containing authentication information
compatible with the `auth` argument of `os_*` Ansible modules.
`nova_flavors` is a list of nova flavors to register. Each item should be a
dict containing the items 'name', 'ram', 'disk', and 'vcpus'. Optionally, the
dict may contain 'ephemeral' and 'swap' items.
Dependencies
------------
This role depends on the Kayobe `shade` role.
Example Playbook
----------------
The following playbook registers a nova flavor.
---
- name: Ensure nova flavors are registered
hosts: nova-api
roles:
- role: nova-flavors
nova_flavors_venv: "~/nova-flavors-venv"
nova_flavors_auth_type: "password"
nova_flavors_auth:
project_name: <keystone project>
username: <keystone user>
password: <keystone password>
auth_url: <keystone auth URL>
nova_flavors:
name: flavor-1
ram: 1024
disk: 1024
vcpus: 2
Author Information
------------------
- Mark Goddard (<mark@stackhpc.com>)

@ -0,0 +1,14 @@
---
# Path to a directory in which to create a virtualenv.
nova_flavors_venv:
# Authentication type.
nova_flavors_auth_type:
# Authentication information.
nova_flavors_auth: {}
# List of nova flavors to register. Each item should be a dict containing the
# items 'name', 'ram', 'disk', and 'vcpus'. Optionally, the dict may contain
# 'ephemeral' and 'swap' items.
nova_flavors: []

@ -0,0 +1,4 @@
---
dependencies:
- role: shade
shade_venv: "{{ nova_flavors_venv }}"

@ -0,0 +1,23 @@
---
- name: Set a fact to ensure Ansible uses the python interpreter in the virtualenv
set_fact:
ansible_python_interpreter: "{{ nova_flavors_venv }}/bin/python"
- name: Ensure nova flavors exist
os_nova_flavor:
auth_type: "{{ nova_flavors_auth_type }}"
auth: "{{ nova_flavors_auth }}"
name: "{{ item.name }}"
ram: "{{ item.ram }}"
vcpus: "{{ item.vcpus }}"
disk: "{{ item.disk }}"
ephemeral: "{{ item.ephemeral | default(omit) }}"
swap: "{{ item.swap | default(omit) }}"
state: present
with_items: "{{ nova_flavors }}"
# This variable is unset before we set it, and it does not appear to be
# possible to unset a variable in Ansible.
- name: Set a fact to reset the Ansible python interpreter
set_fact:
ansible_python_interpreter: /usr/bin/python