Skip to content

Commit

Permalink
Merge pull request #16 from kushaldas/we_want_features
Browse files Browse the repository at this point in the history
Adds features as properties in VMs
  • Loading branch information
kushaldas committed Oct 24, 2018
2 parents becc768 + 74ac094 commit 2169abf
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ansible_module/qubesos.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@
'vcpus': int,
'virt_mode': str,
'default_dispvm': str,
'netvm': str
'netvm': str,
'features': dict,
}


Expand Down Expand Up @@ -370,6 +371,27 @@ def properties(self, vmname, prefs, vmtype, label, vmtemplate):
vm.virt_mode = prefs["virt_mode"]
changed = True
values_changed.append("virt_mode")
if "features" in prefs:
did_feature_changed = False
for key, value in prefs["features"].items():
if value == "" and key in vm.features:
vm.features[key] = ""
changed = True
did_feature_changed = True
elif value == "None" and key in vm.features:
del vm.features[key]
changed = True
did_feature_changed = True
elif key in vm.features and value != vm.features[key]:
vm.features[key] = value
changed = True
did_feature_changed = True
elif not key in vm.features and value != "None":
vm.features[key] = value
changed = True
did_feature_changed = True
if did_feature_changed:
values_changed.append("features")
return changed, values_changed


Expand Down
37 changes: 37 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,49 @@ The following are the different available properties and their data type.
- 'virt_mode': str
- 'default_dispvm': str
- 'netvm': str
- 'features': dict[str,str]


If you want to make changes to any existing vm, then first move it to *shutdown*
state and then use properties along with the *present* state to change any
value.

We can even add/update/remove ``features`` from a VM using properties.

::

---
- hosts: local
connection: local

tasks:
- name: Make sure the VM is present with right features
qubesos:
guest: xchat2
state: present
properties:
memory: 1200
maxmem: 2400
netvm: 'sys-whonix'
default_dispvm: 'fedora-28-dvm'
label: "yellow"
features:
life: "better"
can_fix_world_problem: False
news: "good"


To delete a feature (if that exists), mark the value as **"None"**. To make it
an empty string, that is the False value, use **""** as value. Example is given
below.

::

features:
life: "None"
news: ""


Adding tags to a vm
-------------------

Expand Down

0 comments on commit 2169abf

Please sign in to comment.