github.com/libvirt/libvirt-go-xml@v7.4.0+incompatible/storage_pool.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 StoragePoolSize struct { 31 Unit string `xml:"unit,attr,omitempty"` 32 Value uint64 `xml:",chardata"` 33 } 34 35 type StoragePoolTargetPermissions 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 StoragePoolTargetTimestamps struct { 43 Atime string `xml:"atime"` 44 Mtime string `xml:"mtime"` 45 Ctime string `xml:"ctime"` 46 } 47 48 type StoragePoolTarget struct { 49 Path string `xml:"path,omitempty"` 50 Permissions *StoragePoolTargetPermissions `xml:"permissions"` 51 Timestamps *StoragePoolTargetTimestamps `xml:"timestamps"` 52 Encryption *StorageEncryption `xml:"encryption"` 53 } 54 55 type StoragePoolSourceFormat struct { 56 Type string `xml:"type,attr"` 57 } 58 59 type StoragePoolSourceProtocol struct { 60 Version string `xml:"ver,attr"` 61 } 62 63 type StoragePoolSourceHost struct { 64 Name string `xml:"name,attr"` 65 Port string `xml:"port,attr,omitempty"` 66 } 67 68 type StoragePoolSourceDevice struct { 69 Path string `xml:"path,attr"` 70 PartSeparator string `xml:"part_separator,attr,omitempty"` 71 FreeExtents []StoragePoolSourceDeviceFreeExtent `xml:"freeExtent"` 72 } 73 74 type StoragePoolSourceDeviceFreeExtent struct { 75 Start uint64 `xml:"start,attr"` 76 End uint64 `xml:"end,attr"` 77 } 78 79 type StoragePoolSourceAuthSecret struct { 80 Usage string `xml:"usage,attr,omitempty"` 81 UUID string `xml:"uuid,attr,omitempty"` 82 } 83 84 type StoragePoolSourceAuth struct { 85 Type string `xml:"type,attr"` 86 Username string `xml:"username,attr"` 87 Secret *StoragePoolSourceAuthSecret `xml:"secret"` 88 } 89 90 type StoragePoolSourceVendor struct { 91 Name string `xml:"name,attr"` 92 } 93 94 type StoragePoolSourceProduct struct { 95 Name string `xml:"name,attr"` 96 } 97 98 type StoragePoolPCIAddress struct { 99 Domain *uint `xml:"domain,attr"` 100 Bus *uint `xml:"bus,attr"` 101 Slot *uint `xml:"slot,attr"` 102 Function *uint `xml:"function,attr"` 103 } 104 105 type StoragePoolSourceAdapterParentAddr struct { 106 UniqueID uint64 `xml:"unique_id,attr"` 107 Address *StoragePoolPCIAddress `xml:"address"` 108 } 109 110 type StoragePoolSourceAdapter struct { 111 Type string `xml:"type,attr,omitempty"` 112 Name string `xml:"name,attr,omitempty"` 113 Parent string `xml:"parent,attr,omitempty"` 114 Managed string `xml:"managed,attr,omitempty"` 115 WWNN string `xml:"wwnn,attr,omitempty"` 116 WWPN string `xml:"wwpn,attr,omitempty"` 117 ParentAddr *StoragePoolSourceAdapterParentAddr `xml:"parentaddr"` 118 } 119 120 type StoragePoolSourceDir struct { 121 Path string `xml:"path,attr"` 122 } 123 124 type StoragePoolSourceInitiator struct { 125 IQN StoragePoolSourceInitiatorIQN `xml:"iqn"` 126 } 127 128 type StoragePoolSourceInitiatorIQN struct { 129 Name string `xml:"name,attr,omitempty"` 130 } 131 132 type StoragePoolSource struct { 133 Name string `xml:"name,omitempty"` 134 Dir *StoragePoolSourceDir `xml:"dir"` 135 Host []StoragePoolSourceHost `xml:"host"` 136 Device []StoragePoolSourceDevice `xml:"device"` 137 Auth *StoragePoolSourceAuth `xml:"auth"` 138 Vendor *StoragePoolSourceVendor `xml:"vendor"` 139 Product *StoragePoolSourceProduct `xml:"product"` 140 Format *StoragePoolSourceFormat `xml:"format"` 141 Protocol *StoragePoolSourceProtocol `xml:"protocol"` 142 Adapter *StoragePoolSourceAdapter `xml:"adapter"` 143 Initiator *StoragePoolSourceInitiator `xml:"initiator"` 144 } 145 146 type StoragePoolRefreshVol struct { 147 Allocation string `xml:"allocation,attr"` 148 } 149 150 type StoragePoolRefresh struct { 151 Volume StoragePoolRefreshVol `xml:"volume"` 152 } 153 154 type StoragePoolFeatures struct { 155 COW StoragePoolFeatureCOW `xml:"cow"` 156 } 157 158 type StoragePoolFeatureCOW struct { 159 State string `xml:"state,attr"` 160 } 161 162 type StoragePool struct { 163 XMLName xml.Name `xml:"pool"` 164 Type string `xml:"type,attr"` 165 Name string `xml:"name,omitempty"` 166 UUID string `xml:"uuid,omitempty"` 167 Allocation *StoragePoolSize `xml:"allocation"` 168 Capacity *StoragePoolSize `xml:"capacity"` 169 Available *StoragePoolSize `xml:"available"` 170 Features *StoragePoolFeatures `xml:"features"` 171 Target *StoragePoolTarget `xml:"target"` 172 Source *StoragePoolSource `xml:"source"` 173 Refresh *StoragePoolRefresh `xml:"refresh"` 174 175 /* Pool backend namespcaes must be last */ 176 FSCommandline *StoragePoolFSCommandline 177 RBDCommandline *StoragePoolRBDCommandline 178 } 179 180 type StoragePoolFSCommandlineOption struct { 181 Name string `xml:"name,attr"` 182 } 183 184 type StoragePoolFSCommandline struct { 185 XMLName xml.Name `xml:"http://libvirt.org/schemas/storagepool/fs/1.0 mount_opts"` 186 Options []StoragePoolFSCommandlineOption `xml:"option"` 187 } 188 189 type StoragePoolRBDCommandlineOption struct { 190 Name string `xml:"name,attr"` 191 Value string `xml:"value,attr"` 192 } 193 194 type StoragePoolRBDCommandline struct { 195 XMLName xml.Name `xml:"http://libvirt.org/schemas/storagepool/rbd/1.0 config_opts"` 196 Options []StoragePoolRBDCommandlineOption `xml:"option"` 197 } 198 199 func (a *StoragePoolPCIAddress) MarshalXML(e *xml.Encoder, start xml.StartElement) error { 200 marshalUintAttr(&start, "domain", a.Domain, "0x%04x") 201 marshalUintAttr(&start, "bus", a.Bus, "0x%02x") 202 marshalUintAttr(&start, "slot", a.Slot, "0x%02x") 203 marshalUintAttr(&start, "function", a.Function, "0x%x") 204 e.EncodeToken(start) 205 e.EncodeToken(start.End()) 206 return nil 207 } 208 209 func (a *StoragePoolPCIAddress) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { 210 for _, attr := range start.Attr { 211 if attr.Name.Local == "domain" { 212 if err := unmarshalUintAttr(attr.Value, &a.Domain, 0); err != nil { 213 return err 214 } 215 } else if attr.Name.Local == "bus" { 216 if err := unmarshalUintAttr(attr.Value, &a.Bus, 0); err != nil { 217 return err 218 } 219 } else if attr.Name.Local == "slot" { 220 if err := unmarshalUintAttr(attr.Value, &a.Slot, 0); err != nil { 221 return err 222 } 223 } else if attr.Name.Local == "function" { 224 if err := unmarshalUintAttr(attr.Value, &a.Function, 0); err != nil { 225 return err 226 } 227 } 228 } 229 d.Skip() 230 return nil 231 } 232 233 func (s *StoragePool) Unmarshal(doc string) error { 234 return xml.Unmarshal([]byte(doc), s) 235 } 236 237 func (s *StoragePool) Marshal() (string, error) { 238 doc, err := xml.MarshalIndent(s, "", " ") 239 if err != nil { 240 return "", err 241 } 242 return string(doc), nil 243 }