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 'name=name,type=CephString,req=false',
23 'Add iSCSI gateway configuration')
24 def add_iscsi_gateway(_
, service_url
, name
=None):
26 IscsiGatewaysConfig
.validate_service_url(service_url
)
28 name
= IscsiClient
.instance(service_url
=service_url
).get_hostname()['data']
29 IscsiGatewaysConfig
.add_gateway(name
, service_url
)
30 return 0, 'Success', ''
31 except IscsiGatewayAlreadyExists
as ex
:
32 return -errno
.EEXIST
, '', str(ex
)
33 except InvalidServiceUrl
as ex
:
34 return -errno
.EINVAL
, '', str(ex
)
35 except ManagedByOrchestratorException
as ex
:
36 return -errno
.EINVAL
, '', str(ex
)
37 except RequestException
as ex
:
38 return -errno
.EINVAL
, '', str(ex
)
41 @CLIWriteCommand('dashboard iscsi-gateway-rm',
42 'name=name,type=CephString',
43 'Remove iSCSI gateway configuration')
44 def remove_iscsi_gateway(_
, name
):
46 IscsiGatewaysConfig
.remove_gateway(name
)
47 return 0, 'Success', ''
48 except IscsiGatewayDoesNotExist
as ex
:
49 return -errno
.ENOENT
, '', str(ex
)
50 except ManagedByOrchestratorException
as ex
:
51 return -errno
.EINVAL
, '', str(ex
)