-
Notifications
You must be signed in to change notification settings - Fork 0
/
bios_templates.py
executable file
·68 lines (68 loc) · 3.16 KB
/
bios_templates.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
#!/usr/bin/env python3
#=============================================================================
# Source Modules
#=============================================================================
def prRed(skk): print("\033[91m {}\033[00m" .format(skk))
import os, sys
script_path= os.path.dirname(os.path.realpath(sys.argv[0]))
sys.path.insert(0, f'{script_path}{os.sep}classes')
try:
from classes import ezfunctions, isight, pcolor
from dotmap import DotMap
from stringcase import snakecase
import argparse, json, os, re, urllib3, yaml
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
except ImportError as e:
prRed(f'!!! ERROR !!!\n{e.__class__.__name__}')
prRed(f" Module {e.name} is required to run this script")
prRed(f" Install the module using the following: `pip install {e.name}`")
sys.exit(1)
class yaml_dumper(yaml.Dumper):
def increase_indent(self, flow=False, indentless=False):
return super(yaml_dumper, self).increase_indent(flow, False)
#=================================================================
# Function: Parse Arguments
#=================================================================
def cli_arguments():
parser = argparse.ArgumentParser(description ='Intersight BIOS Key Check Module')
parser = ezfunctions.base_arguments(parser)
return DotMap(args = parser.parse_args())
#=================================================================
# Function: Main Script
#=================================================================
def main():
#=============================================================
# Configure Base Module Setup
#=============================================================
kwargs = cli_arguments()
kwargs = ezfunctions.base_script_settings(kwargs)
kwargs = isight.api('organization').all_organizations(kwargs)
#=============================================================
# Sorting BIOS Tokens from easy-imm.json
#=============================================================
keys = list(kwargs.ezdata.bios.allOf[1].properties.keys())
bios_keys = DotMap()
bios_json = DotMap()
bios_yaml = DotMap()
for e in keys: bios_keys[kwargs.ezdata.bios.allOf[1].properties[e].intersight_api] = e
bkeys = list(bios_keys.keys())
kwargs.method = 'get'
kwargs.names = list(kwargs.org_names.keys()) + ['5ddfd9ff6972652d31ee6582']
kwargs.org = 'default'
kwargs.uri = kwargs.ezdata.bios.intersight_uri
kwargs = isight.api('multi_org').calls(kwargs)
for e in list(kwargs.results):
if e.Organization.Moid == '5ddfd9ff6972652d31ee6582':
jdict = DotMap(); ydict = DotMap()
for k,v in e.items():
if k in bkeys and v != 'platform-default':
jdict[k] = v
ydict[bios_keys[k]] = v
bios_json[e.Name] = jdict
bios_yaml[e.Name] = ydict
bios_json = DotMap(sorted(bios_json.items()))
bios_yaml = DotMap(sorted(bios_yaml.items()))
print(json.dumps(bios_json, indent=4))
print(yaml.dump(bios_yaml.toDict(), Dumper = yaml_dumper, default_flow_style=False))
if __name__ == '__main__':
main()