34
34
35
35
from jinja2 import Environment
36
36
import six
37
- import traceback
38
37
import yaml
39
- import wrapt
40
-
41
- from hpecp import (
42
- APIException ,
43
- APIItemConflictException ,
44
- ContainerPlatformClient ,
45
- ContainerPlatformClientException ,
46
- )
38
+
47
39
from hpecp .logger import Logger
48
- from hpecp .exceptions import (
49
- APIForbiddenException ,
50
- APIItemNotFoundException ,
51
- APIUnknownException ,
52
- )
53
40
from textwrap import dedent
54
41
import inspect
55
42
import collections
56
- from hpecp .tenant import Tenant
57
43
from hpecp .user import User
58
44
from hpecp .role import Role
59
45
from hpecp .cli import base
60
46
from hpecp .cli .catalog import CatalogProxy
61
47
from hpecp .cli .gateway import GatewayProxy
62
48
from hpecp .cli .k8sworker import K8sWorkerProxy
63
49
from hpecp .cli .k8scluster import K8sClusterProxy
50
+ from hpecp .cli .tenant import TenantProxy
51
+ from hpecp import ContainerPlatformClient
52
+
64
53
65
54
if sys .version_info [0 ] >= 3 :
66
55
unicode = str
67
56
68
57
_log = Logger .get_logger ()
69
58
70
59
71
- @wrapt .decorator
72
- def intercept_exception (wrapped , instance , args , kwargs ):
73
- """Handle Exceptions.""" # noqa: D202
74
-
75
- def _unknown_exception_handler (ex ):
76
- """Handle unknown exceptions."""
77
- if _log .level == 10 : # "DEBUG"
78
- print (
79
- "Unknown error." , file = sys .stderr ,
80
- )
81
- else :
82
- print (
83
- "Unknown error. To debug run with env var LOG_LEVEL=DEBUG" ,
84
- file = sys .stderr ,
85
- )
86
- tb = traceback .format_exc ()
87
- _log .debug (tb )
88
- _log .debug (ex )
89
- sys .exit (1 )
90
-
91
- try :
92
- return wrapped (* args , ** kwargs )
93
- except SystemExit as se :
94
- sys .exit (se .code )
95
- except AssertionError as ae :
96
- print (ae , file = sys .stderr )
97
- sys .exit (1 )
98
- except APIUnknownException as ue :
99
- _unknown_exception_handler (ue )
100
- except (
101
- APIException ,
102
- APIItemNotFoundException ,
103
- APIItemConflictException ,
104
- APIForbiddenException ,
105
- ContainerPlatformClientException ,
106
- ) as e :
107
- print (e .message , file = sys .stderr )
108
- sys .exit (1 )
109
- except Exception as ex :
110
- _unknown_exception_handler (ex )
111
-
112
-
113
- class TenantProxy (base .BaseProxy ):
114
- """Proxy object to :py:attr:`<hpecp.client.tenant>`."""
115
-
116
- def __dir__ (self ):
117
- """Return the CLI method names."""
118
- return [
119
- "add_external_user_group" ,
120
- "assign_user_to_role" ,
121
- "create" ,
122
- "delete" ,
123
- "delete_external_user_group" ,
124
- "examples" ,
125
- "get" ,
126
- "get_external_user_groups" ,
127
- "k8skubeconfig" ,
128
- "list" ,
129
- # "status", # TODO: implement me!
130
- "users" ,
131
- "wait_for_status" ,
132
- ]
133
-
134
- def __init__ (self ):
135
- """Create instance of proxy class with the client module name."""
136
- super (TenantProxy , self ).new_instance ("tenant" , Tenant )
137
-
138
- @intercept_exception
139
- def create (
140
- self ,
141
- name = None ,
142
- description = None ,
143
- tenant_type = None ,
144
- k8s_cluster_id = None ,
145
- ):
146
- """Create a tenant.
147
-
148
- Parameters
149
- ----------
150
- name : [type], optional
151
- [description], by default None
152
- description : [type], optional
153
- [description], by default None
154
- tenant_type : [type], optional
155
- [description], by default None
156
- k8s_cluster_id : [type], optional
157
- [description], by default None
158
- """
159
- tenant_id = base .get_client ().tenant .create (
160
- name = name ,
161
- description = description ,
162
- tenant_type = tenant_type ,
163
- k8s_cluster = k8s_cluster_id ,
164
- )
165
- print (tenant_id )
166
-
167
- def examples (self ):
168
- """Show usage_examples of the list method."""
169
- print (
170
- dedent (
171
- """\
172
-
173
- hpecp tenant list --query "[?tenant_type == 'k8s']" --output json-pp
174
-
175
- """ # noqa: E501
176
- )
177
- )
178
-
179
- @intercept_exception
180
- def k8skubeconfig (self ):
181
- """Retrieve the tenant kubeconfig.
182
-
183
- This requires the ContainerPlatformClient to be created with
184
- a 'tenant' parameter.
185
-
186
- Returns
187
- -------
188
- str
189
- Tenant KubeConfig
190
- """
191
- conf = base .get_client ().tenant .k8skubeconfig ()
192
- print (conf )
193
-
194
- @intercept_exception
195
- def users (self , id , output = "table" , columns = "ALL" , query = {}):
196
- """Retrieve users assigned to tenant.
197
-
198
- Parameters
199
- ----------
200
- id : str
201
- The tenant ID.
202
- """
203
- list_instance = base .get_client ().tenant .users (id = id )
204
- self .print_list (
205
- list_instance = list_instance ,
206
- output = output ,
207
- columns = columns ,
208
- query = query ,
209
- )
210
-
211
- @intercept_exception
212
- def assign_user_to_role (self , tenant_id , user_id , role_id ):
213
- """Assign user to role in tenant."""
214
- base .get_client ().tenant .assign_user_to_role (
215
- tenant_id = tenant_id , user_id = user_id , role_id = role_id
216
- )
217
-
218
- @intercept_exception
219
- def get_external_user_groups (self , tenant_id ):
220
- """Retrieve External User Groups."""
221
- print (
222
- base .get_client ().tenant .get_external_user_groups (
223
- tenant_id = tenant_id
224
- )
225
- )
226
-
227
- @intercept_exception
228
- def add_external_user_group (self , tenant_id , group , role_id ):
229
- """Add External User Group."""
230
- base .get_client ().tenant .add_external_user_group (
231
- tenant_id = tenant_id , group = group , role_id = role_id
232
- )
233
-
234
- @intercept_exception
235
- def delete_external_user_group (self , tenant_id , group ):
236
- """Delete External User Group."""
237
- base .get_client ().tenant .delete_external_user_group (
238
- tenant_id = tenant_id , group = group
239
- )
60
+ # @wrapt.decorator
61
+ # def intercept_exception(wrapped, instance, args, kwargs):
62
+ # """Handle Exceptions.""" # noqa: D202
63
+
64
+ # def _unknown_exception_handler(ex):
65
+ # """Handle unknown exceptions."""
66
+ # if _log.level == 10: # "DEBUG"
67
+ # print(
68
+ # "Unknown error.", file=sys.stderr,
69
+ # )
70
+ # else:
71
+ # print(
72
+ # "Unknown error. To debug run with env var LOG_LEVEL=DEBUG",
73
+ # file=sys.stderr,
74
+ # )
75
+ # tb = traceback.format_exc()
76
+ # _log.debug(tb)
77
+ # _log.debug(ex)
78
+ # sys.exit(1)
79
+
80
+ # try:
81
+ # return wrapped(*args, **kwargs)
82
+ # except SystemExit as se:
83
+ # sys.exit(se.code)
84
+ # except AssertionError as ae:
85
+ # print(ae, file=sys.stderr)
86
+ # sys.exit(1)
87
+ # except APIUnknownException as ue:
88
+ # _unknown_exception_handler(ue)
89
+ # except (
90
+ # APIException,
91
+ # APIItemNotFoundException,
92
+ # APIItemConflictException,
93
+ # APIForbiddenException,
94
+ # ContainerPlatformClientException,
95
+ # ) as e:
96
+ # print(e.message, file=sys.stderr)
97
+ # sys.exit(1)
98
+ # except Exception as ex:
99
+ # _unknown_exception_handler(ex)
240
100
241
101
242
102
class LockProxy (object ):
@@ -275,21 +135,21 @@ def list(
275
135
else :
276
136
print (json .dumps (response ))
277
137
278
- @intercept_exception
138
+ @base . intercept_exception
279
139
def create (
280
140
self , reason ,
281
141
):
282
142
"""Create a lock."""
283
143
print (base .get_client ().lock .create (reason ), file = sys .stdout )
284
144
285
- @intercept_exception
145
+ @base . intercept_exception
286
146
def delete (
287
147
self , id ,
288
148
):
289
149
"""Delete a user lock."""
290
150
base .get_client ().lock .delete (id )
291
151
292
- @intercept_exception
152
+ @base . intercept_exception
293
153
def delete_all (
294
154
self , timeout_secs = 300 ,
295
155
):
@@ -307,7 +167,7 @@ def __dir__(self):
307
167
"""Return the CLI method names."""
308
168
return ["delete" , "delete_all" , "list" , "platform_id" , "register" ]
309
169
310
- @intercept_exception
170
+ @base . intercept_exception
311
171
def platform_id (self ,):
312
172
"""Get the platform ID."""
313
173
print (base .get_client ().license .platform_id ())
@@ -337,7 +197,7 @@ def list(
337
197
else :
338
198
print (json .dumps (response ))
339
199
340
- @intercept_exception
200
+ @base . intercept_exception
341
201
def register (
342
202
self , server_filename ,
343
203
):
@@ -394,7 +254,7 @@ def register(
394
254
# "'/srv/bluedata/license/'"
395
255
# )
396
256
397
- @intercept_exception
257
+ @base . intercept_exception
398
258
def delete (
399
259
self , license_key ,
400
260
):
@@ -405,7 +265,7 @@ def delete(
405
265
"""
406
266
base .get_client ().license .delete (license_key = license_key )
407
267
408
- @intercept_exception
268
+ @base . intercept_exception
409
269
def delete_all (self ,):
410
270
"""Delete all licenses."""
411
271
response = base .get_client ().license .list ()
@@ -423,7 +283,7 @@ def __dir__(self):
423
283
"""Return the CLI method names."""
424
284
return ["delete" , "get" , "post" , "put" ]
425
285
426
- @intercept_exception
286
+ @base . intercept_exception
427
287
def get (
428
288
self , url ,
429
289
):
@@ -438,7 +298,7 @@ def get(
438
298
)
439
299
print (response .text , file = sys .stdout )
440
300
441
- @intercept_exception
301
+ @base . intercept_exception
442
302
def delete (
443
303
self , url ,
444
304
):
@@ -452,7 +312,7 @@ def delete(
452
312
url , http_method = "delete" , description = "CLI HTTP DELETE" ,
453
313
)
454
314
455
- @intercept_exception
315
+ @base . intercept_exception
456
316
def post (
457
317
self , url , json_file = "" ,
458
318
):
@@ -487,7 +347,7 @@ def post(
487
347
)
488
348
print (response .text , file = sys .stdout )
489
349
490
- @intercept_exception
350
+ @base . intercept_exception
491
351
def put (
492
352
self , url , json_file = "" ,
493
353
):
@@ -517,7 +377,7 @@ def __init__(self):
517
377
"""Create instance of proxy class with the client module name."""
518
378
super (UserProxy , self ).new_instance ("user" , User )
519
379
520
- @intercept_exception
380
+ @base . intercept_exception
521
381
def create (
522
382
self , name , password , description , is_external = False ,
523
383
):
0 commit comments