]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/services/iscsi_cli.py
update sources to ceph Nautilus 14.2.1
[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, IscsiGatewayInUse
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 'Add iSCSI gateway configuration')
23 def add_iscsi_gateway(_, service_url):
24 try:
25 IscsiGatewaysConfig.validate_service_url(service_url)
26 name = IscsiClient.instance(service_url=service_url).get_hostname()['data']
27 IscsiGatewaysConfig.add_gateway(name, service_url)
28 return 0, 'Success', ''
29 except IscsiGatewayAlreadyExists as ex:
30 return -errno.EEXIST, '', str(ex)
31 except InvalidServiceUrl as ex:
32 return -errno.EINVAL, '', str(ex)
33 except ManagedByOrchestratorException as ex:
34 return -errno.EINVAL, '', str(ex)
35 except RequestException as ex:
36 return -errno.EINVAL, '', str(ex)
37
38
39 @CLIWriteCommand('dashboard iscsi-gateway-rm',
40 'name=name,type=CephString',
41 'Remove iSCSI gateway configuration')
42 def remove_iscsi_gateway(_, name):
43 try:
44 try:
45 iscsi_config = IscsiClient.instance(gateway_name=name).get_config()
46 if name in iscsi_config['gateways']:
47 raise IscsiGatewayInUse(name)
48 except RequestException:
49 pass
50 IscsiGatewaysConfig.remove_gateway(name)
51 return 0, 'Success', ''
52 except IscsiGatewayInUse as ex:
53 return -errno.EBUSY, '', str(ex)
54 except IscsiGatewayDoesNotExist as ex:
55 return -errno.ENOENT, '', str(ex)
56 except ManagedByOrchestratorException as ex:
57 return -errno.EINVAL, '', str(ex)