Commit 407f3782 by adamtorok

upgrades

parent b84611e4
import Volume
import openstack
import StorageManager import StorageManager
from openstack.exceptions import ResourceNotFound
from interface.storage.Volume import Volume
class OpenstackStorageManager(StorageManager.StorageManager): class OpenstackStorageManager(StorageManager.StorageManager):
def __init__(self, cloud) -> None: def __init__(self, openstack) -> None:
super().__init__() super().__init__()
self.openstack = openstack.connect(cloud=cloud)
self.openstack = openstack
@staticmethod @staticmethod
def os_volume_to_rc_volume(os_volume): def os_volume_to_rc_volume(os_volume):
return Volume.Volume( return Volume(
os_volume.id, os_volume.id,
os_volume.size, os_volume.size,
os_volume.is_bootable os_volume.is_bootable,
os_volume.status,
os_volume.created_at
) )
def create(self, size, bootable): def create(self, size, bootable):
os_volume = self.openstack.block_storage.create_volume(size=size, bootable=bootable) os_volume = self.openstack.block_storage.create_volume(
size=size,
bootable=bootable
)
return self.os_volume_to_rc_volume(os_volume)
def create_from_snapshot(self, id):
os_volume = self.openstack.block_storage.create_volume(snapshot_id=id)
return self.os_volume_to_rc_volume(os_volume) return self.os_volume_to_rc_volume(os_volume)
def get(self, id): def get(self, id):
os_volume = self.openstack.block_storage.get_volume(id) try:
os_volume = self.openstack.block_storage.get_volume(id)
except ResourceNotFound:
return None
return self.os_volume_to_rc_volume(os_volume) return self.os_volume_to_rc_volume(os_volume)
def delete(self, id): def delete(self, id):
print(self.openstack.block_storage.delete_volume(id)) try:
self.openstack.block_storage.delete_volume(id)
except ResourceNotFound:
return False
return True
def list(self): def list(self):
volumes = [] volumes = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment