forked from avocado-framework/avocado-vt
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Xu Tian <[email protected]>
- Loading branch information
Xu Tian
committed
Sep 25, 2019
1 parent
a21d905
commit 239350f
Showing
9 changed files
with
860 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.