storage_vol.go 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 StorageVolumeSize struct {
  28. Unit string `xml:"unit,attr,omitempty"`
  29. Value uint64 `xml:",chardata"`
  30. }
  31. type StorageVolumeTargetPermissions 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 StorageVolumeTargetFeature struct {
  38. LazyRefcounts *struct{} `xml:"lazy_refcounts"`
  39. }
  40. type StorageVolumeTargetFormat struct {
  41. Type string `xml:"type,attr"`
  42. }
  43. type StorageVolumeTargetTimestamps struct {
  44. Atime string `xml:"atime"`
  45. Mtime string `xml:"mtime"`
  46. Ctime string `xml:"ctime"`
  47. }
  48. type StorageVolumeTarget struct {
  49. Path string `xml:"path,omitempty"`
  50. Format *StorageVolumeTargetFormat `xml:"format"`
  51. Permissions *StorageVolumeTargetPermissions `xml:"permissions"`
  52. Timestamps *StorageVolumeTargetTimestamps `xml:"timestamps"`
  53. Compat string `xml:"compat,omitempty"`
  54. NoCOW *struct{} `xml:"nocow"`
  55. Features []StorageVolumeTargetFeature `xml:"features"`
  56. Encryption *StorageEncryption `xml:"encryption"`
  57. }
  58. type StorageVolumeBackingStore struct {
  59. Path string `xml:"path"`
  60. Format *StorageVolumeTargetFormat `xml:"format"`
  61. Permissions *StorageVolumeTargetPermissions `xml:"permissions"`
  62. }
  63. type StorageVolume struct {
  64. XMLName xml.Name `xml:"volume"`
  65. Type string `xml:"type,attr,omitempty"`
  66. Name string `xml:"name"`
  67. Key string `xml:"key,omitempty"`
  68. Allocation *StorageVolumeSize `xml:"allocation"`
  69. Capacity *StorageVolumeSize `xml:"capacity"`
  70. Physical *StorageVolumeSize `xml:"physical"`
  71. Target *StorageVolumeTarget `xml:"target"`
  72. BackingStore *StorageVolumeBackingStore `xml:"backingStore"`
  73. }
  74. func (s *StorageVolume) Unmarshal(doc string) error {
  75. return xml.Unmarshal([]byte(doc), s)
  76. }
  77. func (s *StorageVolume) Marshal() (string, error) {
  78. doc, err := xml.MarshalIndent(s, "", " ")
  79. if err != nil {
  80. return "", err
  81. }
  82. return string(doc), nil
  83. }