]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/services/iscsi_cli.py
a290337c10c2490b0c376f4ca725fa4e0476697e
[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 CLICheckNonemptyFileInput, 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=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):
25 service_url = inbuf
26 try:
27 IscsiGatewaysConfig.validate_service_url(service_url)
28 if name is None:
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)
40
41
42 @CLIWriteCommand('dashboard iscsi-gateway-rm',
43 'name=name,type=CephString',
44 'Remove iSCSI gateway configuration')
45 def remove_iscsi_gateway(_, name):
46 try:
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)