github.com/libvirt/libvirt-go-xml@v7.4.0+incompatible/storage_vol.go (about) 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 26 package libvirtxml 27 28 import "encoding/xml" 29 30 type StorageVolumeSize struct { 31 Unit string `xml:"unit,attr,omitempty"` 32 Value uint64 `xml:",chardata"` 33 } 34 35 type StorageVolumeTargetPermissions struct { 36 Owner string `xml:"owner,omitempty"` 37 Group string `xml:"group,omitempty"` 38 Mode string `xml:"mode,omitempty"` 39 Label string `xml:"label,omitempty"` 40 } 41 42 type StorageVolumeTargetFeature struct { 43 LazyRefcounts *struct{} `xml:"lazy_refcounts"` 44 } 45 46 type StorageVolumeTargetFormat struct { 47 Type string `xml:"type,attr"` 48 } 49 50 type StorageVolumeTargetTimestamps struct { 51 Atime string `xml:"atime"` 52 Mtime string `xml:"mtime"` 53 Ctime string `xml:"ctime"` 54 } 55 56 type StorageVolumeTargetCluterSize struct { 57 Unit string `xml:"unit,attr,omitempty"` 58 Value uint64 `xml:",chardata"` 59 } 60 61 type StorageVolumeTarget struct { 62 Path string `xml:"path,omitempty"` 63 Format *StorageVolumeTargetFormat `xml:"format"` 64 Permissions *StorageVolumeTargetPermissions `xml:"permissions"` 65 Timestamps *StorageVolumeTargetTimestamps `xml:"timestamps"` 66 Compat string `xml:"compat,omitempty"` 67 ClusterSize *StorageVolumeTargetCluterSize `xml:"clusterSize"` 68 NoCOW *struct{} `xml:"nocow"` 69 Features []StorageVolumeTargetFeature `xml:"features"` 70 Encryption *StorageEncryption `xml:"encryption"` 71 } 72 73 type StorageVolumeBackingStore struct { 74 Path string `xml:"path"` 75 Format *StorageVolumeTargetFormat `xml:"format"` 76 Permissions *StorageVolumeTargetPermissions `xml:"permissions"` 77 } 78 79 type StorageVolume struct { 80 XMLName xml.Name `xml:"volume"` 81 Type string `xml:"type,attr,omitempty"` 82 Name string `xml:"name"` 83 Key string `xml:"key,omitempty"` 84 Allocation *StorageVolumeSize `xml:"allocation"` 85 Capacity *StorageVolumeSize `xml:"capacity"` 86 Physical *StorageVolumeSize `xml:"physical"` 87 Target *StorageVolumeTarget `xml:"target"` 88 BackingStore *StorageVolumeBackingStore `xml:"backingStore"` 89 } 90 91 func (s *StorageVolume) Unmarshal(doc string) error { 92 return xml.Unmarshal([]byte(doc), s) 93 } 94 95 func (s *StorageVolume) Marshal() (string, error) { 96 doc, err := xml.MarshalIndent(s, "", " ") 97 if err != nil { 98 return "", err 99 } 100 return string(doc), nil 101 }