1 # -*- coding: utf-8 -*-
2 from __future__
import absolute_import
7 from mgr_module
import CLIReadCommand
, CLIWriteCommand
9 from .iscsi_client
import IscsiClient
10 from .iscsi_config
import IscsiGatewaysConfig
, IscsiGatewayAlreadyExists
, InvalidServiceUrl
, \
11 ManagedByOrchestratorException
, IscsiGatewayDoesNotExist
12 from ..rest_client
import RequestException
15 @CLIReadCommand('dashboard iscsi-gateway-list', desc
='List iSCSI gateways')
16 def list_iscsi_gateways(_
):
17 return 0, json
.dumps(IscsiGatewaysConfig
.get_gateways_config()), ''
20 @CLIWriteCommand('dashboard iscsi-gateway-add',
21 'name=service_url,type=CephString',
22 'Add iSCSI gateway configuration')
23 def add_iscsi_gateway(_
, service_url
):
25 IscsiGatewaysConfig
.validate_service_url(service_url
)
26 name
= IscsiClient
.instance(service_url
=service_url
).get_hostname()['data']
27 IscsiGatewaysConfig
.add_gateway(name
, service_url
)
28 return 0, 'Success', ''
29 except IscsiGatewayAlreadyExists
as ex
:
30 return -errno
.EEXIST
, '', str(ex
)
31 except InvalidServiceUrl
as ex
:
32 return -errno
.EINVAL
, '', str(ex
)
33 except ManagedByOrchestratorException
as ex
:
34 return -errno
.EINVAL
, '', str(ex
)
35 except RequestException
as ex
:
36 return -errno
.EINVAL
, '', str(ex
)
39 @CLIWriteCommand('dashboard iscsi-gateway-rm',
40 'name=name,type=CephString',
41 'Remove iSCSI gateway configuration')
42 def remove_iscsi_gateway(_
, name
):
44 IscsiGatewaysConfig
.remove_gateway(name
)
45 return 0, 'Success', ''
46 except IscsiGatewayDoesNotExist
as ex
:
47 return -errno
.ENOENT
, '', str(ex
)
48 except ManagedByOrchestratorException
as ex
:
49 return -errno
.EINVAL
, '', str(ex
)