envelope.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. Copyright (c) 2015-2023 VMware, Inc. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package ovf
  14. import (
  15. "fmt"
  16. )
  17. type Envelope struct {
  18. References []File `xml:"References>File"`
  19. // Package level meta-data
  20. Annotation *AnnotationSection `xml:"AnnotationSection"`
  21. Product *ProductSection `xml:"ProductSection"`
  22. Network *NetworkSection `xml:"NetworkSection"`
  23. Disk *DiskSection `xml:"DiskSection"`
  24. OperatingSystem *OperatingSystemSection `xml:"OperatingSystemSection"`
  25. Eula *EulaSection `xml:"EulaSection"`
  26. VirtualHardware *VirtualHardwareSection `xml:"VirtualHardwareSection"`
  27. ResourceAllocation *ResourceAllocationSection `xml:"ResourceAllocationSection"`
  28. DeploymentOption *DeploymentOptionSection `xml:"DeploymentOptionSection"`
  29. // Content: A VirtualSystem or a VirtualSystemCollection
  30. VirtualSystem *VirtualSystem `xml:"VirtualSystem"`
  31. }
  32. type VirtualSystem struct {
  33. Content
  34. Annotation []AnnotationSection `xml:"AnnotationSection"`
  35. Product []ProductSection `xml:"ProductSection"`
  36. OperatingSystem []OperatingSystemSection `xml:"OperatingSystemSection"`
  37. Eula []EulaSection `xml:"EulaSection"`
  38. VirtualHardware []VirtualHardwareSection `xml:"VirtualHardwareSection"`
  39. }
  40. type File struct {
  41. ID string `xml:"id,attr"`
  42. Href string `xml:"href,attr"`
  43. Size uint `xml:"size,attr"`
  44. Compression *string `xml:"compression,attr"`
  45. ChunkSize *int `xml:"chunkSize,attr"`
  46. }
  47. type Content struct {
  48. ID string `xml:"id,attr"`
  49. Info string `xml:"Info"`
  50. Name *string `xml:"Name"`
  51. }
  52. type Section struct {
  53. Required *bool `xml:"required,attr"`
  54. Info string `xml:"Info"`
  55. Category string `xml:"Category"`
  56. }
  57. type AnnotationSection struct {
  58. Section
  59. Annotation string `xml:"Annotation"`
  60. }
  61. type ProductSection struct {
  62. Section
  63. Class *string `xml:"class,attr"`
  64. Instance *string `xml:"instance,attr"`
  65. Product string `xml:"Product"`
  66. Vendor string `xml:"Vendor"`
  67. Version string `xml:"Version"`
  68. FullVersion string `xml:"FullVersion"`
  69. ProductURL string `xml:"ProductUrl"`
  70. VendorURL string `xml:"VendorUrl"`
  71. AppURL string `xml:"AppUrl"`
  72. Property []Property `xml:"Property"`
  73. }
  74. func (p ProductSection) Key(prop Property) string {
  75. // From OVF spec, section 9.5.1:
  76. // key-value-env = [class-value "."] key-value-prod ["." instance-value]
  77. k := prop.Key
  78. if p.Class != nil {
  79. k = fmt.Sprintf("%s.%s", *p.Class, k)
  80. }
  81. if p.Instance != nil {
  82. k = fmt.Sprintf("%s.%s", k, *p.Instance)
  83. }
  84. return k
  85. }
  86. type Property struct {
  87. Key string `xml:"key,attr"`
  88. Type string `xml:"type,attr"`
  89. Qualifiers *string `xml:"qualifiers,attr"`
  90. UserConfigurable *bool `xml:"userConfigurable,attr"`
  91. Default *string `xml:"value,attr"`
  92. Password *bool `xml:"password,attr"`
  93. Label *string `xml:"Label"`
  94. Description *string `xml:"Description"`
  95. Values []PropertyConfigurationValue `xml:"Value"`
  96. }
  97. type PropertyConfigurationValue struct {
  98. Value string `xml:"value,attr"`
  99. Configuration *string `xml:"configuration,attr"`
  100. }
  101. type NetworkSection struct {
  102. Section
  103. Networks []Network `xml:"Network"`
  104. }
  105. type Network struct {
  106. Name string `xml:"name,attr"`
  107. Description string `xml:"Description"`
  108. }
  109. type DiskSection struct {
  110. Section
  111. Disks []VirtualDiskDesc `xml:"Disk"`
  112. }
  113. type VirtualDiskDesc struct {
  114. DiskID string `xml:"diskId,attr"`
  115. FileRef *string `xml:"fileRef,attr"`
  116. Capacity string `xml:"capacity,attr"`
  117. CapacityAllocationUnits *string `xml:"capacityAllocationUnits,attr"`
  118. Format *string `xml:"format,attr"`
  119. PopulatedSize *int `xml:"populatedSize,attr"`
  120. ParentRef *string `xml:"parentRef,attr"`
  121. }
  122. type OperatingSystemSection struct {
  123. Section
  124. ID int16 `xml:"id,attr"`
  125. Version *string `xml:"version,attr"`
  126. OSType *string `xml:"osType,attr"`
  127. Description *string `xml:"Description"`
  128. }
  129. type EulaSection struct {
  130. Section
  131. License string `xml:"License"`
  132. }
  133. type Config struct {
  134. Required *bool `xml:"required,attr"`
  135. Key string `xml:"key,attr"`
  136. Value string `xml:"value,attr"`
  137. }
  138. type VirtualHardwareSection struct {
  139. Section
  140. ID *string `xml:"id,attr"`
  141. Transport *string `xml:"transport,attr"`
  142. System *VirtualSystemSettingData `xml:"System"`
  143. Item []ResourceAllocationSettingData `xml:"Item"`
  144. StorageItem []StorageAllocationSettingData `xml:"StorageItem"`
  145. Config []Config `xml:"Config"`
  146. ExtraConfig []Config `xml:"ExtraConfig"`
  147. }
  148. type VirtualSystemSettingData struct {
  149. CIMVirtualSystemSettingData
  150. }
  151. type ResourceAllocationSettingData struct {
  152. CIMResourceAllocationSettingData
  153. Required *bool `xml:"required,attr"`
  154. Configuration *string `xml:"configuration,attr"`
  155. Bound *string `xml:"bound,attr"`
  156. }
  157. type StorageAllocationSettingData struct {
  158. CIMStorageAllocationSettingData
  159. Required *bool `xml:"required,attr"`
  160. Configuration *string `xml:"configuration,attr"`
  161. Bound *string `xml:"bound,attr"`
  162. }
  163. type ResourceAllocationSection struct {
  164. Section
  165. Item []ResourceAllocationSettingData `xml:"Item"`
  166. }
  167. type DeploymentOptionSection struct {
  168. Section
  169. Configuration []DeploymentOptionConfiguration `xml:"Configuration"`
  170. }
  171. type DeploymentOptionConfiguration struct {
  172. ID string `xml:"id,attr"`
  173. Default *bool `xml:"default,attr"`
  174. Label string `xml:"Label"`
  175. Description string `xml:"Description"`
  176. }