-
Notifications
You must be signed in to change notification settings - Fork 2
/
olt_reboot.py
executable file
·60 lines (43 loc) · 1.7 KB
/
olt_reboot.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
#!/usr/bin/python
import mymod
import argparse
import sys
from creds import *
OLT = [name for name in olts.keys()]
def check_arg(args=None):
parser = argparse.ArgumentParser(description='Cisco OLT rebooter')
mand = parser.add_argument_group(title='mandatory arguments')
mand.add_argument('-o', '--olt', choices = olts, help=', '.join(OLT), metavar='', required='True')
exgroup = parser.add_argument_group(title='one or the other')
group = exgroup.add_mutually_exclusive_group(required=True)
group.add_argument('-s','--slot', help='slot number', default=None)
group.add_argument('-r','--reboot', help='reboot machine', action='store_true')
opt = parser.add_argument_group("optional arguments")
opt.add_argument('-c', '--check', help='check mode', action='store_true')
args = parser.parse_args(args)
return (args.olt, args.check, args.slot, args.reboot)
def main():
olt_arg, check, slot, reboot = check_arg(sys.argv[1:])
if olt_arg in OLT:
olt = olts[olt_arg]
else:
print ("No OLT specified")
myolt = mymod.Olt(olt)
ssh = myolt.connect()
remote_conn = ssh.invoke_shell()
myolt.send_command(remote_conn)
if check:
send_confirm = "no"
else:
send_confirm = "yes"
if reboot:
send_reboot = "equipment/system/reboot"
output = myolt.send_command(remote_conn, send_reboot)
myolt.send_command(remote_conn, send_confirm)
else:
send_reboot = "equipment/boards/reboot --slot=" + slot
output = myolt.send_command(remote_conn, send_reboot)
myolt.send_command(remote_conn, send_confirm)
remote_conn.close()
if __name__ == "__main__":
main()