]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/services/iscsi_cli.py
import ceph 15.2.10
[ceph.git] / ceph / src / pybind / mgr / dashboard / services / iscsi_cli.py
CommitLineData
11fdf7f2
TL
1# -*- coding: utf-8 -*-
2from __future__ import absolute_import
3
4import errno
5import json
6
cd265ab1 7from mgr_module import CLICheckNonemptyFileInput, CLIReadCommand, CLIWriteCommand
11fdf7f2
TL
8
9from .iscsi_client import IscsiClient
10from .iscsi_config import IscsiGatewaysConfig, IscsiGatewayAlreadyExists, InvalidServiceUrl, \
92f5a8d4 11 ManagedByOrchestratorException, IscsiGatewayDoesNotExist
11fdf7f2
TL
12from ..rest_client import RequestException
13
14
15@CLIReadCommand('dashboard iscsi-gateway-list', desc='List iSCSI gateways')
16def list_iscsi_gateways(_):
17 return 0, json.dumps(IscsiGatewaysConfig.get_gateways_config()), ''
18
19
20@CLIWriteCommand('dashboard iscsi-gateway-add',
e306af50 21 'name=name,type=CephString,req=false',
cd265ab1
TL
22 'Add iSCSI gateway configuration. Gateway URL read from -i <file>')
23@CLICheckNonemptyFileInput
24def add_iscsi_gateway(_, inbuf, name=None):
25 service_url = inbuf
11fdf7f2
TL
26 try:
27 IscsiGatewaysConfig.validate_service_url(service_url)
e306af50
TL
28 if name is None:
29 name = IscsiClient.instance(service_url=service_url).get_hostname()['data']
11fdf7f2
TL
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')
45def remove_iscsi_gateway(_, name):
46 try:
11fdf7f2
TL
47 IscsiGatewaysConfig.remove_gateway(name)
48 return 0, 'Success', ''
11fdf7f2
TL
49 except IscsiGatewayDoesNotExist as ex:
50 return -errno.ENOENT, '', str(ex)
51 except ManagedByOrchestratorException as ex:
52 return -errno.EINVAL, '', str(ex)