X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fv1%2Fclient.py;h=7d01cfad64ad62516ffd98bb49cd98d3c1d270f4;hb=refs%2Fheads%2Fv11.0;hp=cfaf15a7342f42a28e00173f158f2ce2a7d037be;hpb=4c7e237e45bc6fe209006b4837a8e6b031e78e1c;p=osm%2Fosmclient.git diff --git a/osmclient/v1/client.py b/osmclient/v1/client.py index cfaf15a..7d01cfa 100644 --- a/osmclient/v1/client.py +++ b/osmclient/v1/client.py @@ -24,67 +24,98 @@ from osmclient.v1 import ns from osmclient.v1 import nsd from osmclient.v1 import vim from osmclient.v1 import package -from osmclient.v1 import vca from osmclient.v1 import utils from osmclient.common import http +from osmclient.common import package_tool class Client(object): - def __init__( self, host=None, so_port=8008, + so_project="default", ro_host=None, ro_port=9090, upload_port=8443, - **kwargs): - self._user = 'admin' - self._password = 'admin' + **kwargs + ): + self._user = "admin" + self._password = "admin" - if len(host.split(':')) > 1: + 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._host = host.split(":")[0] + self._so_port = host.split(":")[1] else: self._host = host self._so_port = so_port - http_client = http.Http( - 'https://{}:{}/'.format( - self._host, - self._so_port)) + self._so_project = so_project + + http_client = http.Http("https://{}:{}/".format(self._host, self._so_port)) http_client.set_http_header( - ['Accept: application/vnd.yand.data+json', - 'Content-Type: application/json']) + ["Accept: application/vnd.yand.data+json", "Content-Type: application/json"] + ) + + self._so_version = self.get_so_version(http_client) if ro_host is None: ro_host = host - ro_http_client = http.Http('http://{}:{}/'.format(ro_host, ro_port)) + 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']) - - upload_client = http.Http( - 'https://{}:{}/composer/upload?api_server={}{}'.format( - self._host, - upload_port, - 'https://localhost&upload_server=https://', - self._host)) - - self.vnf = vnf.Vnf(http_client, **kwargs) - self.vnfd = vnfd.Vnfd(http_client, **kwargs) + ["Accept: application/vnd.yand.data+json", "Content-Type: application/json"] + ) + + upload_client_url = "https://{}:{}/composer/upload?api_server={}{}".format( + self._host, + upload_port, + "https://localhost&upload_server=https://", + self._host, + ) + + if self._so_version == "v3": + upload_client_url = ( + "https://{}:{}/composer/upload?api_server={}{}&project_name={}".format( + self._host, + upload_port, + "https://localhost&upload_server=https://", + self._host, + self._so_project, + ) + ) + + upload_client = http.Http(upload_client_url) + + self.vnf = vnf.Vnf(http_client, client=self, **kwargs) + self.vnfd = vnfd.Vnfd(http_client, client=self, **kwargs) self.ns = ns.Ns(http=http_client, client=self, **kwargs) - self.nsd = nsd.Nsd(http_client, **kwargs) + self.nsd = nsd.Nsd(http_client, client=self, **kwargs) self.vim = vim.Vim( - http=http_client, - ro_http=ro_http_client, - client=self, - **kwargs) + http=http_client, ro_http=ro_http_client, client=self, **kwargs + ) self.package = package.Package( - http=http_client, - upload_http=upload_client, - client=self, - **kwargs) - self.vca = vca.Vca(http_client, **kwargs) + http=http_client, upload_http=upload_client, client=self, **kwargs + ) self.utils = utils.Utils(http_client, **kwargs) + self.package_tool = package_tool.PackageTool(client=self) + + @property + def so_rbac_project_path(self): + if self._so_version == "v3": + return "project/{}/".format(self._so_project) + else: + return "" + + def get_so_version(self, http_client): + try: + resp = http_client.get_cmd("api/operational/version") + if not resp or "rw-base:version" not in resp: + return "v2" + + if resp["rw-base:version"]["version"].split(".")[0] == "5": + # SO Version 5.x.x.x.x translates to OSM V3 + return "v3" + return "v2" + except Exception: + return "v2"