67
67
if "HPECP_CONFIG_FILE" in os .environ :
68
68
HPECP_CONFIG_FILE = os .getenv ("HPECP_CONFIG_FILE" )
69
69
_log .debug (
70
- "HPECP_CONFIG_FILE envirionment variable exists with value '{}'" .format (
70
+ "HPECP_CONFIG_FILE env variable exists with value '{}'" .format (
71
71
HPECP_CONFIG_FILE
72
72
)
73
73
)
74
74
else :
75
75
HPECP_CONFIG_FILE = "~/.hpecp.conf"
76
76
_log .debug (
77
- "HPECP_CONFIG_FILE envirionment variable not found, setting to '{}'" .format (
77
+ "HPECP_CONFIG_FILE env variable not found, setting to '{}'" .format (
78
78
HPECP_CONFIG_FILE
79
79
)
80
80
)
81
81
82
82
83
83
def get_client ():
84
- """Utility function to retrieve an authenticated client object"""
84
+ """Utility function to retrieve an authenticated client object. """
85
85
try :
86
86
client = ContainerPlatformClient .create_from_config_file (
87
87
config_file = HPECP_CONFIG_FILE , profile = PROFILE ,
@@ -114,10 +114,14 @@ def create_with_ssh_key(
114
114
):
115
115
"""Create a Gateway using SSH key authentication
116
116
117
- :param ip: The IP address of the proxy host. Used for internal communication.
118
- :param proxy_node_hostname: Clients will access cluster services will be accessed using this name.
119
- :param ssh_key: The ssh key data as a string. Alternatively, use the ssh_key_file parameter.
120
- :param ssh_key_file: The file path to the ssh key. Alternatively, use the ssh_key parameter.
117
+ :param ip: The IP address of the proxy host. Used for internal
118
+ communication.
119
+ :param proxy_node_hostname: Clients will access cluster services will
120
+ be accessed using this name.
121
+ :param ssh_key: The ssh key data as a string. Alternatively, use the
122
+ ssh_key_file parameter.
123
+ :param ssh_key_file: The file path to the ssh key. Alternatively, use
124
+ the ssh_key parameter.
121
125
:param tags: Tags to use, e.g. "{ 'tag1': 'foo', 'tag2', 'bar' }".
122
126
"""
123
127
@@ -154,7 +158,8 @@ def get(
154
158
):
155
159
"""Retrieve a Gateway by Id
156
160
157
- :param gateway_id: the id of the gateway with format: '/api/v1/workers/[0-9]+'
161
+ :param gateway_id: the id of the gateway with format:
162
+ '/api/v1/workers/[0-9]+'
158
163
:param output: how to display the output ['yaml'|'json']
159
164
"""
160
165
response = get_client ().gateway .get (gateway_id )
@@ -172,6 +177,7 @@ def get(
172
177
def list (
173
178
self , output = "table" , columns = Gateway .default_display_fields , query = {}
174
179
):
180
+
175
181
"""Retrieve the list of Gateways
176
182
177
183
:param output: how to display the output [text|table|json]
@@ -180,12 +186,15 @@ def list(
180
186
Example::
181
187
182
188
> hpecp gateway list --output json --query '[0].ip'
189
+
183
190
10.1.0.185
184
-
185
- > hpecp gateway list --output json --query '[*].[ip, purpose, state, hostname]'
186
- [['10.1.0.185', 'proxy', 'installed', 'ip-10-1-0-185.us-west-2.compute.internal']]
187
-
188
- """
191
+
192
+ > hpecp gateway list --output json --query
193
+ '[*].[ip, purpose, state, hostname]'
194
+
195
+ [['10.1.0.185', 'proxy', 'installed',
196
+ 'ip-10-1-0-185.us-west-2.compute.internal']]
197
+ """ # noqa: W293
189
198
if output == "table" :
190
199
print (get_client ().gateway .list ().tabulate (columns = columns ))
191
200
elif output == "text" :
@@ -208,8 +217,10 @@ def delete(
208
217
):
209
218
"""Retrieve a Gateway by Id
210
219
211
- :param gateway_id: the id of the gateway with format: '/api/v1/workers/[0-9]+'
212
- :param wait_for_delete_secs: if 0 return immediately after calling delete
220
+ :param gateway_id: the id of the gateway with format:
221
+ '/api/v1/workers/[0-9]+'
222
+ :param wait_for_delete_secs: if 0 return immediately after calling
223
+ delete
213
224
214
225
wait_for_delete_secs > 0 `calls wait_for_delete()`
215
226
"""
@@ -243,9 +254,11 @@ def wait_for_state(
243
254
"""
244
255
Wait for Gateway to have one or more statuses
245
256
:param gateway_id: Cluster id with format: /api/v1/workers/[0-9]+
246
- :param status: status(es) to wait for with format: ['status1', 'status2', 'statusn'] - set to [] to wait for item to be deleted
257
+ :param status: status(es) to wait for with format: ['status1',
258
+ 'status2', 'statusn'] - set to [] to wait for item to be deleted
247
259
:param timeout_secs: how many secs to wait before exiting
248
- :returns True/False if status was found within timeout_secs. May raise APIException.
260
+ :returns True/False if status was found within timeout_secs. May raise
261
+ APIException.
249
262
250
263
See also: `hpecp gateway states`
251
264
"""
@@ -277,9 +290,12 @@ def create_with_ssh_key(
277
290
):
278
291
"""Create a K8s Worker using SSH key authentication
279
292
280
- :param ip: The IP address of the host. Used for internal communication.
281
- :param ssh_key: The ssh key data as a string. Alternatively, use the ssh_key_file parameter.
282
- :param ssh_key_file: The file path to the ssh key. Alternatively, use the ssh_key parameter.
293
+ :param ip: The IP address of the host. Used for internal
294
+ communication.
295
+ :param ssh_key: The ssh key data as a string. Alternatively, use the
296
+ ssh_key_file parameter.
297
+ :param ssh_key_file: The file path to the ssh key. Alternatively, use
298
+ the ssh_key parameter.
283
299
:param tags: Tags to use, e.g. "{ 'tag1': 'foo', 'tag2', 'bar' }".
284
300
"""
285
301
if ssh_key is None and ssh_key_file is None :
@@ -326,16 +342,20 @@ def list(
326
342
> hpecp k8sworker list --output json --query '[0].ip'
327
343
10.1.0.185
328
344
329
- > hpecp k8sworker list --output json --query "[*].[status, hostname, ipaddr]"
330
- [['configured', 'ip-10-1-0-72.us-west-2.compute.internal', '10.1.0.72'],
331
- ['configured', 'ip-10-1-0-238.us-west-2.compute.internal', '10.1.0.238']]
345
+ > hpecp k8sworker list --output json --query "[*].[status, hostname,
346
+ ipaddr]"
347
+
348
+ [['configured', 'ip-10-1-0-72.us-west-2.compute.internal', '10.1.0.72']
349
+ ,['configured', 'ip-10-1-0-238.us-west-2.compute.internal',
350
+ '10.1.0.238']]
332
351
333
352
# Using jq to convert the json output to a table
334
- > hpecp k8sworker list --output json --query "[*].[status, hostname, ipaddr]" | jq -r '.[] | @csv'
353
+ > hpecp k8sworker list --output json --query "[*].[status, hostname,
354
+ ipaddr]" | jq -r '.[] | @csv'
335
355
"configured","ip-10-1-0-72.us-west-2.compute.internal","10.1.0.72"
336
356
"configured","ip-10-1-0-238.us-west-2.compute.internal","10.1.0.238"
337
357
338
- """
358
+ """ # noqa: W293
339
359
if output == "table" :
340
360
print (get_client ().k8s_worker .list ().tabulate (columns = columns ))
341
361
elif output == "text" :
@@ -380,8 +400,10 @@ def set_storage(
380
400
"""Set Storage
381
401
382
402
:param k8sworker_id: the worker ID
383
- :param persistent_disks: a comma separated list of zero or more persistent disks, e.g. "/dev/nvme2n1"
384
- :param ephemeral_disks: a comma separated list of zero or more ephemeral_disks disks, e.g. "/dev/nvme1n1"
403
+ :param persistent_disks: a comma separated list of zero or more
404
+ persistent disks, e.g. "/dev/nvme2n1"
405
+ :param ephemeral_disks: a comma separated list of zero or more
406
+ ephemeral_disks disks, e.g. "/dev/nvme1n1"
385
407
"""
386
408
387
409
p_disks = persistent_disks .split ("," )
@@ -399,9 +421,11 @@ def wait_for_status(
399
421
"""
400
422
Wait for Worker to have one or more statuses
401
423
:param worker_id: Worker id with format: /api/v1/workers/[0-9]+
402
- :param status: status(es) to wait for with format: ['status1', 'status2', 'statusn'] - set to [] to wait for item to be deleted
424
+ :param status: status(es) to wait for with format: ['status1',
425
+ 'status2', 'statusn'] - set to [] to wait for item to be deleted
403
426
:param timeout_secs: how many secs to wait before exiting
404
- :returns True/False if status was found within timeout_secs. May raise APIException.
427
+ :returns True/False if status was found within timeout_secs. May raise
428
+ APIException.
405
429
406
430
See also: `hpecp k8sworker states`
407
431
"""
@@ -447,11 +471,14 @@ def create(
447
471
"""Create a K8s Cluster
448
472
449
473
:param name: the cluster name
450
- :param k8shosts_config: k8s host ids and roles 'id1:master|worker,id2:master|worker,...'
474
+ :param k8shosts_config: k8s host ids and roles 'id1:master|worker,id2:
475
+ master|worker,...'
451
476
:param description: the cluster descripton
452
477
:param k8s_version: e.g. 1.17.0
453
- :param pod_network_range: the pod network range, default='10.192.0.0/12'
454
- :param service_network_range: the service network range, default='10.96.0.0/12'
478
+ :param pod_network_range: the pod network range,
479
+ default='10.192.0.0/12'
480
+ :param service_network_range: the service network range,
481
+ default='10.96.0.0/12'
455
482
:param pod_dns_domain: the pod dns domain, default='cluster.local'
456
483
:param persistent_storage_local: True/False
457
484
:param persistent_storage_nimble_csi: True/False
@@ -570,9 +597,11 @@ def wait_for_status(
570
597
"""
571
598
Wait for K8s Cluster to have one or more statuses
572
599
:param k8scluster_id: Cluster id with format: /api/v2/k8scluster/[0-9]+
573
- :param status: status(es) to wait for with format: ['status1', 'status2', 'statusn']
600
+ :param status: status(es) to wait for with format:
601
+ ['status1', 'status2', 'statusn']
574
602
:param timeout_secs: how many secs to wait before exiting
575
- :returns True/False if status was found within timeout_secs. May raise APIException.
603
+ :returns True/False if status was found within timeout_secs. May
604
+ raise APIException.
576
605
"""
577
606
cluster_status = [K8sClusterStatus [s ] for s in status ]
578
607
@@ -582,7 +611,7 @@ def wait_for_status(
582
611
status = cluster_status ,
583
612
timeout_secs = timeout_secs ,
584
613
)
585
- except :
614
+ except Exception :
586
615
success = False
587
616
588
617
if not success :
@@ -614,7 +643,8 @@ def k8s_supported_versions(
614
643
615
644
Example::
616
645
617
- hpecp k8scluster k8s_supported_versions --major-filter 1 --minor-filter 17
646
+ hpecp k8scluster k8s_supported_versions --major-filter 1
647
+ --minor-filter 17
618
648
"""
619
649
assert output in [
620
650
"json" ,
@@ -739,7 +769,8 @@ def register(
739
769
):
740
770
"""Register a license
741
771
742
- :param server_filename: Filepath to the license on the server, e.g. '/srv/bluedata/license/LICENSE-1.txt'
772
+ :param server_filename: Filepath to the license on the server, e.g.
773
+ '/srv/bluedata/license/LICENSE-1.txt'
743
774
"""
744
775
get_client ().license .register (server_filename = server_filename )
745
776
print ("Done." )
@@ -763,7 +794,8 @@ def upload_with_ssh_key(
763
794
- run client.license.register(server_filename) to register the license
764
795
"""
765
796
raise Exception (
766
- "Not implemented yet! Workaround: scp your license to '/srv/bluedata/license/'"
797
+ "Not implemented yet! Workaround: scp your license to"
798
+ "'/srv/bluedata/license/'"
767
799
)
768
800
769
801
def upload_with_ssh_pass (
@@ -785,17 +817,20 @@ def upload_with_ssh_pass(
785
817
- run client.license.register(server_filename) to register the license
786
818
"""
787
819
raise Exception (
788
- "Not implemented yet! Workaround: scp your license to '/srv/bluedata/license/'"
820
+ "Not implemented yet! Workaround: scp your license to"
821
+ "'/srv/bluedata/license/'"
789
822
)
790
823
791
824
def delete (
792
825
self , license_key ,
793
826
):
794
827
"""Delete a license by LicenseKey
795
828
796
- :param license_key: The license key, e.g. '1234 1234 ... 1234 "SOMETEXT"'
829
+ :param license_key: The license key, e.g. '1234 1234 ... 1234
830
+ "SOMETEXT"'
797
831
798
- TIP: use `hpecp license list --license_key_only True` to get the license key
832
+ TIP: use `hpecp license list --license_key_only True` to get the
833
+ license key
799
834
"""
800
835
get_client ().license .delete (license_key = license_key )
801
836
print ("Delete submitted - verify with: `hpecp license list`" )
@@ -882,7 +917,7 @@ def put(
882
917
Example:
883
918
884
919
hpecp httpclient put /api/v2/config/auth --json-file my.json
885
- """
920
+ """ # noqa: W293
886
921
with open (json_file , "r" ,) as f :
887
922
data = json .load (f )
888
923
@@ -1037,7 +1072,7 @@ def bash(self,):
1037
1072
1038
1073
} &&
1039
1074
complete -F _hpecp_complete hpecp
1040
- """
1075
+ """ # noqa: E501
1041
1076
)
1042
1077
1043
1078
@@ -1063,6 +1098,9 @@ def configure_cli():
1063
1098
controller_username = config_reader .username
1064
1099
controller_password = config_reader .password
1065
1100
1101
+ if sys .version_info [0 ] >= 3 :
1102
+ raw_input = input
1103
+
1066
1104
sys .stdout .write ("Controller API Host [{}]: " .format (controller_api_host ))
1067
1105
tmp = raw_input ()
1068
1106
if tmp != "" :
0 commit comments