Commit 8edd7811 by Belákovics Ádám

Merge branch 'extend_volume' into 'DEV'

Extend volume

See merge request !5
parents f22ec7f1 c551e4f0
Pipeline #736 passed with stage
in 40 seconds
from typing import Optional
from openstack.exceptions import ResourceNotFound from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.image.ImageManager import ImageManager from interface_openstack.interface.image.ImageManager import ImageManager
...@@ -12,14 +14,14 @@ class OpenstackImageManager(ImageManager): ...@@ -12,14 +14,14 @@ class OpenstackImageManager(ImageManager):
self.openstack = openstack self.openstack = openstack
@staticmethod @staticmethod
def os_image_to_rc_image(os_image): def os_image_to_rc_image(os_image) -> Image:
return Image( return Image(
os_image.id, os_image.id,
os_image.name, os_image.name,
os_image.disk_format os_image.disk_format
) )
def upload_file(self, name, path, format): def upload_file(self, name, path, format) -> Image:
os_image = self.openstack.image.create_image( os_image = self.openstack.image.create_image(
name=name, name=name,
filename=path, filename=path,
...@@ -28,7 +30,7 @@ class OpenstackImageManager(ImageManager): ...@@ -28,7 +30,7 @@ class OpenstackImageManager(ImageManager):
return self.os_image_to_rc_image(os_image) return self.os_image_to_rc_image(os_image)
def get(self, id): def get(self, id) -> Optional[Image]:
try: try:
os_image = self.openstack.image.get_image(id) os_image = self.openstack.image.get_image(id)
except ResourceNotFound: except ResourceNotFound:
...@@ -39,7 +41,7 @@ class OpenstackImageManager(ImageManager): ...@@ -39,7 +41,7 @@ class OpenstackImageManager(ImageManager):
def download(self, id): def download(self, id):
return self.openstack.image.download_image(id) return self.openstack.image.download_image(id)
def delete(self, id): def delete(self, id) -> bool:
try: try:
self.openstack.image.delete_image(id) self.openstack.image.delete_image(id)
except ResourceNotFound: except ResourceNotFound:
...@@ -47,7 +49,7 @@ class OpenstackImageManager(ImageManager): ...@@ -47,7 +49,7 @@ class OpenstackImageManager(ImageManager):
return True return True
def list(self): def list(self) -> []:
images = [] images = []
for os_image in self.openstack.image.images(): for os_image in self.openstack.image.images():
......
from typing import Optional
from openstack.exceptions import ResourceNotFound from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.storage.Snapshot import Snapshot from interface_openstack.interface.storage.Snapshot import Snapshot
...@@ -12,7 +14,7 @@ class OpenstackSnapshotManager(SnapshotManager): ...@@ -12,7 +14,7 @@ class OpenstackSnapshotManager(SnapshotManager):
self.openstack = os self.openstack = os
@staticmethod @staticmethod
def os_snapshot_to_rc_snapshot(os_snapshot): def os_snapshot_to_rc_snapshot(os_snapshot) -> Snapshot:
return Snapshot( return Snapshot(
os_snapshot.id, os_snapshot.id,
os_snapshot.volume_id, os_snapshot.volume_id,
...@@ -21,12 +23,12 @@ class OpenstackSnapshotManager(SnapshotManager): ...@@ -21,12 +23,12 @@ class OpenstackSnapshotManager(SnapshotManager):
os_snapshot.created_at os_snapshot.created_at
) )
def create_from_volume(self, id): def create_from_volume(self, id) -> Snapshot:
os_snapshot = self.openstack.block_storage.create_snapshot(volume_id=id) os_snapshot = self.openstack.block_storage.create_snapshot(volume_id=id)
return self.os_snapshot_to_rc_snapshot(os_snapshot) return self.os_snapshot_to_rc_snapshot(os_snapshot)
def get(self, id): def get(self, id) -> Optional[Snapshot]:
try: try:
os_snapshot = self.openstack.block_storage.get_snapshot(id) os_snapshot = self.openstack.block_storage.get_snapshot(id)
except ResourceNotFound: except ResourceNotFound:
...@@ -34,7 +36,7 @@ class OpenstackSnapshotManager(SnapshotManager): ...@@ -34,7 +36,7 @@ class OpenstackSnapshotManager(SnapshotManager):
return self.os_snapshot_to_rc_snapshot(os_snapshot) return self.os_snapshot_to_rc_snapshot(os_snapshot)
def list(self): def list(self) -> []:
snapshots = [] snapshots = []
for os_snapshot in self.openstack.block_storage.snapshots(): for os_snapshot in self.openstack.block_storage.snapshots():
...@@ -42,7 +44,7 @@ class OpenstackSnapshotManager(SnapshotManager): ...@@ -42,7 +44,7 @@ class OpenstackSnapshotManager(SnapshotManager):
return snapshots return snapshots
def delete(self, id): def delete(self, id) -> bool:
try: try:
self.openstack.block_storage.delete_snapshot(id) self.openstack.block_storage.delete_snapshot(id)
except ResourceNotFound: except ResourceNotFound:
......
from typing import Optional
from openstack.exceptions import ResourceNotFound from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.storage.StorageManager import StorageManager from interface_openstack.interface.storage.StorageManager import StorageManager
...@@ -12,7 +14,7 @@ class OpenstackStorageManager(StorageManager): ...@@ -12,7 +14,7 @@ class OpenstackStorageManager(StorageManager):
self.openstack = openstack self.openstack = openstack
@staticmethod @staticmethod
def os_volume_to_rc_volume(os_volume): def os_volume_to_rc_volume(os_volume) -> Volume:
return Volume( return Volume(
os_volume.id, os_volume.id,
os_volume.image_id, os_volume.image_id,
...@@ -22,14 +24,14 @@ class OpenstackStorageManager(StorageManager): ...@@ -22,14 +24,14 @@ class OpenstackStorageManager(StorageManager):
os_volume.created_at os_volume.created_at
) )
def create(self, size): def create(self, size) -> Volume:
os_volume = self.openstack.block_storage.create_volume( os_volume = self.openstack.block_storage.create_volume(
size=size size=size
) )
return self.os_volume_to_rc_volume(os_volume) return self.os_volume_to_rc_volume(os_volume)
def create_from_image(self, id, size, bootable): def create_from_image(self, id, size, bootable) -> Volume:
os_volume = self.openstack.block_storage.create_volume( os_volume = self.openstack.block_storage.create_volume(
image_id=id, image_id=id,
size=size, size=size,
...@@ -38,14 +40,14 @@ class OpenstackStorageManager(StorageManager): ...@@ -38,14 +40,14 @@ class OpenstackStorageManager(StorageManager):
return self.os_volume_to_rc_volume(os_volume) return self.os_volume_to_rc_volume(os_volume)
def create_from_snapshot(self, id): def create_from_snapshot(self, id) -> Volume:
os_volume = self.openstack.block_storage.create_volume( os_volume = self.openstack.block_storage.create_volume(
snapshot_id=id 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) -> Optional[Volume]:
try: try:
os_volume = self.openstack.block_storage.get_volume(id) os_volume = self.openstack.block_storage.get_volume(id)
except ResourceNotFound: except ResourceNotFound:
...@@ -61,7 +63,15 @@ class OpenstackStorageManager(StorageManager): ...@@ -61,7 +63,15 @@ class OpenstackStorageManager(StorageManager):
return True return True
def list(self): def extend(self, id, size) -> bool:
try:
self.openstack.block_storage.extend_volume(id, size)
except ResourceNotFound:
return False
return True
def list(self) -> []:
volumes = [] volumes = []
for os_volume in self.openstack.block_storage.volumes(): for os_volume in self.openstack.block_storage.volumes():
......
...@@ -17,5 +17,8 @@ class StorageManager: ...@@ -17,5 +17,8 @@ class StorageManager:
def delete(self, id): def delete(self, id):
raise NotImplementedError raise NotImplementedError
def extend(self, id, size):
raise NotImplementedError
def list(self): def list(self):
raise NotImplementedError raise NotImplementedError
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