Commit 78644782 by adamtorok

upgrade

parent 444c3a93
import Snapshot
import SnapshotManager
import openstack
from openstack.exceptions import ResourceNotFound
from interface.storage.Snapshot import Snapshot
class OpenstackSnapshotManager(SnapshotManager.SnapshotManager):
def __init__(self, cloud) -> None:
def __init__(self, os) -> None:
super().__init__()
self.openstack = openstack.connect(cloud=cloud)
self.openstack = os
@staticmethod
def os_snapshot_to_rc_snapshot(os_snapshot):
return Snapshot.Snapshot(
return Snapshot(
os_snapshot.id,
os_snapshot.size
os_snapshot.volume_id,
os_snapshot.size,
os_snapshot.status,
os_snapshot.created_at
)
def create_from_volume(self, id):
......@@ -23,7 +27,10 @@ class OpenstackSnapshotManager(SnapshotManager.SnapshotManager):
return self.os_snapshot_to_rc_snapshot(os_snapshot)
def get(self, id):
os_snapshot = self.openstack.block_storage.get_snapshot(id)
try:
os_snapshot = self.openstack.block_storage.get_snapshot(id)
except ResourceNotFound:
return None
return self.os_snapshot_to_rc_snapshot(os_snapshot)
......@@ -36,4 +43,9 @@ class OpenstackSnapshotManager(SnapshotManager.SnapshotManager):
return snapshots
def delete(self, id):
print(self.openstack.block_storage.delete_snapshot(id))
try:
self.openstack.block_storage.delete_snapshot(id)
except ResourceNotFound:
return False
return True
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