storage_pool.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * This file is part of the libvirt-go-xml project
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. * THE SOFTWARE.
  21. *
  22. * Copyright (C) 2017 Red Hat, Inc.
  23. *
  24. */
  25. package libvirtxml
  26. import "encoding/xml"
  27. type StoragePoolSize struct {
  28. Unit string `xml:"unit,attr,omitempty"`
  29. Value uint64 `xml:",chardata"`
  30. }
  31. type StoragePoolTargetPermissions struct {
  32. Owner string `xml:"owner,omitempty"`
  33. Group string `xml:"group,omitempty"`
  34. Mode string `xml:"mode,omitempty"`
  35. Label string `xml:"label,omitempty"`
  36. }
  37. type StoragePoolTargetTimestamps struct {
  38. Atime string `xml:"atime"`
  39. Mtime string `xml:"mtime"`
  40. Ctime string `xml:"ctime"`
  41. }
  42. type StoragePoolTarget struct {
  43. Path string `xml:"path,omitempty"`
  44. Permissions *StoragePoolTargetPermissions `xml:"permissions"`
  45. Timestamps *StoragePoolTargetTimestamps `xml:"timestamps"`
  46. Encryption *StorageEncryption `xml:"encryption"`
  47. }
  48. type StoragePoolSourceFormat struct {
  49. Type string `xml:"type,attr"`
  50. }
  51. type StoragePoolSourceProtocol struct {
  52. Version string `xml:"ver,attr"`
  53. }
  54. type StoragePoolSourceHost struct {
  55. Name string `xml:"name,attr"`
  56. Port string `xml:"port,attr,omitempty"`
  57. }
  58. type StoragePoolSourceDevice struct {
  59. Path string `xml:"path,attr"`
  60. PartSeparator string `xml:"part_separator,attr,omitempty"`
  61. FreeExtents []StoragePoolSourceDeviceFreeExtent `xml:"freeExtent"`
  62. }
  63. type StoragePoolSourceDeviceFreeExtent struct {
  64. Start uint64 `xml:"start,attr"`
  65. End uint64 `xml:"end,attr"`
  66. }
  67. type StoragePoolSourceAuthSecret struct {
  68. Usage string `xml:"usage,attr,omitempty"`
  69. UUID string `xml:"uuid,attr,omitempty"`
  70. }
  71. type StoragePoolSourceAuth struct {
  72. Type string `xml:"type,attr"`
  73. Username string `xml:"username,attr"`
  74. Secret *StoragePoolSourceAuthSecret `xml:"secret"`
  75. }
  76. type StoragePoolSourceVendor struct {
  77. Name string `xml:"name,attr"`
  78. }
  79. type StoragePoolSourceProduct struct {
  80. Name string `xml:"name,attr"`
  81. }
  82. type StoragePoolPCIAddress struct {
  83. Domain *uint `xml:"domain,attr"`
  84. Bus *uint `xml:"bus,attr"`
  85. Slot *uint `xml:"slot,attr"`
  86. Function *uint `xml:"function,attr"`
  87. }
  88. type StoragePoolSourceAdapterParentAddr struct {
  89. UniqueID uint64 `xml:"unique_id,attr"`
  90. Address *StoragePoolPCIAddress `xml:"address"`
  91. }
  92. type StoragePoolSourceAdapter struct {
  93. Type string `xml:"type,attr,omitempty"`
  94. Name string `xml:"name,attr,omitempty"`
  95. Parent string `xml:"parent,attr,omitempty"`
  96. Managed string `xml:"managed,attr,omitempty"`
  97. WWNN string `xml:"wwnn,attr,omitempty"`
  98. WWPN string `xml:"wwpn,attr,omitempty"`
  99. ParentAddr *StoragePoolSourceAdapterParentAddr `xml:"parentaddr"`
  100. }
  101. type StoragePoolSourceDir struct {
  102. Path string `xml:"path,attr"`
  103. }
  104. type StoragePoolSourceInitiator struct {
  105. IQN StoragePoolSourceInitiatorIQN `xml:"iqn"`
  106. }
  107. type StoragePoolSourceInitiatorIQN struct {
  108. Name string `xml:"name,attr,omitempty"`
  109. }
  110. type StoragePoolSource struct {
  111. Name string `xml:"name,omitempty"`
  112. Dir *StoragePoolSourceDir `xml:"dir"`
  113. Host []StoragePoolSourceHost `xml:"host"`
  114. Device []StoragePoolSourceDevice `xml:"device"`
  115. Auth *StoragePoolSourceAuth `xml:"auth"`
  116. Vendor *StoragePoolSourceVendor `xml:"vendor"`
  117. Product *StoragePoolSourceProduct `xml:"product"`
  118. Format *StoragePoolSourceFormat `xml:"format"`
  119. Protocol *StoragePoolSourceProtocol `xml:"protocol"`
  120. Adapter *StoragePoolSourceAdapter `xml:"adapter"`
  121. Initiator *StoragePoolSourceInitiator `xml:"initiator"`
  122. }
  123. type StoragePoolRefreshVol struct {
  124. Allocation string `xml:"allocation,attr"`
  125. }
  126. type StoragePoolRefresh struct {
  127. Volume StoragePoolRefreshVol `xml:"volume"`
  128. }
  129. type StoragePool struct {
  130. XMLName xml.Name `xml:"pool"`
  131. Type string `xml:"type,attr"`
  132. Name string `xml:"name,omitempty"`
  133. UUID string `xml:"uuid,omitempty"`
  134. Allocation *StoragePoolSize `xml:"allocation"`
  135. Capacity *StoragePoolSize `xml:"capacity"`
  136. Available *StoragePoolSize `xml:"available"`
  137. Target *StoragePoolTarget `xml:"target"`
  138. Source *StoragePoolSource `xml:"source"`
  139. Refresh *StoragePoolRefresh `xml:"refresh"`
  140. /* Pool backend namespcaes must be last */
  141. FSCommandline *StoragePoolFSCommandline
  142. RBDCommandline *StoragePoolRBDCommandline
  143. }
  144. type StoragePoolFSCommandlineOption struct {
  145. Name string `xml:"name,attr"`
  146. }
  147. type StoragePoolFSCommandline struct {
  148. XMLName xml.Name `xml:"http://libvirt.org/schemas/storagepool/fs/1.0 mount_opts"`
  149. Options []StoragePoolFSCommandlineOption `xml:"option"`
  150. }
  151. type StoragePoolRBDCommandlineOption struct {
  152. Name string `xml:"name,attr"`
  153. Value string `xml:"value,attr"`
  154. }
  155. type StoragePoolRBDCommandline struct {
  156. XMLName xml.Name `xml:"http://libvirt.org/schemas/storagepool/rbd/1.0 config_opts"`
  157. Options []StoragePoolRBDCommandlineOption `xml:"option"`
  158. }
  159. func (a *StoragePoolPCIAddress) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
  160. marshalUintAttr(&start, "domain", a.Domain, "0x%04x")
  161. marshalUintAttr(&start, "bus", a.Bus, "0x%02x")
  162. marshalUintAttr(&start, "slot", a.Slot, "0x%02x")
  163. marshalUintAttr(&start, "function", a.Function, "0x%x")
  164. e.EncodeToken(start)
  165. e.EncodeToken(start.End())
  166. return nil
  167. }
  168. func (a *StoragePoolPCIAddress) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
  169. for _, attr := range start.Attr {
  170. if attr.Name.Local == "domain" {
  171. if err := unmarshalUintAttr(attr.Value, &a.Domain, 0); err != nil {
  172. return err
  173. }
  174. } else if attr.Name.Local == "bus" {
  175. if err := unmarshalUintAttr(attr.Value, &a.Bus, 0); err != nil {
  176. return err
  177. }
  178. } else if attr.Name.Local == "slot" {
  179. if err := unmarshalUintAttr(attr.Value, &a.Slot, 0); err != nil {
  180. return err
  181. }
  182. } else if attr.Name.Local == "function" {
  183. if err := unmarshalUintAttr(attr.Value, &a.Function, 0); err != nil {
  184. return err
  185. }
  186. }
  187. }
  188. d.Skip()
  189. return nil
  190. }
  191. func (s *StoragePool) Unmarshal(doc string) error {
  192. return xml.Unmarshal([]byte(doc), s)
  193. }
  194. func (s *StoragePool) Marshal() (string, error) {
  195. doc, err := xml.MarshalIndent(s, "", " ")
  196. if err != nil {
  197. return "", err
  198. }
  199. return string(doc), nil
  200. }