Skip to content

Commit

Permalink
virt storage draft version 0.1
Browse files Browse the repository at this point in the history
Signed-off-by: Xu Tian <[email protected]>
  • Loading branch information
Xu Tian committed Sep 25, 2019
1 parent a21d905 commit 239350f
Show file tree
Hide file tree
Showing 9 changed files with 860 additions and 0 deletions.
Empty file.
36 changes: 36 additions & 0 deletions virttest/virt_storage/exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class UnsupportedStoragePoolException(Exception):

def __init__(self, sp_manager, sp_type):
self.sp_manager = sp_manager
self.sp_type = sp_type
self.message = "Unsupported StoragePool type '%s', supported type are: %s" % (
self.sp_type, sp_manager.SUPPORTED_STORAGE_POOLS.keys())

def __str__(self):
return "UnsupportedStoragePoolException:%s" % self.message


class UnsupportedVolumeFormatException(Exception):
""""""

def __init__(self, sp_manager, fmt):
self.sp_manager = sp_manager
self.fmt = fmt
self.message = "Unsupported volume format '%s', supported format are: %s" % (
self.fmt, sp_manager.SUPPORTED_VOLUME_FORMAT.keys())

def __str__(self):
return "UnsupportedVolumeFormatException:%s" % self.message


class UnsupportedVolumeProtocolException(Exception):
""""""

def __init__(self, sp_manager, protocol):
self.sp_manager = sp_manager
self.protocol = protocol
self.message = "Unsupported volume protocol '%s', supported protocol are: %s" % (
self.protocol, sp_manager.SUPPORTED_VOLUME_PROTOCOL.keys())

def __str__(self):
return "UnsupportedVolumeProtocolException:%s" % self.message
65 changes: 65 additions & 0 deletions virttest/virt_storage/factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from virttest.virt_storage import exception
from virttest.virt_storage import storage_pool
from virttest.virt_storage import storage_volume


class StoragePoolFactory(object):
supported_storage_type = {
"file": storage_pool.FilePool,
"nfs": storage_pool.NfsPool,
"gluster": storage_pool.GlusterPool,
"iscsi": storage_pool.IscsiDriectPool,
"rbd": storage_pool.RbdPool
}

supported_volume_protocol = {
"file": storage_volume.VolumeProtocolFile,
"nfs": storage_volume.VolumeProtocolNfs,
"iscsi": storage_volume.VolumeProtocolDirectIscsi,
"gluster": storage_volume.VolumeProtocolGluster,
"rbd": storage_volume.VolumeProtocolRbd
}

supported_volume_format = {
"qcow2": storage_volume.Qcow2,
"raw": storage_volume.Raw,
"luks": storage_volume.Luks
}

pools = {}

@classmethod
def produce(cls, name, protocol, params):
try:
cls_storage_pool = cls.supported_storage_type[protocol]
pool = cls_storage_pool(name, cls, params)
cls.pools[name] = pool
return pool
except KeyError:
raise exception.UnsupportedStoragePoolException(cls, protocol)

@classmethod
def list_all_pools(cls):
return cls.pools.values()

@classmethod
def get_pool_by_name(cls, name):
return cls.pools.get(name)

@classmethod
def list_volumes(cls, pool_name):
pool = cls.pools.get(pool_name)
try:
return pool.volumes.values()
except AttributeError:
pass
return list()

@classmethod
def get_volume_by_name(cls, sp_name, vol_name):
pool = cls.get_pool_by_name(sp_name)
try:
return pool.volumes.get(vol_name)
except AttributeError:
pass
return None
Loading

0 comments on commit 239350f

Please sign in to comment.