client = Client()
result = client.ns_delete(user.get_token(), instance_id, force)
print result
- return __response_handler(request, result, 'instances:list', to_redirect=True, type='ns',
- )
+ return __response_handler(request, result, 'instances:list', to_redirect=True, type='ns')
def show_topology(request, instance_id=None, type=None):
def __response_handler(request, data_res, url=None, to_redirect=None, *args, **kwargs):
raw_content_types = request.META.get('HTTP_ACCEPT', '*/*').split(',')
if 'application/json' in raw_content_types or url is None:
- return HttpResponse(json.dumps(data_res), content_type="application/json", *args, **kwargs)
+ return HttpResponse(json.dumps(data_res), content_type="application/json")
elif to_redirect:
return redirect(url, *args, **kwargs)
else:
+#
+# Copyright 2018 EveryUP Srl
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
import requests
import logging
import json
log.exception(e)
result['data'] = str(e)
return result
- if r.status_code == requests.codes.ok:
+ if r:
result['error'] = False
- result['data'] = Util.json_loads_byteified(r.text)
+ if r.status_code != requests.codes.no_content:
+ result['data'] = Util.json_loads_byteified(r.text)
return result
def nsd_onboard(self, token, package):
log.exception(e)
result['data'] = str(e)
return result
- if r.status_code == requests.codes.ok:
+ if r:
result['error'] = False
- result['data'] = Util.json_loads_byteified(r.text)
+ if r.status_code != requests.codes.no_content:
+ result['data'] = Util.json_loads_byteified(r.text)
return result
def ns_get(self, token, id):
del_res = client.sdn_delete(user.get_token(), sdn_id)
except Exception as e:
log.exception(e)
- return __response_handler(request, {}, 'sdns:list', to_redirect=True, )
+ return __response_handler(request, del_res, 'sdns:list', to_redirect=True, )
@login_required
function deleteNs(url, force) {
bootbox.confirm("Are you sure want to delete?", function (result) {
if (result) {
- if(force)
+ if (force)
url = url + '?force=true';
- location.href = url
+ var dialog = bootbox.dialog({
+ message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+ closeButton: true
+ });
+ $.ajax({
+ url: url,
+ type: 'GET',
+ dataType: "json",
+ contentType: "application/json;charset=utf-8",
+ success: function (result) {
+ if (result['error'] == true){
+ dialog.modal('hide');
+ bootbox.alert("An error occurred.");
+ }
+ else {
+ dialog.modal('hide');
+ location.reload();
+ }
+ },
+ error: function (error) {
+ dialog.modal('hide');
+ bootbox.alert("An error occurred.");
+ }
+ });
}
})
}
contentType: "application/json;charset=utf-8",
success: function (result) {
- if(result['data'] !== undefined) {
+ if (result['data'] !== undefined) {
editorJSON.setValue(JSON.stringify(result['data'], null, "\t"));
editorJSON.setOption("autoRefresh", true);
dialog.modal('hide');
$('#modal_show_instance').modal('show');
}
- else{
+ else {
dialog.modal('hide');
bootbox.alert("An error occurred while retrieving the information.");
}
},
contentType: false,
processData: false
- }).done(function (response,textStatus, jqXHR) {
+ }).done(function (response, textStatus, jqXHR) {
$('#modal_instance_new_action').modal('hide');
bootbox.alert({
- title: "Action",
- message: "Action received."
- });
- }).fail(function(result){
- var data = result.responseJSON;
- var title = "Error " + (data.code ? data.code: 'unknown');
- var message = data.detail ? data.detail: 'No detail available.';
- bootbox.alert({
- title: title,
- message: message
- });
+ title: "Action",
+ message: "Action received."
+ });
+ }).fail(function (result) {
+ var data = result.responseJSON;
+ var title = "Error " + (data.code ? data.code : 'unknown');
+ var message = data.detail ? data.detail : 'No detail available.';
+ bootbox.alert({
+ title: title,
+ message: message
+ });
});
});
},
contentType: false,
processData: false
- }).done(function (response,textStatus, jqXHR) {
+ }).done(function (response, textStatus, jqXHR) {
$('#modal_instance_new_action').modal('hide');
bootbox.alert({
- title: "Metric",
- message: "Alarm created."
- });
- }).fail(function(result){
- var data = result.responseJSON;
- var title = "Error " + (data.code ? data.code: 'unknown');
- var message = data.detail ? data.detail: 'No detail available.';
- bootbox.alert({
- title: title,
- message: message
- });
+ title: "Metric",
+ message: "Alarm created."
+ });
+ }).fail(function (result) {
+ var data = result.responseJSON;
+ var title = "Error " + (data.code ? data.code : 'unknown');
+ var message = data.detail ? data.detail : 'No detail available.';
+ bootbox.alert({
+ title: title,
+ message: message
+ });
});
});
},
contentType: false,
processData: false
- }).done(function (response,textStatus, jqXHR) {
+ }).done(function (response, textStatus, jqXHR) {
$('#modal_instance_new_action').modal('hide');
bootbox.alert({
- title: "Metric",
- message: "Metric exported."
- });
- }).fail(function(result){
- var data = result.responseJSON;
- var title = "Error " + (data.code ? data.code: 'unknown');
- var message = data.detail ? data.detail: 'No detail available.';
- bootbox.alert({
- title: title,
- message: message
- });
+ title: "Metric",
+ message: "Metric exported."
+ });
+ }).fail(function (result) {
+ var data = result.responseJSON;
+ var title = "Error " + (data.code ? data.code : 'unknown');
+ var message = data.detail ? data.detail : 'No detail available.';
+ bootbox.alert({
+ title: title,
+ message: message
+ });
});
});
function deletePackage(descriptor_type, package_id) {
+ var dialog = bootbox.dialog({
+ message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+ closeButton: true
+ });
bootbox.confirm("Are you sure want to delete?", function (result) {
if (result) {
- location.href = '/projects/descriptors/' + descriptor_type + '/' + package_id + '/delete'
+
+ $.ajax({
+ url: '/projects/descriptors/' + descriptor_type + '/' + package_id + '/delete',
+ type: 'GET',
+ dataType: "json",
+ contentType: "application/json;charset=utf-8",
+ success: function (result) {
+ dialog.modal('hide');
+ location.reload();
+ },
+ error: function (result) {
+ dialog.modal('hide');
+ bootbox.alert("An error occurred.");
+ }
+ });
}
})
}
function deleteSDN(sdn_uuid) {
bootbox.confirm("Are you sure want to delete?", function (result) {
if (result) {
- location.href = '/sdn/' + sdn_uuid + '/delete'
+ var dialog = bootbox.dialog({
+ message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+ closeButton: true
+ });
+ $.ajax({
+ url: '/sdn/' + sdn_uuid + '/delete',
+ type: 'GET',
+ dataType: "json",
+ contentType: "application/json;charset=utf-8",
+ success: function (result) {
+ if (result['error'] == true){
+ dialog.modal('hide');
+ bootbox.alert("An error occurred.");
+ }
+ else {
+ dialog.modal('hide');
+ location.reload();
+ }
+ },
+ error: function (error) {
+ dialog.modal('hide');
+ bootbox.alert("An error occurred.");
+ }
+ });
}
})
}
$.ajax({
url: '/sdn/' + sdn_uuid ,
- //url: '/sdn/' + sdn_uuid,
type: 'GET',
dataType: "json",
contentType: "application/json;charset=utf-8",
function deleteVim(url) {
bootbox.confirm("Are you sure want to delete?", function (result) {
if (result) {
- location.href = url//'/vims/' + vim_uuid + '/delete'
+ var dialog = bootbox.dialog({
+ message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+ closeButton: true
+ });
+ $.ajax({
+ url: url,
+ type: 'GET',
+ dataType: "json",
+ contentType: "application/json;charset=utf-8",
+ success: function (result) {
+ if (result['error'] == true) {
+ dialog.modal('hide');
+ bootbox.alert("An error occurred.");
+ }
+ else {
+ dialog.modal('hide');
+ location.reload();
+ }
+ },
+ error: function (error) {
+ dialog.modal('hide');
+ bootbox.alert("An error occurred.");
+ }
+ });
}
})
}
del_res = client.vim_delete(user.get_token(), vim_id)
except Exception as e:
log.exception(e)
- return __response_handler(request, {}, 'vims:list', to_redirect=True, )
+ return __response_handler(request, del_res, 'vims:list', to_redirect=True, )
@login_required
def show(request, vim_id=None):