cloudbox-server 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.
- data/.yardopts +3 -0
- data/README.md +17 -0
- data/bin/cb-cluster-allocate +5 -0
- data/bin/cb-cluster-create +5 -0
- data/bin/cb-cluster-delete +5 -0
- data/bin/cb-cluster-desallocate +5 -0
- data/bin/cb-cluster-info +5 -0
- data/bin/cb-cluster-ls +5 -0
- data/bin/cb-node-destroy +5 -0
- data/bin/cb-node-detach +6 -0
- data/bin/cb-node-info +5 -0
- data/bin/cb-node-install +5 -0
- data/bin/cb-node-ls +5 -0
- data/bin/cb-service-add +5 -0
- data/bin/cb-service-component-add +5 -0
- data/bin/cb-service-component-delete +5 -0
- data/bin/cb-service-component-detach +5 -0
- data/bin/cb-service-conf-apply +5 -0
- data/bin/cb-service-conf-create +5 -0
- data/bin/cb-service-conf-get +5 -0
- data/bin/cb-service-conf-ls +5 -0
- data/bin/cb-service-follow-request +5 -0
- data/bin/cb-service-info +5 -0
- data/bin/cb-service-install +5 -0
- data/bin/cb-service-ls +5 -0
- data/bin/cb-service-start +5 -0
- data/bin/cb-service-stop +5 -0
- data/lib/command.rb +61 -0
- data/lib/command/ambari_add_host.rb +19 -0
- data/lib/command/ambari_cluster_command.rb +26 -0
- data/lib/command/ambari_cluster_component_command.rb +26 -0
- data/lib/command/ambari_cluster_component_host_command.rb +26 -0
- data/lib/command/ambari_cluster_create.rb +19 -0
- data/lib/command/ambari_cluster_host_command.rb +27 -0
- data/lib/command/ambari_cluster_list.rb +20 -0
- data/lib/command/ambari_cluster_service_command.rb +26 -0
- data/lib/command/ambari_cluster_service_host_command.rb +26 -0
- data/lib/command/ambari_command.rb +21 -0
- data/lib/command/ambari_create_cluster_configuration.rb +39 -0
- data/lib/command/ambari_get_cluster_configuration.rb +29 -0
- data/lib/command/ambari_host_list.rb +19 -0
- data/lib/command/ambari_install_cluster.rb +19 -0
- data/lib/command/ambari_install_component.rb +19 -0
- data/lib/command/ambari_install_host.rb +19 -0
- data/lib/command/ambari_install_host_component.rb +19 -0
- data/lib/command/ambari_install_host_components.rb +19 -0
- data/lib/command/ambari_install_service_components.rb +19 -0
- data/lib/command/ambari_service_add.rb +27 -0
- data/lib/command/ambari_service_component_add.rb +21 -0
- data/lib/command/ambari_service_component_delete.rb +21 -0
- data/lib/command/ambari_service_component_detach.rb +21 -0
- data/lib/command/ambari_service_component_info.rb +29 -0
- data/lib/command/ambari_service_conf_apply.rb +31 -0
- data/lib/command/ambari_service_conf_ls.rb +30 -0
- data/lib/command/ambari_service_delete.rb +21 -0
- data/lib/command/ambari_service_info.rb +20 -0
- data/lib/command/ambari_service_list.rb +21 -0
- data/lib/command/ambari_start_cluster.rb +19 -0
- data/lib/command/ambari_start_component.rb +19 -0
- data/lib/command/ambari_start_host.rb +19 -0
- data/lib/command/ambari_start_host_component.rb +19 -0
- data/lib/command/ambari_start_host_components.rb +19 -0
- data/lib/command/ambari_start_service_components.rb +19 -0
- data/lib/command/ambari_stop_cluster.rb +19 -0
- data/lib/command/ambari_stop_component.rb +19 -0
- data/lib/command/ambari_stop_host.rb +19 -0
- data/lib/command/ambari_stop_host_component.rb +19 -0
- data/lib/command/ambari_stop_host_components.rb +19 -0
- data/lib/command/ambari_stop_service_components.rb +19 -0
- data/lib/command/basic_command.rb +44 -0
- data/lib/command/cluster_create.rb +50 -0
- data/lib/command/cluster_delete.rb +30 -0
- data/lib/command/cluster_info.rb +30 -0
- data/lib/command/cluster_ls.rb +30 -0
- data/lib/command/crowbar_cluster_allocate.rb +42 -0
- data/lib/command/crowbar_command.rb +30 -0
- data/lib/command/crowbar_get_barclamps_list.rb +30 -0
- data/lib/command/crowbar_node_command.rb +21 -0
- data/lib/command/crowbar_node_list.rb +40 -0
- data/lib/command/crowbar_vcluster_command.rb +20 -0
- data/lib/command/filter.rb +15 -0
- data/lib/command/node_destroy.rb +58 -0
- data/lib/command/node_detach.rb +44 -0
- data/lib/command/node_info.rb +27 -0
- data/lib/command/node_install.rb +46 -0
- data/lib/command/node_reinstall.rb +44 -0
- data/lib/command/state_filter.rb +16 -0
- data/lib/common.rb +11 -0
- data/lib/common/cb-lib-node-erase-hard-disk.sh +29 -0
- data/lib/common/cloudbox_exceptions.rb +631 -0
- data/lib/common/cloudbox_logger.rb +81 -0
- data/lib/common/cloudbox_logger_mock.rb +43 -0
- data/lib/common/color.rb +267 -0
- data/lib/common/config_properties.rb +2027 -0
- data/lib/common/services_description.rb +192 -0
- data/lib/exec.rb +35 -0
- data/lib/exec/check_parameter.rb +208 -0
- data/lib/exec/cluster_allocate.rb +163 -0
- data/lib/exec/cluster_create.rb +99 -0
- data/lib/exec/cluster_delete.rb +38 -0
- data/lib/exec/cluster_desallocate.rb +37 -0
- data/lib/exec/cluster_info.rb +177 -0
- data/lib/exec/cluster_ls.rb +150 -0
- data/lib/exec/command_option.rb +222 -0
- data/lib/exec/executable_command.rb +194 -0
- data/lib/exec/node_destroy.rb +101 -0
- data/lib/exec/node_detach.rb +98 -0
- data/lib/exec/node_info.rb +280 -0
- data/lib/exec/node_install.rb +234 -0
- data/lib/exec/node_ls.rb +160 -0
- data/lib/exec/service_add.rb +224 -0
- data/lib/exec/service_component_add.rb +39 -0
- data/lib/exec/service_component_delete.rb +37 -0
- data/lib/exec/service_component_detach.rb +37 -0
- data/lib/exec/service_conf_apply.rb +57 -0
- data/lib/exec/service_conf_create.rb +80 -0
- data/lib/exec/service_conf_get.rb +165 -0
- data/lib/exec/service_conf_ls.rb +103 -0
- data/lib/exec/service_follow_request.rb +49 -0
- data/lib/exec/service_info.rb +346 -0
- data/lib/exec/service_install.rb +87 -0
- data/lib/exec/service_ls.rb +124 -0
- data/lib/exec/service_start.rb +110 -0
- data/lib/exec/service_stop.rb +112 -0
- data/lib/receiver.rb +14 -0
- data/lib/receiver/ambari_receiver.rb +812 -0
- data/lib/receiver/ambari_rest_api_connector.rb +599 -0
- data/lib/receiver/basic_receiver.rb +28 -0
- data/lib/receiver/connector.rb +28 -0
- data/lib/receiver/crowbar_receiver.rb +588 -0
- data/lib/receiver/crowbar_rest_api_connector.rb +518 -0
- data/lib/receiver/crowbar_shell_api.rb +643 -0
- data/lib/receiver/rest_api_connector.rb +275 -0
- data/resources/ambari-configurations/HBASE/default_hbase-site +33 -0
- data/resources/ambari-configurations/HDFS/default_hdfs-site +49 -0
- data/resources/ambari-configurations/HIVE/default_hive-site +33 -0
- data/resources/ambari-configurations/MAPREDUCE/default_mapred-site +72 -0
- data/resources/ambari-configurations/OOZIE/default_oozie-site +28 -0
- data/resources/ambari-configurations/WEBHCAT/default_webhcat-site +18 -0
- data/resources/ambari-configurations/ZOOKEEPER/default_zookeeper-site +8 -0
- data/resources/ambari-configurations/default_core-site +22 -0
- data/resources/ambari-configurations/default_global +141 -0
- data/resources/cloudbox-server.conf +10 -0
- data/spec/common/services_description.rb +130 -0
- data/spec/exec/check_parameter.rb +152 -0
- data/spec/exec/command_option_spec.rb +97 -0
- metadata +328 -0
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
# This file is part of cloudbox-server project
|
|
2
|
+
# Author: mbr (INGENSI)
|
|
3
|
+
# Created: 21/08/13 14:03
|
|
4
|
+
|
|
5
|
+
# You are a good developer if you document this class
|
|
6
|
+
require 'common/color'
|
|
7
|
+
require 'json'
|
|
8
|
+
require 'receiver/rest_api_connector'
|
|
9
|
+
|
|
10
|
+
module Receiver
|
|
11
|
+
# Class linking to the crowbar Rest API.
|
|
12
|
+
# @author tnoguer
|
|
13
|
+
class CrowbarRestAPIConnector < RestApiConnector
|
|
14
|
+
|
|
15
|
+
public
|
|
16
|
+
# Constructor of CrowbarRestApiConnector.
|
|
17
|
+
# @param logger is the object that allow log all action and error , exception
|
|
18
|
+
def initialize(logger)
|
|
19
|
+
file = File.new(File.dirname(__FILE__) + "/../../resources/cloudbox-server.conf", "r")
|
|
20
|
+
json = file.read()
|
|
21
|
+
conf = JSON.parse(json)
|
|
22
|
+
super(conf["crowbar_server_ip"], conf["crowbar_server_port"], "DIGEST", conf["crowbar_user"], conf["crowbar_password"], 10000, logger)
|
|
23
|
+
@logger.info("Receiver::CrowbarRestAPIConnector initialize the parameters...")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Set the configuration of proposal .
|
|
27
|
+
# @param vcluster_name the name of cluster
|
|
28
|
+
# @param network is network adress
|
|
29
|
+
# @param mask is the cidr of network adress
|
|
30
|
+
# @param vlan_id the value of VLANID
|
|
31
|
+
# @param cpu is the weight of cpu
|
|
32
|
+
# @param ram is the weight of ram memory
|
|
33
|
+
# @param description is description of cluster
|
|
34
|
+
# @return Boolean true is successful and false if error
|
|
35
|
+
# @author mbretaud
|
|
36
|
+
def configure_proposal(vcluster_name, network, mask, vlan_id, cpu, ram, description)
|
|
37
|
+
barclamp_name = "cb#{vcluster_name}"
|
|
38
|
+
proposal_name = "default"
|
|
39
|
+
|
|
40
|
+
begin
|
|
41
|
+
res = launch_request("GET", "/crowbar/#{barclamp_name}/1.0/proposals/#{proposal_name}", "")
|
|
42
|
+
json = res.body
|
|
43
|
+
rescue
|
|
44
|
+
raise Common::ConfigureProposalError.new("Retrieve the data on the proposal '#{proposal_name}' of the barclamp '#{barclamp_name}'.")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
begin
|
|
48
|
+
p = JSON.parse(json)
|
|
49
|
+
p['attributes'][barclamp]['conf']['name']=name
|
|
50
|
+
p['attributes'][barclamp]['network']['address']=network
|
|
51
|
+
p['attributes'][barclamp]['network']['mask']=mask
|
|
52
|
+
p['attributes'][barclamp]['network']['idvlan']=vlan_id
|
|
53
|
+
p['attributes'][barclamp]['resources']['cpu']=cpu
|
|
54
|
+
p['attributes'][barclamp]['resources']['ram']=ram
|
|
55
|
+
p['attributes'][barclamp]['description']=description
|
|
56
|
+
|
|
57
|
+
json = p.to_json
|
|
58
|
+
rescue
|
|
59
|
+
raise Common::ConfigureProposalError.new("Error to set attributes of the barclamp '#{barclamp}'.")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
path = "/crowbar/#{barclamp_name}/1.0/proposals/#{proposal_name}"
|
|
63
|
+
|
|
64
|
+
begin
|
|
65
|
+
res = launch_request("POST", path, json)
|
|
66
|
+
|
|
67
|
+
if res.code != "302"
|
|
68
|
+
raise Common::ConfigureProposalError.new("Code error '#{res.code}' of launching request POST on '#{path}' with data '#{json}'.")
|
|
69
|
+
end
|
|
70
|
+
rescue
|
|
71
|
+
raise Common::ConfigureProposalError.new("Code error '#{res.code}' of launching request POST on '#{path}' with data '#{json}'.")
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
public
|
|
76
|
+
# create a proposal for a barclamp
|
|
77
|
+
# @param barclamp_name the name of barclamp
|
|
78
|
+
# @param proposal_name the name of proposal
|
|
79
|
+
# @return Boolean true is successful and false if error
|
|
80
|
+
# @author mbretaud
|
|
81
|
+
def create_proposal(barclamp_name, proposal_name)
|
|
82
|
+
path = "/crowbar/#{barclamp_name}/1.0/proposals"
|
|
83
|
+
data = "{\"id\":\"#{proposal_name.strip}\"}"
|
|
84
|
+
|
|
85
|
+
begin
|
|
86
|
+
res = launch_request("PUT", path.strip, data.strip)
|
|
87
|
+
if res.code != "200"
|
|
88
|
+
raise Common::CreateProposalError.new("Create the proposal '#{proposal_name}' on the barclamp '#{barclamp_name}'.")
|
|
89
|
+
end
|
|
90
|
+
return true
|
|
91
|
+
rescue
|
|
92
|
+
raise Common::CreateProposalError.new("Create the proposal '#{proposal_name}' on the barclamp '#{barclamp_name}'.")
|
|
93
|
+
end
|
|
94
|
+
return true
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
public
|
|
98
|
+
# Delete node in the proposal
|
|
99
|
+
# @param node_name the name of node
|
|
100
|
+
# @return Boolean true is successful and false if error
|
|
101
|
+
# @author mbretaud
|
|
102
|
+
def delete_node_proposal(node_name)
|
|
103
|
+
dnode_name = nil
|
|
104
|
+
hnode_name = nil
|
|
105
|
+
|
|
106
|
+
if node_name[0, 1] == "d"
|
|
107
|
+
dnode_name = node_name
|
|
108
|
+
hnode_name = "h" + node_name[1..-1]
|
|
109
|
+
else
|
|
110
|
+
if node_name[0, 1] == "h"
|
|
111
|
+
hnode_name = node_name
|
|
112
|
+
dnode_name = "d" + node_name[1..-1]
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
if dnode_name == nil && hnode_name == nil
|
|
117
|
+
raise Common::DeleteNodeProposalError.new("The name of the name is not correct : '#{node_name}'.")
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
begin
|
|
121
|
+
res = launch_request("GET", "/crowbar/barclamp/1.0/proposals/status", "")
|
|
122
|
+
|
|
123
|
+
json = res.body
|
|
124
|
+
rescue => e
|
|
125
|
+
raise Common::DeleteNodeProposalError.new("Retrieve the list of barclamps and their status.")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
p = JSON.parse(json)
|
|
129
|
+
|
|
130
|
+
list_barclamps = Array.new
|
|
131
|
+
if p['i18n'] != nil
|
|
132
|
+
get_keys = p['i18n'].keys
|
|
133
|
+
get_keys.each{|e|
|
|
134
|
+
if p['i18n'][e]['proposal'] != nil
|
|
135
|
+
proposal = p['i18n'][e]['proposal'].downcase
|
|
136
|
+
barclamp = e
|
|
137
|
+
list_barclamps << barclamp.gsub('_' + proposal, '')
|
|
138
|
+
end
|
|
139
|
+
}
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
list_barclamps.each{|barclamp|
|
|
143
|
+
res = launch_request("GET", "/crowbar/#{barclamp}/1.0/proposals", "")
|
|
144
|
+
|
|
145
|
+
if res.body != ""
|
|
146
|
+
proposals = JSON.parse(res.body)
|
|
147
|
+
|
|
148
|
+
if proposals.empty?
|
|
149
|
+
puts "Warning: The barclamp '#{barclamp}' has no proposals!"
|
|
150
|
+
else
|
|
151
|
+
proposals.each { |proposal|
|
|
152
|
+
#puts "Delete the node '#{node_name}' into the proposal '#{proposal}' of the barclamp '#{barclamp}'."
|
|
153
|
+
path="/crowbar/#{barclamp}/1.0/proposals/#{proposal}"
|
|
154
|
+
begin
|
|
155
|
+
res = launch_request("GET", path, "")
|
|
156
|
+
|
|
157
|
+
json = res.body
|
|
158
|
+
rescue => e
|
|
159
|
+
raise Common::DeleteNodeProposalError.new("Retrieve the data on the proposal '#{proposal}' of the barclamp '#{barclamp}'.")
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
#if $? != 0
|
|
163
|
+
# out="#{out}" + "Proposal '#{proposal}' of the barclamps '#{barclamp}' doesn't exists.\n"
|
|
164
|
+
#else
|
|
165
|
+
p = JSON.parse(json)
|
|
166
|
+
|
|
167
|
+
attributes=p['attributes'][barclamp]
|
|
168
|
+
deployment=p['deployment'][barclamp]
|
|
169
|
+
|
|
170
|
+
if deployment['elements'] != nil
|
|
171
|
+
get_keys = deployment['elements'].keys
|
|
172
|
+
get_keys.each { |role|
|
|
173
|
+
if deployment['elements'][role] != nil
|
|
174
|
+
deployment['elements'][role].each do |name|
|
|
175
|
+
if dnode_name == name
|
|
176
|
+
deployment['elements'][role].delete(dnode_name)
|
|
177
|
+
end
|
|
178
|
+
if hnode_name == name
|
|
179
|
+
deployment['elements'][role].delete(hnode_name)
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
}
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
if deployment['crowbar-committing'] != nil
|
|
187
|
+
deployment['crowbar-committing'] = false
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
attributes = attributes.to_json.strip
|
|
191
|
+
deployment = deployment.to_json.strip
|
|
192
|
+
|
|
193
|
+
data_save = "barclamp=#{barclamp.strip}&name=#{proposal.strip}&proposal_attributes=#{attributes.strip}&proposal_deployment=#{deployment.strip}&submit=Save"
|
|
194
|
+
data_apply = "barclamp=#{barclamp.strip}&name=#{proposal.strip}&proposal_attributes=#{attributes.strip}&proposal_deployment=#{deployment.strip}&submit=Apply"
|
|
195
|
+
|
|
196
|
+
begin
|
|
197
|
+
res = launch_request("POST", path, data_save)
|
|
198
|
+
if res.code != "302"
|
|
199
|
+
raise Common::DeleteNodeProposalError.new("Code error '#{res.code}' of launching request POST on '#{path}' with data '#{data_save}'.")
|
|
200
|
+
end
|
|
201
|
+
rescue => e
|
|
202
|
+
puts "Error to Save : " + e.message
|
|
203
|
+
raise Common::DeleteNodeProposalError.new("Error to Save : Code error '#{res.code}' of launching request POST on '#{path}' with data '#{data_save}'.")
|
|
204
|
+
end
|
|
205
|
+
res=nil
|
|
206
|
+
if barclamp.strip =~ /^[c][b]+/ || barclamp.strip == "vcluster_core"
|
|
207
|
+
begin
|
|
208
|
+
path_post = "/crowbar/#{barclamp.strip}/1.0/proposals/#{proposal.strip}"
|
|
209
|
+
|
|
210
|
+
res = launch_request("POST", path_post, data_apply)
|
|
211
|
+
if res.code != "302"
|
|
212
|
+
raise Common::DeleteNodeProposalError.new("Code error '#{res.code}' of launching request POST on '#{path_post}' with data '#{data_apply}'.")
|
|
213
|
+
end
|
|
214
|
+
rescue => e
|
|
215
|
+
raise Common::DeleteNodeProposalError.new("Error to Apply : Code error '#{res.code}' of launching request POST on '#{path_post}' with data '#{data_apply}'.")
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
#end
|
|
219
|
+
}
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
}
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
public
|
|
226
|
+
# Get a list of barclamps
|
|
227
|
+
# @return list The list of barclamps
|
|
228
|
+
# @raise [ArgumentError] if an error occured while launching a request GET
|
|
229
|
+
# @author mbretaud
|
|
230
|
+
def get_barclamps_list()
|
|
231
|
+
begin
|
|
232
|
+
res = launch_request("GET", "/crowbar/barclamp/1.0/proposals/status", "")
|
|
233
|
+
|
|
234
|
+
json = res.body
|
|
235
|
+
rescue => e
|
|
236
|
+
raise Common::GetBarclampsListError.new("Retrieve the list of barclamps and their status.")
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
return JSON.parse(json)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
public
|
|
243
|
+
# Remove node in proposal's barclamp
|
|
244
|
+
# @param vcluster_name the name of barclamp
|
|
245
|
+
# @return boolean true is successful and false if error
|
|
246
|
+
# @author mbretaud
|
|
247
|
+
def remove_nodes(vcluster_name)
|
|
248
|
+
barclamp_name = "cb#{vcluster_name}"
|
|
249
|
+
proposal_name = "default"
|
|
250
|
+
|
|
251
|
+
path_get = "/crowbar/#{barclamp_name}/1.0/proposals/#{proposal_name}"
|
|
252
|
+
path_post = "/crowbar/#{barclamp_name}/1.0/proposals/#{proposal_name}"
|
|
253
|
+
|
|
254
|
+
begin
|
|
255
|
+
res = launch_request("GET", path_get, "")
|
|
256
|
+
json = res.body
|
|
257
|
+
rescue => e
|
|
258
|
+
raise Common::RemoveNodesError.new("Retrieve the data on the proposal '#{proposal_name}' of the barclamp '#{barclamp_name}'.")
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
if res.code != "200"
|
|
262
|
+
creation = true
|
|
263
|
+
create_proposal(barclamp_name, proposal_name)
|
|
264
|
+
|
|
265
|
+
begin
|
|
266
|
+
res = launch_request("GET", path_get, "")
|
|
267
|
+
json = res.body
|
|
268
|
+
rescue => e
|
|
269
|
+
raise Common::RemoveNodesError.new("The barclamp '#{barclamp_name}' don't exists.")
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
begin
|
|
274
|
+
p = JSON.parse(json)
|
|
275
|
+
|
|
276
|
+
attributes=p['attributes'][barclamp_name]
|
|
277
|
+
deployment=p['deployment'][barclamp_name]
|
|
278
|
+
|
|
279
|
+
if deployment['elements'] != nil
|
|
280
|
+
get_keys = deployment['elements'].keys
|
|
281
|
+
get_keys.each { |role|
|
|
282
|
+
deployment['elements'][role].each do |name|
|
|
283
|
+
if name != nil
|
|
284
|
+
deployment['elements'][role].delete(name)
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
}
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
if deployment['crowbar-committing'] != nil
|
|
291
|
+
deployment['crowbar-committing'] = false
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
attributes = attributes.to_json.strip
|
|
295
|
+
deployment = deployment.to_json.strip
|
|
296
|
+
|
|
297
|
+
data_save = "barclamp=#{barclamp_name}&name=#{proposal_name}&proposal_attributes=#{attributes}&proposal_deployment=#{deployment}&submit=Save"
|
|
298
|
+
rescue => e
|
|
299
|
+
raise Common::RemoveNodesError.new("Modify the body of the request.")
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
res=nil
|
|
303
|
+
begin
|
|
304
|
+
res = launch_request("POST", path_post, data_save)
|
|
305
|
+
if res.code != "302"
|
|
306
|
+
raise Common::RemoveNodesError.new("Code error '#{res.code}' of launching request POST on '#{path_post}' with data '#{data_save}'")
|
|
307
|
+
end
|
|
308
|
+
rescue => e
|
|
309
|
+
raise Common::RemoveNodesError.new("Error to Save : " + e.message)
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
public
|
|
314
|
+
# set bios name of node
|
|
315
|
+
# @param node_name the name of node
|
|
316
|
+
# @param bios_name the name of bios
|
|
317
|
+
# @return true is successful and false if error
|
|
318
|
+
# @author mbretaud
|
|
319
|
+
def set_bios(node_name, bios_name)
|
|
320
|
+
node = node_name.split(".")
|
|
321
|
+
node = node[0]
|
|
322
|
+
|
|
323
|
+
begin
|
|
324
|
+
res = launch_request("POST", "/nodes/#{node_name}/update", "alias=#{node}&bios=#{bios_name}&submit=Save")
|
|
325
|
+
if res.code != "302"
|
|
326
|
+
raise Common::NodeSetBiosError.new("Code error '#{res.code}' of launching request POST on '/nodes/#{node_name}/update' with data 'alias=#{node}&bios=#{bios_name}&submit=Save'.")
|
|
327
|
+
end
|
|
328
|
+
return true
|
|
329
|
+
rescue => e
|
|
330
|
+
raise Common::NodeSetBiosError.new("Impossible to set the node '#{node_name}' with the bios '#{bios_name}'.")
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
public
|
|
335
|
+
# set raid of node JbodOnly or Raid10
|
|
336
|
+
# @param node_name the name of node
|
|
337
|
+
# @param raid_name the name of raid JbodOnly or Raid10
|
|
338
|
+
# @return true is successful and false if error
|
|
339
|
+
# @author mbretaud
|
|
340
|
+
def set_raid(node_name, raid_name)
|
|
341
|
+
node = node_name.split(".")
|
|
342
|
+
node = node[0]
|
|
343
|
+
|
|
344
|
+
begin
|
|
345
|
+
res = launch_request("POST","/nodes/#{node_name}/update", "alias=#{node}&raid=#{raid_name}&submit=Save")
|
|
346
|
+
if res.code != "302"
|
|
347
|
+
raise Common::NodeSetRaidError.new("Code error '#{res.code}' of launching request POST on '/nodes/#{node_name}/update' with data 'alias=#{node}&raid=#{raid_name}&submit=Save'.")
|
|
348
|
+
end
|
|
349
|
+
return true
|
|
350
|
+
rescue => e
|
|
351
|
+
raise Common::NodeSetRaidError.new("Impossible to set the node '#{node_name}' with the raid '#{raid_name}'.")
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
public
|
|
356
|
+
# set raid JbodOnly or Raid10 and set bios on node
|
|
357
|
+
# @param node_name the name of node
|
|
358
|
+
# @param bios_name the name of bios
|
|
359
|
+
# @param raid_name type of raid JbodOnly or Raid10
|
|
360
|
+
# @return true is successful and false if error
|
|
361
|
+
# @author mbretaud
|
|
362
|
+
def set_bios_raid(node_name, bios_name, raid_name)
|
|
363
|
+
node = node_name.split(".")
|
|
364
|
+
node = node[0]
|
|
365
|
+
|
|
366
|
+
begin
|
|
367
|
+
res = launch_request("POST","/nodes/#{node_name}/update", "alias=#{node}&bios=#{bios_name}&raid=#{raid_name}&submit=Save")
|
|
368
|
+
if res.code != "302"
|
|
369
|
+
raise Common::NodeSetBiosRaidError.new("Code error '#{res.code}' of launching request POST on '/nodes/#{node_name}/update' with data 'alias=#{node}&bios=#{bios_name}&raid=#{raid_name}&submit=Save'")
|
|
370
|
+
end
|
|
371
|
+
return true
|
|
372
|
+
rescue => e
|
|
373
|
+
raise Common::NodeSetBiosRaidError.new("Impossible to set the node '#{node_name}' with the bios '#{bios_name}' and the raid '#{raid_name}'.")
|
|
374
|
+
end
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
public
|
|
378
|
+
# Delete a vcluster
|
|
379
|
+
# @param vcluster_name The name of the vlcuster
|
|
380
|
+
# @author mbretaud
|
|
381
|
+
def vcluster_delete(vcluster_name)
|
|
382
|
+
# @todo
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
public
|
|
386
|
+
# Desallocate a vcluster
|
|
387
|
+
# @param vcluster_name The name of the vlcuster
|
|
388
|
+
# @author mbretaud
|
|
389
|
+
def vcluster_desallocate(vcluster_name)
|
|
390
|
+
# @todo
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
public
|
|
395
|
+
# Verify a barclamp is commited with a good node
|
|
396
|
+
# @param barclamp_name the name of barclamp
|
|
397
|
+
# @param list_machines the list of node
|
|
398
|
+
# @return true is successful and false if error
|
|
399
|
+
# @author mbretaud
|
|
400
|
+
def verify_committed_barclamp(barclamp_name, list_machines)
|
|
401
|
+
proposal_name = "default"
|
|
402
|
+
role="#{barclamp_name}-server"
|
|
403
|
+
|
|
404
|
+
path_get = "/crowbar/#{barclamp_name}/1.0/proposals/#{proposal_name}"
|
|
405
|
+
path_post = "/crowbar/#{barclamp_name}/1.0/proposals/#{proposal_name}"
|
|
406
|
+
|
|
407
|
+
begin
|
|
408
|
+
res = launch_request("GET", "/crowbar/barclamp/1.0/proposals/status", "")
|
|
409
|
+
|
|
410
|
+
json = res.body
|
|
411
|
+
rescue => e
|
|
412
|
+
raise Common::VerifyCommittedBarclampError.new("GET the list of barclamps.")
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
p = JSON.parse(json)
|
|
416
|
+
|
|
417
|
+
proposal_exists = false
|
|
418
|
+
if p['i18n'] != nil
|
|
419
|
+
get_keys = p['i18n'].keys
|
|
420
|
+
get_keys.each{|e|
|
|
421
|
+
if e.include? "#{barclamp_name.strip}"
|
|
422
|
+
proposal_exists = true
|
|
423
|
+
end
|
|
424
|
+
}
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
if !proposal_exists
|
|
428
|
+
creation = true
|
|
429
|
+
if !create_proposal(barclamp_name, proposal_name)
|
|
430
|
+
raise Common::VerifyCommittedBarclampError.new("The proposal '#{proposal_name}' could not be created on the barclamp '#{barclamp_name}'.")
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
begin
|
|
435
|
+
res = launch_request("GET", path_get, "")
|
|
436
|
+
json = res.body
|
|
437
|
+
rescue => e
|
|
438
|
+
raise Common::VerifyCommittedBarclampError.new("Retrieve the data on the proposal '#{proposal_name}' of the barclamp '#{barclamp_name}'.")
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
begin
|
|
442
|
+
p = JSON.parse(json)
|
|
443
|
+
|
|
444
|
+
attributes=p['attributes'][barclamp_name]
|
|
445
|
+
deployment=p['deployment'][barclamp_name]
|
|
446
|
+
|
|
447
|
+
if creation
|
|
448
|
+
deployment['elements'][role]=Array.new
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
list_machines_to_allocate = Array.new
|
|
452
|
+
|
|
453
|
+
if deployment['elements'][role] != nil
|
|
454
|
+
deployment['elements'][role].each{|machine_allocated|
|
|
455
|
+
list_machines_to_allocate << machine_allocated
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
list_machines_to_allocate.each{|machine_allocated|
|
|
459
|
+
deployment['elements'][role].delete(machine_allocated)
|
|
460
|
+
}
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
list_machines.each do |machine|
|
|
464
|
+
exists = false
|
|
465
|
+
|
|
466
|
+
list_machines_to_allocate.each{|machine_allocated|
|
|
467
|
+
if machine == machine_allocated
|
|
468
|
+
exists = true
|
|
469
|
+
end
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if !exists
|
|
473
|
+
list_machines_to_allocate << machine
|
|
474
|
+
end
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
deployment['elements'][role] = Array.new
|
|
478
|
+
deployment['elements'][role] = list_machines_to_allocate
|
|
479
|
+
|
|
480
|
+
if deployment['crowbar-committing'] != nil
|
|
481
|
+
deployment['crowbar-committing'] = false
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
attributes = attributes.to_json.strip
|
|
485
|
+
deployment = deployment.to_json.strip
|
|
486
|
+
|
|
487
|
+
data_save = "barclamp=#{barclamp_name.strip}&name=#{proposal_name.strip}&proposal_attributes=#{attributes.strip}&proposal_deployment=#{deployment.strip}&submit=Save"
|
|
488
|
+
data_apply = "barclamp=#{barclamp_name.strip}&name=#{proposal_name.strip}&proposal_attributes=#{attributes.strip}&proposal_deployment=#{deployment.strip}&submit=Apply"
|
|
489
|
+
|
|
490
|
+
path_post = "/crowbar/#{barclamp_name.strip}/1.0/proposals/#{proposal_name.strip}"
|
|
491
|
+
rescue => e
|
|
492
|
+
raise Common::VerifyCommittedBarclampError.new("Modify the body of the request.")
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
res=nil
|
|
496
|
+
begin
|
|
497
|
+
res = launch_request("POST", path_post, data_save)
|
|
498
|
+
if res.code != "302"
|
|
499
|
+
raise Common::VerifyCommittedBarclampError.new("Code error '#{res.code}' of launching request POST on '#{path_post}' with data '#{data_save}'.")
|
|
500
|
+
end
|
|
501
|
+
rescue => e
|
|
502
|
+
raise Common::VerifyCommittedBarclampError.new("Launches of request POST on '#{path_post}' with data '#{data_save}' to Save.")
|
|
503
|
+
end
|
|
504
|
+
|
|
505
|
+
res=nil
|
|
506
|
+
begin
|
|
507
|
+
res = launch_request("POST", path_post, data_apply)
|
|
508
|
+
if res.code != "302"
|
|
509
|
+
raise Common::VerifyCommittedBarclampError.new("Code error '#{res.code}' of launching request POST on '#{path_post}' with data '#{data_apply}'.")
|
|
510
|
+
end
|
|
511
|
+
rescue => e
|
|
512
|
+
raise Common::VerifyCommittedBarclampError.new("Launches of request POST on '#{path_post}' with data '#{data_save}' to Apply.")
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
return "Verify if the barclamp '#{barclamp_name}' is committed with the list of nodes... [ OK ]\n"
|
|
516
|
+
end
|
|
517
|
+
end
|
|
518
|
+
end
|