forked from gethvi/iDRAC6VirtualConsoleLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iDRAC6VirtualConsoleLauncher.py
executable file
·93 lines (78 loc) · 2.99 KB
/
iDRAC6VirtualConsoleLauncher.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
93
#!/usr/bin/env python3
import argparse
import zipfile
import requests
import io
import pathlib
import sys
import urllib3
import subprocess
import re
def get_libraries(url, path):
response = requests.get(url)
with zipfile.ZipFile(file=io.BytesIO(response.content)) as zip:
for member in zip.infolist():
if member.filename.endswith(DYNLIBEX):
print('Extracting: ' + member.filename)
zip.extract(member, path=path)
def main():
parser = argparse.ArgumentParser(description='iDRAC 6 Virtual Console Launcher')
parser.add_argument('-u', '--user', type=str, default='root', action='store', help='iDRAC username [root]')
parser.add_argument('-p', '--passwd', type=str, default='calvin', action='store', help='iDRAC password [calvin]')
parser.add_argument('host', metavar='HOST[:PORT]', action='store', help='host running iDRAC 6 [port:5900]')
args = parser.parse_args()
url = urllib3.util.parse_url(args.host)
args.host = url.host
if url.port:
args.port = url.port
else:
args.port = 5900
avctvm_url = 'http://{0}/software/avctVM{1}.jar'.format(args.host, PLATFORM)
avctkvmio_url = 'http://{0}/software/avctKVMIO{1}.jar'.format(args.host, PLATFORM)
avctkvm_url = 'http://{0}/software/avctKVM.jar'.format(args.host)
pwd = pathlib.Path(sys.path[0])
# Hostdir is a striped version of host, because some chars can avoid LD load within java - as example IPv6 address with []
hostdir = pwd.joinpath('host_' + re.sub('[^a-zA-Z0-9]+', '', args.host))
java = pwd.joinpath('jre').joinpath('bin').joinpath('java' + BINARYEX)
libdir = hostdir.joinpath('lib')
libdir.mkdir(parents=True, exist_ok=True)
get_libraries(url=avctvm_url, path=libdir)
get_libraries(url=avctkvmio_url, path=libdir)
print('Downloading: avctKVM.jar')
response = requests.get(avctkvm_url)
with open('avctKVM.jar', 'w+b') as file:
file.write(response.content)
if java.exists():
subprocess.run([
str(java.absolute()),
'-cp',
'avctKVM.jar',
'-Djava.library.path={}'.format(libdir),
'com.avocent.idrac.kvm.Main',
'ip={}'.format(args.host),
'kmport={}'.format(args.port),
'vport={}'.format(args.port),
'user={}'.format(args.user),
'passwd={}'.format(args.passwd),
'apcp=1',
'version=2',
'vmprivilege=true',
'"helpurl=https://{}/help/contents.html"'.format(args.host)
])
if __name__ == '__main__':
if sys.platform.startswith('linux'):
PLATFORM = 'Linux64'
DYNLIBEX = '.so'
BINARYEX = ''
elif sys.platform.startswith('win'):
PLATFORM = 'Win64'
DYNLIBEX = '.dll'
BINARYEX = '.exe'
elif sys.platform.startswith('darwin'):
PLATFORM = 'Mac64'
DYNLIBEX = '.jnilib'
BINARYEX = ''
else:
print('Unsupported platform.')
sys.exit(0)
main()