Commit f1525f93 by Bodor Máté

Merge branch 'template_interface' into 'DEV'

Template interface

See merge request !10
parents e01d873c 0946a05d
Pipeline #799 failed with stage
in 38 seconds
......@@ -113,6 +113,7 @@ venv/
ENV/
env.bak/
venv.bak/
environment.sh
# Spyder project settings
.spyderproject
......
......@@ -14,7 +14,8 @@ class OpenstackImageManager(ImageManager, OpenStackConnection):
return Image(
os_image.id,
os_image.name,
os_image.disk_format
os_image.disk_format,
os_image.size
)
def upload_file(self, name, path, format) -> Image:
......@@ -34,8 +35,8 @@ class OpenstackImageManager(ImageManager, OpenStackConnection):
return self.os_image_to_rc_image(os_image)
def download(self, id):
return self.openstack.image.download_image(id)
def download(self, id, path):
return self.openstack.image.download_image(image=id, output=path)
def delete(self, id) -> bool:
try:
......
from interface_openstack.interface.vm.instance import InstanceInterface
from interface_openstack.interface.vm.resources import Instance, Flavor
from openstack.exceptions import SDKException
from novaclient import client
import logging
from interface_openstack.implementation.utils.connection import OpenStackConnection
import secrets
from interface_openstack.interface.vm.instance import InstanceInterface
from interface_openstack.interface.vm.resources import Instance, Flavor
from interface_openstack.interface.image.image import Image
def openstackError(func):
def wrap_OpenStackError(*args, **kw):
......@@ -158,11 +160,13 @@ class OSVirtualMachineManager(InstanceInterface, OpenStackConnection):
self.openstack.compute.resize_server(instance, flavor)
@openstackError
def create_template(self, name_or_id, template_name, metadata=None):
instance = self._get_openstack_server(name_or_id)
self.openstack.compute.create_server_image(instance,
template_name,
def create_image(self, instance_id, metadata=None):
image_name = secrets.token_hex(30)
self.openstack.compute.create_server_image(instance_id,
image_name,
metadata)
image = self.openstack.compute.find_image(image_name)
return self.os_image_to_rc_image(image)
def get_vnc_console(self, server_id):
with client.Client("2", session=self.client_session) as nova:
......@@ -196,3 +200,9 @@ class OSVirtualMachineManager(InstanceInterface, OpenStackConnection):
launched_at=server.launched_at,
terminated_at=server.terminated_at,
addresses=server.addresses)
def os_image_to_rc_image(self, os_image):
return Image(
os_image.id,
os_image.name
)
......@@ -2,12 +2,13 @@ import json
class Image:
def __init__(self, id, name, format) -> None:
def __init__(self, id, name, file_format, size) -> None:
super().__init__()
self.id = id
self.name = name
self.format = format
self.file_format = file_format
self.size = size
def __str__(self) -> str:
return self.toJSON()
......
class ImageManager:
def __init__(self) -> None:
super().__init__()
def upload_file(self, name, path, format):
raise NotImplementedError
......@@ -11,11 +8,6 @@ class ImageManager:
def download(self, id):
raise NotImplementedError
def download_to_file(self, id, path):
f = open(path, 'wb')
f.write(self.download(id))
f.close()
def delete(self, id):
raise NotImplementedError
......
......@@ -65,7 +65,7 @@ class InstanceInterface:
def resize_vm(self, name_or_id):
raise NotImplementedError
def create_template(self, name_or_id, template_name):
def create_image(self, instance_id, metadata):
raise NotImplementedError
def attach_volume(self, name_or_id, amount):
......
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