From 6b55524f53e621564425e1fafd097584333576b8 Mon Sep 17 00:00:00 2001
From: sguazt <marco.guazzone@gmail.com>
Date: Sun, 17 Jan 2021 11:35:30 +0100
Subject: [PATCH] OpenStack: updated the authentication part used by Gnocchi
 and Ceilometer clients to fit recent updates in OpenStack

---
 .../modules/openstack_openstacksdk/monitor.py | 46 ++++++++++---------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/easycloud/modules/openstack_openstacksdk/monitor.py b/easycloud/modules/openstack_openstacksdk/monitor.py
index 0ee6150..8ac18e4 100644
--- a/easycloud/modules/openstack_openstacksdk/monitor.py
+++ b/easycloud/modules/openstack_openstacksdk/monitor.py
@@ -2,28 +2,22 @@
 OpenStack monitor implementation (using Ceilometer/Gnocchi API)
 """
 
-__author__ = "Davide Monfrecola, Stefano Garione, Giorgio Gambino, Luca Banzato"
-__copyright__ = "Copyright (C) 2019"
-__credits__ = ["Andrea Lombardo", "Irene Lovotti"]
-__license__ = "GPL v3"
-__version__ = "0.10.0"
-__maintainer__ = "Luca Banzato"
-__email__ = "20005492@studenti.uniupo.it"
-__status__ = "Prototype"
-
-
 import datetime
 from easycloud.core.metamonitor import MetaMonitor
 #from keystoneauth1 import exceptions as ks_exception
-from keystoneauth1 import loading as ks_loading
-#from keystoneauth1 import session as ks_session
+#from keystoneauth1 import loading as ks_loading
 #from keystoneclient.v3 import client as ks_client_v3
+from keystoneauth1 import session as ks_session
+from keystoneauth1.identity import v3 as ks_v3
 import logging
 import pytz
 from tzlocal import get_localzone
 
 
 class OpenStackMonitor(MetaMonitor):
+    """
+    OpenStack Monitor.
+    """
 
     def __init__(self, conf, commands_queue, measurements_queue):
         """
@@ -291,16 +285,26 @@ class OpenStackGnocchiClientDriver():
         """
         Connect to Gnocchi and initialize its client object
         """
-        loader = ks_loading.get_plugin_loader('password')
-        auth = loader.load_from_options(auth_url=self.conf_.os_auth_url,
-                                        username=self.conf_.os_username,
-                                        password=self.conf_.os_password,
-                                        project_id=self.conf_.os_project_id,
-                                        user_domain_name="default")
+        #loader = ks_loading.get_plugin_loader('password')
+        #auth = loader.load_from_options(auth_url=self.conf_.os_auth_url,
+        #                                username=self.conf_.os_username,
+        #                                password=self.conf_.os_password,
+        #                                project_id=self.conf_.os_project_id,
+        #                                user_domain_name="default")
+        #self.client_ = gnocchiclient.client.Client("1",
+        #                                           adapter_options={
+        #                                                "region_name": self.conf_.os_region},
+        #                                                session_options={"auth": auth})
+        auth = ks_v3.Password(auth_url=self.conf_.os_auth_url,
+                              username=self.conf_.os_username,
+                              password=self.conf_.os_password,
+                              project_name=self.conf_.os_project_name,
+                              user_domain_id='default',
+                              project_domain_id='default')
+        sess = ks_session.Session(auth=auth)
         self.client_ = gnocchiclient.client.Client("1",
-                                                   adapter_options={
-                                                        "region_name": self.conf.os_region},
-                                                        session_options={"auth": _auth})
+                                                   session=sess,
+                                                   adapter_options={"region_name": self.conf_.os_region})
 
     # For the complete metrics list available for each instance, please use the
     # res_viewer.py script available in the module main directory, after
-- 
GitLab