]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/services/iscsi_cli.py
e894a56caef73465f775dbbf6c69a40490440da2
[ceph.git] / ceph / src / pybind / mgr / dashboard / services / iscsi_cli.py
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import
3
4 import errno
5 import json
6
7 from mgr_module import CLIReadCommand, CLIWriteCommand
8
9 from .iscsi_client import IscsiClient
10 from .iscsi_config import IscsiGatewaysConfig, IscsiGatewayAlreadyExists, InvalidServiceUrl, \
11 ManagedByOrchestratorException, IscsiGatewayDoesNotExist
12 from ..rest_client import RequestException
13
14
15 @CLIReadCommand('dashboard iscsi-gateway-list', desc='List iSCSI gateways')
16 def list_iscsi_gateways(_):
17 return 0, json.dumps(IscsiGatewaysConfig.get_gateways_config()), ''
18
19
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):
25 try:
26 IscsiGatewaysConfig.validate_service_url(service_url)
27 if name is None:
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)
39
40
41 @CLIWriteCommand('dashboard iscsi-gateway-rm',
42 'name=name,type=CephString',
43 'Remove iSCSI gateway configuration')
44 def remove_iscsi_gateway(_, name):
45 try:
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)