Commit d3e11cc8 by adamtorok

upgrades

parent 34480589
import openstack from openstack.exceptions import ResourceNotFound
import Image
import ImageManager
from interface.image.ImageManager import ImageManager
from interface.image.Image import Image
class OpenstackImageManager(ImageManager.ImageManager):
def __init__(self, cloud) -> None: class OpenstackImageManager(ImageManager):
def __init__(self, openstack) -> None:
super().__init__() super().__init__()
self.openstack = openstack.connect(cloud=cloud)
self.openstack = openstack
@staticmethod @staticmethod
def os_image_to_rc_image(os_image): def os_image_to_rc_image(os_image):
return Image.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, path): def upload_file(self, name, path, format):
os_image = self.openstack.image.create_image(name=path, filename=path, disk_format='iso') os_image = self.openstack.image.create_image(
name=name,
filename=path,
disk_format=format
)
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):
os_image = self.openstack.image.get_image(id) try:
os_image = self.openstack.image.get_image(id)
except ResourceNotFound:
return None
return self.os_image_to_rc_image(os_image) return self.os_image_to_rc_image(os_image)
def delete(self, id): def delete(self, id):
self.openstack.image.delete_image(id) try:
self.openstack.image.delete_image(id)
except ResourceNotFound:
return False
return True
def list(self): def list(self):
images = [] images = []
......
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