forked from scotttyso/intersight_iac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2tools.py
executable file
·92 lines (85 loc) · 3.06 KB
/
day2tools.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
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
from easy_functions import api_key, api_secret
import argparse
import class_day2tools
import os
import platform
import sys
# Global Variables
excel_workbook = None
Parser = argparse.ArgumentParser(description='Intersight Day 2 Tools')
def main():
description = None
if description is not None:
Parser.description = description
Parser.add_argument(
'-a', '--api-key-id',
default=os.getenv('TF_VAR_apikey'),
help='The Intersight API client key id for HTTP signature scheme'
)
Parser.add_argument(
'-s', '--api-key-file',
default=os.getenv('TF_VAR_secret_file'),
help='Name of file containing The Intersight secret key for the HTTP signature scheme'
)
Parser.add_argument(
'--api-key-v3', action='store_true',
help='Use New API client (v3) key'
)
Parser.add_argument(
'-f', '--full-inventory', action='store_true',
help='For Spreadsheet Pull the Full Server Inventory'
)
Parser.add_argument(
'-i', '--ignore-tls', action='store_true',
help='Ignore TLS server-side certificate verification'
)
Parser.add_argument(
'-j',
'--json-file',
default=None,
help='Source JSON File for VLAN Additional Process.'
)
Parser.add_argument(
'-p', '--process',
default='server_inventory',
help='Which Process to run with the Script. Options are 1. add_policies 2. add_vlan 3. server_inventory 4. hcl_status.'
)
Parser.add_argument(
'-u', '--url', default='https://intersight.com',
help='The Intersight root URL for the API endpoint. The default is https://intersight.com'
)
Parser.add_argument(
'-w', '--worksheet', default='Settings.xlsx',
help='The Worksheet Containing the Server Configuration Data.'
)
args = Parser.parse_args()
args.api_key_id = api_key(args)
# Determine the Operating System
opSystem = platform.system()
kwargs = {}
kwargs['args'] = args
kwargs['get_script_path'] = os.path.dirname(os.path.realpath(sys.argv[0]))
if opSystem == 'Windows': kwargs['path_sep'] = '\\'
else: kwargs['path_sep'] = '/'
# Verify the SecretKey
if not args.api_key_file == None:
args.api_key_file = api_secret(args)
else:
if opSystem == 'Windows': args.api_key_file = '$HOME\Downloads\SecretKey.txt'
else: args.api_key_file = '~/Downloads/SecretKey.txt'
args.api_key_file = api_secret(args)
if args.process == 'server_inventory':
type = 'server_inventory'
class_day2tools.intersight_api(type).server_inventory(**kwargs)
elif args.process == 'add_policies':
type = 'add_policies'
class_day2tools.intersight_api(type).add_policies(**kwargs)
elif args.process == 'add_vlan':
type = 'add_vlan'
class_day2tools.intersight_api(type).add_vlan(**kwargs)
elif args.process == 'hcl_status':
type = 'hcl_status'
class_day2tools.intersight_api(type).hcl_status(**kwargs)
if __name__ == '__main__':
main()