Skip to content

Commit

Permalink
Merge pull request #22 from kushaldas/storage_size
Browse files Browse the repository at this point in the history
Adds volume resize option
  • Loading branch information
kushaldas committed Dec 14, 2018
2 parents 1aad06a + a0f419f commit f61c495
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
29 changes: 28 additions & 1 deletion ansible_module/qubesos.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
'default_dispvm': str,
'netvm': str,
'features': dict,
'volume': dict,
}


Expand Down Expand Up @@ -396,6 +397,17 @@ def properties(self, vmname, prefs, vmtype, label, vmtemplate):
did_feature_changed = True
if did_feature_changed:
values_changed.append("features")
if "volume" in prefs:
val = prefs["volume"]
# Let us get the volume
try:
volume = vm.volumes[val["name"]]
volume.resize(val["size"])
except Exception:
return VIRT_FAILED, {"Failure in updating volume": val}
changed = True
values_changed.append("volume")

return changed, values_changed


Expand Down Expand Up @@ -458,7 +470,22 @@ def core(module):
# Also the vm should provide network
if not vm.provides_network:
return VIRT_FAILED, {"Missing netvm capability": val}
template_for_dispvms

# Make sure volume has both name and value
if key == "volume":
if "name" not in val:
return VIRT_FAILED, {"Missing name for the volume": val}
elif "size" not in val:
return VIRT_FAILED, {"Missing size for the volume": val}

allowed_name = []
if vmtype == 'AppVM':
allowed_name.append("private")
elif vmtype in ["StandAloneVM", "TemplateVM"]:
allowed_name.append("root")

if not val["name"] in allowed_name:
return VIRT_FAILED, {"Wrong volume name": val}

# Make sure that the default_dispvm exists
if key == "default_dispvm":
Expand Down
23 changes: 23 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ Setting different property values to a given vm

.. note:: Always remember to move the state to running to get the vm up and running.

Resizing volume
---------------

This can be done using *volume* property. You can set the "private" volume size
in AppVMs, and "root" volume size in StandAloneVM or TemplateVM. Right now it takes
the size in bytes.

::

tasks:
- name: Make sure the VM is present
qubesos:
guest: xchat2
state: present
properties:
memory: 1200
maxmem: 2400
netvm: 'sys-whonix'
label: "yellow"
volume:
name: "private"
size: "5368709120"

Available properties
----------------------
Expand All @@ -110,6 +132,7 @@ The following are the different available properties and their data type.
- 'default_dispvm': str
- 'netvm': str
- 'features': dict[str,str]
- 'volume': dict[str,str]


If you want to make changes to any existing vm, then first move it to *shutdown*
Expand Down
3 changes: 3 additions & 0 deletions examples/presentstate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
maxmem: 2400
netvm: 'sys-whonix'
label: "yellow"
volume:
name: "private"
size: "5368709120"

- name: Run the VM
qubesos:
Expand Down

0 comments on commit f61c495

Please sign in to comment.