setup_oob 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,130 @@
|
|
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 'logger'
|
18
|
+
require 'socket'
|
19
|
+
require 'mixlib/shellout'
|
20
|
+
require_relative 'command/smc'
|
21
|
+
require_relative 'command/drac'
|
22
|
+
|
23
|
+
# A simple class to do the magic to build the right classes and call the
|
24
|
+
# right methods.
|
25
|
+
class OOB
|
26
|
+
def initialize(config)
|
27
|
+
@host = config[:host] || 'localhost'
|
28
|
+
@user = config[:user] || user
|
29
|
+
@password = config[:password]
|
30
|
+
@level = config[:level]
|
31
|
+
@desired_hostname = config[:desired_hn] || build_hostname
|
32
|
+
logger.debug("Desired hostname set to #{@desired_hostname}")
|
33
|
+
@network_mode = config[:network_mode]
|
34
|
+
@network_src = config[:network_src]
|
35
|
+
@key = config[:key]
|
36
|
+
@type = config[:type]
|
37
|
+
end
|
38
|
+
|
39
|
+
def logger
|
40
|
+
@logger ||= begin
|
41
|
+
logger = Logger.new($stdout)
|
42
|
+
logger.level = @level
|
43
|
+
logger
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def user
|
48
|
+
'ADMIN'
|
49
|
+
end
|
50
|
+
|
51
|
+
def converged?
|
52
|
+
do_work
|
53
|
+
end
|
54
|
+
|
55
|
+
def converge!
|
56
|
+
do_work(true)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def do_work(converge = false)
|
62
|
+
# Mmmmm, metaprogramming.
|
63
|
+
todo = {
|
64
|
+
# password MUST come first
|
65
|
+
'password' => @password,
|
66
|
+
'hostname' => @desired_hostname,
|
67
|
+
'ntp' => ['0.pool.ntp.org', '1.pool.ntp.org'],
|
68
|
+
'networkmode' => @network_mode,
|
69
|
+
'networksrc' => @network_src,
|
70
|
+
'ddns' => nil,
|
71
|
+
}
|
72
|
+
|
73
|
+
if @type == 'smc'
|
74
|
+
if @key
|
75
|
+
todo['license'] = @key
|
76
|
+
else
|
77
|
+
logger.warn('Will not check/activate license, no private key available')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
unless @password
|
82
|
+
logger.warn('Will not check/set admin password, no password specified')
|
83
|
+
todo.delete('password')
|
84
|
+
end
|
85
|
+
|
86
|
+
unless @network_src
|
87
|
+
logger.warn('Will not set network_src, not specified')
|
88
|
+
todo.delete('networksrc')
|
89
|
+
end
|
90
|
+
|
91
|
+
unless @network_mode
|
92
|
+
logger.warn('Will not set network_mode, not specified')
|
93
|
+
todo.delete('networkmode')
|
94
|
+
end
|
95
|
+
|
96
|
+
ret = true
|
97
|
+
optionally_supported = ['ntp', 'ddns']
|
98
|
+
cmd = Kernel.const_get("#{@type.upcase}Commands")
|
99
|
+
todo.each do |name, arg|
|
100
|
+
cls = cmd.const_get(name.capitalize)
|
101
|
+
obj = cls.new(@host, logger, arg)
|
102
|
+
begin
|
103
|
+
if converge
|
104
|
+
obj.converge!
|
105
|
+
else
|
106
|
+
ret &= obj.converged?
|
107
|
+
end
|
108
|
+
rescue Mixlib::ShellOut::ShellCommandFailed => e
|
109
|
+
if optionally_supported.include?(name) &&
|
110
|
+
e.message.include?('Invalid data field in request')
|
111
|
+
logger.warn("Host does not seem to support #{name}, skipping")
|
112
|
+
next
|
113
|
+
end
|
114
|
+
raise
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
unless converge
|
119
|
+
return ret
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def build_hostname
|
124
|
+
if @host == 'localhost'
|
125
|
+
"#{Socket.gethostname.split('.').first}-oob"
|
126
|
+
else
|
127
|
+
@host
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: setup_oob
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Phil Dibowitz
|
8
|
+
autorequire:
|
9
|
+
bindir:
|
10
|
+
- bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2021-12-15 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Utility for configuring OOB devices from linux
|
15
|
+
email:
|
16
|
+
executables:
|
17
|
+
- setup-oob
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.md
|
21
|
+
- LICENSE
|
22
|
+
- CHANGELOG.md
|
23
|
+
files:
|
24
|
+
- CHANGELOG.md
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- bin/setup-oob
|
28
|
+
- lib/setup_oob/command/base.rb
|
29
|
+
- lib/setup_oob/command/drac.rb
|
30
|
+
- lib/setup_oob/command/mixins.rb
|
31
|
+
- lib/setup_oob/command/smc.rb
|
32
|
+
- lib/setup_oob/oob.rb
|
33
|
+
- lib/setup_oob/version.rb
|
34
|
+
homepage: https://github.com/vicariousinc/setup-oob
|
35
|
+
licenses:
|
36
|
+
- Apache-2.0
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.5.0
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.7.6
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Setup OOB systems from Linux
|
58
|
+
test_files: []
|