Feature 11037 Changes to work with ingress controller
[osm/osmclient.git] / osmclient / sol005 / client.py
index a69f3cc..fadd377 100644 (file)
@@ -18,7 +18,6 @@
 OSM SOL005 client API
 """
 
-# from osmclient.v1 import vca
 from osmclient.sol005 import vnfd
 from osmclient.sol005 import nsd
 from osmclient.sol005 import nst
@@ -55,7 +54,6 @@ class Client(object):
         project="admin",
         **kwargs
     ):
-
         self._user = user
         self._password = password
         self._project = project
@@ -65,23 +63,22 @@ class Client(object):
         self._auth_endpoint = "/admin/v1/tokens"
         self._headers = {}
         self._token = None
-        if len(host.split(":")) > 1:
-            # backwards compatible, port provided as part of host
-            self._host = host.split(":")[0]
-            self._so_port = host.split(":")[1]
+        self._url = None
+        if host.startswith("http://") or host.startswith("https://"):
+            self._url = self._host
         else:
-            self._host = host
-            self._so_port = so_port
-
-        self._http_client = http.Http(
-            "https://{}:{}/osm".format(self._host, self._so_port), **kwargs
-        )
+            if len(host.split(":")) > 1:
+                # backwards compatible, port provided as part of host
+                self._host = host.split(":")[0]
+                self._so_port = host.split(":")[1]
+            else:
+                self._host = host
+                self._so_port = so_port
+            self._url = "https://{}:{}/osm".format(self._host, self._so_port)
+        self._http_client = http.Http(self._url, **kwargs)
         self._headers["Accept"] = "application/json"
         self._headers["Content-Type"] = "application/yaml"
-        http_header = [
-            "{}: {}".format(key, val) for (key, val) in list(self._headers.items())
-        ]
-        self._http_client.set_http_header(http_header)
+        self._http_client.set_http_header(self._headers)
 
         self.vnfd = vnfd.Vnfd(self._http_client, client=self)
         self.nsd = nsd.Nsd(self._http_client, client=self)
@@ -108,7 +105,7 @@ class Client(object):
         self.utils = utils.Utils(http_client, **kwargs)
         """
 
-    def get_token(self, pwd_change=None):
+    def get_token(self, pwd_change=False):
         self._logger.debug("")
         if self._token is None:
             postfields_dict = {
@@ -138,11 +135,8 @@ class Client(object):
 
             if self._token is not None:
                 self._headers["Authorization"] = "Bearer {}".format(self._token)
-                http_header = [
-                    "{}: {}".format(key, val)
-                    for (key, val) in list(self._headers.items())
-                ]
-                self._http_client.set_http_header(http_header)
+                self._http_client.set_http_header(self._headers)
+            return token
 
     def get_version(self):
         _, resp = self._http_client.get2_cmd(endpoint="/version", skip_query_admin=True)