1 # -*- coding: utf-8 -*-
5 from typing
import Optional
7 from mgr_module
import CLICheckNonemptyFileInput
, CLIReadCommand
, CLIWriteCommand
9 from ..rest_client
import RequestException
10 from .iscsi_client
import IscsiClient
11 from .iscsi_config
import InvalidServiceUrl
, IscsiGatewayAlreadyExists
, \
12 IscsiGatewayDoesNotExist
, IscsiGatewaysConfig
, \
13 ManagedByOrchestratorException
16 @CLIReadCommand('dashboard iscsi-gateway-list')
17 def list_iscsi_gateways(_
):
21 return 0, json
.dumps(IscsiGatewaysConfig
.get_gateways_config()), ''
24 @CLIWriteCommand('dashboard iscsi-gateway-add')
25 @CLICheckNonemptyFileInput(desc
='iSCSI gateway configuration')
26 def add_iscsi_gateway(_
, inbuf
, name
: Optional
[str] = None):
28 Add iSCSI gateway configuration. Gateway URL read from -i <file>
32 IscsiGatewaysConfig
.validate_service_url(service_url
)
34 name
= IscsiClient
.instance(service_url
=service_url
).get_hostname()['data']
35 IscsiGatewaysConfig
.add_gateway(name
, service_url
)
36 return 0, 'Success', ''
37 except IscsiGatewayAlreadyExists
as ex
:
38 return -errno
.EEXIST
, '', str(ex
)
39 except InvalidServiceUrl
as ex
:
40 return -errno
.EINVAL
, '', str(ex
)
41 except ManagedByOrchestratorException
as ex
:
42 return -errno
.EINVAL
, '', str(ex
)
43 except RequestException
as ex
:
44 return -errno
.EINVAL
, '', str(ex
)
47 @CLIWriteCommand('dashboard iscsi-gateway-rm')
48 def remove_iscsi_gateway(_
, name
: str):
50 Remove iSCSI gateway configuration
53 IscsiGatewaysConfig
.remove_gateway(name
)
54 return 0, 'Success', ''
55 except IscsiGatewayDoesNotExist
as ex
:
56 return -errno
.ENOENT
, '', str(ex
)
57 except ManagedByOrchestratorException
as ex
:
58 return -errno
.EINVAL
, '', str(ex
)