github.com/zhaoxuat/libvirt-go-xml@v6.3.1-0.20200612053919-a025f1d30c41+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 StorageVolumeTarget struct { 57 Path string `xml:"path,omitempty"` 58 Format *StorageVolumeTargetFormat `xml:"format"` 59 Permissions *StorageVolumeTargetPermissions `xml:"permissions"` 60 Timestamps *StorageVolumeTargetTimestamps `xml:"timestamps"` 61 Compat string `xml:"compat,omitempty"` 62 NoCOW *struct{} `xml:"nocow"` 63 Features []StorageVolumeTargetFeature `xml:"features"` 64 Encryption *StorageEncryption `xml:"encryption"` 65 } 66 67 type StorageVolumeBackingStore struct { 68 Path string `xml:"path"` 69 Format *StorageVolumeTargetFormat `xml:"format"` 70 Permissions *StorageVolumeTargetPermissions `xml:"permissions"` 71 } 72 73 type StorageVolume struct { 74 XMLName xml.Name `xml:"volume"` 75 Type string `xml:"type,attr,omitempty"` 76 Name string `xml:"name"` 77 Key string `xml:"key,omitempty"` 78 Allocation *StorageVolumeSize `xml:"allocation"` 79 Capacity *StorageVolumeSize `xml:"capacity"` 80 Physical *StorageVolumeSize `xml:"physical"` 81 Target *StorageVolumeTarget `xml:"target"` 82 BackingStore *StorageVolumeBackingStore `xml:"backingStore"` 83 } 84 85 func (s *StorageVolume) Unmarshal(doc string) error { 86 return xml.Unmarshal([]byte(doc), s) 87 } 88 89 func (s *StorageVolume) Marshal() (string, error) { 90 doc, err := xml.MarshalIndent(s, "", " ") 91 if err != nil { 92 return "", err 93 } 94 return string(doc), nil 95 }