5dd6f066b7bf00875d1f78a491c359ce3c52d37f
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
.sol005
import k8scluster
38 from osmclient
.sol005
import vca
39 from osmclient
.sol005
import paas
40 from osmclient
.sol005
import repo
41 from osmclient
.sol005
import osmrepo
42 from osmclient
.sol005
import subscription
43 from osmclient
.common
import package_tool
44 from osmclient
.common
.exceptions
import ClientException
61 self
._password
= password
62 self
._project
= project
63 self
._project
_domain
_name
= kwargs
.get("project_domain_name")
64 self
._user
_domain
_name
= kwargs
.get("user_domain_name")
65 self
._logger
= logging
.getLogger("osmclient")
66 self
._auth
_endpoint
= "/admin/v1/tokens"
69 if len(host
.split(":")) > 1:
70 # backwards compatible, port provided as part of host
71 self
._host
= host
.split(":")[0]
72 self
._so
_port
= host
.split(":")[1]
75 self
._so
_port
= so_port
77 self
._http
_client
= http
.Http(
78 "https://{}:{}/osm".format(self
._host
, self
._so
_port
), **kwargs
80 self
._headers
["Accept"] = "application/json"
81 self
._headers
["Content-Type"] = "application/yaml"
83 "{}: {}".format(key
, val
) for (key
, val
) in list(self
._headers
.items())
85 self
._http
_client
.set_http_header(http_header
)
87 self
.vnfd
= vnfd
.Vnfd(self
._http
_client
, client
=self
)
88 self
.nsd
= nsd
.Nsd(self
._http
_client
, client
=self
)
89 self
.nst
= nst
.Nst(self
._http
_client
, client
=self
)
90 self
.package
= package
.Package(self
._http
_client
, client
=self
)
91 self
.ns
= ns
.Ns(self
._http
_client
, client
=self
)
92 self
.nsi
= nsi
.Nsi(self
._http
_client
, client
=self
)
93 self
.vim
= vim
.Vim(self
._http
_client
, client
=self
)
94 self
.wim
= wim
.Wim(self
._http
_client
, client
=self
)
95 self
.sdnc
= sdncontroller
.SdnController(self
._http
_client
, client
=self
)
96 self
.vnf
= vnf
.Vnf(self
._http
_client
, client
=self
)
97 self
.project
= projectmodule
.Project(self
._http
_client
, client
=self
)
98 self
.user
= usermodule
.User(self
._http
_client
, client
=self
)
99 self
.role
= role
.Role(self
._http
_client
, client
=self
)
100 self
.pdu
= pdud
.Pdu(self
._http
_client
, client
=self
)
101 self
.k8scluster
= k8scluster
.K8scluster(self
._http
_client
, client
=self
)
102 self
.vca
= vca
.VCA(self
._http
_client
, client
=self
)
103 self
.paas
= paas
.PAAS(self
._http
_client
, client
=self
)
104 self
.repo
= repo
.Repo(self
._http
_client
, client
=self
)
105 self
.osmrepo
= osmrepo
.OSMRepo(self
._http
_client
, client
=self
)
106 self
.package_tool
= package_tool
.PackageTool(client
=self
)
107 self
.subscription
= subscription
.Subscription(self
._http
_client
, client
=self
)
109 self.vca = vca.Vca(http_client, client=self, **kwargs)
110 self.utils = utils.Utils(http_client, **kwargs)
113 def get_token(self
, pwd_change
=None):
114 self
._logger
.debug("")
115 if self
._token
is None:
117 "username": self
._user
,
118 "password": self
._password
,
119 "project_id": self
._project
,
121 if self
._project
_domain
_name
:
122 postfields_dict
["project_domain_name"] = self
._project
_domain
_name
123 if self
._user
_domain
_name
:
124 postfields_dict
["user_domain_name"] = self
._user
_domain
_name
125 http_code
, resp
= self
._http
_client
.post_cmd(
126 endpoint
=self
._auth
_endpoint
,
127 postfields_dict
=postfields_dict
,
128 skip_query_admin
=True,
130 # if http_code not in (200, 201, 202, 204):
131 # message ='Authentication error: not possible to get auth token\nresp:\n{}'.format(resp)
132 # raise ClientException(message)
134 token
= json
.loads(resp
) if resp
else None
135 if token
.get("message") == "change_password" and not pwd_change
:
136 raise ClientException(
137 "Password Expired. Please update the password using change_password option"
139 self
._token
= token
["id"]
141 if self
._token
is not None:
142 self
._headers
["Authorization"] = "Bearer {}".format(self
._token
)
144 "{}: {}".format(key
, val
)
145 for (key
, val
) in list(self
._headers
.items())
147 self
._http
_client
.set_http_header(http_header
)
149 def get_version(self
):
150 _
, resp
= self
._http
_client
.get2_cmd(endpoint
="/version", skip_query_admin
=True)
151 # print(http_code, resp)
153 resp
= json
.loads(resp
)
154 version
= resp
.get("version")
155 date
= resp
.get("date")
157 version
= resp
.split()[2]
158 date
= resp
.split()[4]
159 return "{} {}".format(version
, date
)
161 def set_default_params(self
, **kwargs
):
162 host
= kwargs
.pop("host", None)
165 port
= kwargs
.pop("port", None)
168 self
._http
_client
.set_query_admin(**kwargs
)