]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/services/iscsi_cli.py
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / pybind / mgr / dashboard / services / iscsi_cli.py
1 # -*- coding: utf-8 -*-
2
3 import errno
4 import json
5 from typing import Optional
6
7 from mgr_module import CLICheckNonemptyFileInput, CLIReadCommand, CLIWriteCommand
8
9 from ..rest_client import RequestException
10 from .iscsi_client import IscsiClient
11 from .iscsi_config import InvalidServiceUrl, IscsiGatewayAlreadyExists, \
12 IscsiGatewayDoesNotExist, IscsiGatewaysConfig, \
13 ManagedByOrchestratorException
14
15
16 @CLIReadCommand('dashboard iscsi-gateway-list')
17 def list_iscsi_gateways(_):
18 '''
19 List iSCSI gateways
20 '''
21 return 0, json.dumps(IscsiGatewaysConfig.get_gateways_config()), ''
22
23
24 @CLIWriteCommand('dashboard iscsi-gateway-add')
25 @CLICheckNonemptyFileInput(desc='iSCSI gateway configuration')
26 def add_iscsi_gateway(_, inbuf, name: Optional[str] = None):
27 '''
28 Add iSCSI gateway configuration. Gateway URL read from -i <file>
29 '''
30 service_url = inbuf
31 try:
32 IscsiGatewaysConfig.validate_service_url(service_url)
33 if name is None:
34 name = IscsiClient.instance(service_url=service_url).get_hostname()['data']
35 IscsiGatewaysConfig.add_gateway(name, service_url)
36 return 0, 'Success', ''
37 except IscsiGatewayAlreadyExists as ex:
38 return -errno.EEXIST, '', str(ex)
39 except InvalidServiceUrl as ex:
40 return -errno.EINVAL, '', str(ex)
41 except ManagedByOrchestratorException as ex:
42 return -errno.EINVAL, '', str(ex)
43 except RequestException as ex:
44 return -errno.EINVAL, '', str(ex)
45
46
47 @CLIWriteCommand('dashboard iscsi-gateway-rm')
48 def remove_iscsi_gateway(_, name: str):
49 '''
50 Remove iSCSI gateway configuration
51 '''
52 try:
53 IscsiGatewaysConfig.remove_gateway(name)
54 return 0, 'Success', ''
55 except IscsiGatewayDoesNotExist as ex:
56 return -errno.ENOENT, '', str(ex)
57 except ManagedByOrchestratorException as ex:
58 return -errno.EINVAL, '', str(ex)