-
Notifications
You must be signed in to change notification settings - Fork 0
/
ezclaim.py
executable file
·77 lines (74 loc) · 3.63 KB
/
ezclaim.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
#!/usr/bin/env python3
"""Intersight Device Connector API configuration and device claim via the Intersight API."""
#=============================================================================
# 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 claim_device, ezfunctions, isight, pcolor
from dotmap import DotMap
from pathlib import Path
import argparse, os, traceback, yaml
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}`")
#=============================================================================
# Parse Arguments
#=============================================================================
def cli_arguments():
parser = argparse.ArgumentParser(description ='Intersight Easy IMM Deployment Module')
parser = ezfunctions.base_arguments(parser)
parser.add_argument( '-ilp', '--local-user-password-1', help='Password used to login to the device for claiming.' )
parser.add_argument( '-pxp', '--proxy-password', help='Proxy password when using proxy and authentication is required.' )
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)
#=========================================================================
# EZCLAIM Setup
#=========================================================================
return_code = 0
kwargs.args.dir = os.path.abspath(kwargs.args.yaml_file.split('/')[0])
kwargs.deployment_type ='claim_devices'
#=========================================================================
# Send Notification Message
#=========================================================================
pcolor.LightGray(f'\n{"-"*108}\n')
pcolor.LightGray(f' * Begin Device Claims.')
pcolor.LightGray(f'\n{"-"*108}\n')
yfile = open(os.path.abspath(kwargs.args.yaml_file), 'r')
kwargs.yaml = DotMap(yaml.safe_load(yfile))
try:
kwargs.sensitive_var = 'local_user_password_1'
kwargs = ezfunctions.sensitive_var_value(kwargs)
kwargs.password = kwargs.var_value
kwargs.yaml.password = kwargs.password
kwargs = claim_device.claim_targets(kwargs)
except Exception as err:
print("Exception:", str(err))
print('-' * 60)
traceback.print_exc(file=sys.stdout)
print('-' * 60)
if kwargs.return_code:
sys.exit(kwargs.return_code)
else: sys.exit(return_code)
#=========================================================================
# Send Notification Message and Exit
#=========================================================================
pcolor.LightGray(f'\n{"-"*108}\n')
pcolor.LightGray(f' * Completed Device Claims.')
pcolor.LightGray(f'\n{"-"*108}\n')
sys.exit(1)
if __name__ == '__main__':
main()