Skip to content

Commit 13f8d02

Browse files
F OpenNebula/engineering#730: Sunstone views role (#176)
Signed-off-by: ArnauGabrielAtienza <agabriel@opennebula.io> Signed-off-by: Michal Opala <sk4zuzu@gmail.com> Co-authored-by: Michal Opala <sk4zuzu@gmail.com>
1 parent cda91a4 commit 13f8d02

5 files changed

Lines changed: 102 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ __pycache__/
44
/ansible_collections/*
55
!/ansible_collections/opennebula/deploy
66
/inventory/.one-deploy/
7+
/inventory/views/
78
/inventory/*.yml
89
!/inventory/example.yml
910
!/inventory/local.yml

roles/gui/README.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,23 @@ N/A
1111
Role Variables
1212
--------------
1313

14-
| Name | Type | Default | Example | Description |
15-
|-----------------------------|--------|-------------------------------------------|---------------------|--------------------------------------------------------------------------------|
16-
| `private_fireedge_endpoint` | `str` | `http://localhost:2616` | | FireEdge URL used internally in Sunstone / reverse proxies. |
17-
| `one_token` | `str` | undefined | `asd123as:123asd12` | OpenNebula Enterprise Edition subscription token. |
18-
| `one_fqdn` | `str` | undefined | `nebula.example.io` | Fully qualified domain name of the OpenNebula instance. |
19-
| `one_vip` | `str` | undefined | `10.11.12.13` | When OpenNebula is in HA mode it points to the Leader. |
20-
| `ssl.web_server` | `enum` | `apache` | (check below) | Enable reverse proxy with SSL termination with Apache2 or nginx over HTTPS/443.|
21-
| `ssl.key` | `str` | `/etc/ssl/private/opennebula-key.pem` | | Private key path on the target Front-end (the file must be readable). |
22-
| `ssl.certchain` | `str` | `/etc/ssl/certs/opennebula-certchain.pem` | | Certificate chain path on the target Front-end (the file must be readable). |
23-
| `ssl.generate_cert` | `bool` | `false` | `true` | Generate a CA and a certificate signed by that CA for the reverse proxy. |
14+
| Name | Type | Default | Example | Description |
15+
|--------------------------------|--------|--------------------------------------------------------|---------------------|----------------------------------------------------------------------------------|
16+
| `private_fireedge_endpoint` | `str` | `http://localhost:2616` | | FireEdge URL used internally in Sunstone / reverse proxies. |
17+
| `one_token` | `str` | undefined | `asd123as:123asd12` | OpenNebula Enterprise Edition subscription token. |
18+
| `one_fqdn` | `str` | undefined | `nebula.example.io` | Fully qualified domain name of the OpenNebula instance. |
19+
| `one_vip` | `str` | undefined | `10.11.12.13` | When OpenNebula is in HA mode it points to the Leader. |
20+
| `ssl.web_server` | `enum` | `apache` | (check below) | Enable reverse proxy with SSL termination with Apache2 or nginx over HTTPS/443. |
21+
| `ssl.key` | `str` | `/etc/ssl/private/opennebula-key.pem` | | Private key path on the target Front-end (the file must be readable). |
22+
| `ssl.certchain` | `str` | `/etc/ssl/certs/opennebula-certchain.pem` | | Certificate chain path on the target Front-end (the file must be readable). |
23+
| `ssl.generate_cert` | `bool` | `false` | `true` | Generate a CA and a certificate signed by that CA for the reverse proxy. |
24+
| `sunstone_views_base_dir` | `str` | `/etc/one/fireedge/sunstone/views/` | | Default destination for view definitions on OpenNebula Front-ends. |
25+
| `sunstone_views_config_file` | `str` | `/etc/one/fireedge/sunstone/views/sunstone-views.yaml` | | Default sunstone-views.yaml file path on OpenNebula Front-ends. |
26+
| `sunstone_views[].name` | `str` | undefined | `customview` | A name of the view (a key inside sunstone_views.yml). |
27+
| `sunstone_views[].label` | `str` | undefined | `Custom View` | A label of the view (visible in Sunstone UI). |
28+
| `sunstone_views[].description` | `str` | undefined | `A custom view` | A description of the view. |
29+
| `sunstone_views[].groups` | `list` | undefined | `[users]` | Members of these groups can use the view in Sunstone UI. |
30+
| `sunstone_views[].source_dir` | `str` | undefined | `customview` | A directory relative to "{{ inventory_dir }}/views/" containing view definition. |
2431

2532
Dependencies
2633
------------
@@ -39,6 +46,12 @@ Example Playbook
3946
web_server: nginx
4047
key: /etc/ssl/private/ssl-cert-snakeoil.key
4148
certchain: /etc/ssl/certs/ssl-cert-snakeoil.pem
49+
sunstone_views:
50+
- name: customview
51+
label: Custom View
52+
description: A custom view
53+
groups: [oneadmin, users]
54+
source_dir: customview/ # "{{ inventory_dir }}/views/customview/" -> "{{ sunstone_views_base_dir }}/customview/"
4255
roles:
4356
- role: opennebula.deploy.helper.facts
4457
- role: opennebula.deploy.gui

roles/gui/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ ssl_defaults:
55
web_server: apache # could be nginx
66
key: /etc/ssl/private/opennebula-key.pem
77
certchain: /etc/ssl/certs/opennebula-certchain.pem
8+
9+
sunstone_views: []
10+
sunstone_views_base_dir: /etc/one/fireedge/sunstone/views/
11+
sunstone_views_config_file: "{{ sunstone_views_base_dir }}/sunstone-views.yaml"

roles/gui/tasks/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@
6868
ansible.builtin.include_tasks:
6969
file: "{{ role_path }}/tasks/{{ ssl.web_server }}.yml"
7070
when: ssl is defined
71+
72+
- name: Deploy Sunstone Views
73+
ansible.builtin.include_tasks:
74+
file: "{{ role_path }}/tasks/sunstone_views.yml"

roles/gui/tasks/sunstone_views.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
- when: _input | count > 0
3+
vars:
4+
_input: >-
5+
{{ sunstone_views | d([]) }}
6+
7+
_values_loaded: >-
8+
{{ cfgtool_groups_and_views['values'] }}
9+
10+
_groups_loaded: >-
11+
{{ _values_loaded.0.0 }}
12+
13+
_views_loaded: >-
14+
{{ _values_loaded.1.0 }}
15+
16+
_groups_updated: >-
17+
{%- set output = _groups_loaded -%}
18+
{%- for v in _input -%}
19+
{%- for g in v.groups -%}
20+
{{-
21+
output.update({ g: (output.get(g, []) + [v.name]) | unique })
22+
-}}
23+
{%- endfor -%}
24+
{%- endfor -%}
25+
{{- output -}}
26+
27+
_views_updated: >-
28+
{%- set output = _views_loaded -%}
29+
{%- for v in _input -%}
30+
{{-
31+
output.update({ v.name: { "name": v.label, "description": v.description } })
32+
-}}
33+
{%- endfor -%}
34+
{{- output -}}
35+
block:
36+
- name: Copy custom Sunstone views from inventory
37+
ansible.builtin.copy:
38+
dest: "{{ _dest | normpath }}/" # / is strictly required here
39+
src: "{{ _src | normpath }}/" # / is strictly required here
40+
mode: u=rw,go=r
41+
vars:
42+
_dest: >-
43+
{{ sunstone_views_base_dir }}/{{ item.name }}
44+
_src: >-
45+
{{ inventory_dir }}/views/{{ item.source_dir }}
46+
loop: "{{ _input }}"
47+
loop_control: { label: "{{ item.name }}" }
48+
49+
- name: Read 'groups' and 'views' from sunstone-views.yaml
50+
opennebula.deploy.cfgtool:
51+
dest: "{{ sunstone_views_config_file }}"
52+
parser: Yaml
53+
actions:
54+
- get:
55+
path: [groups]
56+
- get:
57+
path: [views]
58+
register: cfgtool_groups_and_views
59+
60+
- name: Write updated 'groups' and 'views' into sunstone-views.yaml
61+
opennebula.deploy.cfgtool:
62+
dest: "{{ sunstone_views_config_file }}"
63+
parser: Yaml
64+
actions:
65+
- put:
66+
path: [groups]
67+
value: "{{ _groups_updated }}"
68+
- put:
69+
path: [views]
70+
value: "{{ _views_updated }}"

0 commit comments

Comments
 (0)