github.com/mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/pkg/virt/storage_interface.go (about) 1 /* 2 Copyright 2017 Mirantis 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package virt 18 19 import ( 20 "errors" 21 libvirtxml "github.com/libvirt/libvirt-go-xml" 22 ) 23 24 // TODO: move VolumeInfo here from storage_pool.go 25 26 // ErrStoragePoolNotFound error is returned by StorageConnection's 27 // LookupByName() method when the pool in question cannot be found 28 var ErrStoragePoolNotFound = errors.New("storage pool not found") 29 30 // ErrStorageVolumeNotFound error is returned by StoragePool's 31 // LookupVolumeByName() method when the volume in question cannot 32 // be found 33 var ErrStorageVolumeNotFound = errors.New("storage volume not found") 34 35 // StorageConnection provides operations on the storage pools and storage volumes 36 type StorageConnection interface { 37 // CreateStoragePool creates a storage pool based on the specified definition 38 CreateStoragePool(def *libvirtxml.StoragePool) (StoragePool, error) 39 // LookupByName tries to locate the storage pool by its 40 // UUID. In case if the domain cannot be found but no other 41 // error occurred, it returns ErrStoragePoolNotFound 42 LookupStoragePoolByName(name string) (StoragePool, error) 43 // ListPools() retrieves the list of pools 44 ListPools() ([]StoragePool, error) 45 // PutFiles add files to the specified image. 46 PutFiles(imagePath string, files map[string][]byte) error 47 } 48 49 // StoragePool represents a pool of volumes 50 type StoragePool interface { 51 // CreateStorageVol creates a new storage volume based on the specified definition 52 CreateStorageVol(def *libvirtxml.StorageVolume) (StorageVolume, error) 53 // ListVolumes lists all the storage volumes available in the pool 54 ListVolumes() ([]StorageVolume, error) 55 // LookupVolumeByName tries to locate the storage volume by its 56 // UUID. In case if the domain cannot be found but no other 57 // error occurred, it returns ErrStorageVolumeNotFound 58 LookupVolumeByName(name string) (StorageVolume, error) 59 // RemoveVolumeByName removes the storage volume with the 60 // specified name 61 RemoveVolumeByName(name string) error 62 // XML retrieves xml definition of the pool 63 XML() (*libvirtxml.StoragePool, error) 64 } 65 66 // StorageVolume represents a particular volume in pool 67 type StorageVolume interface { 68 // Name returns the name of this storage volume 69 Name() string 70 // Size returns the size of this storage volume 71 Size() (uint64, error) 72 // Path returns the path to the file representing this storage volume 73 Path() (string, error) 74 // Remove removes this storage volume 75 Remove() error 76 // Format formats the volume as ext4 filesystem 77 Format() error 78 // XML retrieves xml definition of the volume 79 XML() (*libvirtxml.StorageVolume, error) 80 }