github.com/vmware/govmomi@v0.51.0/ovf/envelope.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package ovf 6 7 import ( 8 "fmt" 9 ) 10 11 // Envelope is defined according to 12 // https://www.dmtf.org/sites/default/files/standards/documents/DSP0243_2.1.1.pdf. 13 // 14 // Section 9 describes the parent/child relationships. 15 // 16 // A VirtualSystem may have zero or more VirtualHardware sections. 17 type Envelope struct { 18 References []File `xml:"References>File" json:"references,omitempty"` 19 20 // Package level meta-data 21 Disk *DiskSection `xml:"DiskSection,omitempty" json:"diskSection,omitempty"` 22 Network *NetworkSection `xml:"NetworkSection,omitempty" json:"networkSection,omitempty"` 23 DeploymentOption *DeploymentOptionSection `xml:"DeploymentOptionSection,omitempty" json:"deploymentOptionSection,omitempty"` 24 25 // Content: A VirtualSystem or a VirtualSystemCollection 26 VirtualSystem *VirtualSystem `xml:"VirtualSystem,omitempty" json:"virtualSystem,omitempty"` 27 VirtualSystemCollection *VirtualSystemCollection `xml:"VirtualSystemCollection,omitempty" json:"virtualSystemCollection,omitempty"` 28 } 29 30 type VirtualSystem struct { 31 Content 32 33 Annotation *AnnotationSection `xml:"AnnotationSection,omitempty" json:"annotationSection,omitempty"` 34 Product []ProductSection `xml:"ProductSection,omitempty" json:"productSection,omitempty"` 35 Eula []EulaSection `xml:"EulaSection,omitempty" json:"eulaSection,omitempty"` 36 OperatingSystem *OperatingSystemSection `xml:"OperatingSystemSection,omitempty" json:"operatingSystemSection,omitempty"` 37 VirtualHardware []VirtualHardwareSection `xml:"VirtualHardwareSection,omitempty" json:"virtualHardwareSection,omitempty"` 38 } 39 40 type VirtualSystemCollection struct { 41 Content 42 43 // Collection level meta-data 44 ResourceAllocation *ResourceAllocationSection `xml:"ResourceAllocationSection,omitempty" json:"resourceAllocationSection,omitempty"` 45 Annotation *AnnotationSection `xml:"AnnotationSection,omitempty" json:"annotationSection,omitempty"` 46 Product []ProductSection `xml:"ProductSection,omitempty" json:"productSection,omitempty"` 47 Eula []EulaSection `xml:"EulaSection,omitempty" json:"eulaSection,omitempty"` 48 49 // Content: One or more VirtualSystems 50 VirtualSystem []VirtualSystem `xml:"VirtualSystem,omitempty" json:"virtualSystem,omitempty"` 51 } 52 53 type File struct { 54 ID string `xml:"id,attr" json:"id,omitempty"` 55 Href string `xml:"href,attr" json:"href,omitempty"` 56 Size uint `xml:"size,attr" json:"size,omitempty"` 57 Compression *string `xml:"compression,attr" json:"compression,omitempty"` 58 ChunkSize *int `xml:"chunkSize,attr" json:"chunkSize,omitempty"` 59 } 60 61 type Content struct { 62 ID string `xml:"id,attr" json:"id,omitempty"` 63 Info string `xml:"Info" json:"info,omitempty"` 64 Name *string `xml:"Name" json:"name,omitempty"` 65 } 66 67 type Section struct { 68 Required *bool `xml:"required,attr" json:"required,omitempty"` 69 Info string `xml:"Info" json:"info,omitempty"` 70 Category string `xml:"Category" json:"category,omitempty"` 71 } 72 73 type AnnotationSection struct { 74 Section 75 76 Annotation string `xml:"Annotation" json:"annotation,omitempty"` 77 } 78 79 type ProductSection struct { 80 Section 81 82 Class *string `xml:"class,attr" json:"class,omitempty"` 83 Instance *string `xml:"instance,attr" json:"instance,omitempty"` 84 85 Product string `xml:"Product" json:"product,omitempty"` 86 Vendor string `xml:"Vendor" json:"vendor,omitempty"` 87 Version string `xml:"Version" json:"version,omitempty"` 88 FullVersion string `xml:"FullVersion" json:"fullVersion,omitempty"` 89 ProductURL string `xml:"ProductUrl" json:"productUrl,omitempty"` 90 VendorURL string `xml:"VendorUrl" json:"vendorUrl,omitempty"` 91 AppURL string `xml:"AppUrl" json:"appUrl,omitempty"` 92 Property []Property `xml:"Property" json:"property,omitempty"` 93 } 94 95 func (p ProductSection) Key(prop Property) string { 96 // From OVF spec, section 9.5.1: 97 // key-value-env = [class-value "."] key-value-prod ["." instance-value] 98 99 k := prop.Key 100 if p.Class != nil { 101 k = fmt.Sprintf("%s.%s", *p.Class, k) 102 } 103 if p.Instance != nil { 104 k = fmt.Sprintf("%s.%s", k, *p.Instance) 105 } 106 return k 107 } 108 109 type Property struct { 110 Key string `xml:"key,attr" json:"key,omitempty"` 111 Type string `xml:"type,attr" json:"type,omitempty"` 112 Qualifiers *string `xml:"qualifiers,attr" json:"qualifiers,omitempty"` 113 UserConfigurable *bool `xml:"userConfigurable,attr" json:"userConfigurable,omitempty"` 114 Default *string `xml:"value,attr" json:"default,omitempty"` 115 Password *bool `xml:"password,attr" json:"password,omitempty"` 116 Configuration *string `xml:"configuration,attr" json:"configuration,omitempty"` 117 118 Label *string `xml:"Label" json:"label,omitempty"` 119 Description *string `xml:"Description" json:"description,omitempty"` 120 121 Values []PropertyConfigurationValue `xml:"Value" json:"value,omitempty"` 122 } 123 124 type PropertyConfigurationValue struct { 125 Value string `xml:"value,attr" json:"value,omitempty"` 126 Configuration *string `xml:"configuration,attr" json:"configuration,omitempty"` 127 } 128 129 type NetworkSection struct { 130 Section 131 132 Networks []Network `xml:"Network" json:"network,omitempty"` 133 } 134 135 type Network struct { 136 Name string `xml:"name,attr" json:"name,omitempty"` 137 138 Description string `xml:"Description" json:"description,omitempty"` 139 } 140 141 type DiskSection struct { 142 Section 143 144 Disks []VirtualDiskDesc `xml:"Disk" json:"disk,omitempty"` 145 } 146 147 type VirtualDiskDesc struct { 148 DiskID string `xml:"diskId,attr" json:"diskId,omitempty"` 149 FileRef *string `xml:"fileRef,attr" json:"fileRef,omitempty"` 150 Capacity string `xml:"capacity,attr" json:"capacity,omitempty"` 151 CapacityAllocationUnits *string `xml:"capacityAllocationUnits,attr" json:"capacityAllocationUnits,omitempty"` 152 Format *string `xml:"format,attr" json:"format,omitempty"` 153 PopulatedSize *int `xml:"populatedSize,attr" json:"populatedSize,omitempty"` 154 ParentRef *string `xml:"parentRef,attr" json:"parentRef,omitempty"` 155 } 156 157 type OperatingSystemSection struct { 158 Section 159 160 ID int16 `xml:"id,attr" json:"id"` 161 Version *string `xml:"version,attr" json:"version,omitempty"` 162 OSType *string `xml:"osType,attr" json:"osType,omitempty"` 163 164 Description *string `xml:"Description" json:"description,omitempty"` 165 } 166 167 type EulaSection struct { 168 Section 169 170 License string `xml:"License" json:"license,omitempty"` 171 } 172 173 type Config struct { 174 Required *bool `xml:"required,attr" json:"required,omitempty"` 175 Key string `xml:"key,attr" json:"key,omitempty"` 176 Value string `xml:"value,attr" json:"value,omitempty"` 177 } 178 179 type VirtualHardwareSection struct { 180 Section 181 182 ID *string `xml:"id,attr" json:"id"` 183 Transport *string `xml:"transport,attr" json:"transport,omitempty"` 184 185 System *VirtualSystemSettingData `xml:"System" json:"system,omitempty"` 186 Item []ResourceAllocationSettingData `xml:"Item" json:"item,omitempty"` 187 StorageItem []StorageAllocationSettingData `xml:"StorageItem" json:"storageItem,omitempty"` 188 Config []Config `xml:"Config" json:"config,omitempty"` 189 ExtraConfig []Config `xml:"ExtraConfig" json:"extraConfig,omitempty"` 190 } 191 192 type VirtualSystemSettingData struct { 193 CIMVirtualSystemSettingData 194 } 195 196 type ResourceAllocationSettingData struct { 197 CIMResourceAllocationSettingData 198 199 Required *bool `xml:"required,attr" json:"required,omitempty"` 200 Configuration *string `xml:"configuration,attr" json:"configuration,omitempty"` 201 Bound *string `xml:"bound,attr" json:"bound,omitempty"` 202 Config []Config `xml:"Config" json:"config,omitempty"` 203 CoresPerSocket *CoresPerSocket `xml:"CoresPerSocket" json:"coresPerSocket,omitempty"` 204 } 205 206 type StorageAllocationSettingData struct { 207 CIMStorageAllocationSettingData 208 209 Required *bool `xml:"required,attr" json:"required,omitempty"` 210 Configuration *string `xml:"configuration,attr" json:"configuration,omitempty"` 211 Bound *string `xml:"bound,attr" json:"bound,omitempty"` 212 } 213 214 type ResourceAllocationSection struct { 215 Section 216 217 Item []ResourceAllocationSettingData `xml:"Item" json:"item,omitempty"` 218 } 219 220 type DeploymentOptionSection struct { 221 Section 222 223 Configuration []DeploymentOptionConfiguration `xml:"Configuration" json:"configuration,omitempty"` 224 } 225 226 type DeploymentOptionConfiguration struct { 227 ID string `xml:"id,attr" json:"id"` 228 Default *bool `xml:"default,attr" json:"default,omitempty"` 229 230 Label string `xml:"Label" json:"label,omitempty"` 231 Description string `xml:"Description" json:"description,omitempty"` 232 } 233 234 type CoresPerSocket struct { 235 Required *bool `xml:"required,attr" json:"required,omitempty"` 236 Value int32 `xml:",chardata" json:"value,omitempty"` 237 }