aboutsummaryrefslogtreecommitdiffstats
path: root/uci.py
diff options
context:
space:
mode:
authorGravatar Robin Obůrka <r.oburka@gmail.com> 2016-04-07 00:39:22 +0200
committerGravatar Robin Obůrka <r.oburka@gmail.com> 2016-04-07 00:55:07 +0200
commit9e842bf7fdb0b73c814daa6beae3e0dfe83cd58d (patch)
tree94bf5fa3e81b6bb8ca36dd853bcd9db556121e77 /uci.py
parentImprove info gathering section (diff)
downloadansible-uci-9e842bf7fdb0b73c814daa6beae3e0dfe83cd58d.tar.xz
Use completely new part with logic
Diffstat (limited to 'uci.py')
-rw-r--r--uci.py65
1 files changed, 50 insertions, 15 deletions
diff --git a/uci.py b/uci.py
index ab9397a..45e85ca 100644
--- a/uci.py
+++ b/uci.py
@@ -144,26 +144,61 @@ def main():
## Handle deletes
if state == "absent":
- if not val:
- module.exit_json(changed=False)
+ if not key:
+ ## User manipulates with section only
+ if sval:
+ uci_delete(module, bin_path, skey)
+ else:
+ module.exit_json(changed=False)
else:
- uci_delete(module, bin_path, key)
+ ## User manipulates with key
+ if val:
+ uci_delete(module, bin_path, key)
+ else:
+ module.exit_json(changed=False)
## Handle create or update requests
- if not val and not create:
- module.fail_json(msg="Key doesn't exist.")
-
- if not val and create:
- module.fail_json(msg="TODO: Create intermediates")
-
- if val and not value:
- module.fail_json(msg="Value wasn't provided")
-
- if val and value:
- if val == value:
+ if not key:
+ ## User manipulates with section only
+ if not sval:
+ ## ... and section doesn't exists
+ if create:
+ if not type:
+ module.fail_json(msg="Is necessary to create section but type wasn't specified")
+ uci_set(module, bin_path, skey, type)
+ else:
+ module.fail_json(msg="Section doesn't exist.")
+ else:
+ ## Section exists
module.exit_json(changed=False)
+ else:
+ ## User manipulates with key
+ if val:
+ ## Some value under key is available
+ if val == value:
+ module.exit_json(changed=False)
+ else:
+ uci_set(module, bin_path, key, value)
+
+ elif not val and sval and create:
+ ## Option doesn't exists but is possible to create it
+ uci_set(module, bin_path, key, value)
+
+ elif not val and sval and not create:
+ module.fail_json(msg="Key doesn't exist.")
+
+ elif not val and not sval and create:
+ ## Option doesn't exists because section doesn't exists and is possible to create it
+ if not type:
+ module.fail_json(msg="Is necessary to create section but type wasn't specified")
+ uci_set(module, bin_path, skey, type, noreturn=True)
+ uci_set(module, bin_path, key, value)
+
+ elif not val and not sval and not create:
+ module.fail_json(msg="Section doesn't exist.")
+
else:
- uci_set(module, bin_path, key, p["value"])
+ module.fail_json(msg="There is some bug in logic")
# import module snippets