knife-baremetalcloud 0.0.3 → 0.0.4
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.
- data/.gitignore +6 -5
- data/README.md +119 -9
- data/knife-baremetalcloud.gemspec +1 -1
- data/lib/chef/knife/{baremetalcloud_list_available_servers.rb → baremetalcloud_list_configurations.rb} +27 -13
- data/lib/chef/knife/baremetalcloud_list_images.rb +32 -10
- data/lib/chef/knife/baremetalcloud_list_servers.rb +61 -10
- data/lib/chef/knife/baremetalcloud_server_create.rb +121 -67
- data/lib/knife-baremetalcloud/version.rb +1 -1
- metadata +5 -6
- data/.project +0 -18
data/.gitignore
CHANGED
@@ -2,12 +2,8 @@
|
|
2
2
|
*.rbc
|
3
3
|
.bundle
|
4
4
|
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
5
|
coverage
|
10
|
-
|
6
|
+
InstalledFiles
|
11
7
|
lib/bundler/man
|
12
8
|
pkg
|
13
9
|
rdoc
|
@@ -15,3 +11,8 @@ spec/reports
|
|
15
11
|
test/tmp
|
16
12
|
test/version_tmp
|
17
13
|
tmp
|
14
|
+
|
15
|
+
# YARD artifacts
|
16
|
+
.yardoc
|
17
|
+
_yardoc
|
18
|
+
doc/
|
data/README.md
CHANGED
@@ -1,26 +1,136 @@
|
|
1
|
-
|
1
|
+
Knife baremetalcloud plugin
|
2
|
+
===========================
|
2
3
|
|
3
|
-
|
4
|
+
This is the baremetalcloud implementation for Chef's Knife command. The plugin allows Chef users to manage compute nodes on baremetalcloud infrastructure.
|
4
5
|
|
5
|
-
|
6
|
+
Installation
|
7
|
+
------------
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
9
|
-
gem 'knife-baremetalcloud'
|
11
|
+
command(gem 'knife-baremetalcloud')
|
10
12
|
|
11
13
|
And then execute:
|
12
14
|
|
13
|
-
$ bundle
|
15
|
+
command($ bundle)
|
14
16
|
|
15
17
|
Or install it yourself as:
|
16
18
|
|
17
|
-
$ gem install knife-baremetalcloud
|
19
|
+
command($ gem install knife-baremetalcloud)
|
18
20
|
|
19
|
-
|
21
|
+
Usage
|
22
|
+
-----
|
20
23
|
|
21
|
-
|
24
|
+
## Available commands:
|
25
|
+
command(knife baremetalcloud list configurations (options))
|
26
|
+
command(knife baremetalcloud list images (options))
|
27
|
+
command(knife baremetalcloud list servers (options))
|
28
|
+
command(knife baremetalcloud server create (options))
|
22
29
|
|
23
|
-
|
30
|
+
### List Configurations
|
31
|
+
#### Description
|
32
|
+
This command list all available server's configurations at baremetalcloud.
|
33
|
+
|
34
|
+
|
35
|
+
#### Parameters
|
36
|
+
-P, --password PASSWORD Customer password
|
37
|
+
-x, --username USERNAME Customer username
|
38
|
+
|
39
|
+
#### Usage
|
40
|
+
command($ knife baremetalcloud list configurations -x USERNAME -P PASSWORD)
|
41
|
+
|
42
|
+
#### Example of Output
|
43
|
+
Column description:
|
44
|
+
<table>
|
45
|
+
<tr>
|
46
|
+
<th>quantity</th><th>configuration</th>
|
47
|
+
</tr>
|
48
|
+
</table>
|
49
|
+
- *configuration* string is a required argument when running command($ knife baremetalcloud server create).
|
50
|
+
|
51
|
+
```
|
52
|
+
19 santaclara-ca-usa 2.8 GHz Paxville 2GB DDR-400 73.0GB 3.5" SCSI 10000RPM
|
53
|
+
4 santaclara-ca-usa 2.66 GHz Clovertown X5355 8GB DDR2-667 250.0GB 2.5" SATA 7200RPM
|
54
|
+
4 santaclara-ca-usa 2.8 GHz Paxville 4GB DDR-400 73.0GB 3.5" SCSI 10000RPM
|
55
|
+
5 santaclara-ca-usa 2.66 GHz Woodcrest E5150 8GB DDR2-667 250.0GB 2.5" SATA 7200RPM
|
56
|
+
1 miami-fl-usa 2.0 GHz Gainestown E5504 48GB DDR3-1066 120.0GB 2.5" SATA 7200RPM
|
57
|
+
3 santaclara-ca-usa 2.66 GHz Clovertown X5355 8GB DDR-400 500.0GB 2.5" SATA 7200RPM
|
58
|
+
9 santaclara-ca-usa 2.66 GHz Woodcrest E5150 4GB DDR-400 73.0GB 2.5" SAS 10000RPM
|
59
|
+
1 miami-fl-usa 2.8 GHz Paxville 8GB DDR-400 73.0GB 3.5" SCSI 10000RPM
|
60
|
+
```
|
61
|
+
|
62
|
+
### List Images
|
63
|
+
#### Description
|
64
|
+
This command list all available images at baremetalcloud.
|
65
|
+
|
66
|
+
#### Parameters
|
67
|
+
-P, --password PASSWORD Customer password
|
68
|
+
-x, --username USERNAME Customer username
|
69
|
+
|
70
|
+
#### Usage
|
71
|
+
command($ knife baremetalcloud list images -x USERNAME -P PASSWORD)
|
72
|
+
|
73
|
+
#### Example of Output
|
74
|
+
Column description:
|
75
|
+
<table>
|
76
|
+
<tr>
|
77
|
+
<th>image size</th><th>image name</th>
|
78
|
+
</tr>
|
79
|
+
</table>
|
80
|
+
- *image name* string is a required argument when running command($ knife baremetalcloud server create).
|
81
|
+
```
|
82
|
+
361M CentOS 5.8
|
83
|
+
565M CentOS 6.2
|
84
|
+
319M XenServer 5.6 SP2
|
85
|
+
321M Ubuntu 11.10
|
86
|
+
441M Ubuntu 12.04
|
87
|
+
6.1G Windows Server 2008 Standard
|
88
|
+
3.7G Windows Server 2003 Standard R2
|
89
|
+
183M SmartOS
|
90
|
+
```
|
91
|
+
|
92
|
+
### List Servers
|
93
|
+
#### Description
|
94
|
+
This command list all servers from a customer account at baremetalcloud.
|
95
|
+
|
96
|
+
|
97
|
+
#### Parameters
|
98
|
+
-P, --password PASSWORD Customer password
|
99
|
+
-x, --username USERNAME Customer username
|
100
|
+
|
101
|
+
#### Usage
|
102
|
+
command($ knife baremetalcloud list servers -x USERNAME -P PASSWORD)
|
103
|
+
|
104
|
+
#### Example of Output
|
105
|
+
Column description:
|
106
|
+
<table>
|
107
|
+
<tr>
|
108
|
+
<th>id</th><th>status</th><th>name</th><th>location</th><th>IP</th><th>username</th><th>password</th>
|
109
|
+
</tr>
|
110
|
+
</table>
|
111
|
+
```
|
112
|
+
1234 Active server-baa miami-fl-usa 111.222.333.444 ubuntu PASSWORD
|
113
|
+
5678 Active server-foo miami-fl-usa 555.666.777.888 root PASSWORD
|
114
|
+
```
|
115
|
+
|
116
|
+
### Server Create
|
117
|
+
#### Description
|
118
|
+
This command add and bootstrap a server at baremetalcloud.
|
119
|
+
|
120
|
+
#### Parameters
|
121
|
+
-P, --password PASSWORD Customer password
|
122
|
+
-x, --username USERNAME Customer username
|
123
|
+
-C, --configuration CONFIG Hardware configuration string of the server
|
124
|
+
-i, --image IMAGE_NAME Either baremetalcloud published or customer images
|
125
|
+
-n, --name NAME Label for the new servers
|
126
|
+
-r, --run-list RUN_LIST Comma separated list of roles/recipes to apply
|
127
|
+
|
128
|
+
#### Usage
|
129
|
+
command($ knife baremetalcloud list images -x USERNAME -P PASSWORD -C 'santaclara-ca-usa 2.8 GHz Paxville 2GB DDR-400 73.0GB 3.5" SCSI 10000RPM' -i 'CentOS 5.8' -n 'myChefServer' -r 'myrole[cookbook]' )
|
130
|
+
|
131
|
+
|
132
|
+
Contributing
|
133
|
+
------------
|
24
134
|
|
25
135
|
1. Fork it
|
26
136
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
@@ -3,7 +3,7 @@ require File.expand_path('../lib/knife-baremetalcloud/version', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.name = ["knife-baremetalcloud"]
|
6
|
-
gem.version = '0.0.
|
6
|
+
gem.version = '0.0.4'
|
7
7
|
gem.authors = ["Diego Desani"]
|
8
8
|
gem.email = ["diego@newservers.com"]
|
9
9
|
gem.summary = %q{baremetalcloud Compute Support for Chef's Knife Command}
|
@@ -2,9 +2,9 @@ require 'fog'
|
|
2
2
|
|
3
3
|
class Chef
|
4
4
|
class Knife
|
5
|
-
class
|
5
|
+
class BaremetalcloudListConfigurations < Knife
|
6
6
|
|
7
|
-
banner "knife baremetalcloud list
|
7
|
+
banner "knife baremetalcloud list configurations (options)"
|
8
8
|
|
9
9
|
option :baremetalcloud_username,
|
10
10
|
:short => '-x USERNAME',
|
@@ -16,13 +16,18 @@ class Chef
|
|
16
16
|
:long => '--password PASSWORD',
|
17
17
|
:description => 'Customer password'
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
# Method to handle baremetalcloud errors
|
20
|
+
def errorHandling(response)
|
21
|
+
# Error handling
|
22
|
+
unless response[:error].nil?
|
23
|
+
puts "#{ui.color("ERROR:", :bold)} #{response[:error][:name]}"
|
24
|
+
puts "Description: #{response[:error][:description]}"
|
25
|
+
exit 1
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
|
-
|
25
|
-
|
29
|
+
# Method to verify mandatory arguments
|
30
|
+
def verifyArguments
|
26
31
|
# Parameters :baremetalcloud_username and :baremetalcloud_password are mandatory
|
27
32
|
unless config[:baremetalcloud_username]
|
28
33
|
ui.error("--username is a mandatory parameter")
|
@@ -34,6 +39,14 @@ class Chef
|
|
34
39
|
exit 1
|
35
40
|
end
|
36
41
|
|
42
|
+
end
|
43
|
+
|
44
|
+
# Plugin method called by Knife
|
45
|
+
def run
|
46
|
+
|
47
|
+
# Verify mandatory arguments
|
48
|
+
verifyArguments
|
49
|
+
|
37
50
|
# Configure the API abstraction @bmc
|
38
51
|
@bmc = Fog::Compute.new({
|
39
52
|
:bare_metal_cloud_username => config[:baremetalcloud_username],
|
@@ -41,13 +54,14 @@ class Chef
|
|
41
54
|
:provider => 'BareMetalCloud'
|
42
55
|
})
|
43
56
|
|
44
|
-
|
57
|
+
# Get the API response
|
58
|
+
response = @bmc.list_available_servers.body
|
59
|
+
|
60
|
+
# Error handling
|
61
|
+
errorHandling(response)
|
45
62
|
|
46
|
-
|
47
|
-
|
48
|
-
response.each do |r|
|
49
|
-
puts "#{r[:configuration]}\t#{r[:quantity]}"
|
50
|
-
end
|
63
|
+
response[:"available-server"].each do |resp|
|
64
|
+
puts "#{resp[:quantity]}\t#{resp[:configuration]}"
|
51
65
|
end
|
52
66
|
|
53
67
|
end
|
@@ -16,13 +16,23 @@ class Chef
|
|
16
16
|
:long => '--password PASSWORD',
|
17
17
|
:description => 'Customer password'
|
18
18
|
|
19
|
-
def
|
19
|
+
def locateConfigValue(key)
|
20
20
|
key = key.to_sym
|
21
21
|
config[key] || Chef::Config[:knife][key]
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# Method to handle baremetalcloud errors
|
25
|
+
def errorHandling(response)
|
26
|
+
# Error handling
|
27
|
+
unless response[:error].nil?
|
28
|
+
puts "#{ui.color("ERROR:", :bold)} #{response[:error][:name]}"
|
29
|
+
puts "Description: #{response[:error][:description]}"
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Method to verify mandatory arguments
|
35
|
+
def verifyArguments
|
26
36
|
# Parameters :baremetalcloud_username and :baremetalcloud_password are mandatory
|
27
37
|
unless config[:baremetalcloud_username]
|
28
38
|
ui.error("--username is a mandatory parameter")
|
@@ -34,18 +44,30 @@ class Chef
|
|
34
44
|
exit 1
|
35
45
|
end
|
36
46
|
|
47
|
+
end
|
48
|
+
|
49
|
+
# Plugin method called by Knife
|
50
|
+
def run
|
51
|
+
|
52
|
+
# Verify mandatory arguments
|
53
|
+
verifyArguments
|
54
|
+
|
37
55
|
# Configure the API abstraction @bmc
|
38
56
|
@bmc = Fog::Compute.new({
|
39
|
-
:bare_metal_cloud_username =>
|
40
|
-
:bare_metal_cloud_password =>
|
57
|
+
:bare_metal_cloud_username => locateConfigValue(:baremetalcloud_username),
|
58
|
+
:bare_metal_cloud_password => locateConfigValue(:baremetalcloud_password),
|
41
59
|
:provider => 'BareMetalCloud'
|
42
60
|
})
|
43
61
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
62
|
+
# Get the API response
|
63
|
+
response = @bmc.list_images.body
|
64
|
+
|
65
|
+
# Error handling
|
66
|
+
errorHandling(response)
|
67
|
+
|
68
|
+
if response[:image].length > 1
|
69
|
+
response[:image].each do |resp|
|
70
|
+
puts "#{resp[:size]}\t#{resp[:name]}"
|
49
71
|
end
|
50
72
|
end
|
51
73
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'fog'
|
2
2
|
|
3
3
|
class Chef
|
4
4
|
class Knife
|
@@ -16,13 +16,24 @@ class Chef
|
|
16
16
|
:long => '--password PASSWORD',
|
17
17
|
:description => 'Customer password'
|
18
18
|
|
19
|
-
def
|
19
|
+
def locateConfigValue(key)
|
20
20
|
key = key.to_sym
|
21
21
|
config[key] || Chef::Config[:knife][key]
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# Method to handle baremetalcloud errors
|
25
|
+
def errorHandling(response)
|
26
|
+
# Error handling
|
27
|
+
unless response[:error].nil?
|
28
|
+
puts "#{ui.color("ERROR:", :bold)} #{response[:error][:name]}"
|
29
|
+
puts "Description: #{response[:error][:description]}"
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# Method to verify mandatory arguments
|
36
|
+
def verifyArguments
|
26
37
|
# Parameters :baremetalcloud_username and :baremetalcloud_password are mandatory
|
27
38
|
unless config[:baremetalcloud_username]
|
28
39
|
ui.error("--username is a mandatory parameter")
|
@@ -33,24 +44,64 @@ class Chef
|
|
33
44
|
ui.error("--password is a mandatory parameter")
|
34
45
|
exit 1
|
35
46
|
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
# Plugin method called by Knife
|
51
|
+
def run
|
52
|
+
|
53
|
+
# Verify mandatory arguments
|
54
|
+
verifyArguments
|
36
55
|
|
37
56
|
# Configure the API abstraction @bmc
|
38
57
|
@bmc = Fog::Compute.new({
|
39
|
-
:bare_metal_cloud_username =>
|
40
|
-
:bare_metal_cloud_password =>
|
58
|
+
:bare_metal_cloud_username => locateConfigValue(:baremetalcloud_username),
|
59
|
+
:bare_metal_cloud_password => locateConfigValue(:baremetalcloud_password),
|
41
60
|
:provider => 'BareMetalCloud'
|
42
61
|
})
|
43
62
|
|
63
|
+
# Get the API response
|
64
|
+
response = @bmc.list_servers.body
|
65
|
+
|
66
|
+
# Error handling
|
67
|
+
errorHandling(response)
|
44
68
|
|
45
|
-
|
69
|
+
# only one server
|
70
|
+
if ( response[:server].class == Hash )
|
71
|
+
puts "#{response[:server][:id]}\t#{response[:server][:state]}\t#{response[:server][:name]}\t#{response[:server][:location]}\t#{response[:server][:ip][:address]}\t#{response[:server][:login][:username]}\t#{response[:server][:login][:password]}"
|
46
72
|
|
47
|
-
|
48
|
-
|
49
|
-
|
73
|
+
# more than one server
|
74
|
+
elsif ( response[:server].class == Array )
|
75
|
+
response[:server].each do |resp|
|
76
|
+
|
77
|
+
# 1855 and 1955 have only "system" credentials
|
78
|
+
if ( resp[:login].class == Hash )
|
79
|
+
puts "#{resp[:id]}\t#{resp[:state]}\t#{resp[:name]}\t#{resp[:location]}\t#{resp[:ip][:address]}\t#{resp[:login][:username]}\t#{resp[:login][:password]}"
|
80
|
+
|
81
|
+
# M600 and M610 have iDRAC credentials
|
82
|
+
else
|
83
|
+
# Username and password variables
|
84
|
+
username = password = nil
|
85
|
+
|
86
|
+
# Get only system login. Skip iDRAC
|
87
|
+
resp[:login].each do |r|
|
88
|
+
if ( r[:name] == "system")
|
89
|
+
username = r[:username]
|
90
|
+
password = r[:password]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
puts "#{resp[:id]}\t#{resp[:state]}\t#{resp[:name]}\t#{resp[:location]}\t#{resp[:ip][:address]}\t#{username}\t#{password}"
|
94
|
+
|
95
|
+
end
|
96
|
+
|
50
97
|
end
|
98
|
+
|
51
99
|
end
|
52
100
|
|
53
101
|
end
|
102
|
+
|
54
103
|
end
|
104
|
+
|
55
105
|
end
|
106
|
+
|
56
107
|
end
|
@@ -6,13 +6,12 @@ class Chef
|
|
6
6
|
|
7
7
|
deps do
|
8
8
|
require 'fog'
|
9
|
-
require 'readline'
|
10
|
-
require 'chef/json_compat'
|
9
|
+
# require 'readline'
|
11
10
|
require 'chef/knife/bootstrap'
|
12
11
|
Chef::Knife::Bootstrap.load_deps
|
13
12
|
end
|
14
13
|
|
15
|
-
banner "knife baremetalcloud server create
|
14
|
+
banner "knife baremetalcloud server create (options)"
|
16
15
|
|
17
16
|
attr_accessor :initial_sleep_delay, :bmc
|
18
17
|
|
@@ -25,11 +24,21 @@ class Chef
|
|
25
24
|
:short => '-P PASSWORD',
|
26
25
|
:long => '--password PASSWORD',
|
27
26
|
:description => 'Customer password'
|
27
|
+
|
28
|
+
option :config,
|
29
|
+
:short => '-C CONFIG',
|
30
|
+
:long => '--configuration CONFIG',
|
31
|
+
:description => 'Hardware configuration string of the server'
|
28
32
|
|
29
|
-
|
33
|
+
option :name,
|
30
34
|
:short => '-n NAME',
|
31
35
|
:long => '--name NAME',
|
32
36
|
:description => 'Label for the new servers'
|
37
|
+
|
38
|
+
option :imageName,
|
39
|
+
:short => '-i IMAGE_NAME',
|
40
|
+
:long => '--image IMAGE_NAME',
|
41
|
+
:description => 'Either baremetalcloud published or customer images'
|
33
42
|
|
34
43
|
option :run_list,
|
35
44
|
:short => "-r RUN_LIST",
|
@@ -38,18 +47,42 @@ class Chef
|
|
38
47
|
:proc => lambda { |o| o.split(/[\s,]+/) },
|
39
48
|
:default => []
|
40
49
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
50
|
+
|
51
|
+
|
52
|
+
# Method to check when "system" credentials are available
|
53
|
+
# Node's IP Address is updated
|
54
|
+
def isNodeReady(serverId)
|
46
55
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
56
|
+
# Sleep @initial_sleep_delay seconds
|
57
|
+
sleep @initial_sleep_delay
|
58
|
+
|
59
|
+
# Get server's status
|
60
|
+
response = @bmc.get_server(serverId).body
|
61
|
+
|
62
|
+
# 1855 and 1955 have only "system" credentials
|
63
|
+
if ( response[:server][:login].class == Hash )
|
64
|
+
if ( response[:server][:login][:name] == "system" )
|
65
|
+
config[:ssh_user] = response[:server][:login][:username]
|
66
|
+
config[:ssh_password] = response[:server][:login][:password]
|
67
|
+
config[:chef_node_name] = response[:server][:ip][:address]
|
68
|
+
return true
|
69
|
+
end
|
70
|
+
elsif ( response[:server][:login].class == Array ) # M600 and M610 have iDRAC credentials
|
71
|
+
response[:server][:login].each do |r|
|
72
|
+
if ( r[:name] == "system")
|
73
|
+
config[:ssh_user] = r[:username]
|
74
|
+
config[:ssh_password] = r[:password]
|
75
|
+
config[:chef_node_name] = response[:server][:ip][:address]
|
76
|
+
return true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
false
|
81
|
+
end
|
51
82
|
|
52
|
-
|
83
|
+
# Method to test if SSH service is running on a node
|
84
|
+
def testSSH(hostname)
|
85
|
+
sleep @initial_sleep_delay
|
53
86
|
tcp_socket = TCPSocket.new(hostname, "22")
|
54
87
|
readable = IO.select([tcp_socket], nil, nil, 5)
|
55
88
|
if readable
|
@@ -84,49 +117,64 @@ class Chef
|
|
84
117
|
tcp_socket && tcp_socket.close
|
85
118
|
end
|
86
119
|
|
87
|
-
|
88
|
-
def
|
120
|
+
# Method to lacate configuration variables
|
121
|
+
def locateConfigValue(key)
|
89
122
|
key = key.to_sym
|
90
123
|
config[key] || Chef::Config[:knife][key]
|
91
124
|
end
|
92
125
|
|
93
|
-
|
94
|
-
|
126
|
+
# Method to configure Knife Bootstrap object
|
127
|
+
def bootstrapNode()
|
128
|
+
puts "Bootstrapping node id #{locateConfigValue(:chef_node_name)}"
|
95
129
|
bootstrap = Chef::Knife::Bootstrap.new
|
96
|
-
bootstrap.name_args =
|
97
|
-
bootstrap.config[:run_list] =
|
98
|
-
bootstrap.config[:
|
99
|
-
bootstrap.config[:
|
130
|
+
bootstrap.name_args = locateConfigValue(:chef_node_name)
|
131
|
+
bootstrap.config[:run_list] = locateConfigValue(:run_list)
|
132
|
+
bootstrap.config[:identity_file] = locateConfigValue[:identity_file]
|
133
|
+
bootstrap.config[:ssh_user] = locateConfigValue(:ssh_user)
|
134
|
+
bootstrap.config[:ssh_password] = locateConfigValue(:ssh_password)
|
135
|
+
bootstrap.config[:use_sudo] = true unless locateConfigValue[:ssh_user] == 'root'
|
136
|
+
bootstrap.config[:environment] = config[:environment]
|
100
137
|
bootstrap
|
101
138
|
end
|
102
139
|
|
140
|
+
# Method to handle baremetalcloud errors
|
141
|
+
def errorHandling(response)
|
142
|
+
# Error handling
|
143
|
+
unless response[:error].nil?
|
144
|
+
puts "#{ui.color("ERROR:", :bold)} #{response[:error][:name]}"
|
145
|
+
puts "Description: #{response[:error][:description]}"
|
146
|
+
exit 1
|
147
|
+
end
|
148
|
+
end
|
103
149
|
|
104
|
-
|
105
|
-
def
|
106
|
-
puts "Connecting to baremetalcloud"
|
150
|
+
# Method to add baremetalcloud's node and configure
|
151
|
+
def addNode(config, options = {})
|
107
152
|
|
108
|
-
#
|
109
|
-
response = @bmc.
|
153
|
+
# Get the API response
|
154
|
+
response = @bmc.add_server_by_configuration(config,options).body
|
110
155
|
|
111
|
-
#
|
112
|
-
|
113
|
-
sleep @initial_sleep_delay
|
114
|
-
print("done")
|
115
|
-
}
|
156
|
+
# Error handling
|
157
|
+
errorHandling(response)
|
116
158
|
|
117
|
-
#
|
118
|
-
|
119
|
-
config[:ssh_password] = response[:server][:login][:password]
|
159
|
+
# get Server id
|
160
|
+
serverId = response[:server][:id]
|
120
161
|
|
121
|
-
#
|
122
|
-
|
162
|
+
# Loop while server's status is not "Active"
|
163
|
+
print "Waiting for server#{serverId} to be ready"
|
164
|
+
print(".") until isNodeReady(serverId){
|
165
|
+
print "done\n"
|
166
|
+
}
|
167
|
+
|
168
|
+
# Loop while SSH is not available and sleep @initial_sleep_delay seconds
|
169
|
+
print "Connecting to server#{serverId}"
|
170
|
+
print(".") until testSSH(response[:server][:ip][:address]) {
|
171
|
+
print "done\n"
|
172
|
+
}
|
173
|
+
|
123
174
|
end
|
124
175
|
|
125
|
-
|
126
|
-
|
127
|
-
# sleeptime for testing ssh connectivity
|
128
|
-
@initial_sleep_delay = 3
|
129
|
-
|
176
|
+
# Method to verify mandatory arguments
|
177
|
+
def verifyArguments
|
130
178
|
# Parameters :baremetalcloud_username and :baremetalcloud_password are mandatory
|
131
179
|
unless config[:baremetalcloud_username]
|
132
180
|
ui.error("--username is a mandatory parameter")
|
@@ -138,40 +186,46 @@ class Chef
|
|
138
186
|
exit 1
|
139
187
|
end
|
140
188
|
|
189
|
+
unless config[:config]
|
190
|
+
ui.error("--configuration is a mandatory parameter")
|
191
|
+
exit 1
|
192
|
+
end
|
193
|
+
|
194
|
+
unless config[:imageName]
|
195
|
+
ui.error("--image is a mandatory parameter")
|
196
|
+
exit 1
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
# Plugin method called by Knife
|
202
|
+
def run
|
203
|
+
|
204
|
+
# sleeptime for testing ssh connectivity
|
205
|
+
@initial_sleep_delay = 3
|
206
|
+
|
207
|
+
# Verify mandatory arguments
|
208
|
+
verifyArguments
|
209
|
+
|
141
210
|
# Configure the API abstraction @bmc
|
142
211
|
@bmc = Fog::Compute.new({
|
143
|
-
:bare_metal_cloud_username =>
|
144
|
-
:bare_metal_cloud_password =>
|
212
|
+
:bare_metal_cloud_username => locateConfigValue(:baremetalcloud_username),
|
213
|
+
:bare_metal_cloud_password => locateConfigValue(:baremetalcloud_password),
|
145
214
|
:provider => 'BareMetalCloud'
|
146
215
|
})
|
147
216
|
|
148
|
-
|
149
|
-
# Waiting for API rectoring
|
150
|
-
# PlanId = 7
|
151
|
-
## CentOS small
|
152
|
-
config[:planId] = 7
|
153
|
-
|
154
217
|
# Options
|
155
218
|
options = {
|
156
|
-
:
|
157
|
-
:
|
158
|
-
:name => locate_config_value(:name)
|
219
|
+
:imageName => locateConfigValue(:imageName),
|
220
|
+
:name => locateConfigValue(:name)
|
159
221
|
}
|
160
222
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
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
|
223
|
+
# Add server method
|
224
|
+
addNode(locateConfigValue(:config), options)
|
225
|
+
|
226
|
+
# Configure bootstrap and trigger "run" to start up
|
227
|
+
bootstrapNode().run
|
228
|
+
|
175
229
|
end
|
176
230
|
end
|
177
231
|
end
|
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: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Diego Desani
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-08-
|
18
|
+
date: 2012-08-23 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: fog
|
@@ -44,13 +44,12 @@ extra_rdoc_files: []
|
|
44
44
|
|
45
45
|
files:
|
46
46
|
- .gitignore
|
47
|
-
- .project
|
48
47
|
- Gemfile
|
49
48
|
- LICENSE
|
50
49
|
- README.md
|
51
50
|
- Rakefile
|
52
51
|
- knife-baremetalcloud.gemspec
|
53
|
-
- lib/chef/knife/
|
52
|
+
- lib/chef/knife/baremetalcloud_list_configurations.rb
|
54
53
|
- lib/chef/knife/baremetalcloud_list_images.rb
|
55
54
|
- lib/chef/knife/baremetalcloud_list_servers.rb
|
56
55
|
- lib/chef/knife/baremetalcloud_server_create.rb
|
data/.project
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<projectDescription>
|
3
|
-
<name>knife-baremetalcloud</name>
|
4
|
-
<comment></comment>
|
5
|
-
<projects>
|
6
|
-
</projects>
|
7
|
-
<buildSpec>
|
8
|
-
<buildCommand>
|
9
|
-
<name>com.aptana.ide.core.unifiedBuilder</name>
|
10
|
-
<arguments>
|
11
|
-
</arguments>
|
12
|
-
</buildCommand>
|
13
|
-
</buildSpec>
|
14
|
-
<natures>
|
15
|
-
<nature>com.aptana.ruby.core.rubynature</nature>
|
16
|
-
<nature>com.aptana.projects.webnature</nature>
|
17
|
-
</natures>
|
18
|
-
</projectDescription>
|