UNPKG

azure-cli

Version:

Microsoft Azure Cross Platform Command Line tool

197 lines (101 loc) 12.2 kB
/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var __ = require("underscore"); var util = require("util"); var utils = require("../../../util/utils"); var $ = utils.getLocaleString; function NetworkPublicIP(cli, networkResourceProviderClient, resourceGroupName, params) { this.cli = cli; this.networkResourceProviderClient = networkResourceProviderClient; this.resourceGroupName = resourceGroupName; this.params = params;}; __.extend(NetworkPublicIP.prototype, { _parsePublicIPCreateParams: function _parsePublicIPCreateParams__1(params, _) { var createRequestProfile, timeoutAsInt, supportedAllocationTypes, __this = this; var __frame = { name: "_parsePublicIPCreateParams__1", line: 31 }; return __func(_, this, arguments, _parsePublicIPCreateParams__1, 1, __frame, function __$_parsePublicIPCreateParams__1() { return (function __$_parsePublicIPCreateParams__1(__then) { if (utils.stringIsNullOrEmpty(params.publicipName)) { return __this.cli.interaction.prompt($("Enter public IP name: "), __cb(_, __frame, 2, 51, function ___(__0, __1) { params.publicipName = __1; __then(); }, true)); } else { __then(); } ; })(function __$_parsePublicIPCreateParams__1() { return (function __$_parsePublicIPCreateParams__1(__then) { if (utils.stringIsNullOrEmpty(params.publicipDomainName)) { return __this.cli.interaction.prompt($("Enter public IP domain name: "), __cb(_, __frame, 6, 57, function ___(__0, __2) { params.publicipDomainName = __2; __then(); }, true)); } else { __then(); } ; })(function __$_parsePublicIPCreateParams__1() { return (function __$_parsePublicIPCreateParams__1(__then) { if (utils.stringIsNullOrEmpty(params.location)) { return __this.cli.interaction.prompt($("Enter location: "), __cb(_, __frame, 10, 47, function ___(__0, __3) { params.location = __3; __then(); }, true)); } else { __then(); } ; })(function __$_parsePublicIPCreateParams__1() { createRequestProfile = { dnsSettings: { domainNameLabel: params.publicipDomainName }, location: params.location }; if (params.publicipIdletimeout) { timeoutAsInt = utils.parseInt(params.publicipIdletimeout); if ((isNaN(timeoutAsInt) || (timeoutAsInt === 0))) { return _(new Error($("publicipIdletimeout is an optional parameter but when it is specified it must be an integer"))); } ; createRequestProfile.idleTimeoutInMinutes = timeoutAsInt; } ; supportedAllocationTypes = ["Dynamic",]; if (!utils.stringIsNullOrEmpty(params.publicipAllocationmethod)) { createRequestProfile.publicIpAllocationMethod = utils.verifyParamExistsInCollection(supportedAllocationTypes, params.publicipAllocationmethod, "publicipAllocationmethod"); } else { createRequestProfile.publicIpAllocationMethod = supportedAllocationTypes[0]; } ; return _(null, createRequestProfile); }); }); }); }); }, hasAnyPubIPParameters: function(params) { var allPublicIPParams = [params.publicipName,params.publicipDomainname,params.publicipIdletimeout,params.publicipAllocationmethod,]; return utils.atLeastOneParameIsSet(allPublicIPParams); }, createPublicIPIfRequired: function createPublicIPIfRequired__2(_) { var publicipInfo, createRequestProfile, __this = this; var __frame = { name: "createPublicIPIfRequired__2", line: 81 }; return __func(_, this, arguments, createPublicIPIfRequired__2, 0, __frame, function __$createPublicIPIfRequired__2() { return (function __$createPublicIPIfRequired__2(__then) { if (utils.stringIsNullOrEmpty(__this.params.publicipName)) { return __this.cli.interaction.prompt($("Enter public IP name: "), __cb(_, __frame, 2, 56, function ___(__0, __1) { __this.params.publicipName = __1; __then(); }, true)); } else { __then(); } ; })(function __$createPublicIPIfRequired__2() { return (function __$createPublicIPIfRequired__2(__then) { if (utils.stringIsNullOrEmpty(__this.params.location)) { return __this.cli.interaction.prompt($("Enter location: "), __cb(_, __frame, 6, 52, function ___(__0, __2) { __this.params.location = __2; __then(); }, true)); } else { __then(); } ; })(function __$createPublicIPIfRequired__2() { return __this.getPublicIPInfoByName(__this.resourceGroupName, __this.params.publicipName, __cb(_, __frame, 9, 30, function ___(__0, __3) { publicipInfo = __3; return (function __$createPublicIPIfRequired__2(__then) { if (publicipInfo.profile) { if (!utils.ignoreCaseAndSpaceEquals(publicipInfo.profile.location, __this.params.location)) { return _(new Error(util.format($("A PublicIP with name \"%s\" already exists in another region \"%s\""), publicipInfo.profile.name, publicipInfo.profile.location))); } ; __this.cli.output.info(util.format($("Found an existing PublicIP \"%s\""), publicipInfo.profile.name)); __then(); } else { __this.cli.output.info(util.format($("PublicIP with given name \"%s\" not found, creating a new one"), publicipInfo.publicipName)); return __this._createNewPublicIP(publicipInfo.resourceGroupName, __this.params, __cb(_, __frame, 18, 40, function ___(__0, __4) { createRequestProfile = __4; return __this.getPublicIPInfoByName(publicipInfo.resourceGroupName, publicipInfo.publicipName, __cb(_, __frame, 20, 28, function ___(__0, __5) { publicipInfo = __5; publicipInfo.createdNew = true; publicipInfo.createRequestProfile = createRequestProfile; __then(); }, true)); }, true)); } ; })(function __$createPublicIPIfRequired__2() { return _(null, publicipInfo); }); }, true)); }); }); }); }, getPublicIPInfoById: function getPublicIPInfoById__3(referenceUri, _) { var resourceInfo, __this = this; var __frame = { name: "getPublicIPInfoById__3", line: 109 }; return __func(_, this, arguments, getPublicIPInfoById__3, 1, __frame, function __$getPublicIPInfoById__3() { resourceInfo = utils.parseResourceReferenceUri(referenceUri); return __this.getPublicIPInfoByName(resourceInfo.resourceGroupName, resourceInfo.resourceName, __cb(_, __frame, 2, 18, _, true)); }); }, getPublicIPInfoByName: function getPublicIPInfoByName__4(resourceGroupName, publicipName, _) { var publicipInfo, publicIP, __this = this; var __frame = { name: "getPublicIPInfoByName__4", line: 114 }; return __func(_, this, arguments, getPublicIPInfoByName__4, 2, __frame, function __$getPublicIPInfoByName__4() { publicipInfo = { publicipName: publicipName, resourceGroupName: resourceGroupName, createdNew: false, createRequestProfile: { }, profile: null }; return __this._getPublicIP(resourceGroupName, publicipName, __cb(_, __frame, 9, 26, function ___(__0, __1) { publicIP = __1; if (publicIP) { publicipInfo.profile = publicIP; } ; return _(null, publicipInfo); }, true)); }); }, getPublicIPByIdExpanded: function getPublicIPByIdExpanded__5(referenceUri, depth, memoize, dependencies, _) { var resourceInfo, expandedPublicIP, __this = this; var __frame = { name: "getPublicIPByIdExpanded__5", line: 131 }; return __func(_, this, arguments, getPublicIPByIdExpanded__5, 4, __frame, function __$getPublicIPByIdExpanded__5() { referenceUri = referenceUri.toLowerCase(); if (memoize[referenceUri]) { return _(null, memoize[referenceUri]); } ; resourceInfo = utils.parseResourceReferenceUri(referenceUri); return __this.getPublicIPByNameExpanded(resourceInfo.resourceGroupName, resourceInfo.resourceName, depth, memoize, dependencies, __cb(_, __frame, 7, 34, function ___(__0, __1) { expandedPublicIP = __1; return _(null, expandedPublicIP); }, true)); }); }, getPublicIPByNameExpanded: function getPublicIPByNameExpanded__6(resourceGroupName, publicipName, depth, memoize, dependencies, _) { var publicIP, expandedPublicIP, __this = this; var __frame = { name: "getPublicIPByNameExpanded__6", line: 142 }; return __func(_, this, arguments, getPublicIPByNameExpanded__6, 5, __frame, function __$getPublicIPByNameExpanded__6() { return __this._getPublicIP(resourceGroupName, publicipName, __cb(_, __frame, 1, 26, function ___(__0, __1) { publicIP = __1; expandedPublicIP = __this._expandPublicIP(publicIP, depth, memoize); return _(null, expandedPublicIP); }, true)); }); }, _expandPublicIP: function(publicIP, depth, memoize) { if (((depth === 0) || (publicIP === null))) { return publicIP; } ; if ((depth !== -1)) { depth--; } ; var referenceUri = publicIP.id.toLowerCase(); memoize[referenceUri] = publicIP; return memoize[referenceUri]; }, _getPublicIP: function _getPublicIP__7(resourceGroupName, publicipName, _) { var progress, publicIP, __this = this; var __frame = { name: "_getPublicIP__7", line: 164 }; return __func(_, this, arguments, _getPublicIP__7, 2, __frame, function __$_getPublicIP__7() { progress = __this.cli.interaction.progress(util.format($("Looking up the public ip \"%s\""), publicipName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$_getPublicIP__7() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$_getPublicIP__7() { return __this.networkResourceProviderClient.publicIPAddresses.get(resourceGroupName, publicipName, __cb(_, __frame, 3, 76, function ___(__0, __1) { publicIP = __1; return _(null, publicIP); }, true)); }); })(function ___(e, __result) { __catch(function __$_getPublicIP__7() { if (e) { if ((e.code === "ResourceNotFound")) { return _(null, null); } ; return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$_getPublicIP__7() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$_getPublicIP__7() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$_getPublicIP__7() { _(); }); }); }); }, _createNewPublicIP: function _createNewPublicIP__8(resourceGroupName, params, _) { var createRequestProfile, progress, __this = this; var __frame = { name: "_createNewPublicIP__8", line: 179 }; return __func(_, this, arguments, _createNewPublicIP__8, 2, __frame, function __$_createNewPublicIP__8() { return __this._parsePublicIPCreateParams(params, __cb(_, __frame, 1, 38, function ___(__0, __1) { createRequestProfile = __1; progress = __this.cli.interaction.progress(util.format($("Creating public ip \"%s\""), params.publicipName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$_createNewPublicIP__8() { return __this.networkResourceProviderClient.publicIPAddresses.createOrUpdate(resourceGroupName, params.publicipName, createRequestProfile, __cb(_, __frame, 4, 61, function __$_createNewPublicIP__8() { return _(null, createRequestProfile); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$_createNewPublicIP__8() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$_createNewPublicIP__8() { _(); }); }); }, true)); }); }, buildIdFromParams: function() { return (((("/resourceGroups/" + this.resourceGroupName) + "/providers/Microsoft.Network/publicIPAddresses/") + this.params.publicipName)).toLocaleLowerCase(); }}); module.exports = NetworkPublicIP;