1 # -*- coding: utf-8 -*-
2 from __future__
import absolute_import
7 from mgr_module
import CLICheckNonemptyFileInput
, 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=name,type=CephString,req=false',
22 'Add iSCSI gateway configuration. Gateway URL read from -i <file>')
23 @CLICheckNonemptyFileInput
24 def add_iscsi_gateway(_
, inbuf
, name
=None):
27 IscsiGatewaysConfig
.validate_service_url(service_url
)
29 name
= IscsiClient
.instance(service_url
=service_url
).get_hostname()['data']
30 IscsiGatewaysConfig
.add_gateway(name
, service_url
)
31 return 0, 'Success', ''
32 except IscsiGatewayAlreadyExists
as ex
:
33 return -errno
.EEXIST
, '', str(ex
)
34 except InvalidServiceUrl
as ex
:
35 return -errno
.EINVAL
, '', str(ex
)
36 except ManagedByOrchestratorException
as ex
:
37 return -errno
.EINVAL
, '', str(ex
)
38 except RequestException
as ex
:
39 return -errno
.EINVAL
, '', str(ex
)
42 @CLIWriteCommand('dashboard iscsi-gateway-rm',
43 'name=name,type=CephString',
44 'Remove iSCSI gateway configuration')
45 def remove_iscsi_gateway(_
, name
):
47 IscsiGatewaysConfig
.remove_gateway(name
)
48 return 0, 'Success', ''
49 except IscsiGatewayDoesNotExist
as ex
:
50 return -errno
.ENOENT
, '', str(ex
)
51 except ManagedByOrchestratorException
as ex
:
52 return -errno
.EINVAL
, '', str(ex
)