Merge "improve tc002 to make packet size parameterize"
[yardstick.git] / ansible / library / os_stack_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 module: os_stack_facts
26 short_description: Retrieve facts about an stack within OpenStack.
27 version_added: "2.0"
28 author: "Originally: Davide Agnello (@dagnello); modified"
29 description:
30     - Retrieve facts about a stack from OpenStack.
31 notes:
32     - Facts are placed in the C(openstack) variable.
33 requirements:
34     - "python >= 2.6"
35     - "shade"
36 options:
37 extends_documentation_fragment: openstack
38 '''
39
40 EXAMPLES = '''
41 # Gather facts about a previously created stack named stack1
42 - os_stack_facts:
43     auth:
44       auth_url: https://your_api_url.com:9000/v2.0
45       username: user
46       password: password
47       project_name: someproject
48 - debug: var=openstack_stacks
49 '''
50
51 RETURN = '''
52 openstack_stack:
53     description: has all the openstack facts about the stack
54     returned: always, but can be null
55     type: complex
56 '''
57
58
59 def main():
60
61     argument_spec = openstack_full_argument_spec(
62     )
63     module_kwargs = openstack_module_kwargs()
64     module = AnsibleModule(argument_spec, **module_kwargs)
65
66     if not HAS_SHADE:
67         module.fail_json(msg='shade is required for this module')
68
69
70     try:
71         cloud = shade.openstack_cloud(**module.params)
72         stacks = cloud.list_stacks()
73         module.exit_json(changed=False, ansible_facts={
74             'openstack_stacks': stacks})
75
76     except shade.OpenStackCloudException as e:
77         module.fail_json(msg=str(e))
78
79 # this is magic, see lib/ansible/module_common.py
80 from ansible.module_utils.basic import *
81 from ansible.module_utils.openstack import *
82 if __name__ == '__main__':
83     main()