Commit c551e4f0 by edems

return type added

parent 729cb080
from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface.image.ImageManager import ImageManager
......@@ -12,14 +14,14 @@ class OpenstackImageManager(ImageManager):
self.openstack = openstack
@staticmethod
def os_image_to_rc_image(os_image):
def os_image_to_rc_image(os_image) -> Image:
return Image(
os_image.id,
os_image.name,
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(
name=name,
filename=path,
......@@ -28,7 +30,7 @@ class OpenstackImageManager(ImageManager):
return self.os_image_to_rc_image(os_image)
def get(self, id):
def get(self, id) -> Optional[Image]:
try:
os_image = self.openstack.image.get_image(id)
except ResourceNotFound:
......@@ -39,7 +41,7 @@ class OpenstackImageManager(ImageManager):
def download(self, id):
return self.openstack.image.download_image(id)
def delete(self, id):
def delete(self, id) -> bool:
try:
self.openstack.image.delete_image(id)
except ResourceNotFound:
......@@ -47,7 +49,7 @@ class OpenstackImageManager(ImageManager):
return True
def list(self):
def list(self) -> []:
images = []
for os_image in self.openstack.image.images():
......
from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface.storage.Snapshot import Snapshot
......@@ -12,7 +14,7 @@ class OpenstackSnapshotManager(SnapshotManager):
self.openstack = os
@staticmethod
def os_snapshot_to_rc_snapshot(os_snapshot):
def os_snapshot_to_rc_snapshot(os_snapshot) -> Snapshot:
return Snapshot(
os_snapshot.id,
os_snapshot.volume_id,
......@@ -21,12 +23,12 @@ class OpenstackSnapshotManager(SnapshotManager):
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)
return self.os_snapshot_to_rc_snapshot(os_snapshot)
def get(self, id):
def get(self, id) -> Optional[Snapshot]:
try:
os_snapshot = self.openstack.block_storage.get_snapshot(id)
except ResourceNotFound:
......@@ -34,7 +36,7 @@ class OpenstackSnapshotManager(SnapshotManager):
return self.os_snapshot_to_rc_snapshot(os_snapshot)
def list(self):
def list(self) -> []:
snapshots = []
for os_snapshot in self.openstack.block_storage.snapshots():
......@@ -42,7 +44,7 @@ class OpenstackSnapshotManager(SnapshotManager):
return snapshots
def delete(self, id):
def delete(self, id) -> bool:
try:
self.openstack.block_storage.delete_snapshot(id)
except ResourceNotFound:
......
from typing import Optional
from openstack.exceptions import ResourceNotFound
from interface.storage.StorageManager import StorageManager
......@@ -12,7 +14,7 @@ class OpenstackStorageManager(StorageManager):
self.openstack = openstack
@staticmethod
def os_volume_to_rc_volume(os_volume):
def os_volume_to_rc_volume(os_volume) -> Volume:
return Volume(
os_volume.id,
os_volume.image_id,
......@@ -22,14 +24,14 @@ class OpenstackStorageManager(StorageManager):
os_volume.created_at
)
def create(self, size):
def create(self, size) -> Volume:
os_volume = self.openstack.block_storage.create_volume(
size=size
)
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(
image_id=id,
size=size,
......@@ -38,14 +40,14 @@ class OpenstackStorageManager(StorageManager):
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(
snapshot_id=id
)
return self.os_volume_to_rc_volume(os_volume)
def get(self, id):
def get(self, id) -> Optional[Volume]:
try:
os_volume = self.openstack.block_storage.get_volume(id)
except ResourceNotFound:
......@@ -61,7 +63,7 @@ class OpenstackStorageManager(StorageManager):
return True
def extend(self, id, size):
def extend(self, id, size) -> bool:
try:
self.openstack.block_storage.extend_volume(id, size)
except ResourceNotFound:
......@@ -69,7 +71,7 @@ class OpenstackStorageManager(StorageManager):
return True
def list(self):
def list(self) -> []:
volumes = []
for os_volume in self.openstack.block_storage.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