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
|
$NS = [System.Xml.XmlNamespaceManager]$XML.NameTable
|
||||||
[void]$NS.AddNamespace('ns', $XML.DocumentElement.xmlns)
|
[void]$NS.AddNamespace('ns', $XML.DocumentElement.xmlns)
|
||||||
[void]$NS.AddNamespace('ovf', $XML.DocumentElement.ovf)
|
[void]$NS.AddNamespace('ovf', $XML.DocumentElement.ovf)
|
||||||
|
[void]$NS.AddNamespace('rasd', $XML.DocumentElement.rasd)
|
||||||
|
|
||||||
ForEach ($ReferencedDisk in $OVFConfig.Disks.Referenced) {
|
# Create copy of default resourceType=17 (=Harddisk) node
|
||||||
$XMLDisk = $XML.SelectSingleNode("//ns:DiskSection/ns:Disk[@ovf:diskId='$($ReferencedDisk.Id)']", $NS)
|
$XMLDiskTemplate = $XML.SelectSingleNode("//ns:VirtualHardwareSection/ns:Item/rasd:ResourceType[.='17']", $NS).ParentNode.CloneNode($True)
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
If (($FactorMap.Keys -contains $ReferencedDisk.UnitSize)) {
|
ForEach ($Disk in $OVFConfig.DynamicDisks) {
|
||||||
# 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) {
|
|
||||||
# Determine next free available diskId
|
# Determine next free available diskId
|
||||||
$XMLDisks = $XML.SelectNodes("//ns:DiskSection/ns:Disk[contains(@ovf:diskId,'vmdisk')]", $NS)
|
$XMLDisks = $XML.SelectNodes("//ns:DiskSection/ns:Disk[contains(@ovf:diskId,'vmdisk')]", $NS)
|
||||||
$DiskId = $XMLDisks.Count + 1
|
$DiskId = $XMLDisks.Count + 1
|
||||||
@ -94,7 +64,7 @@ ForEach ($DynamicDisk in $OVFConfig.Disks.Dynamic) {
|
|||||||
|
|
||||||
$XMLDisk = $XML.CreateElement('Disk', $XML.DocumentElement.xmlns)
|
$XMLDisk = $XML.CreateElement('Disk', $XML.DocumentElement.xmlns)
|
||||||
$XMLDiskAttrUnits = $XML.CreateAttribute('capacityAllocationUnits', $XML.DocumentElement.ovf)
|
$XMLDiskAttrUnits = $XML.CreateAttribute('capacityAllocationUnits', $XML.DocumentElement.ovf)
|
||||||
Switch ($DynamicDisk.UnitSize) {
|
Switch ($Disk.UnitSize) {
|
||||||
'KB' {
|
'KB' {
|
||||||
$Powers = 10
|
$Powers = 10
|
||||||
}
|
}
|
||||||
@ -133,22 +103,36 @@ ForEach ($DynamicDisk in $OVFConfig.Disks.Dynamic) {
|
|||||||
|
|
||||||
[void]$XML.SelectSingleNode('//ns:DiskSection', $NS).AppendChild($XMLDisk)
|
[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 += @{
|
$OVFConfig.PropertyCategories[0].ProductProperties += @{
|
||||||
Key = "vmconfig.disksize.$($DiskId)"
|
Key = "vmconfig.disksize.$($DiskId)"
|
||||||
Type = If ([boolean]$DynamicDisk.Constraints.Minimum -or [boolean]$DynamicDisk.Constraints.Maximum) {
|
Type = If ([boolean]$Disk.Constraints.Minimum -or [boolean]$Disk.Constraints.Maximum) {
|
||||||
"Int($($DynamicDisk.Constraints.Minimum)..$($DynamicDisk.Constraints.Maximum))"
|
"Int($($Disk.Constraints.Minimum)..$($Disk.Constraints.Maximum))"
|
||||||
}
|
}
|
||||||
Else {
|
Else {
|
||||||
'Int'
|
'Int'
|
||||||
}
|
}
|
||||||
Label = "Disk $($DiskId) size*"
|
Label = "Disk $($DiskId) size*"
|
||||||
Description = "$($DynamicDisk.Description) (in $($DynamicDisk.UnitSize))".Trim()
|
Description = "$($Disk.Description) (in $($Disk.UnitSize))".Trim()
|
||||||
DefaultValue = "$($DynamicDisk.Constraints.Minimum)"
|
DefaultValue = "$($Disk.Constraints.Minimum)"
|
||||||
Configurations = '*'
|
Configurations = '*'
|
||||||
UserConfigurable = 'true'
|
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) {
|
If ($OVFConfig.DeploymentConfigurations.Count -gt 0) {
|
||||||
$XMLSection = $XML.CreateElement('DeploymentOptionSection', $XML.DocumentElement.xmlns)
|
$XMLSection = $XML.CreateElement('DeploymentOptionSection', $XML.DocumentElement.xmlns)
|
||||||
|
@ -23,12 +23,7 @@ DeploymentConfigurations:
|
|||||||
Size:
|
Size:
|
||||||
CPU: 4
|
CPU: 4
|
||||||
Memory: 8192
|
Memory: 8192
|
||||||
Disks:
|
DynamicDisks:
|
||||||
Referenced:
|
|
||||||
- Id: vmdisk1
|
|
||||||
UnitSize: GB
|
|
||||||
Capacity: 50
|
|
||||||
Dynamic:
|
|
||||||
- Description: Data
|
- Description: Data
|
||||||
UnitSize: GB
|
UnitSize: GB
|
||||||
Constraints:
|
Constraints:
|
||||||
|
Loading…
Reference in New Issue
Block a user