Skip to content

Commit

Permalink
F #91: Improve ds "generic" and "simple" modes (#92)
Browse files Browse the repository at this point in the history
- Assume true if "managed" attribute is undefined.
- Assert that all symlink targets must exist.
- Provide rationale for manual "generic" ds id management.
  • Loading branch information
sk4zuzu authored Oct 23, 2024
1 parent 73a7d5d commit 0dcf07b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 21 deletions.
7 changes: 6 additions & 1 deletion roles/datastore/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Example Playbook
# Configure OpenNebula to use "ssh" datastores.
# Create symlinks accordingly.
# NOTE: In case of HA OpenNebula, image and file datastores
# should be shared among all Frontends.
# should be shared among all Frontends.
ds:
mode: ssh
config:
Expand Down Expand Up @@ -68,6 +68,11 @@ Example Playbook
vars:
# Configure OpenNebula to use "shared" image and system datastores.
# Create new datastores and symlinks accordingly.
# NOTE: 1. In OpenNebula all user-created datastores start from ID=100.
# 2. If the 'id' attribute refers to an existing datastore, then one-deploy tries to update it.
# 3. If 2. is false, then a new datastore is created using the next available ID.
# 4. Users *MUST* provide the 'id' attribute for each new entry in the 'ds.config' dict
# (starting from 100, then incrementing by 1 further down the line).
ds:
mode: generic
config:
Expand Down
6 changes: 3 additions & 3 deletions roles/datastore/generic/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ds_defaults:
enabled: true
symlink:
groups: [node]
src: /var/lib/one/datastores/
src: /var/lib/one/datastores/ # this skips symlinking
template:
TYPE: SYSTEM_DS
TM_MAD: ssh
Expand All @@ -21,7 +21,7 @@ ds_defaults:
managed: true
symlink:
groups: [frontend, node]
src: /var/lib/one/datastores/
src: /var/lib/one/datastores/ # this skips symlinking
template:
TYPE: IMAGE_DS
DS_MAD: fs
Expand All @@ -32,7 +32,7 @@ ds_defaults:
managed: true
symlink:
groups: [frontend]
src: /var/lib/one/datastores/
src: /var/lib/one/datastores/ # this skips symlinking
template:
TYPE: FILE_DS
DS_MAD: fs
Expand Down
38 changes: 27 additions & 11 deletions roles/datastore/generic/tasks/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
{{ _items | items2dict }}
vars:
_ds: >-
{{ ds_defaults | combine(ds.config | default({}), recursive=true) }}
{{ ds_defaults | combine(ds.config | d({}), recursive=true) }}
_items: >-
{{ _ds | dict2items
| map(attribute='value')
| map('dict2items')
| flatten
| selectattr('value.managed', 'true')
| list }}
| rejectattr('value.managed', 'false') }}
- name: Ensure /var/lib/one/datastores/ exists
ansible.builtin.file:
Expand All @@ -31,26 +30,43 @@
if [[ -L '{{ _base_path }}' ]]; then exit 0; fi
if [[ -d '{{ _base_path }}/' ]] && ! rmdir '{{ _base_path }}/'; then exit 1; fi
if ! [[ -d '{{ _mount_path }}' ]]; then
echo "Symlink target does not exist or is not a directory." >&2
exit 1
fi
if ! ln -s '{{ _mount_path }}/' '{{ _base_path }}'; then exit 1; fi
if [[ -d '{{ _base_path }}' ]] && ! rmdir '{{ _base_path }}'; then exit 1; fi
if ! ln -s '{{ _mount_path }}' '{{ _base_path }}'; then exit 1; fi
exit 78
executable: /bin/bash
when: inventory_hostname in _hosts and _mount_path != '/var/lib/one/datastores'
when:
- inventory_hostname in _hosts
# NOTE: It doesn't really make sense to symlink /var/lib/one/datastores/,
# so we use that as a skip condition.
- _mount_path != '/var/lib/one/datastores'
vars:
# This isn't strictly a "mountpoint" (that's completely irrelevant).
_mount_path: >-
{{ ds_dict[item].symlink.src | normpath }}
{{ ds_dict[item].symlink.src | d('/var/lib/one/datastores/') | normpath }}
# NOTE: 1. In OpenNebula all user-created datastores start from ID=100.
# 2. If the ds_dict[item].id refers to an existing datastore, then one-deploy tries to update it (later).
# 3. If 2. is false, then a new datastore is created using the next available ID (later).
# 4. If 3. is true, then at this exact point in time one-deploy does *NOT* know the ID.
# 5. The 'generic' mode has been specifically designed in such a way that reduces code complexity.
# Users *MUST* provide the 'id' attribute for each new entry in the 'ds.config' dict
# (starting from 100, then incrementing by 1 further down the line).
_base_path: >-
/var/lib/one/datastores/{{ ds_dict[item].id }}
_hosts: >-
{{ ds_dict[item].symlink.groups | map('extract', groups)
{{ ds_dict[item].symlink.groups | d([])
| map('extract', groups)
| flatten
| unique
| list }}
loop: "{{ ds_names }}"
| unique }}
register: shell
changed_when:
- shell.rc == 78 # EREMCHG "Remote address changed" 8^)
failed_when:
- shell.rc != 0 and shell.rc != 78
loop: "{{ ds_names }}"
4 changes: 2 additions & 2 deletions roles/datastore/generic/tasks/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
_document: >-
{{ shell.stdout | from_json }}
_datastores: >-
{{ [_document.DATASTORE_POOL.DATASTORE | default([])] | flatten | list }}
{{ [_document.DATASTORE_POOL.DATASTORE | d([])] | flatten }}
_names: >-
{{ _datastores | map(attribute='NAME') | default([]) | list }}
{{ _datastores | map(attribute='NAME') | d([]) | list }}
- when: inventory_hostname == leader
block:
Expand Down
9 changes: 7 additions & 2 deletions roles/datastore/simple/tasks/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
if [[ -L '{{ _base_path }}' ]]; then exit 0; fi
if [[ -d '{{ _base_path }}/' ]] && ! rmdir '{{ _base_path }}/'; then exit 1; fi
if ! [[ -d '{{ _mount_path }}' ]]; then
echo "Symlink target does not exist or is not a directory." >&2
exit 1
fi
if ! ln -s '{{ _mount_path }}/' '{{ _base_path }}'; then exit 1; fi
if [[ -d '{{ _base_path }}' ]] && ! rmdir '{{ _base_path }}'; then exit 1; fi
if ! ln -s '{{ _mount_path }}' '{{ _base_path }}'; then exit 1; fi
exit 78
executable: /bin/bash
Expand Down
9 changes: 7 additions & 2 deletions roles/datastore/simple/tasks/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
if [[ -L '{{ _base_path }}' ]]; then exit 0; fi
if [[ -d '{{ _base_path }}/' ]] && ! rmdir '{{ _base_path }}/'; then exit 1; fi
if ! [[ -d '{{ _mount_path }}' ]]; then
echo "Symlink target does not exist or is not a directory." >&2
exit 1
fi
if ! ln -s '{{ _mount_path }}/' '{{ _base_path }}'; then exit 1; fi
if [[ -d '{{ _base_path }}' ]] && ! rmdir '{{ _base_path }}'; then exit 1; fi
if ! ln -s '{{ _mount_path }}' '{{ _base_path }}'; then exit 1; fi
exit 78
executable: /bin/bash
Expand Down

0 comments on commit 0dcf07b

Please sign in to comment.