summaryrefslogtreecommitdiff
path: root/cloud/lxd
diff options
context:
space:
mode:
authorHiroaki Nakamura <hnakamur@gmail.com>2016-06-30 01:59:37 +0900
committerHiroaki Nakamura <hnakamur@gmail.com>2016-06-30 01:59:37 +0900
commiteb7488854b93c4398e5a9afd245d83a857e9b8d3 (patch)
treed82365cdaa0d95bd59a4679a26726dc0ad12f8de /cloud/lxd
parent61020a87dd57a56de26160ca8140dd5ada584bd3 (diff)
downloadansible-modules-extras-eb7488854b93c4398e5a9afd245d83a857e9b8d3.tar.gz
Check argument choices according to type value
Diffstat (limited to 'cloud/lxd')
-rw-r--r--cloud/lxd/lxd_container.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/cloud/lxd/lxd_container.py b/cloud/lxd/lxd_container.py
index 04198c04..9d4c7420 100644
--- a/cloud/lxd/lxd_container.py
+++ b/cloud/lxd/lxd_container.py
@@ -317,7 +317,6 @@ except ImportError:
# LXD_ANSIBLE_STATES is a map of states that contain values of methods used
# when a particular state is evoked.
LXD_ANSIBLE_STATES = {
- 'present': '', # TODO: Separate state for profile
'started': '_started',
'stopped': '_stopped',
'restarted': '_restarted',
@@ -325,6 +324,11 @@ LXD_ANSIBLE_STATES = {
'frozen': '_frozen'
}
+# PROFILE_STATES is a list for states supported for type=profiles
+PROFILES_STATES = [
+ 'present', 'absent'
+]
+
# ANSIBLE_LXD_STATES is a map of states of lxd containers to the Ansible
# lxc_container module state parameter value.
ANSIBLE_LXD_STATES = {
@@ -361,8 +365,13 @@ class LxdContainerManagement(object):
self.name = self.module.params['name']
self.type = self.module.params['type']
self._build_config()
- # TODO: check state value according to type
+
self.state = self.module.params['state']
+ if self.type == 'container':
+ self._check_argument_choices('state', self.state, LXD_ANSIBLE_STATES.keys())
+ elif self.type == 'profile':
+ self._check_argument_choices('state', self.state, PROFILES_STATES)
+
self.new_name = self.module.params.get('new_name', None)
self.timeout = self.module.params['timeout']
self.wait_for_ipv4_addresses = self.module.params['wait_for_ipv4_addresses']
@@ -383,6 +392,12 @@ class LxdContainerManagement(object):
self.logs = []
self.actions = []
+ def _check_argument_choices(self, name, value, choices):
+ if value not in choices:
+ choices_str=",".join([str(c) for c in choices])
+ msg="value of %s must be one of: %s, got: %s" % (name, choices_str, value)
+ self.module.fail_json(msg=msg)
+
def _build_config(self):
self.config = {}
for attr in CONFIG_PARAMS[self.type]:
@@ -767,7 +782,7 @@ def main():
type='dict',
),
state=dict(
- choices=LXD_ANSIBLE_STATES.keys(),
+ choices=list(set(LXD_ANSIBLE_STATES.keys()) | set(PROFILES_STATES)),
default='started'
),
timeout=dict(