This commit is contained in:
Anu Chandy 2012-07-13 12:09:55 -07:00
Родитель a9a3f174cc
Коммит 5bdfa3cf48
3 изменённых файлов: 109 добавлений и 7 удалений

Просмотреть файл

@ -119,6 +119,7 @@ exports.init = function(cli) {
.option('-a, --affinity-group <name>', 'affinity group')
.option('-t, --ssh-cert <pem-file>', 'Upload SSH certificate')
.option('-s, --subscription <id>', 'use the subscription id')
.option('-w, --virtual-network-name <name>', 'virtual network name')
.execute(function(dnsName, roleFile, options, callback) {
function stripBOM(content) {
@ -139,10 +140,12 @@ exports.init = function(cli) {
createVM({
subscription: options.subscription,
location: options.location,
affinityGroup: options.affinityGroup,
dnsPrefix: dnsPrefix,
connect: options.connect,
role: role,
sshCert: options.sshCert
sshCert: options.sshCert,
virtualNetworkName: options.virtualNetworkName
}, callback);
});
@ -217,7 +220,17 @@ exports.init = function(cli) {
}
captureVM(vmName, targetImageName, options, callback);
});
vm.command('export <vm-name> <file-path>')
.whiteListPowershell()
.usage('<vm-name> <file-path>')
.description('Export Azure VM to a file')
.option('-s, --subscription <id>', 'use the subscription id')
.option('-d, --dns-name <name>', 'Export the VM for this DNS name')
.execute(function(vmName, filePath, options, callback) {
exportVM(vmName, filePath, options, callback);
});
vm.command('portal') // possible TODO: portal [name] [--dns-name <dns-name>] [--subscription <id>]
.whiteListPowershell()
.description('Opens the portal in a browser to manage your VMs')
@ -1381,6 +1394,85 @@ exports.init = function(cli) {
});
}
function exportVM(name, filePath, options, cmdCallback) {
var channel = utils.createServiceManagementService(cli.category('account').lookupSubscriptionId(options.subscription),
cli.category('account'), logger);
var progress = cli.progress('Fetching VMs');
enumDeployments(channel, options, function() {
progress.end();
if (options.rsps.length === 0 && options.errs.length > 0) {
cmdCallback(options.errs[0]);
} else if (options.rsps.length > 0) {
var found = null;
for (var i = 0; i < options.rsps.length; i++) {
var roles = options.rsps[i].deploy.RoleList;
if (roles) {
for (var j = 0; j < roles.length; j++) {
if (roles[j].RoleType === 'PersistentVMRole' &&
roles[j].RoleName === name) {
if (found) {
// found duplicates
cmdCallback('VM name is not unique');
}
found = roles[j];
}
}
}
}
// got unique role, export it to file
if (found) {
progress = cli.progress('Exporting the VM');
function _prepareForExport(role) {
for(var key in role) {
// Remove namespace @ node
if (key === '@' || key === 'OsVersion') {
delete role[key];
} else if (key === 'DataVirtualHardDisks') {
// Remove Links of all DataVirtualHardDisks since
// while importing we need to pass only DiskName
// which will be already linked with a vhd
for(var i = 0; i < role[key].length; i++) {
delete role[key][i]['MediaLink'];
delete role[key][i]['SourceMediaLink'];
}
} else if (key === 'OSVirtualHardDisk') {
delete role[key]['MediaLink'];
delete role[key]['SourceImageName'];
}
// Remove namespace inner objects
if (typeof role[key] === 'object') {
_prepareForExport(role[key]);
}
}
}
_prepareForExport(found);
if (found.DataVirtualHardDisks.length && !found.DataVirtualHardDisks[0].Lun) {
found.DataVirtualHardDisks[0].Lun = "0";
}
progress.end();
var roleAsString = JSON.stringify(found);
fs.writeFile(filePath, roleAsString, function (err) {
if (err) {
cmdCallback(err);
} else {
logger.info('VM ' + name + ' exported to ' + filePath);
cmdCallback();
}
});
} else {
logger.warn('No VMs found');
cmdCallback();
}
}
});
}
function endpointCreateDelete(options, cmdCallback) {
var channel = utils.createServiceManagementService(cli.category('account').lookupSubscriptionId(options.subscription),
cli.category('account'), logger);

Просмотреть файл

@ -330,7 +330,7 @@
"InputEndpoints":
{
"Name": "InputEndpoints",
"Required": true,
"Required": false,
"Type": "Collection(Complex.InputEndpoint)",
"XmlNode": "InputEndpoints",
"ItemXmlNode": "InputEndpoint",
@ -551,7 +551,7 @@
"SourceImageName":
{
"Name": "SourceImageName",
"Required": true,
"Required": false,
"Type": "Primitive.String",
"RegEx": "NIL",
"XmlNode": "SourceImageName"

Просмотреть файл

@ -1431,9 +1431,14 @@ function applyTransformIfRequired(name, response, hasTopLevelList) {
ConfigurationSet:
[
{
InputEndpoints: {
InputEndpoint: null
}
InputEndpoints: {
InputEndpoint: null
}
},
{
SubnetNames: {
SubnetName: null
}
}
]
}
@ -1460,6 +1465,11 @@ function applyTransformIfRequired(name, response, hasTopLevelList) {
InputEndpoints: {
InputEndpoint: null
}
},
{
SubnetNames: {
SubnetName: null
}
}
]
}