-
Notifications
You must be signed in to change notification settings - Fork 13
/
get-items.py
executable file
·74 lines (57 loc) · 2.14 KB
/
get-items.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
"""
Retrieves vRealize provisioned items that match the value passed into '-n'
"""
# TODO set an environment variable that stores the auth token
# TODO create a check for auth token env variable. If present don't prompt for password
__version__ = "$Revision$"
# $Source$
import getpass
import argparse
import vralib
from prettytable import PrettyTable
def getargs():
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--server',
required=True,
action='store',
help='FQDN of the Cloud Provider.')
parser.add_argument('-u', '--username',
required=False,
action='store',
help='Username to access the cloud provider')
parser.add_argument('-t', '--tenant',
required=True,
action='store',
help='vRealize tenant')
parser.add_argument('-n', '--name',
required=False,
action='store',
help='The partial or full name of the catalog item you want the ID for')
args = parser.parse_args()
return args
def main():
args = getargs()
cloudurl = args.server
username = args.username
tenant = args.tenant
name = args.name
if not username:
username = input("vRA Username (user@domain):")
password = getpass.getpass("vRA Password:")
vra = vralib.Session.login(username, password, cloudurl, tenant, ssl_verify=False)
items = vra.get_consumer_resources()
out = PrettyTable(['Name', 'ID'])
out.align['Name'] = 'l'
out.padding_width = 1
# TODO VMware doesn't appear to use the same format for data it gets back from the API
# TODO will need to check for this and deal with it somehow.
# TODO I think I need to determine what the item is first then based on that find the label
for i in items['content']:
out.add_row((i['name'], i['id']))
# print i['id']
# print i['parentResourceRef']
#
print(out)
if __name__ == '__main__':
main()