Add rpm,image directories and SLA options to Livemigration
[yardstick.git] / ansible / library / my_os_networks_facts.py
1 #!/usr/bin/python
2
3 # Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
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 ---
26 module: my_os_network_facts
27 short_description: Retrieve facts about one or more OpenStack networks.
28 version_added: "2.0"
29 author: "Davide Agnello (@dagnello)"
30 description:
31     - Retrieve facts about one or more networks from OpenStack.
32 requirements:
33     - "python >= 2.6"
34     - "shade"
35 options:
36    network:
37      description:
38         - Name or ID of the Network
39      required: false
40    filters:
41      description:
42         - A dictionary of meta data to use for further filtering.  Elements of
43           this dictionary may be additional dictionaries.
44      required: false
45 extends_documentation_fragment: openstack
46 '''
47
48 EXAMPLES = '''
49 # Gather facts about previously created networks
50 - my_os_network_facts:
51     auth:
52       auth_url: https://your_api_url.com:9000/v2.0
53       username: user
54       password: password
55       project_name: someproject
56 - debug: var=openstack_networks
57
58 # Gather facts about a previously created network by name
59 - my_os_network_facts:
60     auth:
61       auth_url: https://your_api_url.com:9000/v2.0
62       username: user
63       password: password
64       project_name: someproject
65     name:  network1
66 - debug: var=openstack_networks
67
68 # Gather facts about a previously created network with filter (note: name and
69   filters parameters are Not mutually exclusive)
70 - my_os_network_facts:
71     auth:
72       auth_url: https://your_api_url.com:9000/v2.0
73       username: user
74       password: password
75       project_name: someproject
76     filters:
77       tenant_id: 55e2ce24b2a245b09f181bf025724cbe
78       subnets:
79         - 057d4bdf-6d4d-4728-bb0f-5ac45a6f7400
80         - 443d4dc0-91d4-4998-b21c-357d10433483
81 - debug: var=openstack_networks
82 '''
83
84 RETURN = '''
85 openstack_networks:
86     description: has all the openstack facts about the networks
87     returned: always, but can be null
88     type: complex
89     contains:
90         id:
91             description: Unique UUID.
92             returned: success
93             type: string
94         name:
95             description: Name given to the network.
96             returned: success
97             type: string
98         status:
99             description: Network status.
100             returned: success
101             type: string
102         subnets:
103             description: Subnet(s) included in this network.
104             returned: success
105             type: list of strings
106         tenant_id:
107             description: Tenant id associated with this network.
108             returned: success
109             type: string
110         shared:
111             description: Network shared flag.
112             returned: success
113             type: boolean
114 '''
115
116 def main():
117
118     argument_spec = openstack_full_argument_spec(
119         network={'required': False, 'default': None},
120         filters={'required': False, 'default': None}
121     )
122     module_kwargs = openstack_module_kwargs()
123     module = AnsibleModule(argument_spec)
124
125     if not HAS_SHADE:
126         module.fail_json(msg='shade is required for this module')
127
128     network = module.params.pop('network')
129     filters = module.params.pop('filters')
130
131     try:
132         cloud = shade.openstack_cloud(**module.params)
133         networks = cloud.search_networks(network, filters)
134         module.exit_json(changed=False, ansible_facts={
135             'openstack_networks': networks})
136
137     except shade.OpenStackCloudException as e:
138         module.fail_json(msg=str(e))
139
140 # this is magic, see lib/ansible/module_common.py
141 from ansible.module_utils.basic import *
142 from ansible.module_utils.openstack import *
143 if __name__ == '__main__':
144     main()