Merge "Add REST API for stats list"

This commit is contained in:
Jenkins 2017-07-21 05:15:26 +00:00 committed by Gerrit Code Review
commit 2a1d74d8d6
4 changed files with 61 additions and 18 deletions

View File

@ -186,3 +186,9 @@ def certificate_show(request, id):
def certificate_rotate(request, id):
args = {"cluster_uuid": id}
return magnumclient(request).certificates.rotate_ca(**args)
def stats_list(request, limit=None, marker=None, sort_key=None,
sort_dir=None, detail=True):
return magnumclient(request).stats.list(
limit, marker, sort_key, sort_dir, detail)

View File

@ -192,6 +192,22 @@ class Certificates(generic.View):
new_cert.to_dict())
@urls.register
class Stats(generic.View):
"""API for Magnum Stats"""
url_regex = r'container_infra/stats/$'
@rest_utils.ajax()
def get(self, request):
"""Get a list of the Stats.
The returned result is an object with property 'items' and each
item under this is a Stat.
"""
result = magnum.stats_list(request)
return {'items': [change_to_id(n.to_dict()) for n in result]}
@urls.register
class Networks(generic.View):
"""API for Neutron networks for Cluster Templates creation"""

View File

@ -44,8 +44,9 @@
showCertificate: showCertificate,
signCertificate: signCertificate,
rotateCertificate: rotateCertificate,
downloadTextAsFile: downloadTextAsFile,
getNetworks: getNetworks
getStats: getStats,
getNetworks: getNetworks,
downloadTextAsFile: downloadTextAsFile
};
return service;
@ -171,23 +172,15 @@
});
}
function downloadTextAsFile(text, filename) {
// create text file as object url
var blob = new Blob([ text ], { "type" : "text/plain" });
window.URL = window.URL || window.webkitURL;
var fileurl = window.URL.createObjectURL(blob);
///////////
// Stats //
///////////
// provide text as downloaded file
$timeout(function() {
//Update view
var a = angular.element('<a></a>');
a.attr("href", fileurl);
a.attr("download", filename);
a.attr("target", "_blank");
angular.element(document.body).append(a);
a[0].click();
a.remove();
}, 0);
function getStats() {
return apiService.get('/api/container_infra/stats/')
.error(function() {
toastService.add('error', gettext('Unable to retrieve the stats.'));
});
}
//////////////////
@ -208,5 +201,27 @@
});
}
///////////
// Utils //
///////////
function downloadTextAsFile(text, filename) {
// create text file as object url
var blob = new Blob([ text ], { "type" : "text/plain" });
window.URL = window.URL || window.webkitURL;
var fileurl = window.URL.createObjectURL(blob);
// provide text as downloaded file
$timeout(function() {
//Update view
var a = angular.element('<a></a>');
a.attr("href", fileurl);
a.attr("download", filename);
a.attr("target", "_blank");
angular.element(document.body).append(a);
a[0].click();
a.remove();
}, 0);
}
}
}());

View File

@ -160,6 +160,12 @@
"data": [123],
"error": "Unable to rotate the certificate.",
"testInput": [123, [123]]
},
{
"func": "getStats",
"method": "get",
"path": "/api/container_infra/stats/",
"error": "Unable to retrieve the stats."
}
];