setup_oob 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +201 -0
- data/README.md +73 -0
- data/bin/setup-oob +137 -0
- data/lib/setup_oob/command/base.rb +91 -0
- data/lib/setup_oob/command/drac.rb +164 -0
- data/lib/setup_oob/command/mixins.rb +270 -0
- data/lib/setup_oob/command/smc.rb +341 -0
- data/lib/setup_oob/oob.rb +130 -0
- data/lib/setup_oob/version.rb +3 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ef36b57d84c15b988bdd3bafdcde5ec3f6a7b14a5d5af7a3b9e1755d427a2af6
|
4
|
+
data.tar.gz: 0a22b11dd0a28a56a5fb99436645ce276789809b4d39dfd2f95a4afe54bb9ee3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fad91e1545018c965d3ec0ef487f514bab543e229dcb9b181ff2fa3327ba6b7b08f69d156fd462559573a08c3f3e9ac833b4808faea466a2ff03db63b1a65dbd
|
7
|
+
data.tar.gz: 596e877ee79a6bbe5a9923dbff6734bb7ffed2a7f7641c35620956e6042185cc7dc228860b7502b9c910ad17385d93df600c5c902c39f59ce12a848ad4d977db
|
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Setup OOB
|
2
|
+
|
3
|
+
[](https://github.com/vicariousinc/setup-oob/actions?query=workflow%3AContinuous%20Integration)
|
4
|
+
|
5
|
+
This is a utility for configuring out-of-band management systems from within
|
6
|
+
the running (Linux) OS.
|
7
|
+
|
8
|
+
It is built to be highly modular and easy to add support for new types of OOB
|
9
|
+
devices.
|
10
|
+
|
11
|
+
As of current writing it supports SuperMicro's SMC systems and Dell's iDRAC
|
12
|
+
systems.
|
13
|
+
|
14
|
+
It is specifically designed to be easy to run from a Configuration Management
|
15
|
+
system such as Chef, and thus has a 'check' mode to enable idempotent behavior.
|
16
|
+
|
17
|
+
Setup OOB attempts to do as much as possible with the generic `ipmitool`, and
|
18
|
+
falls back to vendor-specific tools only where necessary. In fact, great
|
19
|
+
lengths were taken to determine the underlying IPMI commands in order to not
|
20
|
+
rely on vendor tools.
|
21
|
+
|
22
|
+
## General Use
|
23
|
+
|
24
|
+
Note that the `--help` message is always the best place to find all the current
|
25
|
+
options. This section instead attempts to provide and overview of usage, not an
|
26
|
+
exhaustive list of all options.
|
27
|
+
|
28
|
+
You must tell Setup OOB what type of device it needs to configure with the
|
29
|
+
`--type` option. As of now it takes either `smc` or `drac`. Let's say you want
|
30
|
+
to configure an iDRAC system, you might check to see if it's configured
|
31
|
+
properly with:
|
32
|
+
|
33
|
+
```shell
|
34
|
+
setup_oob --type drac --check --name server001-oob --network-mode shared \
|
35
|
+
--network-src dhcp
|
36
|
+
```
|
37
|
+
|
38
|
+
This would return 0 if these were all configured this way or non-zero if
|
39
|
+
something didn't match. If it was not correct, you could converge it to the
|
40
|
+
desired settings by re-running without `--check`:
|
41
|
+
|
42
|
+
```shell
|
43
|
+
setup_oob --type drac --name server001-oob --network-mode shared \
|
44
|
+
--network-src dhcp
|
45
|
+
```
|
46
|
+
|
47
|
+
If configuring a local system, IPMI does not need a password, however for some
|
48
|
+
devices, when vendor-specific tooling is required, it may fail without
|
49
|
+
specifying the password via `--old-password` (unless it's still the device
|
50
|
+
default).
|
51
|
+
|
52
|
+
## SMC Licensing
|
53
|
+
|
54
|
+
Setup OOB can "activate" SMC systems for you. Automating this can be a bit
|
55
|
+
difficult without having to store every single license in code or have your
|
56
|
+
Configuration Management system reach out to an external database.
|
57
|
+
|
58
|
+
However, license keys can be derived from the host MAC address and a private
|
59
|
+
key. *IF YOU HAVE PURCHASED LICENSES* (and if your legal team approves), you
|
60
|
+
can find the key on the internet and pass it into `--key-file`. If you do this,
|
61
|
+
then Setup OOB can generate the license key and activate the license for you.
|
62
|
+
|
63
|
+
To be clear: *DO NOT DO THIS IF YOU HAVE NOT PURCHASED A LICENSE FOR THE
|
64
|
+
MACHINES IN QUESTION*. Doing so is certainly a violation of your agreement with
|
65
|
+
SMC.
|
66
|
+
|
67
|
+
The authors of this software are not responsible for illegal use of this
|
68
|
+
option.
|
69
|
+
|
70
|
+
## External tools
|
71
|
+
|
72
|
+
Setup OOB requires `ipmitool` at a minimum. For SMC hosts, that is the only
|
73
|
+
requirement. For DRAC hosts, it also requires racadm.
|
data/bin/setup-oob
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
#!/opt/chef/embedded/bin/ruby
|
2
|
+
# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
|
3
|
+
|
4
|
+
# Copyright 2021-present Vicarious
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
# Helpful hints for figuring things out on the SMC:
|
19
|
+
#
|
20
|
+
# Run the SMCIPMITool in shell mode, then you can turn on copious debugging:
|
21
|
+
#
|
22
|
+
# ./SMCIPMITool $host $user $pass shell
|
23
|
+
#
|
24
|
+
# Once you're in the shell you can do 'debug 1' to dump all IPMI traffic
|
25
|
+
# for any command you run (there's also 2 and 3 for more)
|
26
|
+
#
|
27
|
+
# Then you can test things with:
|
28
|
+
# ipmitool -H $host -U $user -p $pass raw 0xYY 0xZZ ...
|
29
|
+
#
|
30
|
+
# In almost all cases the netfn is 0x30.
|
31
|
+
|
32
|
+
require 'logger'
|
33
|
+
require 'optparse'
|
34
|
+
require_relative '../lib/setup_oob/oob'
|
35
|
+
require_relative '../lib/setup_oob/version'
|
36
|
+
|
37
|
+
options = {
|
38
|
+
:level => Logger::INFO,
|
39
|
+
:host => 'localhost',
|
40
|
+
}
|
41
|
+
OptionParser.new do |opts|
|
42
|
+
opts.on(
|
43
|
+
'-l', '--log-level LEVEL', String, 'Logging level. Defaults to "info"'
|
44
|
+
) do |l|
|
45
|
+
options[:level] = l
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on('-c', '--check', 'Check current settings') do
|
49
|
+
options[:check] = true
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on('-h', '--help') do
|
53
|
+
puts opts
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
|
57
|
+
opts.on(
|
58
|
+
'-H', '--host HOST', String,
|
59
|
+
'Host to operate on. If the host is "localhost", then local IPMI is ' +
|
60
|
+
'used and no authentication is needed (which is great for setting the ' +
|
61
|
+
'right password no matter what it currently is. (default: localhost)'
|
62
|
+
) do |h|
|
63
|
+
unless h == 'localhost' || h.end_with?('-oob') || h.include?('.')
|
64
|
+
h << '-oob'
|
65
|
+
end
|
66
|
+
options[:host] = h
|
67
|
+
end
|
68
|
+
|
69
|
+
opts.on(
|
70
|
+
'-k', '--key-file FILE', String,
|
71
|
+
'A file containing a secret key used to generate licenses. Do not use ' +
|
72
|
+
'unless you have already purchased licenses!'
|
73
|
+
) do |k|
|
74
|
+
options[:key] = File.read(k)
|
75
|
+
end
|
76
|
+
|
77
|
+
opts.on(
|
78
|
+
'-n', '--name NAME', String,
|
79
|
+
'Desired name for the OOB. You probably do NOT want to use this ' +
|
80
|
+
'option. By default it is automatically generated for you. If ' +
|
81
|
+
'operating on "localhost", then the host\'s hostname is determined ' +
|
82
|
+
'and "-oob" is appended to the end. If operating on a remote host, then ' +
|
83
|
+
'"-oob" is appended to whatever was passed into -H'
|
84
|
+
) do |name|
|
85
|
+
options[:desired_hn] = name
|
86
|
+
end
|
87
|
+
|
88
|
+
opts.on(
|
89
|
+
'--network-mode MODE', ['dedicated', 'shared', 'failover'],
|
90
|
+
'Desired network mode.'
|
91
|
+
) do |mode|
|
92
|
+
options[:network_mode] = mode
|
93
|
+
end
|
94
|
+
|
95
|
+
opts.on(
|
96
|
+
'--network-src MODE', String, 'Desired network src.'
|
97
|
+
) do |src|
|
98
|
+
options[:network_src] = src
|
99
|
+
end
|
100
|
+
|
101
|
+
opts.on(
|
102
|
+
'-o', '--old-password PASSWORD', String,
|
103
|
+
'The password to use to authenticate. If using in local mode, this is ' +
|
104
|
+
'ignored. If needed, but not specified, the "-p" password will be tried ' +
|
105
|
+
'and then the default password.'
|
106
|
+
) do |pass|
|
107
|
+
options[:old_password] = pass
|
108
|
+
end
|
109
|
+
|
110
|
+
opts.on(
|
111
|
+
'-p', '--password PASSWORD', String,
|
112
|
+
'The desired password for the ADMIN user.'
|
113
|
+
) do |pass|
|
114
|
+
options[:password] = pass
|
115
|
+
end
|
116
|
+
|
117
|
+
opts.on('-t', '--type TYPE', String, 'The type of OOB (drac or smc)') do |t|
|
118
|
+
options[:type] = t
|
119
|
+
end
|
120
|
+
|
121
|
+
opts.on('--version') do
|
122
|
+
puts SetupOOB::VERSION
|
123
|
+
exit
|
124
|
+
end
|
125
|
+
end.parse!
|
126
|
+
|
127
|
+
unless options[:type]
|
128
|
+
fail 'must specify type'
|
129
|
+
end
|
130
|
+
|
131
|
+
puts "Configuring #{options[:host]}"
|
132
|
+
ipmi = OOB.new(options)
|
133
|
+
if options[:check]
|
134
|
+
exit(ipmi.converged? ? 0 : 1)
|
135
|
+
else
|
136
|
+
ipmi.converge!
|
137
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
|
2
|
+
|
3
|
+
# Copyright 2021-present Vicarious
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# The base class for a command
|
18
|
+
class CommandBase
|
19
|
+
attr_accessor :logger
|
20
|
+
|
21
|
+
def initialize(host, logger, data)
|
22
|
+
@host = host
|
23
|
+
@logger = logger
|
24
|
+
# data is any extra data subcommands might need
|
25
|
+
@data = data
|
26
|
+
end
|
27
|
+
|
28
|
+
def converged?
|
29
|
+
converged = _converged?
|
30
|
+
logger.info("#{pretty_self}: converged: #{converged}")
|
31
|
+
converged
|
32
|
+
end
|
33
|
+
|
34
|
+
def converge!
|
35
|
+
logger.info("Validating #{pretty_self}")
|
36
|
+
_converge!
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def _converged?
|
42
|
+
fail NotImplementedError
|
43
|
+
end
|
44
|
+
|
45
|
+
def _converge!
|
46
|
+
fail NotImplementedError
|
47
|
+
end
|
48
|
+
|
49
|
+
def pretty_self
|
50
|
+
self.class.to_s.split('::').last
|
51
|
+
end
|
52
|
+
|
53
|
+
# not applicable to all sub-classes, but common enough might
|
54
|
+
# as well include it here.
|
55
|
+
def enabled?
|
56
|
+
fail NotImplementedError
|
57
|
+
end
|
58
|
+
|
59
|
+
# get a single value you from the device
|
60
|
+
def getval(_key)
|
61
|
+
fail NotImplementedError
|
62
|
+
end
|
63
|
+
|
64
|
+
# set key to val
|
65
|
+
def setval(_key, _val)
|
66
|
+
fail NotImplementedError
|
67
|
+
end
|
68
|
+
|
69
|
+
# same as get, but handles multi-value gets and returns a hash
|
70
|
+
def getvals(_key)
|
71
|
+
fail NotImplementedError
|
72
|
+
end
|
73
|
+
|
74
|
+
# Simpler wrapper around Mixlib::ShellOut to log the command
|
75
|
+
def run(cmd, forcefail = true)
|
76
|
+
logger.debug("Running: #{cmd.join(' ')}")
|
77
|
+
s = Mixlib::ShellOut.new(*cmd)
|
78
|
+
s.run_command
|
79
|
+
s.error! if forcefail
|
80
|
+
s
|
81
|
+
end
|
82
|
+
|
83
|
+
# Given an array of bytes, get a string out of it.
|
84
|
+
def bytes_to_str(bytes)
|
85
|
+
bytes.pack('C*').force_encoding('utf-8')
|
86
|
+
end
|
87
|
+
|
88
|
+
def basecmd(_defaultpass)
|
89
|
+
fail NotImplementedError
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
|
2
|
+
|
3
|
+
# Copyright 2021-present Vicarious
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'mixlib/shellout'
|
18
|
+
require_relative 'base'
|
19
|
+
require_relative 'mixins'
|
20
|
+
|
21
|
+
# A slight extension of the Command class to add some DRAC-specific
|
22
|
+
# utility functions. Will be the base class for all DRAC commands
|
23
|
+
class DRACCommandBase < CommandBase
|
24
|
+
def getval(key)
|
25
|
+
s = run(basecmd + ['get', key])
|
26
|
+
s.stdout.lines[1].strip.split('=')[1]
|
27
|
+
end
|
28
|
+
|
29
|
+
def setval(key, val)
|
30
|
+
run(basecmd + ['set', key, val])
|
31
|
+
end
|
32
|
+
|
33
|
+
def getvals(key)
|
34
|
+
s = run(basecmd + ['get', key])
|
35
|
+
data = {}
|
36
|
+
s.stdout.each_line do |line|
|
37
|
+
next if line.start_with?('[')
|
38
|
+
next if line.strip.empty?
|
39
|
+
|
40
|
+
k, v = line.strip.split('=')
|
41
|
+
data[k] = v
|
42
|
+
end
|
43
|
+
data
|
44
|
+
end
|
45
|
+
|
46
|
+
def basecmd(_defaultpass = false)
|
47
|
+
if @host == 'localhost'
|
48
|
+
['racadm']
|
49
|
+
else
|
50
|
+
fail NotImplementedError
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# The collection of all DRAC command classes
|
56
|
+
class DRACCommands
|
57
|
+
# Manage the hostname
|
58
|
+
class Hostname < DRACCommandBase
|
59
|
+
private
|
60
|
+
|
61
|
+
include CommandMixins::Hostname
|
62
|
+
|
63
|
+
def hostname
|
64
|
+
getval('iDRAC.NIC.DnsRacName')
|
65
|
+
# data = getvals('iDRAC.NIC')
|
66
|
+
# "#{data['DNSRacName']}.#{data['DNSDomainName']}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def set_hostname
|
70
|
+
setval('iDRAC.NIC.DNSRacName', desired_hostname)
|
71
|
+
# setval('iDRAC.NIC.DNSDomainName', dn)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Manage NTP
|
76
|
+
class Ntp < DRACCommandBase
|
77
|
+
private
|
78
|
+
|
79
|
+
include CommandMixins::Ntp
|
80
|
+
|
81
|
+
def vals
|
82
|
+
@vals ||= getvals('idrac.NTPConfigGroup')
|
83
|
+
end
|
84
|
+
|
85
|
+
# Like the super-class, except we have to save the magic bytes...
|
86
|
+
def enabled?
|
87
|
+
vals['NTPEnable'] == 'Enabled'
|
88
|
+
end
|
89
|
+
|
90
|
+
def enable
|
91
|
+
setval('idrac.NTPConfigGroup.NTPEnable', 'Enabled')
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_server(idx)
|
95
|
+
vals["NTP#{idx + 1}"]
|
96
|
+
end
|
97
|
+
|
98
|
+
def set_server(idx)
|
99
|
+
setval("idrac.NTPConfigGroup.NTP#{idx + 1}", servers[idx])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class Ddns < DRACCommandBase
|
104
|
+
private
|
105
|
+
|
106
|
+
include CommandMixins::Ddns
|
107
|
+
|
108
|
+
def enabled?
|
109
|
+
getval('iDRAC.NIC.DNSRegister') == 'Enabled'
|
110
|
+
end
|
111
|
+
|
112
|
+
def enable
|
113
|
+
setval('iDRAC.NIC.DNSRegister', 'Enabled')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class Networksrc < DRACCommandBase
|
118
|
+
include CommandMixins::Networksrc
|
119
|
+
end
|
120
|
+
|
121
|
+
class Networkmode < DRACCommandBase
|
122
|
+
private
|
123
|
+
|
124
|
+
include CommandMixins::Networkmode
|
125
|
+
|
126
|
+
def mode_correct?
|
127
|
+
logger.debug(' - Checking NIC mode')
|
128
|
+
getval('iDRAC.NIC.Selection').downcase == desired_mode
|
129
|
+
end
|
130
|
+
|
131
|
+
def set_mode
|
132
|
+
case desired_mode
|
133
|
+
when 'shared'
|
134
|
+
setval('iDRAC.NIC.Selection', 'LOM1')
|
135
|
+
when 'dedicated'
|
136
|
+
setval('iDRAC.NIC.Selection', desired_mode.capitalize)
|
137
|
+
else
|
138
|
+
fail "Unknown NIC mode: #{desired_mode}"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
class Password < DRACCommandBase
|
144
|
+
private
|
145
|
+
|
146
|
+
include CommandMixins::Password
|
147
|
+
|
148
|
+
def admin_id
|
149
|
+
return @admin_id if @admin_id
|
150
|
+
|
151
|
+
s = run(basecmd + ['get', 'iDrac.Users'])
|
152
|
+
s.stdout.each_line do |line|
|
153
|
+
next unless line.start_with?('iDRAC.Users')
|
154
|
+
|
155
|
+
key = line.split[0]
|
156
|
+
info = getvals(key)
|
157
|
+
if info['UserName'] == 'root'
|
158
|
+
@admin_id = key.split('.')[2]
|
159
|
+
return @admin_id
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|