-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredfish.py
More file actions
64 lines (58 loc) · 1.69 KB
/
redfish.py
File metadata and controls
64 lines (58 loc) · 1.69 KB
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
import click
import lib.ImportSysConfigFile as imp
import lib.ResetDracPass as rstpwd
import lib.GeneratePass as np
import yaml
import os
def common_params(func):
@click.option('-s', '--source', envvar='SOURCE', default=os.path.join(os.getcwd(), "config.yml"),
type=str, help='Source YAML file.')
# @functools.wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper
@click.group()
def cli():
"""
This is a Redfish CLI Tool.
"""
@cli.command('enableAD', short_help='Enable AD to DELL.')
@common_params
def enableAD(source):
"""
Enable AD to iDRAC.
"""
print("AD Enabled")
y = getConfig(source)
for x in y['IDRAC']:
imp.args['ip'] = x['host']
imp.args['u'] = x['user']
imp.args['p'] = x['pass']
imp.Run()
@cli.command('resetPWD', short_help='Reset root password for DELL iDrac.')
@click.option('-f', '--file', envvar='FILE', default=os.path.join(os.getcwd(), "passwords.csv"),
type=str)
@common_params
def resetPWD(source,file):
"""
Reset root password for DELL idrac.
"""
print("Reset Root Password")
y = getConfig(source)
np.export(file, 'create', 'h')
for x in y['IDRAC']:
newpwd = np.get_password()
rstpwd.args['ip'] = x['host']
rstpwd.args['u'] = x['user']
rstpwd.args['p'] = x['pass']
rstpwd.args['np'] = newpwd
rstpwd.Run()
data = [ x['host'], newpwd ]
print(data)
np.export(file, data, 'a')
def getConfig(source):
with open(source, 'r') as stream:
try:
return yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)