Merge "Update release note for Danube.3.2"
[yardstick.git] / ansible / library / os_images_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_images_facts
26 short_description: Retrieve facts about an image within OpenStack.
27 version_added: "2.0"
28 author: "Originally: Davide Agnello (@dagnello); modified"
29 description:
30     - Retrieve facts about a image image from OpenStack.
31 notes:
32     - Facts are placed in the C(openstack) variable.
33 requirements:
34     - "python >= 2.6"
35     - "shade"
36 options:
37    image:
38      description:
39         - Name or ID of the image
40      required: false
41    filters:
42      description:
43         - A dictionary of meta data to use for further filtering.  Elements of
44           this dictionary may be additional dictionaries.
45      required: false
46 extends_documentation_fragment: openstack
47 '''
48
49 EXAMPLES = '''
50 # Gather facts about a previously created image named image1
51 - os_images_facts:
52     auth:
53       auth_url: https://your_api_url.com:9000/v2.0
54       username: user
55       password: password
56       project_name: someproject
57     image: image1
58 - debug: var=openstack
59 '''
60
61 RETURN = '''
62 openstack_image:
63     description: has all the openstack facts about the image
64     returned: always, but can be null
65     type: complex
66     contains:
67         id:
68             description: Unique UUID.
69             returned: success
70             type: string
71         name:
72             description: Name given to the image.
73             returned: success
74             type: string
75         status:
76             description: Image status.
77             returned: success
78             type: string
79         created_at:
80             description: Image created at timestamp.
81             returned: success
82             type: string
83         deleted:
84             description: Image deleted flag.
85             returned: success
86             type: boolean
87         container_format:
88             description: Container format of the image.
89             returned: success
90             type: string
91         min_ram:
92             description: Min amount of RAM required for this image.
93             returned: success
94             type: int
95         disk_format:
96             description: Disk format of the image.
97             returned: success
98             type: string
99         updated_at:
100             description: Image updated at timestamp.
101             returned: success
102             type: string
103         properties:
104             description: Additional properties associated with the image.
105             returned: success
106             type: dict
107         min_disk:
108             description: Min amount of disk space required for this image.
109             returned: success
110             type: int
111         protected:
112             description: Image protected flag.
113             returned: success
114             type: boolean
115         checksum:
116             description: Checksum for the image.
117             returned: success
118             type: string
119         owner:
120             description: Owner for the image.
121             returned: success
122             type: string
123         is_public:
124             description: Is public flag of the image.
125             returned: success
126             type: boolean
127         deleted_at:
128             description: Image deleted at timestamp.
129             returned: success
130             type: string
131         size:
132             description: Size of the image.
133             returned: success
134             type: int
135 '''
136
137
138 def main():
139
140     argument_spec = openstack_full_argument_spec(
141         image={'required': False, 'default': None},
142         filters={'required': False, 'default': None},
143     )
144     module_kwargs = openstack_module_kwargs()
145     module = AnsibleModule(argument_spec, **module_kwargs)
146
147     if not HAS_SHADE:
148         module.fail_json(msg='shade is required for this module')
149
150     image = module.params.pop('image')
151     filters = module.params.pop('filters')
152
153     try:
154         cloud = shade.openstack_cloud(**module.params)
155         images = cloud.search_images(image, filters)
156         module.exit_json(changed=False, ansible_facts={
157             'openstack_images': images})
158
159     except shade.OpenStackCloudException as e:
160         module.fail_json(msg=str(e))
161
162 # this is magic, see lib/ansible/module_common.py
163 from ansible.module_utils.basic import *
164 from ansible.module_utils.openstack import *
165 if __name__ == '__main__':
166     main()