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