Commit 0b5dc350 by Belákovics Ádám

Fix novclient connection

parent cc7bd247
Pipeline #1380 failed with stage
in 11 seconds
import openstack
from keystoneauth1.identity import v3
from keystoneauth1 import session
from keystoneauth1 import loading
from novaclient import client
class OpenStackConnection(object):
......@@ -16,10 +17,16 @@ class OpenStackConnection(object):
project_name=auth["project_name"],
region_name=auth["region_name"]
)
client_auth = v3.Password(auth_url=auth["auth_url"],
username=auth["username"],
password=auth["password"],
user_domain_id=auth["user_domain_id"],
project_id=auth["project_id"],)
self.client_session = session.Session(auth=client_auth)
loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(auth_url=auth["auth_url"],
username=auth["username"],
user_domain_name="default",
password=auth["password"],
project_id=auth["project_id"],
project_name=auth["project_name"])
client_session = session.Session(auth=auth)
self.nova_client = client.Client("2", session=client_session)
from openstack.exceptions import SDKException
from novaclient import client
import logging
from interface_openstack.implementation.utils.connection import OpenStackConnection
import secrets
......@@ -8,6 +7,7 @@ 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):
""" Decorator to wrap openstack error in simple Exception.
......@@ -17,10 +17,10 @@ def openstackError(func):
try:
return func(*args, **kw)
except SDKException as e:
logging.error(e)
new_e = Exception(e)
new_e.OpenStackError = True
raise new_e
logging.error(e)
new_e = Exception(e)
new_e.OpenStackError = True
raise new_e
return wrap_OpenStackError
......@@ -171,13 +171,12 @@ class OSVirtualMachineManager(InstanceInterface, OpenStackConnection):
image_name,
metadata)
image = self.openstack.compute.find_image(image_name)
return self.os_image_to_rc_image(image)
return self.os_image_to_rc_image(image)
@openstackError
def get_vnc_console(self, server_id):
with client.Client("2", session=self.client_session) as nova:
if server_id:
instance = nova.servers.get(server_id)
return instance.get_vnc_console("novnc")
instance = self.nova_client.servers.get(server_id)
return instance.get_vnc_console("novnc")
@openstackError
def attach_volume(self, server_id, volume_id, device=None):
......@@ -209,5 +208,7 @@ class OSVirtualMachineManager(InstanceInterface, OpenStackConnection):
def os_image_to_rc_image(self, os_image):
return Image(
os_image.id,
os_image.name
os_image.name,
"unknown",
os_image.size
)
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