This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
__init__.py
59 lines (41 loc) · 1.5 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# encoding: utf-8
from ec2stack import helpers
from ec2stack.providers.cloudstack import requester
def describe_item(args, keyname, not_found, prefix):
if helpers.contains_parameter_with_keyword(prefix):
response = _describe_specific_item(args, keyname, not_found, prefix)
else:
response = describe_items_request(args, {})
return response
def _describe_specific_item(args, keyname, not_found, prefix):
keys = helpers.get_request_parameter_keys(prefix)
response = {keyname: []}
for key in keys:
name = helpers.get(key)
if 'Id' in key:
args['id'] = name
elif 'Name' in key:
args['name'] = name
request = describe_item_request(args, keyname, not_found)
response[keyname].append(request)
return response
def describe_item_request(args, keyname, not_found):
request = describe_items_request(args, not_found)
request = request[keyname]
for item in request:
if 'id' in args and args['id'].lower() == item['id'].lower():
return item
elif 'name' in args and args['name'].lower() == item['name'].lower():
return item
return not_found()
def describe_items_request(args, not_found):
args['listAll'] = 'true'
response = requester.make_request(args)
response = response[response.keys()[0]]
if 'count' in response:
return response
elif callable(not_found):
return not_found()
else:
return not_found