Remove ReferencedDisks;Add missing resourceType=17 XML items
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5cf101d641
commit
0fc1cb12c7
@ -49,42 +49,12 @@ $XML = [xml](Get-Content @GetContentSplat)
|
||||
$NS = [System.Xml.XmlNamespaceManager]$XML.NameTable
|
||||
[void]$NS.AddNamespace('ns', $XML.DocumentElement.xmlns)
|
||||
[void]$NS.AddNamespace('ovf', $XML.DocumentElement.ovf)
|
||||
[void]$NS.AddNamespace('rasd', $XML.DocumentElement.rasd)
|
||||
|
||||
ForEach ($ReferencedDisk in $OVFConfig.Disks.Referenced) {
|
||||
$XMLDisk = $XML.SelectSingleNode("//ns:DiskSection/ns:Disk[@ovf:diskId='$($ReferencedDisk.Id)']", $NS)
|
||||
If ($XMLDisk.Count -eq 1) {
|
||||
$FactorMap = @{
|
||||
'KB' = [Math]::Pow(2,10)
|
||||
'MB' = [Math]::Pow(2,20)
|
||||
'GB' = [Math]::Pow(2,30)
|
||||
'TB' = [Math]::Pow(2,40)
|
||||
'PB' = [Math]::Pow(2,50)
|
||||
}
|
||||
# Create copy of default resourceType=17 (=Harddisk) node
|
||||
$XMLDiskTemplate = $XML.SelectSingleNode("//ns:VirtualHardwareSection/ns:Item/rasd:ResourceType[.='17']", $NS).ParentNode.CloneNode($True)
|
||||
|
||||
If (($FactorMap.Keys -contains $ReferencedDisk.UnitSize)) {
|
||||
# Convert new capacity to same scale as existing capacity
|
||||
If ($XMLDisk.capacityAllocationUnits -match 'byte \* 2\^(\d+)') {
|
||||
$NewSize = [Math]::Truncate($ReferencedDisk.Capacity * $FactorMap[$ReferencedDisk.UnitSize] / [Math]::Pow(2,$Matches[1]))
|
||||
}
|
||||
ElseIf ($XMLDisk.capacityAllocationUnits -eq 'byte') {
|
||||
$NewSize = $ReferencedDisk.Capacity * $FactorMap[$ReferencedDisk.UnitSize]
|
||||
}
|
||||
Else {
|
||||
Throw "Unexpected value '$($XMLDisk.capacityAllocationUnits)' for property 'capacityAllocationUnits'; aborting."
|
||||
}
|
||||
# Determine if specified capacity is equal or larger than current & allocated capacity
|
||||
If ($XMLDisk.populatedSize -le $NewSize -and $XMLDisk.capacity -le $NewSize) {
|
||||
[void]$XMLDisk.SetAttribute('ovf:capacity', $NewSize)
|
||||
Write-Host "Updated 'Disk' with new property value"
|
||||
}
|
||||
}
|
||||
Else {
|
||||
# Invalid UnitSize; skipping modification of existing disk
|
||||
Continue
|
||||
}
|
||||
}
|
||||
}
|
||||
ForEach ($DynamicDisk in $OVFConfig.Disks.Dynamic) {
|
||||
ForEach ($Disk in $OVFConfig.DynamicDisks) {
|
||||
# Determine next free available diskId
|
||||
$XMLDisks = $XML.SelectNodes("//ns:DiskSection/ns:Disk[contains(@ovf:diskId,'vmdisk')]", $NS)
|
||||
$DiskId = $XMLDisks.Count + 1
|
||||
@ -94,7 +64,7 @@ ForEach ($DynamicDisk in $OVFConfig.Disks.Dynamic) {
|
||||
|
||||
$XMLDisk = $XML.CreateElement('Disk', $XML.DocumentElement.xmlns)
|
||||
$XMLDiskAttrUnits = $XML.CreateAttribute('capacityAllocationUnits', $XML.DocumentElement.ovf)
|
||||
Switch ($DynamicDisk.UnitSize) {
|
||||
Switch ($Disk.UnitSize) {
|
||||
'KB' {
|
||||
$Powers = 10
|
||||
}
|
||||
@ -133,22 +103,36 @@ ForEach ($DynamicDisk in $OVFConfig.Disks.Dynamic) {
|
||||
|
||||
[void]$XML.SelectSingleNode('//ns:DiskSection', $NS).AppendChild($XMLDisk)
|
||||
|
||||
# Add new resourceType nodes
|
||||
$XMLDiskItem = $XMLDiskTemplate.CloneNode($True)
|
||||
$XMLDiskItem.SelectSingleNode('rasd:AddressOnParent', $NS).InnerText = ($DiskId - 1)
|
||||
$XMLDiskItem.SelectSingleNode('rasd:ElementName', $NS).InnerText = "Hard Disk $($DiskId)"
|
||||
$XMLDiskItem.SelectSingleNode('rasd:HostResource', $NS).InnerText = "ovf:/disk/vmdisk$($DiskId)"
|
||||
# Determine next free available InstanceID
|
||||
$InstanceIDs = $XML.SelectNodes('//ns:VirtualHardwareSection/ns:Item/rasd:InstanceID', $NS)
|
||||
$InstanceID = 1
|
||||
While ($InstanceIDs.InnerText -contains $InstanceID) {
|
||||
$InstanceID++
|
||||
}
|
||||
$XMLDiskItem.SelectSingleNode('rasd:InstanceID', $NS).InnerText = $InstanceID
|
||||
$XML.SelectSingleNode('//ns:VirtualHardwareSection', $NS).AppendChild($XMLDiskItem)
|
||||
|
||||
$OVFConfig.PropertyCategories[0].ProductProperties += @{
|
||||
Key = "vmconfig.disksize.$($DiskId)"
|
||||
Type = If ([boolean]$DynamicDisk.Constraints.Minimum -or [boolean]$DynamicDisk.Constraints.Maximum) {
|
||||
"Int($($DynamicDisk.Constraints.Minimum)..$($DynamicDisk.Constraints.Maximum))"
|
||||
Type = If ([boolean]$Disk.Constraints.Minimum -or [boolean]$Disk.Constraints.Maximum) {
|
||||
"Int($($Disk.Constraints.Minimum)..$($Disk.Constraints.Maximum))"
|
||||
}
|
||||
Else {
|
||||
'Int'
|
||||
}
|
||||
Label = "Disk $($DiskId) size*"
|
||||
Description = "$($DynamicDisk.Description) (in $($DynamicDisk.UnitSize))".Trim()
|
||||
DefaultValue = "$($DynamicDisk.Constraints.Minimum)"
|
||||
Description = "$($Disk.Description) (in $($Disk.UnitSize))".Trim()
|
||||
DefaultValue = "$($Disk.Constraints.Minimum)"
|
||||
Configurations = '*'
|
||||
UserConfigurable = 'true'
|
||||
}
|
||||
}
|
||||
Write-Host "Inserted $($OVFConfig.Disks.Dynamic.Count) new nodes into 'DiskSection'"
|
||||
Write-Host "Inserted $($OVFConfig.DynamicDisks.Count) new node(s) into 'DiskSection' and 'VirtualHardwareSection' respectively"
|
||||
|
||||
If ($OVFConfig.DeploymentConfigurations.Count -gt 0) {
|
||||
$XMLSection = $XML.CreateElement('DeploymentOptionSection', $XML.DocumentElement.xmlns)
|
||||
|
@ -23,18 +23,13 @@ DeploymentConfigurations:
|
||||
Size:
|
||||
CPU: 4
|
||||
Memory: 8192
|
||||
Disks:
|
||||
Referenced:
|
||||
- Id: vmdisk1
|
||||
UnitSize: GB
|
||||
Capacity: 50
|
||||
Dynamic:
|
||||
- Description: Data
|
||||
DynamicDisks:
|
||||
- Description: Data
|
||||
UnitSize: GB
|
||||
Constraints:
|
||||
Minimum: 10
|
||||
Maximum: 500
|
||||
- Description: Scratch
|
||||
- Description: Scratch
|
||||
UnitSize: GB
|
||||
Constraints:
|
||||
Minimum: 5
|
||||
|
Loading…
Reference in New Issue
Block a user