Commit 0f9c85a8 by Chif Gergő

Inherit connection class

parent 10f3194e
...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound ...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.image.image_manager import ImageManager from interface_openstack.interface.image.image_manager import ImageManager
from interface_openstack.interface.image.image import Image from interface_openstack.interface.image.image import Image
from interface_openstack.implementation.utils.connection import OpenStackConnection
class OpenstackImageManager(ImageManager): class OpenstackImageManager(ImageManager, OpenStackConnection):
def __init__(self, openstack) -> None:
super().__init__()
self.openstack = openstack
@staticmethod @staticmethod
def os_image_to_rc_image(os_image) -> Image: def os_image_to_rc_image(os_image) -> Image:
......
...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound ...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.network.FloatingIP import floating_ip from interface_openstack.interface.network.FloatingIP import floating_ip
from interface_openstack.interface.network.FloatingIPManager import floating_ip_manager from interface_openstack.interface.network.FloatingIPManager import floating_ip_manager
from interface_openstack.implementation.utils.connection import OpenStackConnection
class OpenstackFloatingIPManager(FloatingIPManager): class OpenstackFloatingIPManager(FloatingIPManager, OpenStackConnection):
def __init__(self, openstack) -> None:
super().__init__()
self.openstack = openstack
@staticmethod @staticmethod
def os_floating_ip_to_rc_floating_ip(os_floating_ip) -> FloatingIP: def os_floating_ip_to_rc_floating_ip(os_floating_ip) -> FloatingIP:
......
...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound ...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.network.Network import network from interface_openstack.interface.network.Network import network
from interface_openstack.interface.network.NetworkManager import network_manager from interface_openstack.interface.network.NetworkManager import network_manager
from interface_openstack.implementation.utils.connection import OpenStackConnection
class OpenstackNetworkManager(NetworkManager): class OpenstackNetworkManager(NetworkManager, OpenStackConnection):
def __init__(self, openstack) -> None:
super().__init__()
self.openstack = openstack
@staticmethod @staticmethod
def os_network_to_rc_network(os_network) -> Network: def os_network_to_rc_network(os_network) -> Network:
......
...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound ...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.network.Port import port from interface_openstack.interface.network.Port import port
from interface_openstack.interface.network.PortManager import port_manager from interface_openstack.interface.network.PortManager import port_manager
from interface_openstack.implementation.utils.connection import OpenStackConnection
class OpenstackPortManager(PortManager): class OpenstackPortManager(PortManager, OpenStackConnection):
def __init__(self, openstack) -> None:
super().__init__()
self.openstack = openstack
@staticmethod @staticmethod
def os_port_to_rc_port(os_port): def os_port_to_rc_port(os_port):
......
...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound ...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.network.Router import router from interface_openstack.interface.network.Router import router
from interface_openstack.interface.network.RouterManager import router_manager from interface_openstack.interface.network.RouterManager import router_manager
from interface_openstack.implementation.utils.connection import OpenStackConnection
class OpenstackRouterManager(RouterManager): class OpenstackRouterManager(RouterManager, OpenStackConnection):
def __init__(self, openstack) -> None:
super().__init__()
self.openstack = openstack
@staticmethod @staticmethod
def os_router_to_rc_router(os_router) -> Router: def os_router_to_rc_router(os_router) -> Router:
......
...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound ...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.network.Subnet import subnet from interface_openstack.interface.network.Subnet import subnet
from interface_openstack.interface.network.SubnetManager import subnet_manager from interface_openstack.interface.network.SubnetManager import subnet_manager
from interface_openstack.implementation.utils.connection import OpenStackConnection
class OpenstackSubnetManager(SubnetManager): class OpenstackSubnetManager(SubnetManager, OpenStackConnection):
def __init__(self, openstack) -> None:
super().__init__()
self.openstack = openstack
@staticmethod @staticmethod
def os_subnet_to_rc_subnet(os_subnet): def os_subnet_to_rc_subnet(os_subnet):
......
...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound ...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.storage.snapshot import Snapshot from interface_openstack.interface.storage.snapshot import Snapshot
from interface_openstack.interface.storage.snapshot_manager import SnapshotManager from interface_openstack.interface.storage.snapshot_manager import SnapshotManager
from interface_openstack.implementation.utils.connection import OpenStackConnection
class OpenstackSnapshotManager(SnapshotManager): class OpenstackSnapshotManager(SnapshotManager, OpenStackConnection):
def __init__(self, os) -> None:
super().__init__()
self.openstack = os
@staticmethod @staticmethod
def os_snapshot_to_rc_snapshot(os_snapshot) -> Snapshot: def os_snapshot_to_rc_snapshot(os_snapshot) -> Snapshot:
......
...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound ...@@ -4,14 +4,10 @@ from openstack.exceptions import ResourceNotFound
from interface_openstack.interface.storage.storage_manager import StorageManager from interface_openstack.interface.storage.storage_manager import StorageManager
from interface_openstack.interface.storage.volume import Volume from interface_openstack.interface.storage.volume import Volume
from interface_openstack.implementation.utils.connection import OpenStackConnection
class OpenstackStorageManager(StorageManager): class OpenstackStorageManager(StorageManager, OpenStackConnection):
def __init__(self, openstack) -> None:
super().__init__()
self.openstack = openstack
@staticmethod @staticmethod
def os_volume_to_rc_volume(os_volume) -> Volume: def os_volume_to_rc_volume(os_volume) -> Volume:
......
from interface.vm.instance import InstanceInterface from interface_openstack.interface.vm.instance import InstanceInterface
from interface.vm.resources import Instance, Flavor 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 keystoneauth1.identity import v3 from interface_openstack.implementation.utils.connection import OpenStackConnection
from keystoneauth1 import session
auth = v3.Password(auth_url="http://10.34.0.113/identity/v3",
username="admin",
password="64c7ee341d03844c548c",
user_domain_id='default',
project_id="2db5309f541c4466bc80bc534cf579d7")
sess = session.Session(auth=auth)
def openstackError(func): def openstackError(func):
...@@ -31,11 +22,7 @@ def openstackError(func): ...@@ -31,11 +22,7 @@ def openstackError(func):
return wrap_OpenStackError return wrap_OpenStackError
class OSVirtualMachineManager(InstanceInterface): class OSVirtualMachineManager(InstanceInterface, OpenStackConnection):
def __init__(self, cloud):
super().__init__()
self.openstack = cloud
@openstackError @openstackError
def _get_openstack_server(self, name_or_id): def _get_openstack_server(self, name_or_id):
...@@ -52,16 +39,18 @@ class OSVirtualMachineManager(InstanceInterface): ...@@ -52,16 +39,18 @@ class OSVirtualMachineManager(InstanceInterface):
b_device = block_dev_map.__dict__ b_device = block_dev_map.__dict__
devices.append(b_device) devices.append(b_device)
flavor = self.get_flavor(flavor) flavor = self.get_flavor(flavor)
new_server = self.openstack.compute.create_server(name=name, new_server = self.openstack.compute.create_server(
flavorRef=flavor.id, name=name,
networks=networks, flavorRef=flavor.id,
block_device_mapping=devices networks=networks,
) block_device_mapping=devices
)
return self.convert_server_to_instance(new_server) return self.convert_server_to_instance(new_server)
@openstackError @openstackError
def create_vm_from_template(self, name, image, flavor, networks): def create_vm_from_template(self, name, image, flavor, networks):
return self.create_multiple_vm_from_template(name, image, flavor, networks, 1) return self.create_multiple_vm_from_template(name, image, flavor,
networks, 1)
@openstackError @openstackError
def create_multiple_vm_from_template(self, name, image, flavor, networks, def create_multiple_vm_from_template(self, name, image, flavor, networks,
...@@ -176,7 +165,7 @@ class OSVirtualMachineManager(InstanceInterface): ...@@ -176,7 +165,7 @@ class OSVirtualMachineManager(InstanceInterface):
metadata) metadata)
def get_vnc_console(self, server_id): def get_vnc_console(self, server_id):
with client.Client("2", session=sess) as nova: with client.Client("2", session=self.client_session) as nova:
if server_id: if server_id:
instance = nova.servers.get(server_id) instance = nova.servers.get(server_id)
return instance.get_vnc_console("novnc") return instance.get_vnc_console("novnc")
......
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