72
72
73
73
_log = Logger .get_logger ()
74
74
75
- PROFILE = os .getenv ("PROFILE" , default = "default" )
76
-
77
- _log .debug (
78
- "PROFILE envirionment variable exists with value '{}'" .format (PROFILE )
79
- )
80
-
81
-
82
- def get_config_file ():
83
- """Retrieve the CLI config file."""
84
- return base .get_config_file ()
85
-
86
75
87
76
@wrapt .decorator
88
77
def intercept_exception (wrapped , instance , args , kwargs ):
@@ -126,17 +115,6 @@ def _unknown_exception_handler(ex):
126
115
_unknown_exception_handler (ex )
127
116
128
117
129
- @intercept_exception
130
- def get_client (start_session = True ):
131
- """Retrieve a reference to an authenticated client object."""
132
- client = ContainerPlatformClient .create_from_config_file (
133
- config_file = get_config_file (), profile = PROFILE ,
134
- )
135
- if start_session :
136
- client .create_session ()
137
- return client
138
-
139
-
140
118
class K8sClusterProxy (base .BaseProxy ):
141
119
"""Proxy object to :py:attr:`<hpecp.client.k8s_cluster>`."""
142
120
@@ -200,7 +178,7 @@ def create(
200
178
]
201
179
202
180
print (
203
- get_client ().k8s_cluster .create (
181
+ base . get_client ().k8s_cluster .create (
204
182
name = name ,
205
183
description = description ,
206
184
k8s_version = k8s_version ,
@@ -220,7 +198,7 @@ def admin_kube_config(self, id):
220
198
:param id: the cluster ID
221
199
"""
222
200
print (
223
- get_client ()
201
+ base . get_client ()
224
202
.k8s_cluster .get (id )
225
203
.admin_kube_config .replace ("\\ n" , "\n " ,)
226
204
)
@@ -232,7 +210,9 @@ def dashboard_url(
232
210
233
211
:param id: the cluster ID
234
212
"""
235
- url = get_client ().k8s_cluster .get (id = id ).dashboard_endpoint_access
213
+ url = (
214
+ base .get_client ().k8s_cluster .get (id = id ).dashboard_endpoint_access
215
+ )
236
216
print (url )
237
217
238
218
def dashboard_token (
@@ -242,7 +222,7 @@ def dashboard_token(
242
222
243
223
:param id: the cluster ID
244
224
"""
245
- token = get_client ().k8s_cluster .get (id = id ).dashboard_token
225
+ token = base . get_client ().k8s_cluster .get (id = id ).dashboard_token
246
226
if six .PY2 :
247
227
print (base64 .b64decode (token .encode ()))
248
228
else :
@@ -251,7 +231,7 @@ def dashboard_token(
251
231
@intercept_exception
252
232
def k8smanifest (self ):
253
233
"""Retrieve the k8smanifest."""
254
- response = get_client ().k8s_cluster .k8smanifest ()
234
+ response = base . get_client ().k8s_cluster .k8smanifest ()
255
235
print (
256
236
yaml .dump (yaml .load (json .dumps (response ), Loader = yaml .FullLoader ,))
257
237
)
@@ -261,7 +241,7 @@ def get_installed_addons(self, id):
261
241
262
242
:param id: get installed addons for a specific cluster
263
243
"""
264
- print (get_client ().k8s_cluster .get (id = id ).addons )
244
+ print (base . get_client ().k8s_cluster .get (id = id ).addons )
265
245
266
246
def get_available_addons (self , id = None , k8s_version = None ):
267
247
"""Retrieve the available addons for a cluster.
@@ -284,10 +264,10 @@ def get_available_addons(self, id=None, k8s_version=None):
284
264
sys .exit (1 )
285
265
286
266
if id :
287
- print (get_client ().k8s_cluster .get_available_addons (id = id ))
267
+ print (base . get_client ().k8s_cluster .get_available_addons (id = id ))
288
268
else :
289
269
print (
290
- get_client ().k8s_cluster .get_available_addons (
270
+ base . get_client ().k8s_cluster .get_available_addons (
291
271
k8s_version = k8s_version
292
272
)
293
273
)
@@ -310,7 +290,7 @@ def add_addons(self, id, addons, wait_for_ready_sec=0):
310
290
)
311
291
sys .exit (1 )
312
292
313
- get_client ().k8s_cluster .add_addons (id = id , addons = addons )
293
+ base . get_client ().k8s_cluster .add_addons (id = id , addons = addons )
314
294
315
295
if wait_for_ready_sec > 0 :
316
296
self .wait_for_status (
@@ -371,7 +351,7 @@ def k8s_supported_versions(
371
351
patch_filter = int (patch_filter )
372
352
373
353
vers = []
374
- for v in get_client ().k8s_cluster .k8s_supported_versions ():
354
+ for v in base . get_client ().k8s_cluster .k8s_supported_versions ():
375
355
(major , minor , patch ) = v .split ("." )
376
356
major = int (major )
377
357
minor = int (minor )
@@ -437,7 +417,7 @@ def create(
437
417
k8s_cluster_id : [type], optional
438
418
[description], by default None
439
419
"""
440
- tenant_id = get_client ().tenant .create (
420
+ tenant_id = base . get_client ().tenant .create (
441
421
name = name ,
442
422
description = description ,
443
423
tenant_type = tenant_type ,
@@ -469,7 +449,7 @@ def k8skubeconfig(self):
469
449
str
470
450
Tenant KubeConfig
471
451
"""
472
- conf = get_client ().tenant .k8skubeconfig ()
452
+ conf = base . get_client ().tenant .k8skubeconfig ()
473
453
print (conf )
474
454
475
455
@intercept_exception
@@ -481,7 +461,7 @@ def users(self, id, output="table", columns="ALL", query={}):
481
461
id : str
482
462
The tenant ID.
483
463
"""
484
- list_instance = get_client ().tenant .users (id = id )
464
+ list_instance = base . get_client ().tenant .users (id = id )
485
465
self .print_list (
486
466
list_instance = list_instance ,
487
467
output = output ,
@@ -492,28 +472,30 @@ def users(self, id, output="table", columns="ALL", query={}):
492
472
@intercept_exception
493
473
def assign_user_to_role (self , tenant_id , user_id , role_id ):
494
474
"""Assign user to role in tenant."""
495
- get_client ().tenant .assign_user_to_role (
475
+ base . get_client ().tenant .assign_user_to_role (
496
476
tenant_id = tenant_id , user_id = user_id , role_id = role_id
497
477
)
498
478
499
479
@intercept_exception
500
480
def get_external_user_groups (self , tenant_id ):
501
481
"""Retrieve External User Groups."""
502
482
print (
503
- get_client ().tenant .get_external_user_groups (tenant_id = tenant_id )
483
+ base .get_client ().tenant .get_external_user_groups (
484
+ tenant_id = tenant_id
485
+ )
504
486
)
505
487
506
488
@intercept_exception
507
489
def add_external_user_group (self , tenant_id , group , role_id ):
508
490
"""Add External User Group."""
509
- get_client ().tenant .add_external_user_group (
491
+ base . get_client ().tenant .add_external_user_group (
510
492
tenant_id = tenant_id , group = group , role_id = role_id
511
493
)
512
494
513
495
@intercept_exception
514
496
def delete_external_user_group (self , tenant_id , group ):
515
497
"""Delete External User Group."""
516
- get_client ().tenant .delete_external_user_group (
498
+ base . get_client ().tenant .delete_external_user_group (
517
499
tenant_id = tenant_id , group = group
518
500
)
519
501
@@ -543,7 +525,7 @@ def list(
543
525
)
544
526
sys .exit (1 )
545
527
546
- response = get_client ().lock .get ()
528
+ response = base . get_client ().lock .get ()
547
529
548
530
if output == "yaml" :
549
531
print (
@@ -559,21 +541,21 @@ def create(
559
541
self , reason ,
560
542
):
561
543
"""Create a lock."""
562
- print (get_client ().lock .create (reason ), file = sys .stdout )
544
+ print (base . get_client ().lock .create (reason ), file = sys .stdout )
563
545
564
546
@intercept_exception
565
547
def delete (
566
548
self , id ,
567
549
):
568
550
"""Delete a user lock."""
569
- get_client ().lock .delete (id )
551
+ base . get_client ().lock .delete (id )
570
552
571
553
@intercept_exception
572
554
def delete_all (
573
555
self , timeout_secs = 300 ,
574
556
):
575
557
"""Delete all locks."""
576
- success = get_client ().lock .delete_all (timeout_secs = timeout_secs )
558
+ success = base . get_client ().lock .delete_all (timeout_secs = timeout_secs )
577
559
if not success :
578
560
print ("Could not delete locks." , file = sys .stderr )
579
561
sys .exit (1 )
@@ -589,7 +571,7 @@ def __dir__(self):
589
571
@intercept_exception
590
572
def platform_id (self ,):
591
573
"""Get the platform ID."""
592
- print (get_client ().license .platform_id ())
574
+ print (base . get_client ().license .platform_id ())
593
575
594
576
def list (
595
577
self , output = "yaml" , license_key_only = False ,
@@ -598,7 +580,7 @@ def list(
598
580
599
581
:param output: how to display the output ['yaml'|'json']
600
582
"""
601
- response = get_client ().license .list ()
583
+ response = base . get_client ().license .list ()
602
584
if license_key_only :
603
585
response = [
604
586
str (unicode (li ["LicenseKey" ])) for li in response ["Licenses" ]
@@ -625,7 +607,9 @@ def register(
625
607
:param server_filename: Filepath to the license on the server, e.g.
626
608
'/srv/bluedata/license/LICENSE-1.txt'
627
609
"""
628
- print (get_client ().license .register (server_filename = server_filename ))
610
+ print (
611
+ base .get_client ().license .register (server_filename = server_filename )
612
+ )
629
613
630
614
# TODO implement me!
631
615
# def upload_with_ssh_key(
@@ -680,17 +664,17 @@ def delete(
680
664
:param license_key: The license key, e.g. '1234 1234 ... 1234
681
665
"SOMETEXT"'
682
666
"""
683
- get_client ().license .delete (license_key = license_key )
667
+ base . get_client ().license .delete (license_key = license_key )
684
668
685
669
@intercept_exception
686
670
def delete_all (self ,):
687
671
"""Delete all licenses."""
688
- response = get_client ().license .list ()
672
+ response = base . get_client ().license .list ()
689
673
all_license_keys = [
690
674
str (unicode (li ["LicenseKey" ])) for li in response ["Licenses" ]
691
675
]
692
676
for licence_key in all_license_keys :
693
- get_client ().license .delete (license_key = licence_key )
677
+ base . get_client ().license .delete (license_key = licence_key )
694
678
695
679
696
680
class HttpClientProxy (object ):
@@ -710,7 +694,7 @@ def get(
710
694
--------
711
695
$ hpecp httpclient get /api/v1/workers
712
696
"""
713
- response = get_client ()._request (
697
+ response = base . get_client ()._request (
714
698
url , http_method = "get" , description = "CLI HTTP GET" ,
715
699
)
716
700
print (response .text , file = sys .stdout )
@@ -725,7 +709,7 @@ def delete(
725
709
--------
726
710
$ hpecp httpclient delete /api/v1/workers/1
727
711
"""
728
- get_client ()._request (
712
+ base . get_client ()._request (
729
713
url , http_method = "delete" , description = "CLI HTTP DELETE" ,
730
714
)
731
715
@@ -759,7 +743,7 @@ def post(
759
743
with open (json_file , "r" ,) as f :
760
744
data = json .load (f )
761
745
762
- response = get_client ()._request (
746
+ response = base . get_client ()._request (
763
747
url , http_method = "post" , data = data , description = "CLI HTTP POST" ,
764
748
)
765
749
print (response .text , file = sys .stdout )
@@ -777,7 +761,7 @@ def put(
777
761
with open (json_file , "r" ,) as f :
778
762
data = json .load (f )
779
763
780
- response = get_client ()._request (
764
+ response = base . get_client ()._request (
781
765
url , http_method = "put" , data = data , description = "CLI HTTP PUT" ,
782
766
)
783
767
print (response .text , file = sys .stdout )
@@ -805,7 +789,7 @@ def create(
805
789
:param description: the user descripton
806
790
807
791
"""
808
- user_id = get_client ().user .create (
792
+ user_id = base . get_client ().user .create (
809
793
name = name ,
810
794
password = password ,
811
795
description = description ,
0 commit comments