1 # Copyright 2017 Sandvine
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
21 from osmclient
.v1
import vnf
22 from osmclient
.v1
import vnfd
23 from osmclient
.v1
import ns
24 from osmclient
.v1
import nsd
25 from osmclient
.v1
import vim
26 from osmclient
.v1
import package
27 from osmclient
.v1
import vca
28 from osmclient
.v1
import utils
29 from osmclient
.common
import http
30 from osmclient
.common
import package_tool
45 self
._password
= 'admin'
47 if len(host
.split(':')) > 1:
48 # backwards compatible, port provided as part of host
49 self
._host
= host
.split(':')[0]
50 self
._so
_port
= host
.split(':')[1]
53 self
._so
_port
= so_port
55 self
._so
_project
= so_project
57 http_client
= http
.Http(
58 'https://{}:{}/'.format(
61 http_client
.set_http_header(
62 ['Accept: application/vnd.yand.data+json',
63 'Content-Type: application/json'])
65 self
._so
_version
= self
.get_so_version(http_client
)
69 ro_http_client
= http
.Http('http://{}:{}/'.format(ro_host
, ro_port
))
70 ro_http_client
.set_http_header(
71 ['Accept: application/vnd.yand.data+json',
72 'Content-Type: application/json'])
74 upload_client_url
= 'https://{}:{}/composer/upload?api_server={}{}'.format(
77 'https://localhost&upload_server=https://',
80 if self
._so
_version
== 'v3':
81 upload_client_url
= 'https://{}:{}/composer/upload?api_server={}{}&project_name={}'.format(
84 'https://localhost&upload_server=https://',
88 upload_client
= http
.Http(upload_client_url
)
90 self
.vnf
= vnf
.Vnf(http_client
, client
=self
, **kwargs
)
91 self
.vnfd
= vnfd
.Vnfd(http_client
, client
=self
, **kwargs
)
92 self
.ns
= ns
.Ns(http
=http_client
, client
=self
, **kwargs
)
93 self
.nsd
= nsd
.Nsd(http_client
, client
=self
, **kwargs
)
96 ro_http
=ro_http_client
,
99 self
.package
= package
.Package(
101 upload_http
=upload_client
,
104 self
.vca
= vca
.Vca(http_client
, client
=self
, **kwargs
)
105 self
.utils
= utils
.Utils(http_client
, **kwargs
)
106 self
.package_tool
= package_tool
.PackageTool(client
=self
)
109 def so_rbac_project_path(self
):
110 if self
._so
_version
== 'v3':
111 return 'project/{}/'.format(self
._so
_project
)
115 def get_so_version(self
, http_client
):
117 resp
= http_client
.get_cmd('api/operational/version')
118 if not resp
or 'rw-base:version' not in resp
:
121 if resp
['rw-base:version']['version'].split('.')[0] == '5':
122 # SO Version 5.x.x.x.x translates to OSM V3