-
Notifications
You must be signed in to change notification settings - Fork 0
/
dracstart.py
executable file
·170 lines (133 loc) · 5.39 KB
/
dracstart.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python3
"""
Use this script to easily open downloaded jnlp files from Dell. Typically, the
file names aren't in a useful format, security settings won't easily allow
you to easily start by double-clicking, etc.
You'll probably want to move this script to a location where it's easily
executable, like maybe ~/bin. Don't forget to chown it +x if you want to.
Also check out the adjustable variables at the top of the script, things like
the location to your Downloads folder, etc.
Once that's done, simply download a jnlp file into your Downloads folder, then
run this script. You don't need to specify any parameters, as long as the
jnlp is the newest file in your Downloads folder, it'll find it.
In most cases, you'll have to also add the DRAC's IP to your Java Exceptions
file, as well.
On my Mac, I find that here:
/Users/$USER/Library/Application Support/Oracle/Java/Deployment/security/exception.sites
Simply add each IP on a seperate line, following this format:
https://xx.xx.xx.xx/
Tested mostly with iDRAC6 files, as you can upgrade iDRAC7 to allow HTML5
console access. I highly recommend you do that, if you're able.
---
Copyright 2024 derek.moyes @ gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. https://opensource.org/licenses/MIT
"""
import argparse
import textwrap
import glob
import os
import pprint
from datetime import datetime
from time import sleep
# Adjust these variables for your environment.
DebugString = "==> DEBUG:"
DownloadsPath = "/Users/dmoyes/Downloads/"
FileExt = "jnlp"
Snippet = "drac"
JavaRunner = "/usr/bin/javaws"
DeleteFileAfterUse = 1
DeleteAfterSeconds = 30
# Setup command-line arguments.
verbose = False
debug = False
parser = argparse.ArgumentParser(
prog='dracstart',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=__doc__)
parser.add_argument(
'-v', '--verbose',
action='store_true',
help="Print verbose information")
parser.add_argument(
'-d', '--debug',
action='store_true',
help="Print additional debug information")
args = parser.parse_args()
if args.verbose:
verbose = True
print("Setting verbose to %s." % verbose)
if args.debug:
debug = True
print("Setting debug to %s." % debug)
pp = pprint.PrettyPrinter(indent=4)
# Begin.
# Locate the latest FileExt file in DownloadsPath.
if verbose:
print("Checking for new %s files in %s..." % (FileExt, DownloadsPath))
list_of_files = glob.glob(DownloadsPath + '*' + FileExt)
if not list_of_files:
if verbose:
print("Specific %s file not found, checking all files in %s..."
% (FileExt, DownloadsPath))
list_of_files = glob.glob(DownloadsPath + '*')
try:
latest_file = max(list_of_files, key=os.path.getctime)
except ValueError as ve:
raise SystemExit("Sorry, I don't see any files in %s." % DownloadsPath)
else:
try:
latest_file = max(list_of_files, key=os.path.getctime)
except ValueError as ve:
raise SystemExit("Sorry, I don't see any files in %s." % DownloadsPath)
if verbose:
print("Found newest file %s..." % (latest_file))
# Validate that it is a DRAC config file.
try:
validate = open(latest_file, 'r').readlines()
except IOError as err:
print("Error: %s" % err)
except UnicodeDecodeError as err:
raise SystemExit("Sorry, the newest file %s seems to be a binary file."
% latest_file)
matches = []
for word in validate:
if Snippet in word.lower():
matches.append(word)
if debug:
print("%s List of read lines matching %s: " % (DebugString, Snippet))
pp.pprint(matches)
print("%s" % DebugString)
if not matches:
raise SystemExit("Sorry, the newest file %s doesn't seem to be of %s type."
% (latest_file, FileExt))
# Rename it to something nicer.
dt = datetime.now().strftime('%Y%m%d%M%S')
new_file_name = DownloadsPath + Snippet + dt + "." + FileExt
os.rename(latest_file, new_file_name)
if verbose:
print("Renamed to %s..." % (new_file_name))
# Run it with JavaRunner.
builtcommand = JavaRunner + " " + new_file_name
print("Starting %s..." % builtcommand)
os.system(builtcommand)
# Optionally move the file to trash after a specified period.
if DeleteFileAfterUse:
print("Waiting %s seconds to remove %s..."
% (DeleteAfterSeconds, new_file_name))
sleep(DeleteAfterSeconds)
os.remove(new_file_name)
print("Removed.")