Merge pull request #243 from andrerod/management
Aligning coding conventions for service management APIs.
This commit is contained in:
Коммит
b81d991a87
|
@ -1,6 +1,17 @@
|
|||
//
|
||||
// Build request body from parameters and parse response body
|
||||
//
|
||||
/**
|
||||
* Copyright 2011 Microsoft Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
var xmlbuilder = require('xmlbuilder');
|
||||
|
@ -18,9 +29,7 @@ ServiceManagementSerialize.invalidContentType = 'The response content type is in
|
|||
*
|
||||
* @constructor
|
||||
*/
|
||||
function ServiceManagementSerialize() {
|
||||
}
|
||||
|
||||
function ServiceManagementSerialize() { }
|
||||
|
||||
/**
|
||||
* Create the message body for CreateHostedService
|
||||
|
@ -31,10 +40,11 @@ function ServiceManagementSerialize() {
|
|||
* @param {object} client The servicemanagement object.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype.buildCreateHostedService = function(serviceName, serviceOptions, client) {
|
||||
var encLabel;
|
||||
var encLabel = undefined;
|
||||
if (serviceOptions.Label) {
|
||||
encLabel = new Buffer(serviceOptions.Label).toString('base64');
|
||||
}
|
||||
|
||||
if (client.serializetype === 'XML') {
|
||||
var doc = _createXmlRoot('CreateHostedService');
|
||||
_addDefinedValueXml(doc, 'ServiceName', serviceName);
|
||||
|
@ -45,12 +55,25 @@ ServiceManagementSerialize.prototype.buildCreateHostedService = function(service
|
|||
|
||||
return doc.toString();
|
||||
} else {
|
||||
var jdoc = {};
|
||||
jdoc.ServiceName = serviceName;
|
||||
if (encLabel) jdoc.Label = encLabel;
|
||||
if (serviceOptions.Description) jdoc.Description = serviceOptions.Description;
|
||||
if (serviceOptions.Location) jdoc.Location = serviceOptions.Location;
|
||||
if (serviceOptions.AffinityGroup) jdoc.AffinityGroup = serviceOptions.AffinityGroup;
|
||||
var jdoc = {
|
||||
ServiceName: serviceName
|
||||
};
|
||||
|
||||
if (encLabel) {
|
||||
jdoc.Label = encLabel;
|
||||
}
|
||||
|
||||
if (serviceOptions.Description) {
|
||||
jdoc.Description = serviceOptions.Description;
|
||||
}
|
||||
|
||||
if (serviceOptions.Location) {
|
||||
jdoc.Location = serviceOptions.Location;
|
||||
}
|
||||
|
||||
if (serviceOptions.AffinityGroup) {
|
||||
jdoc.AffinityGroup = serviceOptions.AffinityGroup;
|
||||
}
|
||||
|
||||
return JSON.stringify(jdoc);
|
||||
}
|
||||
|
@ -64,10 +87,11 @@ ServiceManagementSerialize.prototype.buildCreateHostedService = function(service
|
|||
* @param {object} client The servicemanagement object.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype.buildCreateStorageAccount = function(serviceName, serviceOptions, client) {
|
||||
var encLabel;
|
||||
var encLabel = undefined;
|
||||
if (serviceOptions.Label) {
|
||||
encLabel = new Buffer(serviceOptions.Label).toString('base64');
|
||||
}
|
||||
|
||||
if (client.serializetype === 'XML') {
|
||||
var doc = _createXmlRoot('CreateStorageServiceInput');
|
||||
_addDefinedValueXml(doc, 'ServiceName', serviceName);
|
||||
|
@ -78,12 +102,25 @@ ServiceManagementSerialize.prototype.buildCreateStorageAccount = function(servic
|
|||
|
||||
return doc.toString();
|
||||
} else {
|
||||
var jdoc = {};
|
||||
jdoc.ServiceName = serviceName;
|
||||
if (encLabel) jdoc.Label = encLabel;
|
||||
if (serviceOptions.Description) jdoc.Description = serviceOptions.Description;
|
||||
if (serviceOptions.Location) jdoc.Location = serviceOptions.Location;
|
||||
if (serviceOptions.AffinityGroup) jdoc.AffinityGroup = serviceOptions.AffinityGroup;
|
||||
var jdoc = {
|
||||
ServiceName: serviceName
|
||||
};
|
||||
|
||||
if (encLabel) {
|
||||
jdoc.Label = encLabel;
|
||||
}
|
||||
|
||||
if (serviceOptions.Description) {
|
||||
jdoc.Description = serviceOptions.Description;
|
||||
}
|
||||
|
||||
if (serviceOptions.Location) {
|
||||
jdoc.Location = serviceOptions.Location;
|
||||
}
|
||||
|
||||
if (serviceOptions.AffinityGroup) {
|
||||
jdoc.AffinityGroup = serviceOptions.AffinityGroup;
|
||||
}
|
||||
|
||||
return JSON.stringify(jdoc);
|
||||
}
|
||||
|
@ -91,35 +128,40 @@ ServiceManagementSerialize.prototype.buildCreateStorageAccount = function(servic
|
|||
|
||||
/**
|
||||
* Create the message body for CreateOSImage
|
||||
* Use the specified serialization - for now only XML
|
||||
* Use the specified serialization - for now only XML.
|
||||
*
|
||||
* @param {string} typeOS Either 'Linux' or 'Windows'.
|
||||
* @param {string} typeOs Either 'Linux' or 'Windows'.
|
||||
* @param {string} imageName The name of the image.
|
||||
* @param {string} mediaLink The mediaLink value.
|
||||
* @param {object} imageOptions The optional properties for the new image.
|
||||
* @param {object} client The servicemanagement object.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype.buildCreateOSImage = function(typeOS, imageName, mediaLink, imageOptions, client) {
|
||||
ServiceManagementSerialize.prototype.buildCreateOSImage = function(typeOs, imageName, mediaLink, imageOptions, client) {
|
||||
if (!imageOptions) {
|
||||
imageOptions = {};
|
||||
}
|
||||
|
||||
if (!imageOptions.Label) {
|
||||
imageOptions.Label = imageName;
|
||||
}
|
||||
|
||||
if (client.serializetype === 'XML') {
|
||||
var doc = _createXmlRoot('OSImage');
|
||||
|
||||
// add required and optional elements in alpha order
|
||||
_addDefinedValueXml(doc, 'Label', imageOptions.Label);
|
||||
_addDefinedValueXml(doc, 'MediaLink', mediaLink);
|
||||
_addDefinedValueXml(doc, 'Name', imageName);
|
||||
_addDefinedValueXml(doc, 'OS', typeOS);
|
||||
_addDefinedValueXml(doc, 'OS', typeOs);
|
||||
|
||||
return doc.toString();
|
||||
} else {
|
||||
var jdoc = {};
|
||||
jdoc.Label = imageOptions.Label;
|
||||
jdoc.MediaLink = mediaLink;
|
||||
jdoc.Name = imageName;
|
||||
jdoc.OS = typeOS;
|
||||
var jdoc = {
|
||||
Label: imageOptions.Label,
|
||||
MediaLink: mediaLink,
|
||||
Name: imageName,
|
||||
OS: typeOs
|
||||
};
|
||||
|
||||
return JSON.stringify(jdoc);
|
||||
}
|
||||
|
@ -127,7 +169,7 @@ ServiceManagementSerialize.prototype.buildCreateOSImage = function(typeOS, image
|
|||
|
||||
/**
|
||||
* Create the message body for buildAddDisk
|
||||
* Use the specified serialization - for now only XML
|
||||
* Use the specified serialization - for now only XML.
|
||||
*
|
||||
* @param {string} diskName The name of the disk.
|
||||
* @param {string} mediaLink The mediaLink value.
|
||||
|
@ -138,25 +180,39 @@ ServiceManagementSerialize.prototype.buildAddDisk = function(diskName, mediaLink
|
|||
if (!diskOptions) {
|
||||
diskOptions = {};
|
||||
}
|
||||
|
||||
if (!diskOptions.Label) {
|
||||
diskOptions.Label = diskName;
|
||||
}
|
||||
|
||||
if (client.serializetype === 'XML') {
|
||||
var doc = _createXmlRoot('Disk');
|
||||
|
||||
// add required and optional elements in alpha order
|
||||
_addDefinedValueXml(doc, 'HasOperatingSystem', diskOptions.HasOperatingSystem);
|
||||
_addDefinedValueXml(doc, 'Label', diskOptions.Label);
|
||||
_addDefinedValueXml(doc, 'MediaLink', mediaLink);
|
||||
_addDefinedValueXml(doc, 'Name', diskName);
|
||||
_addDefinedValueXml(doc, 'OS', diskOptions.OS);
|
||||
|
||||
return doc.toString();
|
||||
} else {
|
||||
var jdoc = {};
|
||||
jdoc.Name = diskName;
|
||||
jdoc.MediaLink = mediaLink;
|
||||
if (diskOptions.HasOperatingSystem) jdoc.HasOperatingSystem = diskOptions.HasOperatingSystem;
|
||||
if (diskOptions.Label) jdoc.Label = diskOptions.Label;
|
||||
if (diskOptions.OS) jdoc.OS = diskOptions.OS;
|
||||
var jdoc = {
|
||||
Name: diskName,
|
||||
MediaLink: mediaLink
|
||||
};
|
||||
|
||||
if (diskOptions.HasOperatingSystem) {
|
||||
jdoc.HasOperatingSystem = diskOptions.HasOperatingSystem;
|
||||
}
|
||||
|
||||
if (diskOptions.Label) {
|
||||
jdoc.Label = diskOptions.Label;
|
||||
}
|
||||
|
||||
if (diskOptions.OS) {
|
||||
jdoc.OS = diskOptions.OS;
|
||||
}
|
||||
|
||||
return JSON.stringify(jdoc);
|
||||
}
|
||||
|
@ -164,16 +220,16 @@ ServiceManagementSerialize.prototype.buildAddDisk = function(diskName, mediaLink
|
|||
|
||||
/**
|
||||
* Create the message body for CreateDeployment
|
||||
* Use the specified serialization - for now only XML
|
||||
* Use the specified serialization - for now only XML.
|
||||
*
|
||||
* @param {string} serviceName The name of the service.
|
||||
* @param {string} deploymentName The name of the deployment.
|
||||
* @param {object} VMRole The properties for the new role.
|
||||
* @param {object} vmRole The properties for the new role.
|
||||
* @param {object} deploymentOptions The optional properties for the new deployment.
|
||||
* @param {object} client The servicemanagement object.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype.buildCreateDeployment = function(serviceName, deploymentName,
|
||||
VMRole, deploymentOptions, client) {
|
||||
vmRole, deploymentOptions, client) {
|
||||
if (client.serializetype === 'XML') {
|
||||
var doc = _createXmlRoot('Deployment');
|
||||
_addDefinedValueXml(doc, 'Name', deploymentName);
|
||||
|
@ -183,47 +239,58 @@ ServiceManagementSerialize.prototype.buildCreateDeployment = function(serviceNam
|
|||
|
||||
// must have 1 role
|
||||
var child = doc.ele('RoleList').ele('Role');
|
||||
this._buildPersistentVMRoleXml(VMRole, child);
|
||||
this._buildPersistentVMRoleXml(vmRole, child);
|
||||
|
||||
return doc.toString();
|
||||
} else {
|
||||
var jdoc = {};
|
||||
jdoc.Name = deploymentName;
|
||||
if (deploymentOptions.DeploymentSlot) jdoc.DeploymentSlot = deploymentOptions.DeploymentSlot;
|
||||
if (deploymentOptions.Label) jdoc.Label = new Buffer(deploymentOptions.Label).toString('base64');
|
||||
if (deploymentOptions.UpgradeDomainCount) jdoc.UpgradeDomainCount = deploymentOptions.UpgradeDomainCount;
|
||||
var jdoc = {
|
||||
Name: deploymentName
|
||||
};
|
||||
|
||||
if (deploymentOptions.DeploymentSlot) {
|
||||
jdoc.DeploymentSlot = deploymentOptions.DeploymentSlot;
|
||||
}
|
||||
|
||||
if (deploymentOptions.Label) {
|
||||
jdoc.Label = new Buffer(deploymentOptions.Label).toString('base64');
|
||||
}
|
||||
|
||||
if (deploymentOptions.UpgradeDomainCount) {
|
||||
jdoc.UpgradeDomainCount = deploymentOptions.UpgradeDomainCount;
|
||||
}
|
||||
|
||||
jdoc.RoleList = [];
|
||||
jdoc.RoleList[0] = this._buildPersistentVMRoleJson(VMRole);
|
||||
jdoc.RoleList[0] = this._buildPersistentVMRoleJson(vmRole);
|
||||
|
||||
return JSON.stringify(jdoc);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the message body for AddRole
|
||||
* Use the specified serialization - for now only XML
|
||||
* Use the specified serialization - for now only XML.
|
||||
*
|
||||
* @param {string} serviceName The name of the service.
|
||||
* @param {string} deploymentName The name of the deployment.
|
||||
* @param {object} VMRole The properties for the new role.
|
||||
* @param {object} vmRole The properties for the new role.
|
||||
* @param {object} client The servicemanagement object.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype.buildAddRole = function(serviceName, deploymentName,
|
||||
VMRole, client) {
|
||||
vmRole, client) {
|
||||
if (client.serializetype === 'XML') {
|
||||
var doc = _createXmlRoot('PersistentVMRole');
|
||||
this._buildPersistentVMRoleXml(VMRole, doc);
|
||||
this._buildPersistentVMRoleXml(vmRole, doc);
|
||||
|
||||
return doc.toString();
|
||||
} else {
|
||||
var jdoc = this._buildPersistentVMRoleJson(VMRole);
|
||||
var jdoc = this._buildPersistentVMRoleJson(vmRole);
|
||||
return JSON.stringify(jdoc);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the message body for ModifyRole
|
||||
* Use the specified serialization - for now only XML
|
||||
* Use the specified serialization - for now only XML.
|
||||
*
|
||||
* @param {string} serviceName The name of the service.
|
||||
* @param {string} deploymentName The name of the deployment.
|
||||
|
@ -232,21 +299,21 @@ ServiceManagementSerialize.prototype.buildAddRole = function(serviceName, deploy
|
|||
* @param {object} client The servicemanagement object.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype.buildModifyRole = function(serviceName, deploymentName,
|
||||
roleName, VMRole, client) {
|
||||
roleName, vmRole, client) {
|
||||
if (client.serializetype === 'XML') {
|
||||
var doc = _createXmlRoot('Role');
|
||||
this._buildPersistentVMRoleXml(VMRole, doc);
|
||||
this._buildPersistentVMRoleXml(vmRole, doc);
|
||||
|
||||
return doc.toString();
|
||||
} else {
|
||||
var jdoc = this._buildPersistentVMRoleJson(VMRole);
|
||||
var jdoc = this._buildPersistentVMRoleJson(vmRole);
|
||||
return JSON.stringify(jdoc);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the message body for AddDataDisk
|
||||
* Use the specified serialization - for now only XML
|
||||
* Use the specified serialization - for now only XML.
|
||||
*
|
||||
* @param {string} serviceName The name of the service.
|
||||
* @param {string} deploymentName The name of the deployment.
|
||||
|
@ -269,7 +336,7 @@ ServiceManagementSerialize.prototype.buildAddDataDisk = function(serviceName, de
|
|||
|
||||
/**
|
||||
* Create the message body for ModifyDataDisk
|
||||
* Use the specified serialization - for now only XML
|
||||
* Use the specified serialization - for now only XML.
|
||||
*
|
||||
* @param {string} serviceName The name of the service.
|
||||
* @param {string} deploymentName The name of the deployment.
|
||||
|
@ -279,7 +346,7 @@ ServiceManagementSerialize.prototype.buildAddDataDisk = function(serviceName, de
|
|||
* @param {object} client The servicemanagement object.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype.buildModifyDataDisk = function(serviceName, deploymentName,
|
||||
roleName, Lun, datadisk, client) {
|
||||
roleName, lun, datadisk, client) {
|
||||
if (client.serializetype === 'XML') {
|
||||
var doc = _createXmlRoot('DataVirtualHardDisk');
|
||||
this._buildDataDiskXml(datadisk, doc);
|
||||
|
@ -293,7 +360,7 @@ ServiceManagementSerialize.prototype.buildModifyDataDisk = function(serviceName,
|
|||
|
||||
/**
|
||||
* Create the message body for ShutdownRole
|
||||
* Use the specified serialization - for now only XML
|
||||
* Use the specified serialization - for now only XML.
|
||||
*
|
||||
* @param {string} serviceName The name of the service.
|
||||
* @param {string} deploymentName The name of the deployment.
|
||||
|
@ -316,7 +383,7 @@ ServiceManagementSerialize.prototype.buildShutdownRole = function(serviceName, d
|
|||
|
||||
/**
|
||||
* Create the message body for StartRole
|
||||
* Use the specified serialization - for now only XML
|
||||
* Use the specified serialization - for now only XML.
|
||||
*
|
||||
* @param {string} serviceName The name of the service.
|
||||
* @param {string} deploymentName The name of the deployment.
|
||||
|
@ -373,29 +440,43 @@ ServiceManagementSerialize.prototype.buildRestartRole = function(serviceName, de
|
|||
ServiceManagementSerialize.prototype.buildCaptureRole = function(serviceName, deploymentName,
|
||||
roleName, captureOptions, client) {
|
||||
if (client.serializetype === 'XML') {
|
||||
var inst;
|
||||
|
||||
var doc = _createXmlRoot('CaptureRoleOperation');
|
||||
doc.ele('OperationType').txt('CaptureRoleOperation');
|
||||
_addDefinedValueXml(doc, 'PostCaptureAction', captureOptions.PostCaptureAction);
|
||||
|
||||
if (captureOptions.WindowsProvisioningConfigurationSet) {
|
||||
this._buildWindowsProvisioningConfigurationXml(captureOptions.WindowsProvisioningConfigurationSet, doc);
|
||||
} else if (captureOptions.LinuxProvisioningConfigurationSet) {
|
||||
this._buildLinuxProvisioningConfigurationXml(captureOptions.LinuxProvisioningConfigurationSet, doc);
|
||||
}
|
||||
|
||||
_addDefinedValueXml(doc, 'TargetImageLabel', captureOptions.TargetImageLabel);
|
||||
_addDefinedValueXml(doc, 'TargetImageName', captureOptions.TargetImageName);
|
||||
|
||||
return doc.toString();
|
||||
} else {
|
||||
var jdoc = {};
|
||||
jdoc.OperationType = 'CaptureRoleOperation';
|
||||
if (captureOptions.PostCaptureAction) jdoc.PostCaptureAction = captureOptions.PostCaptureAction;
|
||||
var jdoc = {
|
||||
OperationType: 'CaptureRoleOperation'
|
||||
};
|
||||
|
||||
if (captureOptions.PostCaptureAction) {
|
||||
jdoc.PostCaptureAction = captureOptions.PostCaptureAction;
|
||||
}
|
||||
|
||||
if (captureOptions.WindowsProvisioningConfigurationSet) {
|
||||
jdoc.WindowsProvisioningConfigurationSet = this._buildWindowsProvisioningConfigurationJson(captureOptions.WindowsProvisioningConfigurationSet);
|
||||
} else if (captureOptions.LinuxProvisioningConfigurationSet) {
|
||||
jdoc.LinuxProvisioningConfigurationSet = this._buildLinuxProvisioningConfigurationJson(captureOptions.LinuxProvisioningConfigurationSet);
|
||||
}
|
||||
if (captureOptions.TargetImageLabel) jdoc.TargetImageLabel = captureOptions.TargetImageLabel;
|
||||
if (captureOptions.TargetImageName) jdoc.TargetImageName = captureOptions.TargetImageName;
|
||||
|
||||
if (captureOptions.TargetImageLabel) {
|
||||
jdoc.TargetImageLabel = captureOptions.TargetImageLabel;
|
||||
}
|
||||
|
||||
if (captureOptions.TargetImageName) {
|
||||
jdoc.TargetImageName = captureOptions.TargetImageName;
|
||||
}
|
||||
|
||||
return JSON.stringify(jdoc);
|
||||
}
|
||||
|
@ -411,19 +492,23 @@ ServiceManagementSerialize.prototype.buildCaptureRole = function(serviceName, de
|
|||
*/
|
||||
ServiceManagementSerialize.prototype.buildAddCertificate = function(serviceName, data, format, password, client) {
|
||||
var encData = new Buffer(data).toString('base64');
|
||||
|
||||
if (client.serializetype === 'XML') {
|
||||
var doc = _createXmlRoot('CertificateFile');
|
||||
_addDefinedValueXml(doc, 'Data', encData);
|
||||
_addDefinedValueXml(doc, 'CertificateFormat', format);
|
||||
|
||||
if (password) {
|
||||
_addDefinedValueXml(doc, 'Password', password);
|
||||
}
|
||||
|
||||
return doc.toString();
|
||||
} else {
|
||||
var jdoc = {};
|
||||
jdoc.Data = encData;
|
||||
jdoc.CertificateFormat = format;
|
||||
var jdoc = {
|
||||
Data: encData,
|
||||
CertificateFormat: format
|
||||
};
|
||||
|
||||
if (password) {
|
||||
jdoc.Password = password;
|
||||
}
|
||||
|
@ -440,113 +525,124 @@ ServiceManagementSerialize.prototype.buildAddCertificate = function(serviceName,
|
|||
* Add a VM Role node tree to the specifed node
|
||||
* returns xmlbuilder node object
|
||||
*
|
||||
* @param {object} VMRole The Role object properties.
|
||||
* @param {object} vmRole The Role object properties.
|
||||
* @param {object} node The XML parent node.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype._buildPersistentVMRoleXml = function(VMRole, node) {
|
||||
ServiceManagementSerialize.prototype._buildPersistentVMRoleXml = function(vmRole, node) {
|
||||
var child;
|
||||
var cfgsets;
|
||||
var inst;
|
||||
var alen;
|
||||
var i;
|
||||
_addDefinedValueXml(node, 'RoleName', VMRole.RoleName);
|
||||
_addDefinedValueXml(node, 'RoleType', VMRole.RoleType);
|
||||
if (VMRole.ConfigurationSets) {
|
||||
|
||||
_addDefinedValueXml(node, 'RoleName', vmRole.RoleName);
|
||||
_addDefinedValueXml(node, 'RoleType', vmRole.RoleType);
|
||||
|
||||
if (vmRole.ConfigurationSets) {
|
||||
cfgsets = node.ele('ConfigurationSets');
|
||||
for (i = 0; i < VMRole.ConfigurationSets.length; i++) {
|
||||
if (VMRole.ConfigurationSets[i].ConfigurationSetType === 'WindowsProvisioningConfigurationSet') {
|
||||
this._buildWindowsProvisioningConfigurationXml(VMRole.ConfigurationSets[i], cfgsets);
|
||||
|
||||
for (i = 0; i < vmRole.ConfigurationSets.length; i++) {
|
||||
if (vmRole.ConfigurationSets[i].ConfigurationSetType === 'WindowsProvisioningConfigurationSet') {
|
||||
this._buildWindowsProvisioningConfigurationXml(vmRole.ConfigurationSets[i], cfgsets);
|
||||
}
|
||||
if (VMRole.ConfigurationSets[i].ConfigurationSetType === 'LinuxProvisioningConfigurationSet') {
|
||||
this._buildLinuxProvisioningConfigurationXml(VMRole.ConfigurationSets[i], cfgsets);
|
||||
|
||||
if (vmRole.ConfigurationSets[i].ConfigurationSetType === 'LinuxProvisioningConfigurationSet') {
|
||||
this._buildLinuxProvisioningConfigurationXml(vmRole.ConfigurationSets[i], cfgsets);
|
||||
}
|
||||
if (VMRole.ConfigurationSets[i].ConfigurationSetType === 'NetworkConfigurationSet') {
|
||||
this._buildNetworkConfigurationXml(VMRole.ConfigurationSets[i], cfgsets);
|
||||
|
||||
if (vmRole.ConfigurationSets[i].ConfigurationSetType === 'NetworkConfigurationSet') {
|
||||
this._buildNetworkConfigurationXml(vmRole.ConfigurationSets[i], cfgsets);
|
||||
}
|
||||
}
|
||||
}
|
||||
_addDefinedValueXml(node, 'AvailabilitySetName', VMRole.AvailabilitySetName);
|
||||
if (VMRole.DataVirtualHardDisks) {
|
||||
|
||||
_addDefinedValueXml(node, 'AvailabilitySetName', vmRole.AvailabilitySetName);
|
||||
|
||||
if (vmRole.DataVirtualHardDisks) {
|
||||
child = node.ele('DataVirtualHardDisks');
|
||||
alen = VMRole.DataVirtualHardDisks.length;
|
||||
alen = vmRole.DataVirtualHardDisks.length;
|
||||
|
||||
for (i = 0; i < alen; i++) {
|
||||
inst = child.ele('DataVirtualHardDisk');
|
||||
this._buildDataDiskXml(VMRole.DataVirtualHardDisks[i], inst);
|
||||
this._buildDataDiskXml(vmRole.DataVirtualHardDisks[i], inst);
|
||||
}
|
||||
}
|
||||
if (VMRole.OSVirtualHardDisk) {
|
||||
|
||||
if (vmRole.OSVirtualHardDisk) {
|
||||
child = node.ele('OSVirtualHardDisk');
|
||||
this._buildOSDiskXml(VMRole.OSVirtualHardDisk, child);
|
||||
this._buildOSDiskXml(vmRole.OSVirtualHardDisk, child);
|
||||
}
|
||||
_addDefinedValueXml(node, 'RoleSize', VMRole.RoleSize);
|
||||
|
||||
_addDefinedValueXml(node, 'RoleSize', vmRole.RoleSize);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a VM Role object from input.
|
||||
* May return same object or a modified object
|
||||
* May return same object or a modified object.
|
||||
*
|
||||
* @param {object} VMRole The Role object properties.
|
||||
* @param {object} vmRole The Role object properties.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype._buildPersistentVMRoleJson = function(VMRole) {
|
||||
return VMRole;
|
||||
ServiceManagementSerialize.prototype._buildPersistentVMRoleJson = function(vmRole) {
|
||||
return vmRole;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add OSDisk properties to the specifed node
|
||||
* returns xmlbuilder node object
|
||||
* Add OSDisk properties to the specifed node.
|
||||
* returns xmlbuilder node object.
|
||||
*
|
||||
* @param {object} OSDisk The OSDisk object properties.
|
||||
* @param {object} osDisk The OSDisk object properties.
|
||||
* @param {object} node The XML parent node.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype._buildOSDiskXml = function(OSDisk, node) {
|
||||
_addDefinedValueXml(node, 'HostCaching', OSDisk.HostCaching);
|
||||
_addDefinedValueXml(node, 'DiskLabel', OSDisk.DiskLabel);
|
||||
_addDefinedValueXml(node, 'DiskName', OSDisk.DiskName);
|
||||
_addDefinedValueXml(node, 'MediaLink', OSDisk.MediaLink);
|
||||
_addDefinedValueXml(node, 'SourceImageName', OSDisk.SourceImageName);
|
||||
ServiceManagementSerialize.prototype._buildOSDiskXml = function(osDisk, node) {
|
||||
_addDefinedValueXml(node, 'HostCaching', osDisk.HostCaching);
|
||||
_addDefinedValueXml(node, 'DiskLabel', osDisk.DiskLabel);
|
||||
_addDefinedValueXml(node, 'DiskName', osDisk.DiskName);
|
||||
_addDefinedValueXml(node, 'MediaLink', osDisk.MediaLink);
|
||||
_addDefinedValueXml(node, 'SourceImageName', osDisk.SourceImageName);
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get OSDisk object from input
|
||||
* May return same object or a modified object
|
||||
* Get OSDisk object from input.
|
||||
* May return same object or a modified object.
|
||||
*
|
||||
* @param {object} OSDisk The OSDisk object properties.
|
||||
* @param {object} osDisk The OSDisk object properties.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype._buildOSDiskJson = function(OSDisk) {
|
||||
return OSDisk;
|
||||
ServiceManagementSerialize.prototype._buildOSDiskJson = function(osDisk) {
|
||||
return osDisk;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add DataDisk properties to the specifed node
|
||||
* returns xmlbuilder node object
|
||||
*
|
||||
* @param {object} DataDisk The DataDisk object properties.
|
||||
* @param {object} dataDisk The DataDisk object properties.
|
||||
* @param {object} node The XML parent node.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype._buildDataDiskXml = function(DataDisk, node) {
|
||||
_addDefinedValueXml(node, 'HostCaching', DataDisk.HostCaching);
|
||||
_addDefinedValueXml(node, 'DiskLabel', DataDisk.DiskLabel);
|
||||
_addDefinedValueXml(node, 'DiskName', DataDisk.DiskName);
|
||||
_addDefinedNumericXml(node, 'Lun', DataDisk.Lun);
|
||||
_addDefinedValueXml(node, 'LogicalDiskSizeInGB', DataDisk.LogicalDiskSizeInGB);
|
||||
_addDefinedValueXml(node, 'MediaLink', DataDisk.MediaLink);
|
||||
_addDefinedValueXml(node, 'SourceMediaLink', DataDisk.SourceMediaLink);
|
||||
ServiceManagementSerialize.prototype._buildDataDiskXml = function(dataDisk, node) {
|
||||
_addDefinedValueXml(node, 'HostCaching', dataDisk.HostCaching);
|
||||
_addDefinedValueXml(node, 'DiskLabel', dataDisk.DiskLabel);
|
||||
_addDefinedValueXml(node, 'DiskName', dataDisk.DiskName);
|
||||
_addDefinedNumericXml(node, 'Lun', dataDisk.Lun);
|
||||
_addDefinedValueXml(node, 'LogicalDiskSizeInGB', dataDisk.LogicalDiskSizeInGB);
|
||||
_addDefinedValueXml(node, 'MediaLink', dataDisk.MediaLink);
|
||||
_addDefinedValueXml(node, 'SourceMediaLink', dataDisk.SourceMediaLink);
|
||||
return node;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get DataDisk object from input
|
||||
* May return same object or a modified object
|
||||
* Get DataDisk object from input.
|
||||
* May return same object or a modified object.
|
||||
*
|
||||
* @param {object} DataDisk The DataDisk object properties.
|
||||
* @param {object} dataDisk The DataDisk object properties.
|
||||
*/
|
||||
ServiceManagementSerialize.prototype._buildDataDiskJson = function(DataDisk) {
|
||||
return DataDisk;
|
||||
ServiceManagementSerialize.prototype._buildDataDiskJson = function(dataDisk) {
|
||||
return dataDisk;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add WindowsProvisioningConfiguration properties to the specifed node
|
||||
* Add WindowsProvisioningConfiguration properties to the specifed node.
|
||||
* returns xmlbuilder node object
|
||||
*
|
||||
* @param {object} cfgset The WindowsProvisioningConfiguration object properties.
|
||||
|
@ -560,17 +656,21 @@ ServiceManagementSerialize.prototype._buildWindowsProvisioningConfigurationXml =
|
|||
_addDefinedValueXml(child, 'ResetPasswordOnFirstLogon', cfgset.ResetPasswordOnFirstLogon);
|
||||
_addDefinedValueXml(child, 'EnableAutomaticUpdate', cfgset.EnableAutomaticUpdate);
|
||||
_addDefinedValueXml(child, 'TimeZone', cfgset.TimeZone);
|
||||
|
||||
if (cfgset.DomainJoin) {
|
||||
var domj = child.ele('DomainJoin');
|
||||
|
||||
if (cfgset.DomainJoin.Credentials) {
|
||||
var cred = domj.ele('Credentials');
|
||||
_addDefinedValueXml(cred, 'Domain', cfgset.DomainJoin.Credentials.Domain);
|
||||
_addDefinedValueXml(cred, 'Username', cfgset.DomainJoin.Credentials.Username);
|
||||
_addDefinedValueXml(cred, 'Password', cfgset.DomainJoin.Credentials.Password);
|
||||
}
|
||||
|
||||
_addDefinedValueXml(domj, 'JoinDomain', cfgset.DomainJoin.JoinDomain);
|
||||
_addDefinedValueXml(domj, 'MachineObjectOU', cfgset.DomainJoin.MachineObjectOU);
|
||||
}
|
||||
|
||||
if (cfgset.StoredCertificateSettings) {
|
||||
var cset = child.ele('StoredCertificateSettings');
|
||||
_addDefinedValueXml(cset, 'StoreLocation', cfgset.StoredCertificateSettings.StoreLocation);
|
||||
|
@ -580,8 +680,8 @@ ServiceManagementSerialize.prototype._buildWindowsProvisioningConfigurationXml =
|
|||
};
|
||||
|
||||
/**
|
||||
* Get WindowsProvisioningConfiguration object from input
|
||||
* May return same object or a modified object
|
||||
* Get WindowsProvisioningConfiguration object from input.
|
||||
* May return same object or a modified object.
|
||||
*
|
||||
* @param {object} cfgset The WindowsProvisioningConfiguration object properties.
|
||||
*/
|
||||
|
@ -590,7 +690,7 @@ ServiceManagementSerialize.prototype._buildWindowsProvisioningConfigurationJson
|
|||
};
|
||||
|
||||
/**
|
||||
* Add LinuxProvisioningConfiguration properties to the specifed node
|
||||
* Add LinuxProvisioningConfiguration properties to the specifed node.
|
||||
* returns xmlbuilder node object
|
||||
*
|
||||
* @param {object} cfgset The LinuxProvisioningConfiguration object properties.
|
||||
|
@ -605,20 +705,24 @@ ServiceManagementSerialize.prototype._buildLinuxProvisioningConfigurationXml = f
|
|||
_addDefinedValueXml(child, 'UserName', cfgset.UserName);
|
||||
_addDefinedValueXml(child, 'UserPassword', cfgset.UserPassword);
|
||||
_addDefinedValueXml(child, 'DisableSshPasswordAuthentication', cfgset.DisableSshPasswordAuthentication);
|
||||
|
||||
if (cfgset.SSH) {
|
||||
var ssh = child.ele('SSH');
|
||||
if (cfgset.SSH.PublicKeys) {
|
||||
var pubks = ssh.ele('PublicKeys');
|
||||
alen = cfgset.SSH.PublicKeys.length;
|
||||
|
||||
for (i = 0; i < alen; i++) {
|
||||
var pubk = pubks.ele('PublicKey');
|
||||
_addDefinedValueXml(pubk, 'FingerPrint', cfgset.SSH.PublicKeys[i].FingerPrint);
|
||||
_addDefinedValueXml(pubk, 'Path', cfgset.SSH.PublicKeys[i].Path);
|
||||
}
|
||||
}
|
||||
|
||||
if (cfgset.SSH.KeyPairs) {
|
||||
var keypairs = ssh.ele('KeyPairs');
|
||||
alen = cfgset.SSH.KeyPairs.length;
|
||||
|
||||
for (i = 0; i < alen; i++) {
|
||||
var keyp = keypairs.ele('KeyPair');
|
||||
_addDefinedValueXml(keyp, 'FingerPrint', cfgset.SSH.KeyPairs[i].FingerPrint);
|
||||
|
@ -648,14 +752,17 @@ ServiceManagementSerialize.prototype._buildLinuxProvisioningConfigurationJson =
|
|||
ServiceManagementSerialize.prototype._buildNetworkConfigurationXml = function(cfgset, node) {
|
||||
var child = node.ele('ConfigurationSet');
|
||||
child.ele('ConfigurationSetType').txt('NetworkingConfiguration');
|
||||
|
||||
if (cfgset.InputEndpoints) {
|
||||
var ends = child.ele('InputEndpoints');
|
||||
this._buildInputEndpointsXml(cfgset, ends);
|
||||
}
|
||||
|
||||
if (cfgset.SubnetNames) {
|
||||
var subs = node.ele('SubnetNames');
|
||||
var alen = cfgset.SubnetNames.length;
|
||||
for (i = 0; i < alen; i++) {
|
||||
|
||||
for (var i = 0; i < alen; i++) {
|
||||
_addDefinedValueXml(subs, 'string', cfgset.SubnetNames[i].string);
|
||||
}
|
||||
}
|
||||
|
@ -680,6 +787,7 @@ ServiceManagementSerialize.prototype._buildNetworkConfigurationJson = function(c
|
|||
*/
|
||||
ServiceManagementSerialize.prototype._buildInputEndpointsXml = function(cfgset, node) {
|
||||
var alen = cfgset.InputEndpoints.length;
|
||||
|
||||
for (var i = 0; i < alen; i++) {
|
||||
var endp = cfgset.InputEndpoints[i];
|
||||
var child = node.ele('InputEndpoint');
|
||||
|
@ -688,6 +796,7 @@ ServiceManagementSerialize.prototype._buildInputEndpointsXml = function(cfgset,
|
|||
_addDefinedValueXml(child, 'LocalPort', endp.LocalPort);
|
||||
_addDefinedValueXml(child, 'Name', endp.Name);
|
||||
_addDefinedValueXml(child, 'Port', endp.Port);
|
||||
|
||||
if (endp.LoadBalancerProbe) {
|
||||
var probe = child.ele('LoadBalancerProbe');
|
||||
_addDefinedValueXml(probe, 'Path', endp.LoadBalancerProbe.Path);
|
||||
|
@ -730,7 +839,9 @@ function _createXmlRoot(rootName) {
|
|||
* @param {string} value The value for the new node.
|
||||
*/
|
||||
function _addDefinedValueXml(node, elename, value) {
|
||||
if (value) node.ele(elename).txt(value);
|
||||
if (value) {
|
||||
node.ele(elename).txt(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -742,7 +853,7 @@ function _addDefinedValueXml(node, elename, value) {
|
|||
* @param {string} value The value for the new node.
|
||||
*/
|
||||
function _addDefinedNumericXml(node, elename, value) {
|
||||
if (typeof value === 'number') node.ele(elename).txt(value);
|
||||
}
|
||||
|
||||
|
||||
if (typeof value === 'number') {
|
||||
node.ele(elename).txt(value);
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче