6281ffe766e46f2dc4c09a173edbba7664e0ab6a
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 nst
25 from osmclient
.sol005
import nsi
26 from osmclient
.sol005
import ns
27 from osmclient
.sol005
import vnf
28 from osmclient
.sol005
import vim
29 from osmclient
.sol005
import wim
30 from osmclient
.sol005
import package
31 from osmclient
.sol005
import http
32 from osmclient
.sol005
import sdncontroller
33 from osmclient
.sol005
import project
as projectmodule
34 from osmclient
.sol005
import user
as usermodule
35 from osmclient
.sol005
import role
36 from osmclient
.sol005
import pdud
37 from osmclient
.common
.exceptions
import ClientException
38 from osmclient
.common
import package_tool
54 self
._password
= password
55 self
._project
= project
56 self
._auth
_endpoint
= '/admin/v1/tokens'
60 if len(host
.split(':')) > 1:
61 # backwards compatible, port provided as part of host
62 self
._host
= host
.split(':')[0]
63 self
._so
_port
= host
.split(':')[1]
66 self
._so
_port
= so_port
68 self
._http
_client
= http
.Http(
69 'https://{}:{}/osm'.format(self
._host
,self
._so
_port
))
70 self
._headers
['Accept'] = 'application/json'
71 self
._headers
['Content-Type'] = 'application/yaml'
72 http_header
= ['{}: {}'.format(key
, val
)
73 for (key
, val
) in list(self
._headers
.items())]
74 self
._http
_client
.set_http_header(http_header
)
76 self
.vnfd
= vnfd
.Vnfd(self
._http
_client
, client
=self
)
77 self
.nsd
= nsd
.Nsd(self
._http
_client
, client
=self
)
78 self
.nst
= nst
.Nst(self
._http
_client
, client
=self
)
79 self
.package
= package
.Package(self
._http
_client
, client
=self
)
80 self
.ns
= ns
.Ns(self
._http
_client
, client
=self
)
81 self
.nsi
= nsi
.Nsi(self
._http
_client
, client
=self
)
82 self
.vim
= vim
.Vim(self
._http
_client
, client
=self
)
83 self
.wim
= wim
.Wim(self
._http
_client
, client
=self
)
84 self
.sdnc
= sdncontroller
.SdnController(self
._http
_client
, client
=self
)
85 self
.vnf
= vnf
.Vnf(self
._http
_client
, client
=self
)
86 self
.project
= projectmodule
.Project(self
._http
_client
, client
=self
)
87 self
.user
= usermodule
.User(self
._http
_client
, client
=self
)
88 self
.role
= role
.Role(self
._http
_client
, client
=self
)
89 self
.pdu
= pdud
.Pdu(self
._http
_client
, client
=self
)
92 self.vca = vca.Vca(http_client, client=self, **kwargs)
93 self.utils = utils.Utils(http_client, **kwargs)
95 self
.package_tool
= package_tool
.PackageTool(client
=self
)
98 if self
._token
is None:
99 postfields_dict
= {'username': self
._user
,
100 'password': self
._password
,
101 'project_id': self
._project
}
102 http_code
, resp
= self
._http
_client
.post_cmd(endpoint
=self
._auth
_endpoint
,
103 postfields_dict
=postfields_dict
)
104 if http_code
not in (200, 201, 202, 204):
105 message
='Authentication error: not possible to get auth token\nresp:\n{}'.format(resp
)
106 raise ClientException(message
)
108 token
= json
.loads(resp
) if resp
else None
109 self
._token
= token
['id']
111 if self
._token
is not None:
112 self
._headers
['Authorization'] = 'Bearer {}'.format(self
._token
)
113 http_header
= ['{}: {}'.format(key
, val
)
114 for (key
, val
) in list(self
._headers
.items())]
115 self
._http
_client
.set_http_header(http_header
)