Skip to content

Commit e6b1b07

Browse files
authored
Merge pull request #10 from stackhpc/flavors
Add os_flavors role
2 parents 86b450a + 522a5e1 commit e6b1b07

File tree

8 files changed

+132
-5
lines changed

8 files changed

+132
-5
lines changed
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
# Path to a directory in which to create a virtualenv.
33
os_deploy_templates_venv:
4-
54
# Upper constraints file for installation of python dependencies.
65
#
76
# Use Yoga upper constraints, to avoid incompatibility with openstacksdk
@@ -11,14 +10,11 @@ os_deploy_templates_upper_constraints_file: https://releases.openstack.org/const
1110

1211
# Authentication type.
1312
os_deploy_templates_auth_type:
14-
1513
# Authentication information.
1614
os_deploy_templates_auth: {}
17-
1815
# Endpoint URL type to fetch from the service catalog. Maybe be one of:
1916
# public, admin, or internal.
2017
os_deploy_templates_interface:
21-
2218
# List of Ironic deploy templates to register. Each item should be a dict
2319
# containing the following items:
2420
# - 'name': Name of the deploy template. Required when the deploy template is
@@ -27,4 +23,4 @@ os_deploy_templates_interface:
2723
# - 'extra': Dict of metadata, optional.
2824
# - 'uuid': UUID, optional.
2925
# - 'state': State, optional.
30-
os_deploy_templates: [] # noqa var-naming[no-role-prefix]
26+
os_deploy_templates: [] # noqa var-naming[no-role-prefix]

roles/os_flavors/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
OpenStack Flavors
2+
=================
3+
4+
This role can be used to register flavors in Nova using the
5+
`openstack.cloud.compute_flavor` module.
6+
7+
Requirements
8+
------------
9+
10+
The OpenStack Nova API should be accessible from the target host.
11+
12+
Role Variables
13+
--------------
14+
15+
`os_flavors_venv` is a path to a directory in which to create a
16+
virtualenv.
17+
18+
`os_flavors_auth_type` is an authentication type compatible with
19+
the `auth_type` argument of `openstack.cloud` Ansible modules.
20+
21+
`os_flavors_auth` is a dict containing authentication information
22+
compatible with the `auth` argument of `openstack.cloud` Ansible modules.
23+
24+
`os_flavors_cacert` is an optional path to a CA certificate bundle.
25+
26+
`os_flavors_interface` is the endpoint URL type to fetch from the service
27+
catalog. Maybe be one of `public`, `admin`, or `internal`.
28+
29+
`os_flavors` is a list of Nova flavors to register. Each item should be a dict
30+
containing the items 'name', 'ram', 'disk', and 'vcpus'. Optionally, the dict
31+
may contain 'ephemeral', 'flavorid', 'rxtx_factor' and 'swap' items.
32+
Optionally, the dict may also contain an item 'extra_specs', which is a dict of
33+
metadata to attach to the flavor object.
34+
35+
Dependencies
36+
------------
37+
38+
This role depends on the `stackhpc.openstack.os_openstacksdk` role.
39+
40+
Example Playbook
41+
----------------
42+
43+
The following playbook registers a Nova flavor.
44+
45+
---
46+
- name: Ensure Nova flavors are registered
47+
hosts: localhost
48+
roles:
49+
- role: stackhpc.openstack.os_flavors
50+
os_flavors_venv: "~/os-flavors-venv"
51+
os_flavors_auth_type: "password"
52+
os_flavors_auth:
53+
project_name: <keystone project>
54+
username: <keystone user>
55+
password: <keystone password>
56+
auth_url: <keystone auth URL>
57+
os_flavors:
58+
- name: flavor-1
59+
ram: 1024
60+
disk: 1024
61+
vcpus: 2
62+
extra_specs:
63+
hw:cpu_policy: "dedicated"
64+
hw:numa_nodes: "1"
65+
66+
Author Information
67+
------------------
68+
69+
- Mark Goddard (<[email protected]>)

roles/os_flavors/defaults/main.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
# Path to a directory in which to create a virtualenv.
3+
os_flavors_venv:
4+
# Authentication type.
5+
os_flavors_auth_type:
6+
# Authentication information.
7+
os_flavors_auth: {}
8+
# Endpoint URL type to fetch from the service catalog. Maybe be one of:
9+
# public, admin, or internal.
10+
os_flavors_interface:
11+
# List of nova flavors to register. Each item should be a dict containing the
12+
# following items:
13+
# - 'name': Name of the flavor.
14+
# - 'ram': Size of RAM (MB).
15+
# - 'disk': Size of disk (GB).
16+
# - 'vcpus': Number of vCPUs.
17+
# - 'ephemeral': Size of ephemeral disk (GB), optional.
18+
# - 'swap': Size of swap (GB), optional.
19+
# - 'rxtx_factor': RX/TX factor, optional.
20+
# - 'is_public': Whether the flavor is public.
21+
# - 'flavorid': ID for the flavor, optional.
22+
# - 'extra_specs': Dict of Nova flavor metadata, optional.
23+
os_flavors: [] # noqa var-naming[no-role-prefix]

roles/os_flavors/meta/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
dependencies:
3+
- role: stackhpc.openstack.os_openstacksdk
4+
os_openstacksdk_venv: "{{ os_flavors_venv }}"

roles/os_flavors/tasks/flavors.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
- name: Ensure nova flavors exist
3+
openstack.cloud.compute_flavor:
4+
auth_type: "{{ os_flavors_auth_type }}"
5+
auth: "{{ os_flavors_auth }}"
6+
cacert: "{{ os_flavors_cacert | default(omit) }}"
7+
interface: "{{ os_flavors_interface | default(omit, true) }}"
8+
name: "{{ item.name }}"
9+
ram: "{{ item.ram }}"
10+
vcpus: "{{ item.vcpus }}"
11+
disk: "{{ item.disk }}"
12+
ephemeral: "{{ item.ephemeral | default(omit) }}"
13+
swap: "{{ item.swap | default(omit) }}"
14+
rxtx_factor: "{{ item.rxtx_factor | default(omit) }}"
15+
is_public: "{{ item.is_public | default(omit) }}"
16+
flavorid: "{{ item.flavorid | default(omit) }}"
17+
extra_specs: "{{ item.extra_specs | default(omit) }}"
18+
state: "{{ item.state | default('present') }}"
19+
with_items: "{{ os_flavors }}"

roles/os_flavors/tasks/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: Set a fact about the Ansible python interpreter
3+
ansible.builtin.set_fact:
4+
old_ansible_python_interpreter: "{{ ansible_python_interpreter | default('/usr/bin/python3') }}"
5+
6+
- name: Import flavors.yml
7+
ansible.builtin.import_tasks: flavors.yml
8+
vars:
9+
ansible_python_interpreter: "{{ os_flavors_venv ~ '/bin/python' if os_flavors_venv != None else old_ansible_python_interpreter }}"

roles/os_flavors/tests/inventory

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
localhost ansible_connection='local' ansible_python_interpreter='/usr/bin/env python'

roles/os_flavors/tests/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: Test os_flavors role
3+
hosts: all
4+
connection: local
5+
roles:
6+
- stackhpc.openstack.os_flavors

0 commit comments

Comments
 (0)