Commit 1a821c90 by Chif Gergő

Start openstack implementation

parent 1247484a
...@@ -4,6 +4,7 @@ It should be implemented for using other providers e. g. OpenStack ...@@ -4,6 +4,7 @@ It should be implemented for using other providers e. g. OpenStack
""" """
class InstanceInterface: class InstanceInterface:
def create_vm(self, name, resource): def create_vm(self, name, resource):
...@@ -42,6 +43,9 @@ class InstanceInterface: ...@@ -42,6 +43,9 @@ class InstanceInterface:
def destroy_vm(self): def destroy_vm(self):
pass pass
def migrate_vm(self):
pass
def get_status(self): def get_status(self):
pass pass
......
from ..client_interface.vm.instance import InstanceInterface
import openstack
class OSInstanceInterface(InstanceInterface):
def __init__(self, cloud):
super().__init__(self)
self.openstack = openstack.connect(cloud)
def create_vm_from_template(self, name, resource, template):
flavor = self.openstack.compute.find_flavor(name)
if not flavor:
flavor = self.openstack.compute.Flavor(nam=name, ram=resource.ram, vcpus=resource.cpu)
image = self.openstack.compute.find_image(template)
if not image:
raise ValueError("The template not found")
new_server = self.openstack.compute.create_server(name=name,
flavorRef=flavor.id,
imageRef=image.id)
new_server = conn.compute.wait_for_server(new_server)
return new_server
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