libvirt.org/go/libvirtxml@v1.10003.0/storage_vol.go (about)

     1  /*
     2   * This file is part of the libvirt-go-xml-module 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  	ExtendedL2    *struct{} `xml:"extended_l2"`
    45  }
    46  
    47  type StorageVolumeTargetFormat struct {
    48  	Type string `xml:"type,attr"`
    49  }
    50  
    51  type StorageVolumeTargetTimestamps struct {
    52  	Atime string `xml:"atime"`
    53  	Mtime string `xml:"mtime"`
    54  	Ctime string `xml:"ctime"`
    55  }
    56  
    57  type StorageVolumeTargetClusterSize struct {
    58  	Unit  string `xml:"unit,attr,omitempty"`
    59  	Value uint64 `xml:",chardata"`
    60  }
    61  
    62  type StorageVolumeTarget struct {
    63  	Path        string                          `xml:"path,omitempty"`
    64  	Format      *StorageVolumeTargetFormat      `xml:"format"`
    65  	Permissions *StorageVolumeTargetPermissions `xml:"permissions"`
    66  	Timestamps  *StorageVolumeTargetTimestamps  `xml:"timestamps"`
    67  	Compat      string                          `xml:"compat,omitempty"`
    68  	ClusterSize *StorageVolumeTargetClusterSize `xml:"clusterSize"`
    69  	NoCOW       *struct{}                       `xml:"nocow"`
    70  	Features    []StorageVolumeTargetFeature    `xml:"features"`
    71  	Encryption  *StorageEncryption              `xml:"encryption"`
    72  }
    73  
    74  type StorageVolumeBackingStore struct {
    75  	Path        string                          `xml:"path"`
    76  	Format      *StorageVolumeTargetFormat      `xml:"format"`
    77  	Permissions *StorageVolumeTargetPermissions `xml:"permissions"`
    78  }
    79  
    80  type StorageVolume struct {
    81  	XMLName      xml.Name                   `xml:"volume"`
    82  	Type         string                     `xml:"type,attr,omitempty"`
    83  	Name         string                     `xml:"name"`
    84  	Key          string                     `xml:"key,omitempty"`
    85  	Allocation   *StorageVolumeSize         `xml:"allocation"`
    86  	Capacity     *StorageVolumeSize         `xml:"capacity"`
    87  	Physical     *StorageVolumeSize         `xml:"physical"`
    88  	Target       *StorageVolumeTarget       `xml:"target"`
    89  	BackingStore *StorageVolumeBackingStore `xml:"backingStore"`
    90  }
    91  
    92  func (s *StorageVolume) Unmarshal(doc string) error {
    93  	return xml.Unmarshal([]byte(doc), s)
    94  }
    95  
    96  func (s *StorageVolume) Marshal() (string, error) {
    97  	doc, err := xml.MarshalIndent(s, "", "  ")
    98  	if err != nil {
    99  		return "", err
   100  	}
   101  	return string(doc), nil
   102  }