-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathget-catalog.py
executable file
·83 lines (64 loc) · 2.36 KB
/
get-catalog.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
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
"""
Retrieves vRealize entitled catalog 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')
parser.add_argument('--url',
required=False,
action='store_true',
help='If this argument is set it will return catalog item names and URLs instead of IDs')
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)
catalog = vra.get_catalogitem_byname(name)
if args.url:
out = PrettyTable(['Name', 'URL'])
out.align['Name'] = 'l'
out.padding_width = 1
for i in catalog:
template_url = vra.get_request_template_url(i['id'])
out.add_row((i['name'], template_url))
print(out)
else:
out = PrettyTable(['Name', 'ID'])
out.align['Name'] = 'l'
out.padding_width = 1
for i in catalog:
out.add_row((i['name'], i['id']))
print(out)
if __name__ == '__main__':
main()