Skip to content

Commit

Permalink
B OpenNebula#3280: check import vCenter cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Lobo <[email protected]>
  • Loading branch information
Jorge Lobo committed May 23, 2019
1 parent 0f8fc0d commit e850f78
Showing 1 changed file with 67 additions and 105 deletions.
172 changes: 67 additions & 105 deletions src/sunstone/public/app/utils/vcenter/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,131 +180,93 @@ define(function(require) {
var vcenter_version = $(this).data("cluster").vcenter_version;
var cluster_name = $(this).data("cluster").cluster_name;

if (cluster_id == 0) {

var cluster_json = {
"cluster": {
"name": cluster_name
}
};
var host_json = {
"host": {
"name": cluster_name,
"vm_mad": "vcenter",
"vnm_mad": "dummy",
"im_mad": "vcenter",
"cluster_id": null
}
};

var host_json = {
"host": {
"name": cluster_name,
"vm_mad": "vcenter",
"vnm_mad": "dummy",
"im_mad": "vcenter",
"cluster_id": null
function createHost(){
OpenNebulaHost.create({
timeout: true,
data: host_json,
success: function(request, response) {
VCenterCommon.importSuccess({
context : row_context,
message : Locale.tr("Host created successfully. ID: %1$s", response.HOST.ID)
});
var template_raw =
"VCENTER_USER=\"" + that.opts.vcenter_user + "\"\n" +
"VCENTER_PASSWORD=\"" + that.opts.vcenter_password + "\"\n" +
"VCENTER_HOST=\"" + that.opts.vcenter_host + "\"\n" +
"VCENTER_INSTANCE_ID=\"" + vcenter_uuid + "\"\n" +
"VCENTER_CCR_REF=\"" + cluster_ref + "\"\n" +
"VCENTER_VERSION=\"" + vcenter_version + "\"\n";
Sunstone.runAction("Host.update_template", response.HOST.ID, template_raw);
},
error: function (request, error_json) {
VCenterCommon.importFailure({
context : row_context,
message : (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?"))
});
}
};

function createHost(){
OpenNebulaHost.create({
timeout: true,
data: host_json,
success: function(request, response) {
VCenterCommon.importSuccess({
context : row_context,
message : Locale.tr("Host created successfully. ID: %1$s", response.HOST.ID)
});

var template_raw =
"VCENTER_USER=\"" + that.opts.vcenter_user + "\"\n" +
"VCENTER_PASSWORD=\"" + that.opts.vcenter_password + "\"\n" +
"VCENTER_HOST=\"" + that.opts.vcenter_host + "\"\n" +
"VCENTER_INSTANCE_ID=\"" + vcenter_uuid + "\"\n" +
"VCENTER_CCR_REF=\"" + cluster_ref + "\"\n" +
"VCENTER_VERSION=\"" + vcenter_version + "\"\n";
});
}

Sunstone.runAction("Host.update_template", response.HOST.ID, template_raw);
},
error: function (request, error_json) {
VCenterCommon.importFailure({
context : row_context,
message : (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?"))
});
function successClusterList(request, obj_list){
if (cluster_name && obj_list) {
let r = null;
obj_list.map(cluster => {
if (cluster && cluster.CLUSTER && cluster.CLUSTER.NAME) {
if (cluster.CLUSTER.NAME === cluster_name){
r = cluster.CLUSTER;
}
}
});
}

function successClusterList(request, obj_list){
if (cluster_name && obj_list) {
let r = null;
obj_list.map(cluster => {
if (cluster && cluster.CLUSTER && cluster.CLUSTER.NAME) {
if (cluster.CLUSTER.NAME === cluster_name){
r = cluster.CLUSTER;
}
if(r && r.ID){
host_json.host.cluster_id = r.ID;
createHost();
}else{
var cluster_json = {
"cluster": {
"name": cluster_name
}
};
OpenNebulaCluster.create({
timeout: true,
data: cluster_json,
success: function(request, response) {
host_json.host.cluster_id = response.CLUSTER.ID;
createHost();
},
error: function (request, error_json) {
VCenterCommon.importFailure({
context : row_context,
message : (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?"))
});
}
});
if(r && r.ID){
host_json.host.cluster_id = r.ID;
createHost();
}else{
OpenNebulaCluster.create({
timeout: true,
data: cluster_json,
success: function(request, response) {
createHost();
},
error: function (request, error_json) {
VCenterCommon.importFailure({
context : row_context,
message : (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?"))
});
}
});
}
}
}
}

if (cluster_id == 0) {
OpenNebulaCluster.list({
timeout: true,
success: successClusterList,
error: error => {
console.log("ERROR", error);
}
});

} else {
var host_json = {
"host": {
"name": cluster_name,
"vm_mad": "vcenter",
"vnm_mad": "dummy",
"im_mad": "vcenter",
"cluster_id": cluster_id
}
};

OpenNebulaHost.create({
timeout: true,
data: host_json,
success: function(request, response) {
VCenterCommon.importSuccess({
context : row_context,
message : Locale.tr("Host created successfully. ID: %1$s", response.HOST.ID)
});

var template_raw =
"VCENTER_USER=\"" + that.opts.vcenter_user + "\"\n" +
"VCENTER_PASSWORD=\"" + that.opts.vcenter_password + "\"\n" +
"VCENTER_HOST=\"" + that.opts.vcenter_host + "\"\n" +
"VCENTER_INSTANCE_ID=\"" + vcenter_uuid + "\"\n" +
"VCENTER_CCR_REF=\"" + cluster_ref + "\"\n" +
"VCENTER_VERSION=\"" + vcenter_version + "\"\n";

Sunstone.runAction("Host.update_template", response.HOST.ID, template_raw);
},
error: function (request, error_json) {
VCenterCommon.importFailure({
context : row_context,
message : (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?"))
});
}
});
host_json.host.cluster_id = cluster_id;
createHost();
}

});
});
}
Expand Down

0 comments on commit e850f78

Please sign in to comment.