azure-cli
Version:
Microsoft Azure Cross Platform Command Line tool
83 lines (34 loc) • 4.62 kB
JavaScript
/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ "use strict"; var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__tryCatch=__rt.__tryCatch; var __ = require("underscore");
var util = require("util");
var utils = require("../../../util/utils");
var insightsUtils = require("./insights.utils");
var $ = utils.getLocaleString;
exports.init = function(cli) {
var log = cli.output;
var insightsUsageCommand = cli.category("insights").category("usage").description($("Retrieve usage metrics for a resource."));
insightsUsageCommand.command("list <resourceId>").description($("List usage metrics for a resource.")).usage("[options] <resourceId>").option("-p --ApiVersion <apiVersion>", $("The underlying resource provider API version.")).option("-n --metricNames <metricNames>", $("The list of metric names.")).option("-b --startTime <startTime>", $("The start time of the query.")).option("-e --endTime <endTime>", $("The end time of the query.")).option("-s --subscription <subscription>", $("The subscription identifier.")).execute(function __1(resourceId, options, _) { var __frame = { name: "__1", line: 38 }; return __func(_, this, arguments, __1, 2, __frame, function __$__1() {
return insightsUsageCommand._prepareAndExecute(resourceId, options, __cb(_, __frame, 1, 29, function __$__1() { _(); }, true)); }); });
insightsUsageCommand._processGeneralParameters = function(metricNames, startTime, endTime) {
var clauses = [];
var nameClauses = insightsUtils.addMetricNamesFilter(metricNames);
if ((__.isString(nameClauses) && (nameClauses !== ""))) {
clauses.push(nameClauses); } ;
clauses.push(insightsUtils.validateDateTimeRangeAndAddDefaultsMetrics(startTime, endTime));
return clauses.join(" and "); };
insightsUsageCommand._prepareAndExecute = function insightsUsageCommand__prepareAndExecute__2(resourceId, options, _) { var client, queryFilter, apiVersion, __this = this; var __frame = { name: "insightsUsageCommand__prepareAndExecute__2", line: 55 }; return __func(_, this, arguments, insightsUsageCommand__prepareAndExecute__2, 2, __frame, function __$insightsUsageCommand__prepareAndExecute__2() {
if (!__.isString(resourceId)) {
cli.missingArgument(resourceId); } ;
client = insightsUtils.createInsightsClient(log, options);
queryFilter = __this._processGeneralParameters(options.metricNames, options.startTime, options.endTime);
apiVersion = (options.apiVersion ? options.apiVersion : insightsUtils.defaultApiVersion);
return __this._executeEventsCmd(client, resourceId, queryFilter, apiVersion, options, __cb(_, __frame, 9, 9, function __$insightsUsageCommand__prepareAndExecute__2() { _(); }, true)); }); };
insightsUsageCommand._executeEventsCmd = function insightsUsageCommand__executeEventsCmd__3(client, resourceId, queryFilter, apiVersion, options, _) { var progress, result, response, recordFilter; var __frame = { name: "insightsUsageCommand__executeEventsCmd__3", line: 67 }; return __func(_, this, arguments, insightsUsageCommand__executeEventsCmd__3, 5, __frame, function __$insightsUsageCommand__executeEventsCmd__3() {
progress = cli.interaction.progress(util.format($("Querying \"%s\""), queryFilter));
result = []; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$insightsUsageCommand__executeEventsCmd__3() {
return client.usageMetricOperations.list(resourceId, queryFilter, apiVersion, __cb(_, __frame, 4, 50, function ___(__0, __1) { response = __1;
log.silly((__.isObject(response) ? util.inspect(response) : "nothing in response"));
log.silly(((__.isObject(response) && response.usageMetricCollection) ? util.inspect(response.usageMetricCollection) : "nothing in usageMetricCollection"));
recordFilter = function(element) { if (insightsUtils.passAllFilter(element)) { result.push(element); } ; };
__.each(response.usageMetricCollection.value, recordFilter); _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$insightsUsageCommand__executeEventsCmd__3() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$insightsUsageCommand__executeEventsCmd__3() {
insightsUtils.formatOutputList(cli, log, options, result); _(); }); }); }); };};