osm.py: added config_file option to nsi_create
[osm/osmclient.git] / osmclient / sol005 / client.py
index d1c90aa..7583165 100644 (file)
 OSM SOL005 client API
 """
 
 OSM SOL005 client API
 """
 
-#from osmclient.v1 import vnf
 #from osmclient.v1 import vca
 from osmclient.sol005 import vnfd
 from osmclient.sol005 import nsd
 #from osmclient.v1 import vca
 from osmclient.sol005 import vnfd
 from osmclient.sol005 import nsd
+from osmclient.sol005 import nst
+from osmclient.sol005 import nsi
 from osmclient.sol005 import ns
 from osmclient.sol005 import ns
+from osmclient.sol005 import vnf
 from osmclient.sol005 import vim
 from osmclient.sol005 import package
 from osmclient.sol005 import http
 from osmclient.sol005 import sdncontroller
 from osmclient.sol005 import vim
 from osmclient.sol005 import package
 from osmclient.sol005 import http
 from osmclient.sol005 import sdncontroller
+from osmclient.sol005 import project as projectmodule
+from osmclient.sol005 import user as usermodule
 from osmclient.common.exceptions import ClientException
 from osmclient.common.exceptions import ClientException
+import json
 
 class Client(object):
 
 
 class Client(object):
 
@@ -35,15 +40,14 @@ class Client(object):
         self,
         host=None,
         so_port=9999,
         self,
         host=None,
         so_port=9999,
-        so_project='admin',
-        ro_host=None,
-        ro_port=9090,
+        user='admin',
+        password='admin',
+        project='admin',
         **kwargs):
 
         **kwargs):
 
-        self._user = 'admin'
-        self._password = 'admin'
-        #self._project = so_project
-        self._project = 'admin'
+        self._user = user
+        self._password = password
+        self._project = project
         self._auth_endpoint = '/admin/v1/tokens'
         self._headers = {}
 
         self._auth_endpoint = '/admin/v1/tokens'
         self._headers = {}
 
@@ -55,19 +59,12 @@ class Client(object):
             self._host = host
             self._so_port = so_port
 
             self._host = host
             self._so_port = so_port
 
-        if ro_host is None:
-            ro_host = host
-        ro_http_client = http.Http('http://{}:{}/'.format(ro_host, ro_port))
-        ro_http_client.set_http_header(
-            ['Accept: application/vnd.yand.data+json',
-             'Content-Type: application/json'])
-
         self._http_client = http.Http(
             'https://{}:{}/osm'.format(self._host,self._so_port))
         self._headers['Accept'] = 'application/json'
         self._headers['Content-Type'] = 'application/yaml'
         http_header = ['{}: {}'.format(key,val)
         self._http_client = http.Http(
             'https://{}:{}/osm'.format(self._host,self._so_port))
         self._headers['Accept'] = 'application/json'
         self._headers['Content-Type'] = 'application/yaml'
         http_header = ['{}: {}'.format(key,val)
-                      for (key,val) in self._headers.items()]
+                      for (key,val) in list(self._headers.items())]
         self._http_client.set_http_header(http_header)
 
         token = self.get_token()
         self._http_client.set_http_header(http_header)
 
         token = self.get_token()
@@ -80,12 +77,16 @@ class Client(object):
 
         self.vnfd = vnfd.Vnfd(self._http_client, client=self)
         self.nsd = nsd.Nsd(self._http_client, client=self)
 
         self.vnfd = vnfd.Vnfd(self._http_client, client=self)
         self.nsd = nsd.Nsd(self._http_client, client=self)
+        self.nst = nst.Nst(self._http_client, client=self)
         self.package = package.Package(self._http_client, client=self)
         self.ns = ns.Ns(self._http_client, client=self)
         self.package = package.Package(self._http_client, client=self)
         self.ns = ns.Ns(self._http_client, client=self)
+        self.nsi = nsi.Nsi(self._http_client, client=self)
         self.vim = vim.Vim(self._http_client, client=self)
         self.sdnc = sdncontroller.SdnController(self._http_client, client=self)
         self.vim = vim.Vim(self._http_client, client=self)
         self.sdnc = sdncontroller.SdnController(self._http_client, client=self)
+        self.vnf = vnf.Vnf(self._http_client, client=self)
+        self.project = projectmodule.Project(self._http_client, client=self)
+        self.user = usermodule.User(self._http_client, client=self)
         '''
         '''
-        self.vnf = vnf.Vnf(http_client, client=self, **kwargs)
         self.vca = vca.Vca(http_client, client=self, **kwargs)
         self.utils = utils.Utils(http_client, **kwargs)
         '''
         self.vca = vca.Vca(http_client, client=self, **kwargs)
         self.utils = utils.Utils(http_client, **kwargs)
         '''
@@ -93,9 +94,12 @@ class Client(object):
     def get_token(self):
         postfields_dict = {'username': self._user,
                            'password': self._password,
     def get_token(self):
         postfields_dict = {'username': self._user,
                            'password': self._password,
-                           'project-id': self._project}
-        token = self._http_client.post_cmd(endpoint=self._auth_endpoint,
+                           'project_id': self._project}
+        http_code, resp = self._http_client.post_cmd(endpoint=self._auth_endpoint,
                               postfields_dict=postfields_dict)
                               postfields_dict=postfields_dict)
+        if http_code not in (200, 201, 202, 204):
+            raise ClientException(resp)
+        token = json.loads(resp) if resp else None
         if token is not None:
             return token['_id']
         return None
         if token is not None:
             return token['_id']
         return None