Ansible typo fix, whitespace
[yardstick.git] / ansible / library / my_os_router_facts.py
1 #!/usr/bin/python
2
3 # Copyright (c) 2016 IBM
4 #
5 # This module is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This software is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this software.  If not, see <http://www.gnu.org/licenses/>.
17
18 try:
19     import shade
20     HAS_SHADE = True
21 except ImportError:
22     HAS_SHADE = False
23
24 DOCUMENTATION = '''
25 module: my_os_router_facts
26 short_description: Retrieve facts about routers within OpenStack.
27 version_added: "2.1"
28 author: "Originally: David Shrewsbury (@Shrews); modified"
29 description:
30     - Retrieve facts about routers from OpenStack.
31 notes:
32     - Facts are placed in the C(openstack_routers) variable.
33 requirements:
34     - "python >= 2.6"
35     - "shade"
36 options:
37     port:
38         description:
39             - Unique name or ID of a port.
40         required: false
41         default: null
42     filters:
43         description:
44             - A dictionary of meta data to use for further filtering. Elements
45               of this dictionary will be matched against the returned port
46               dictionaries. Matching is currently limited to strings within
47               the port dictionary, or strings within nested dictionaries.
48         required: false
49         default: null
50 extends_documentation_fragment: openstack
51 '''
52
53 EXAMPLES = '''
54 # Gather facts about all routers
55 - my_os_router_facts:
56     cloud: mycloud
57
58 # Gather facts about a single port
59 - my_os_router_facts:
60     cloud: mycloud
61     port: 6140317d-e676-31e1-8a4a-b1913814a471
62
63 # Gather facts about all routers that have device_id set to a specific value
64 # and with a status of ACTIVE.
65 - my_os_router_facts:
66     cloud: mycloud
67    router:
68      description:
69         - Name or ID of the router
70      required: false
71     filters:
72       device_id: 1038a010-3a37-4a9d-82ea-652f1da36597
73       status: ACTIVE
74 '''
75
76 RETURN = '''
77 openstack_routers:
78     description: List of port dictionaries. A subset of the dictionary keys
79                  listed below may be returned, depending on your cloud provider.
80     returned: always, but can be null
81     type: complex
82     contains:
83 '''
84
85
86 def main():
87     argument_spec = openstack_full_argument_spec(
88         router={'required': False, 'default': None},
89         filters={'required': False, 'type': 'dict', 'default': None},
90     )
91     module_kwargs = openstack_module_kwargs()
92     module = AnsibleModule(argument_spec, **module_kwargs)
93
94     if not HAS_SHADE:
95         module.fail_json(msg='shade is required for this module')
96
97     name = module.params.pop('name')
98     filters = module.params.pop('filters')
99
100     try:
101         cloud = shade.openstack_cloud(**module.params)
102         routers = cloud.search_routers(name, filters)
103         module.exit_json(changed=False, ansible_facts=dict(
104             openstack_routers=routers))
105
106     except shade.OpenStackCloudException as e:
107         module.fail_json(msg=str(e))
108
109 from ansible.module_utils.basic import *
110 from ansible.module_utils.openstack import *
111
112 if __name__ == '__main__':
113     main()