Skip to content

Commit 203fbda

Browse files
add flavor to project mapping
* add flavor to project mapping * add readme and example
1 parent 1d5bade commit 203fbda

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

roles/os_flavors/README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
OpenStack Flavors
22
=================
33

4-
This role can be used to register flavors in Nova using the
5-
`openstack.cloud.compute_flavor` module.
4+
This role can be used to register flavors in Nova and map them to projects
5+
using the `openstack.cloud.compute_flavor` module.
66

77
Requirements
88
------------
@@ -32,6 +32,16 @@ may contain 'ephemeral', 'flavorid', 'rxtx_factor' and 'swap' items.
3232
Optionally, the dict may also contain an item 'extra_specs', which is a dict of
3333
metadata to attach to the flavor object.
3434

35+
`is_public` default is `true`. It is a mandatory parameter when mapping flavor
36+
to project, and it have to be set to `false` in that case. Non public
37+
flavor can't be mapped. However there is possibility to create flavor which
38+
is private and not mapped to any project. Only 'true' and 'false' are
39+
allowed here.
40+
41+
`project` single value, or list of projects, to which flavor should be mapped.
42+
In other words: this flavor will be visible and usable only in said project(s).
43+
44+
3545
Dependencies
3646
------------
3747

@@ -63,6 +73,25 @@ The following playbook registers a Nova flavor.
6373
hw:cpu_policy: "dedicated"
6474
hw:numa_nodes: "1"
6575

76+
The following playbook will allow uasge of `flavor-1` only in project `projectA`.
77+
78+
---
79+
- name: Map Nova flavors to projects
80+
hosts: localhost
81+
roles:
82+
- role: openstack.cloud.compute_flavor_access
83+
os_flavors_venv: "~/os-flavors-venv"
84+
os_flavors_auth_type: "password"
85+
os_flavors_auth:
86+
project_name: <keystone project>
87+
username: <keystone user>
88+
password: <keystone password>
89+
auth_url: <keystone auth URL>
90+
os_flavors:
91+
- name: flavor-1
92+
is_public: false
93+
project: "projectA"
94+
6695
Author Information
6796
------------------
6897

roles/os_flavors/tasks/flavors.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@
1212
ephemeral: "{{ item.ephemeral | default(omit) }}"
1313
swap: "{{ item.swap | default(omit) }}"
1414
rxtx_factor: "{{ item.rxtx_factor | default(omit) }}"
15-
is_public: "{{ item.is_public | default(omit) }}"
15+
is_public: "{{ item.is_public | default('true') }}"
1616
flavorid: "{{ item.flavorid | default(omit) }}"
1717
extra_specs: "{{ item.extra_specs | default(omit) }}"
1818
state: "{{ item.state | default('present') }}"
1919
with_items: "{{ os_flavors }}"
20+
21+
- name: Map nova flavors to projects
22+
openstack.cloud.compute_flavor_access:
23+
auth_type: "{{ os_flavors_auth_type }}"
24+
auth: "{{ os_flavors_auth }}"
25+
cacert: "{{ os_flavors_cacert | default(omit) }}"
26+
interface: "{{ os_flavors_interface | default(omit, true) }}"
27+
name: "{{ item.0.name }}"
28+
state: "{{ item.0.state | default('present') }}"
29+
project: "{{ item.1 | default(omit) }}"
30+
loop: "{{ lookup('subelements', os_flavors, 'project', {'skip_missing': True}) }}"
31+
when: not item.0.is_public | bool

0 commit comments

Comments
 (0)