blob: 2f3e70fa6f8d11e6b88122a855f19c024526bfe3 [file] [log] [blame]
Matteo Scandoloede125b2017-08-08 13:05:25 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Scott Bakerc41914d2017-06-26 14:00:52 -070017#!/usr/bin/python
18
19import json
20import os
21import requests
22import sys
23import traceback
24
25from ansible.module_utils.basic import AnsibleModule
26from auraclienttools import LCDNAPI, LCDNFault
27
28def main():
29 module = AnsibleModule(
30 argument_spec = dict(
31 name = dict(required=True, type='str'),
32 state = dict(required=True, type='str', choices=["present", "absent"]),
33 username = dict(required=True, type='str'),
34 password = dict(required=True, type='str'),
35 hostname = dict(required=True, type='str'),
36 plc_name = dict(required=True, type='str'),
37 )
38 )
39
40 credentials = {"username": module.params["username"],
41 "password": module.params["password"],
42 "hostname": module.params["hostname"],
43 "plc_name": module.params["plc_name"]}
44
45 state = module.params["state"]
46 siteName = module.params["name"]
47
48 api = LCDNAPI(credentials)
49
50 sites = api.ListAll("Site", {"name": siteName})
51
52 if sites and (state=="absent"):
53 api.deleteSite(siteName)
54 module.exit_json(changed=True, msg="site deleted")
55 elif (not sites) and (state=="present"):
56 api.createSite(siteName)
57 module.exit_json(changed=True, msg="site created")
58 else:
59 module.exit_json(changed=False)
60
61
62if __name__ == '__main__':
63 main()