diff --git a/roles/os_flavors/README.md b/roles/os_flavors/README.md index 09ea9e6..0237bf1 100644 --- a/roles/os_flavors/README.md +++ b/roles/os_flavors/README.md @@ -1,8 +1,8 @@ OpenStack Flavors ================= -This role can be used to register flavors in Nova using the -`openstack.cloud.compute_flavor` module. +This role can be used to register flavors in Nova and map them to projects +using the `openstack.cloud.compute_flavor` module. Requirements ------------ @@ -32,6 +32,16 @@ may contain 'ephemeral', 'flavorid', 'rxtx_factor' and 'swap' items. Optionally, the dict may also contain an item 'extra_specs', which is a dict of metadata to attach to the flavor object. +`is_public` default is `true`. It is a mandatory parameter when mapping flavor +to project, and it have to be set to `false` in that case. Non public +flavor can't be mapped. However there is possibility to create flavor which +is private and not mapped to any project. Only 'true' and 'false' are +allowed here. + +`project` single value, or list of projects, to which flavor should be mapped. +In other words: this flavor will be visible and usable only in said project(s). + + Dependencies ------------ @@ -63,6 +73,25 @@ The following playbook registers a Nova flavor. hw:cpu_policy: "dedicated" hw:numa_nodes: "1" +The following playbook will allow uasge of `flavor-1` only in project `projectA`. + + --- + - name: Map Nova flavors to projects + hosts: localhost + roles: + - role: openstack.cloud.compute_flavor_access + os_flavors_venv: "~/os-flavors-venv" + os_flavors_auth_type: "password" + os_flavors_auth: + project_name: + username: + password: + auth_url: + os_flavors: + - name: flavor-1 + is_public: false + project: "projectA" + Author Information ------------------ diff --git a/roles/os_flavors/tasks/flavors.yml b/roles/os_flavors/tasks/flavors.yml index dc45121..e50b9fc 100644 --- a/roles/os_flavors/tasks/flavors.yml +++ b/roles/os_flavors/tasks/flavors.yml @@ -12,8 +12,20 @@ ephemeral: "{{ item.ephemeral | default(omit) }}" swap: "{{ item.swap | default(omit) }}" rxtx_factor: "{{ item.rxtx_factor | default(omit) }}" - is_public: "{{ item.is_public | default(omit) }}" + is_public: "{{ item.is_public | default('true') }}" flavorid: "{{ item.flavorid | default(omit) }}" extra_specs: "{{ item.extra_specs | default(omit) }}" state: "{{ item.state | default('present') }}" with_items: "{{ os_flavors }}" + +- name: Map nova flavors to projects + openstack.cloud.compute_flavor_access: + auth_type: "{{ os_flavors_auth_type }}" + auth: "{{ os_flavors_auth }}" + cacert: "{{ os_flavors_cacert | default(omit) }}" + interface: "{{ os_flavors_interface | default(omit, true) }}" + name: "{{ item.0.name }}" + state: "{{ item.0.state | default('present') }}" + project: "{{ item.1 | default(omit) }}" + loop: "{{ lookup('subelements', os_flavors, 'project', {'skip_missing': True}) }}" + when: not item.0.is_public | bool