From eaeb0c63be1aeddd5af9d6df4bf589064b263419 Mon Sep 17 00:00:00 2001 From: Abel Coronado Date: Tue, 17 Oct 2017 13:13:01 +0200 Subject: [PATCH] B #5459: Importing vcenter resources without any Host (#531) * B #5459: Importing vcenter resources without any Host * B #5459: Importing vcenter vnets without any Host --- .../public/app/utils/vcenter/datastores.js | 75 ++++++++++--------- .../public/app/utils/vcenter/networks.js | 40 +++++----- 2 files changed, 63 insertions(+), 52 deletions(-) diff --git a/src/sunstone/public/app/utils/vcenter/datastores.js b/src/sunstone/public/app/utils/vcenter/datastores.js index 48c97d6148..f63459979f 100644 --- a/src/sunstone/public/app/utils/vcenter/datastores.js +++ b/src/sunstone/public/app/utils/vcenter/datastores.js @@ -168,46 +168,53 @@ define(function(require) { var one_template = $(this).data("one_template"); var one_clusters = $(this).data("one_clusters"); var datastore_ids = []; - $.each(one_template, function(id, element){ - var datastore_json = { - "datastore": { - "datastore_raw": this.one - }, - "cluster_id" : -1 - }; - OpenNebulaDatastore.create({ - timeout: true, - data: datastore_json, - success: function(request, response) { - datastore_ids.push(response.DATASTORE.ID); - VCenterCommon.importSuccess({ - context : row_context, - message : Locale.tr("Datastores created successfully. IDs: %1$s", datastore_ids.join()) - }); + if (one_clusters.length > 0) { + $.each(one_template, function(id, element){ + var datastore_json = { + "datastore": { + "datastore_raw": this.one + }, + "cluster_id" : -1 + }; + OpenNebulaDatastore.create({ + timeout: true, + data: datastore_json, + success: function(request, response) { + datastore_ids.push(response.DATASTORE.ID); + VCenterCommon.importSuccess({ + context : row_context, + message : Locale.tr("Datastores created successfully. IDs: %1$s", datastore_ids.join()) + }); - var datastore_raw = - "VCENTER_USER=\"" + that.opts.vcenter_user + "\"\n" + - "VCENTER_PASSWORD=\"" + that.opts.vcenter_password + "\"\n" + - "VCENTER_HOST=\"" + that.opts.vcenter_host + "\"\n"; + var datastore_raw = + "VCENTER_USER=\"" + that.opts.vcenter_user + "\"\n" + + "VCENTER_PASSWORD=\"" + that.opts.vcenter_password + "\"\n" + + "VCENTER_HOST=\"" + that.opts.vcenter_host + "\"\n"; - Sunstone.runAction("Datastore.append_template", response.DATASTORE.ID, datastore_raw); + Sunstone.runAction("Datastore.append_template", response.DATASTORE.ID, datastore_raw); - $.each(one_clusters, function(index, cluster_id){ - Sunstone.runAction("Cluster.adddatastore",cluster_id,response.DATASTORE.ID); - }); + $.each(one_clusters, function(index, cluster_id){ + Sunstone.runAction("Cluster.adddatastore",cluster_id,response.DATASTORE.ID); + }); - if (one_clusters.length > 0) { - Sunstone.runAction("Cluster.deldatastore",0,response.DATASTORE.ID); + if (one_clusters.length > 0) { + Sunstone.runAction("Cluster.deldatastore",0,response.DATASTORE.ID); + } + }, + 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?")) + }); } - }, - 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?")) - }); - } + }); }); - }); + } else { + VCenterCommon.importFailure({ + context : row_context, + message : Locale.tr("You need to import the associated vcenter cluster as one host first.") + }); + } }); }); } diff --git a/src/sunstone/public/app/utils/vcenter/networks.js b/src/sunstone/public/app/utils/vcenter/networks.js index 30f84688eb..223a8036be 100644 --- a/src/sunstone/public/app/utils/vcenter/networks.js +++ b/src/sunstone/public/app/utils/vcenter/networks.js @@ -305,26 +305,30 @@ define(function(require) { var one_cluster_id = $(this).data("import_data").one_cluster_id; - OpenNebulaNetwork.create({ - timeout: true, - data: vnet_json, - success: function(request, response) { - VCenterCommon.importSuccess({ - context : row_context, - message : Locale.tr("Virtual Network created successfully. ID: %1$s", response.VNET.ID) - }); - - if (one_cluster_id != -1) { + if (one_cluster_id != -1){ + OpenNebulaNetwork.create({ + timeout: true, + data: vnet_json, + success: function(request, response) { + VCenterCommon.importSuccess({ + context : row_context, + message : Locale.tr("Virtual Network created successfully. ID: %1$s", response.VNET.ID) + }); Sunstone.runAction("Cluster.addvnet",one_cluster_id,response.VNET.ID); + }, + 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?")) + }); } - }, - 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?")) - }); - } - }); + }); + } else { + VCenterCommon.importFailure({ + context : row_context, + message : Locale.tr("You need to import the associated vcenter cluster as one host first.") + }); + } }); });