1 # Copyright 2018 Telefonica
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 vca
22 from osmclient
.sol005
import vnfd
23 from osmclient
.sol005
import nsd
24 from osmclient
.sol005
import ns
25 from osmclient
.sol005
import vnf
26 from osmclient
.sol005
import vim
27 from osmclient
.sol005
import package
28 from osmclient
.sol005
import http
29 from osmclient
.sol005
import sdncontroller
30 from osmclient
.common
.exceptions
import ClientException
45 self
._password
= 'admin'
46 #self._project = so_project
47 self
._project
= 'admin'
48 self
._auth
_endpoint
= '/admin/v1/tokens'
51 if len(host
.split(':')) > 1:
52 # backwards compatible, port provided as part of host
53 self
._host
= host
.split(':')[0]
54 self
._so
_port
= host
.split(':')[1]
57 self
._so
_port
= so_port
61 ro_http_client
= http
.Http('http://{}:{}/openmano'.format(ro_host
, ro_port
))
62 ro_http_client
.set_http_header(
63 ['Accept: application/json',
64 'Content-Type: application/json'])
66 self
._http
_client
= http
.Http(
67 'https://{}:{}/osm'.format(self
._host
,self
._so
_port
))
68 self
._headers
['Accept'] = 'application/json'
69 self
._headers
['Content-Type'] = 'application/yaml'
70 http_header
= ['{}: {}'.format(key
,val
)
71 for (key
,val
) in list(self
._headers
.items())]
72 self
._http
_client
.set_http_header(http_header
)
74 token
= self
.get_token()
76 raise ClientException(
77 'Authentication error: not possible to get auth token')
78 self
._headers
['Authorization'] = 'Bearer {}'.format(token
)
79 http_header
.append('Authorization: Bearer {}'.format(token
))
80 self
._http
_client
.set_http_header(http_header
)
82 self
.vnfd
= vnfd
.Vnfd(self
._http
_client
, client
=self
)
83 self
.nsd
= nsd
.Nsd(self
._http
_client
, client
=self
)
84 self
.package
= package
.Package(self
._http
_client
, client
=self
)
85 self
.ns
= ns
.Ns(self
._http
_client
, client
=self
)
86 self
.vim
= vim
.Vim(self
._http
_client
, client
=self
)
87 self
.sdnc
= sdncontroller
.SdnController(self
._http
_client
, client
=self
)
88 self
.vnf
= vnf
.Vnf(self
._http
_client
, client
=self
)
90 self.vca = vca.Vca(http_client, client=self, **kwargs)
91 self.utils = utils.Utils(http_client, **kwargs)
95 postfields_dict
= {'username': self
._user
,
96 'password': self
._password
,
97 'project-id': self
._project
}
98 http_code
, resp
= self
._http
_client
.post_cmd(endpoint
=self
._auth
_endpoint
,
99 postfields_dict
=postfields_dict
)
100 if http_code
not in (200, 201, 202, 204):
101 raise ClientException(resp
)
102 token
= json
.loads(resp
) if resp
else None
103 if token
is not None: