knife-baremetalcloud 0.0.1 → 0.0.2
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.
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-baremetalcloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Diego Desani
|
@@ -50,10 +50,6 @@ files:
|
|
50
50
|
- README.md
|
51
51
|
- Rakefile
|
52
52
|
- knife-baremetalcloud.gemspec
|
53
|
-
- lib/chef/baremetalcloud_list_available_servers.rb
|
54
|
-
- lib/chef/baremetalcloud_list_images.rb
|
55
|
-
- lib/chef/baremetalcloud_list_servers.rb
|
56
|
-
- lib/chef/baremetalcloud_server_create.rb
|
57
53
|
- lib/knife-baremetalcloud.rb
|
58
54
|
- lib/knife-baremetalcloud/version.rb
|
59
55
|
homepage: https://github.com/baremetalcloud/knife-baremetalcloud
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'fog'
|
2
|
-
|
3
|
-
class Chef
|
4
|
-
class Knife
|
5
|
-
class BaremetalcloudListAvailableServers < Knife
|
6
|
-
|
7
|
-
banner "knife baremetalcloud list available servers (options)"
|
8
|
-
|
9
|
-
option :baremetalcloud_username,
|
10
|
-
:short => '-x USERNAME',
|
11
|
-
:long => '--username USERNAME',
|
12
|
-
:description => 'Customer username'
|
13
|
-
|
14
|
-
option :baremetalcloud_password,
|
15
|
-
:short => '-P PASSWORD',
|
16
|
-
:long => '--password PASSWORD',
|
17
|
-
:description => 'Customer password'
|
18
|
-
|
19
|
-
def locate_config_value(key)
|
20
|
-
key = key.to_sym
|
21
|
-
config[key] || Chef::Config[:knife][key]
|
22
|
-
end
|
23
|
-
|
24
|
-
def run
|
25
|
-
|
26
|
-
# Parameters :baremetalcloud_username and :baremetalcloud_password are mandatory
|
27
|
-
unless config[:baremetalcloud_username]
|
28
|
-
ui.error("--username is a mandatory parameter")
|
29
|
-
exit 1
|
30
|
-
end
|
31
|
-
|
32
|
-
unless config[:baremetalcloud_password]
|
33
|
-
ui.error("--password is a mandatory parameter")
|
34
|
-
exit 1
|
35
|
-
end
|
36
|
-
|
37
|
-
# Configure the API abstraction @bmc
|
38
|
-
@bmc = Fog::Compute.new({
|
39
|
-
:bare_metal_cloud_username => config[:baremetalcloud_username],
|
40
|
-
:bare_metal_cloud_password => config[:baremetalcloud_password],
|
41
|
-
:provider => 'BareMetalCloud'
|
42
|
-
})
|
43
|
-
|
44
|
-
response = @bmc.list_available_servers.body[:"available-server"]
|
45
|
-
|
46
|
-
if response.length > 1
|
47
|
-
#puts "#{ui.color("String", :cyan)}\t#{ui.color("Quantity", :cyan)}"
|
48
|
-
response.each do |r|
|
49
|
-
puts "#{r[:configuration]}\t#{r[:quantity]}"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'fog'
|
2
|
-
|
3
|
-
class Chef
|
4
|
-
class Knife
|
5
|
-
class BaremetalcloudListImages < Knife
|
6
|
-
|
7
|
-
banner "knife baremetalcloud list images (options)"
|
8
|
-
|
9
|
-
option :baremetalcloud_username,
|
10
|
-
:short => '-x USERNAME',
|
11
|
-
:long => '--username USERNAME',
|
12
|
-
:description => 'Customer username'
|
13
|
-
|
14
|
-
option :baremetalcloud_password,
|
15
|
-
:short => '-P PASSWORD',
|
16
|
-
:long => '--password PASSWORD',
|
17
|
-
:description => 'Customer password'
|
18
|
-
|
19
|
-
def locate_config_value(key)
|
20
|
-
key = key.to_sym
|
21
|
-
config[key] || Chef::Config[:knife][key]
|
22
|
-
end
|
23
|
-
|
24
|
-
def run
|
25
|
-
|
26
|
-
# Parameters :baremetalcloud_username and :baremetalcloud_password are mandatory
|
27
|
-
unless config[:baremetalcloud_username]
|
28
|
-
ui.error("--username is a mandatory parameter")
|
29
|
-
exit 1
|
30
|
-
end
|
31
|
-
|
32
|
-
unless config[:baremetalcloud_password]
|
33
|
-
ui.error("--password is a mandatory parameter")
|
34
|
-
exit 1
|
35
|
-
end
|
36
|
-
|
37
|
-
# Configure the API abstraction @bmc
|
38
|
-
@bmc = Fog::Compute.new({
|
39
|
-
:bare_metal_cloud_username => locate_config_value(:baremetalcloud_username),
|
40
|
-
:bare_metal_cloud_password => locate_config_value(:baremetalcloud_password),
|
41
|
-
:provider => 'BareMetalCloud'
|
42
|
-
})
|
43
|
-
|
44
|
-
response = @bmc.list_images.body[:image]
|
45
|
-
if response.length > 1
|
46
|
-
#puts "#{ui.color("Id", :cyan)}\t#{ui.color("Name", :cyan)}\t#{ui.color("Size", :cyan)}"
|
47
|
-
response.each do |r|
|
48
|
-
puts "#{r[:id]}\t#{r[:name]}\t#{r[:size]}"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'fog'
|
2
|
-
|
3
|
-
class Chef
|
4
|
-
class Knife
|
5
|
-
class BaremetalcloudListServers < Knife
|
6
|
-
|
7
|
-
banner "knife baremetalcloud list servers (options)"
|
8
|
-
|
9
|
-
option :baremetalcloud_username,
|
10
|
-
:short => '-x USERNAME',
|
11
|
-
:long => '--username USERNAME',
|
12
|
-
:description => 'Customer username'
|
13
|
-
|
14
|
-
option :baremetalcloud_password,
|
15
|
-
:short => '-P PASSWORD',
|
16
|
-
:long => '--password PASSWORD',
|
17
|
-
:description => 'Customer password'
|
18
|
-
|
19
|
-
def locate_config_value(key)
|
20
|
-
key = key.to_sym
|
21
|
-
config[key] || Chef::Config[:knife][key]
|
22
|
-
end
|
23
|
-
|
24
|
-
def run
|
25
|
-
|
26
|
-
# Parameters :baremetalcloud_username and :baremetalcloud_password are mandatory
|
27
|
-
unless config[:baremetalcloud_username]
|
28
|
-
ui.error("--username is a mandatory parameter")
|
29
|
-
exit 1
|
30
|
-
end
|
31
|
-
|
32
|
-
unless config[:baremetalcloud_password]
|
33
|
-
ui.error("--password is a mandatory parameter")
|
34
|
-
exit 1
|
35
|
-
end
|
36
|
-
|
37
|
-
# Configure the API abstraction @bmc
|
38
|
-
@bmc = Fog::Compute.new({
|
39
|
-
:bare_metal_cloud_username => locate_config_value(:baremetalcloud_username),
|
40
|
-
:bare_metal_cloud_password => locate_config_value(:baremetalcloud_password),
|
41
|
-
:provider => 'BareMetalCloud'
|
42
|
-
})
|
43
|
-
|
44
|
-
|
45
|
-
response = @bmc.list_servers.body[:server]
|
46
|
-
|
47
|
-
if response.length > 1
|
48
|
-
response.each do |r|
|
49
|
-
puts "#{r[:id]}\t#{r[:state]}\t#{r[:name]}\t#{r[:location]}\t#{r[:ip][:address]}\t#{r[:login][:username]}\t#{r[:login][:password]}"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,178 +0,0 @@
|
|
1
|
-
require 'fog'
|
2
|
-
|
3
|
-
class Chef
|
4
|
-
class Knife
|
5
|
-
class BaremetalcloudServerCreate < Knife
|
6
|
-
|
7
|
-
deps do
|
8
|
-
require 'fog'
|
9
|
-
require 'readline'
|
10
|
-
require 'chef/json_compat'
|
11
|
-
require 'chef/knife/bootstrap'
|
12
|
-
Chef::Knife::Bootstrap.load_deps
|
13
|
-
end
|
14
|
-
|
15
|
-
banner "knife baremetalcloud server create NAME [RUN LIST...] (options)"
|
16
|
-
|
17
|
-
attr_accessor :initial_sleep_delay, :bmc
|
18
|
-
|
19
|
-
option :baremetalcloud_username,
|
20
|
-
:short => '-x USERNAME',
|
21
|
-
:long => '--username USERNAME',
|
22
|
-
:description => 'Customer username'
|
23
|
-
|
24
|
-
option :baremetalcloud_password,
|
25
|
-
:short => '-P PASSWORD',
|
26
|
-
:long => '--password PASSWORD',
|
27
|
-
:description => 'Customer password'
|
28
|
-
|
29
|
-
option :name,
|
30
|
-
:short => '-n NAME',
|
31
|
-
:long => '--name NAME',
|
32
|
-
:description => 'Label for the new servers'
|
33
|
-
|
34
|
-
option :run_list,
|
35
|
-
:short => "-r RUN_LIST",
|
36
|
-
:long => "--run-list RUN_LIST",
|
37
|
-
:description => "Comma separated list of roles/recipes to apply",
|
38
|
-
:proc => lambda { |o| o.split(/[\s,]+/) },
|
39
|
-
:default => []
|
40
|
-
|
41
|
-
option :location,
|
42
|
-
:short => '-l LOCATION',
|
43
|
-
:long => '--location LOCATION',
|
44
|
-
:description => 'Location of the server (possible values: miami-fl-usa, santaclara-ca-usa)',
|
45
|
-
:default => "miami-fl-usa"
|
46
|
-
|
47
|
-
option :imageName,
|
48
|
-
:short => '-i IMAGE_NAME',
|
49
|
-
:long => '--image IMAGE_NAME',
|
50
|
-
:description => 'Image installed of the server (CentOS5.5x64 or Win2003x64)'
|
51
|
-
|
52
|
-
def tcp_test_ssh(hostname)
|
53
|
-
tcp_socket = TCPSocket.new(hostname, "22")
|
54
|
-
readable = IO.select([tcp_socket], nil, nil, 5)
|
55
|
-
if readable
|
56
|
-
Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
|
57
|
-
yield
|
58
|
-
true
|
59
|
-
else
|
60
|
-
false
|
61
|
-
end
|
62
|
-
rescue SocketError
|
63
|
-
sleep 2
|
64
|
-
false
|
65
|
-
# Connection timed out
|
66
|
-
rescue Errno::ETIMEDOUT
|
67
|
-
false
|
68
|
-
# Operation not permitted
|
69
|
-
rescue Errno::EPERM
|
70
|
-
false
|
71
|
-
# Connection refused
|
72
|
-
rescue Errno::ECONNREFUSED
|
73
|
-
sleep 2
|
74
|
-
false
|
75
|
-
# No route to host
|
76
|
-
rescue Errno::EHOSTUNREACH
|
77
|
-
sleep 2
|
78
|
-
false
|
79
|
-
# Network is unreachable
|
80
|
-
rescue Errno::ENETUNREACH
|
81
|
-
sleep 2
|
82
|
-
false
|
83
|
-
ensure
|
84
|
-
tcp_socket && tcp_socket.close
|
85
|
-
end
|
86
|
-
|
87
|
-
|
88
|
-
def locate_config_value(key)
|
89
|
-
key = key.to_sym
|
90
|
-
config[key] || Chef::Config[:knife][key]
|
91
|
-
end
|
92
|
-
|
93
|
-
def bootstrap_for_node(public_ip)
|
94
|
-
puts "node bootstrap - #{public_ip}"
|
95
|
-
bootstrap = Chef::Knife::Bootstrap.new
|
96
|
-
bootstrap.name_args = [public_ip]
|
97
|
-
bootstrap.config[:run_list] = locate_config_value(:run_list)
|
98
|
-
bootstrap.config[:ssh_user] = locate_config_value(:ssh_user)
|
99
|
-
bootstrap.config[:ssh_password] = locate_config_value(:ssh_password)
|
100
|
-
bootstrap
|
101
|
-
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
def addServer(planId, options = {})
|
106
|
-
puts "Connecting to baremetalcloud"
|
107
|
-
|
108
|
-
# make the request and get the body
|
109
|
-
response = @bmc.add_server(planId,options).body
|
110
|
-
|
111
|
-
# Loop while SSH is not available and sleep @initial_sleep_delay seconds
|
112
|
-
print(".") until tcp_test_ssh(response[:server][:ip][:address]) {
|
113
|
-
sleep @initial_sleep_delay
|
114
|
-
print("done")
|
115
|
-
}
|
116
|
-
|
117
|
-
# Get Server's user and password
|
118
|
-
config[:ssh_user] = response[:server][:login][:username]
|
119
|
-
config[:ssh_password] = response[:server][:login][:password]
|
120
|
-
|
121
|
-
# Configure bootstrap and trigger "run" to start up
|
122
|
-
bootstrap_for_node(response[:server][:ip][:address]).run
|
123
|
-
end
|
124
|
-
|
125
|
-
def run
|
126
|
-
|
127
|
-
# sleeptime for testing ssh connectivity
|
128
|
-
@initial_sleep_delay = 3
|
129
|
-
|
130
|
-
# Parameters :baremetalcloud_username and :baremetalcloud_password are mandatory
|
131
|
-
unless config[:baremetalcloud_username]
|
132
|
-
ui.error("--username is a mandatory parameter")
|
133
|
-
exit 1
|
134
|
-
end
|
135
|
-
|
136
|
-
unless config[:baremetalcloud_password]
|
137
|
-
ui.error("--password is a mandatory parameter")
|
138
|
-
exit 1
|
139
|
-
end
|
140
|
-
|
141
|
-
# Configure the API abstraction @bmc
|
142
|
-
@bmc = Fog::Compute.new({
|
143
|
-
:bare_metal_cloud_username => locate_config_value(:baremetalcloud_username),
|
144
|
-
:bare_metal_cloud_password => locate_config_value(:baremetalcloud_password),
|
145
|
-
:provider => 'BareMetalCloud'
|
146
|
-
})
|
147
|
-
|
148
|
-
|
149
|
-
# Waiting for API rectoring
|
150
|
-
# PlanId = 7
|
151
|
-
## CentOS small
|
152
|
-
config[:planId] = 7
|
153
|
-
|
154
|
-
# Options
|
155
|
-
options = {
|
156
|
-
:location => locate_config_value(:location),
|
157
|
-
:imageName => locate_config_value(:imageName),
|
158
|
-
:name => locate_config_value(:name)
|
159
|
-
}
|
160
|
-
|
161
|
-
if (config[:planId])
|
162
|
-
addServer(locate_config_value(:planId), options)
|
163
|
-
|
164
|
-
elsif (config[:config]) # BLOCK WILL BE REMOVED
|
165
|
-
@bmc.list_plans.body[:plan].each do | plan |
|
166
|
-
if plan[:config] == config[:config]
|
167
|
-
addServer(plan[:id], options) # small plan == 7
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
else
|
172
|
-
ui.error("PlanId or Configuration is mandatory")
|
173
|
-
exit 1
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|