To use this function add it to the class library file named PluginVRAService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: PluginVRAService.ts
Description: Orchestrator Function to Build a Machine Specification
Public Function: VraMachineSpecificationBuild
publicVraMachineSpecificationBuild(objVraProject:VraProject,intMachineCount:number,strName:string,strDescription:string,strFlavor:string,strImage:string,strFlavorRef:string,strImageRef:string,arrTag:string[],arrConstraint:string[],objPropertiesCustom:Properties,strMachineBootConfig:string,strAuthentication:"usernamePassword"|"publicPrivateKey"|"generatedPublicPrivateKey"|"keyPairName",strUsername:string,strPassword:string,strSSHKey:string,strKeyPair:string,blnPhoneHomeShouldWait:boolean=false,blnPhoneHomeFailOnTimeout:boolean=false,intPhoneHomeTimeoutSeconds:number=600):VraMachineSpecification{
letobjVraMachineSpecification:VraMachineSpecification=newVraMachineSpecification();
objVraMachineSpecification.name=strName;
objVraMachineSpecification.description=strDescription;
objVraMachineSpecification.machineCount=intMachineCount;
objVraMachineSpecification.flavor=strFlavor;
objVraMachineSpecification.image=strImage;
objVraMachineSpecification.flavorRef=strFlavorRef;
objVraMachineSpecification.imageRef=strImageRef;
objVraMachineSpecification.projectId=objVraProject.id;
objPropertiesCustom.keys.forEach((strKey:string):void=>{
objVraMachineSpecification.putCustomPropertiesItem(strKey,objPropertiesCustom.get(strKey));
});
arrConstraint.forEach((strConstraint:string):void=>{
letobjVraConstraint:VraConstraint=newVraConstraint();
objVraConstraint.expression=strConstraint;
objVraConstraint.mandatory=true;
objVraMachineSpecification.addConstraintsItem(objVraConstraint);
});
letarrPropertiesTag:Properties[]=this.convertToTagPropertiesArray(arrTag);
arrPropertiesTag.forEach((objPropertiesTag:Properties):void=>{
letobjVraTag:VraTag=newVraTag();
objVraTag.key=objPropertiesTag.key;
objVraTag.value=objPropertiesTag.value;
objVraMachineSpecification.addTagsItem(objVraTag);
});
if (strMachineBootConfig&&strMachineBootConfig!==null&&strMachineBootConfig!==undefined&&strMachineBootConfig!==""){
letobjVraMachineBootConfig:VraMachineBootConfig=newVraMachineBootConfig();
objVraMachineBootConfig.content=strMachineBootConfig;
objVraMachineSpecification.bootConfig=objVraMachineBootConfig;
}
letobjVraMachineBootConfigSettings:VraMachineBootConfigSettings=newVraMachineBootConfigSettings();
if (blnPhoneHomeShouldWait&&blnPhoneHomeShouldWait!==null&&blnPhoneHomeShouldWait!==undefined){
objVraMachineBootConfigSettings.phoneHomeShouldWait=blnPhoneHomeShouldWait;
}
if (blnPhoneHomeFailOnTimeout&&blnPhoneHomeFailOnTimeout!==null&&blnPhoneHomeFailOnTimeout!==undefined){
objVraMachineBootConfigSettings.phoneHomeFailOnTimeout=blnPhoneHomeFailOnTimeout;
}
if (intPhoneHomeTimeoutSeconds&&intPhoneHomeTimeoutSeconds!==null&&intPhoneHomeTimeoutSeconds!==undefined&&intPhoneHomeTimeoutSeconds>0){
objVraMachineBootConfigSettings.phoneHomeTimeoutSeconds=intPhoneHomeTimeoutSeconds;
}
objVraMachineSpecification.bootConfigSettings=objVraMachineBootConfigSettings;
letobjVraRemoteAccessSpecification:VraRemoteAccessSpecification=newVraRemoteAccessSpecification();
if (strAuthentication&&strAuthentication!==null&&strAuthentication!==undefined&&strAuthentication!==""){
objVraRemoteAccessSpecification.authentication=strAuthentication;
if (strAuthentication==="usernamePassword"){
objVraRemoteAccessSpecification.username=strUsername;
objVraRemoteAccessSpecification.password=strPassword;
}
elseif (strAuthentication==="publicPrivateKey"){
objVraRemoteAccessSpecification.username=strUsername;
objVraRemoteAccessSpecification.sshKey=strSSHKey;
}
elseif (strAuthentication==="generatedPublicPrivateKey"){
objVraRemoteAccessSpecification.username=strUsername;
}
elseif (strAuthentication==="keyPairName"){
objVraRemoteAccessSpecification.keyPair=strKeyPair;
}
}
objVraMachineSpecification.remoteAccess=objVraRemoteAccessSpecification;
letarrDisk:{
name:string,
description:string,
unitNumber:string,
blockDevice:VraBlockDevice,
scsiController:string,
diskAttachmentProperties:Properties
}[]= [];
arrDisk.forEach((objDisk)=>{
letobjVraDiskAttachmentSpecification:VraDiskAttachmentSpecification=newVraDiskAttachmentSpecification();
objVraDiskAttachmentSpecification.name=objDisk.name;
objVraDiskAttachmentSpecification.description=objDisk.description;
objVraDiskAttachmentSpecification.unitNumber=objDisk.unitNumber;
objVraDiskAttachmentSpecification.blockDeviceId=objDisk.blockDevice.id;
objVraDiskAttachmentSpecification.scsiController=objDisk.scsiController;
objDisk.diskAttachmentProperties.keys.forEach((strKey:string):void=>{
objVraDiskAttachmentSpecification.putDiskAttachmentPropertiesItem(strKey,objDisk.diskAttachmentProperties.get(strKey));
});
objVraMachineSpecification.addDisksItem(objVraDiskAttachmentSpecification);
});
letarrNetworkAdapter:{
name:string,
description:string,
fabricNetwork:VraFabricNetwork,
networkId:string,
deviceIndex:number,
addresses:string[],
macAddress:string,
securityGroupIds:string[],
customProperties:Properties
}[]= [];
arrNetworkAdapter.forEach((objNetworkAdapter):void=>{
letobjVraNetworkInterfaceSpecification:VraNetworkInterfaceSpecification=newVraNetworkInterfaceSpecification();
objVraNetworkInterfaceSpecification.name=objNetworkAdapter.name;
objVraNetworkInterfaceSpecification.description=objNetworkAdapter.description;
objVraNetworkInterfaceSpecification.networkId=objNetworkAdapter.networkId;
objVraNetworkInterfaceSpecification.deviceIndex=objNetworkAdapter.deviceIndex;
objVraNetworkInterfaceSpecification.macAddress=objNetworkAdapter.macAddress;
objNetworkAdapter.customProperties.keys.forEach((strKey:string):void=>{
objVraNetworkInterfaceSpecification.putCustomPropertiesItem(strKey,objNetworkAdapter.customProperties.get(strKey));
});
if (objNetworkAdapter.fabricNetwork){
letfabricNetworkId=objNetworkAdapter.fabricNetwork.id;
objVraNetworkInterfaceSpecification.fabricNetworkId=fabricNetworkId;
}
objNetworkAdapter.addresses.forEach((strAddress:string):void=>{
objVraNetworkInterfaceSpecification.addAddressesItem(strAddress);
});
objNetworkAdapter.securityGroupIds.forEach((strSecurityGroupId:string):void=>{
objVraNetworkInterfaceSpecification.addSecurityGroupIdsItem(strSecurityGroupId);
});
objVraMachineSpecification.addNicsItem(objVraNetworkInterfaceSpecification);
});
returnobjVraMachineSpecification;
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
