From df06980ab7851ff4c594fe7c8189783dea1ac636 Mon Sep 17 00:00:00 2001 From: Sergey S Shinkevich Date: Wed, 2 May 2012 13:21:58 -0700 Subject: [PATCH] limit vmName to 15 chars for Windows --- lib/cli/commands/vm.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/cli/commands/vm.js b/lib/cli/commands/vm.js index 55ef9cf57..fb4f04c1b 100644 --- a/lib/cli/commands/vm.js +++ b/lib/cli/commands/vm.js @@ -682,7 +682,24 @@ exports.init = function(cli) { }); } - var vmName = dnsPrefix + crypto.randomBytes(8).toString('hex'); + var roleList = response.body.RoleList; + var maxNum = 1; + for (var i = 0; i < roleList.length; i++) { + var numSplit = roleList[i].RoleName.split('-'); + if (numSplit.length > 1) { + // did it start with dnsPrefix? If not, ignore. + var leftSplit = numSplit.slice(0, -1).join('-'); + if (leftSplit === dnsPrefix.slice(0, leftSplit.length)) { + var num = parseInt(numSplit[numSplit.length - 1], 10); + if (!isNaN(num) && num !== num + 1 && num > maxNum) { // number that is not too big + maxNum = num; + } + } + } + } + var tag = '-' + (maxNum + 1); + var vmName = image.OS.toLowerCase() === 'linux' ? dnsPrefix : dnsPrefix.slice(0, 15 - tag.length); + vmName += tag; if (!role) { createDefaultRole(vmName, addRole_); } else { @@ -884,7 +901,7 @@ exports.init = function(cli) { var mediaLink = diskInfo.MediaLink; logger.verbose('Deleting disk ' + diskName + ' @ ' + mediaLink); deleteImage.deleteImage('Disk', 'Disk', logger, channel, diskName, mediaLink, - null, null, true, function(error) { + progress, true, function(error) { doneCount++; logger.silly('Finished deleding disk ' + doneCount + ' of ' + allCount + error ? 'error' : '');