]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
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, \ | |
92f5a8d4 | 11 | ManagedByOrchestratorException, IscsiGatewayDoesNotExist |
11fdf7f2 TL |
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', | |
e306af50 TL |
21 | 'name=service_url,type=CephString ' |
22 | 'name=name,type=CephString,req=false', | |
11fdf7f2 | 23 | 'Add iSCSI gateway configuration') |
e306af50 | 24 | def add_iscsi_gateway(_, service_url, name=None): |
11fdf7f2 TL |
25 | try: |
26 | IscsiGatewaysConfig.validate_service_url(service_url) | |
e306af50 TL |
27 | if name is None: |
28 | name = IscsiClient.instance(service_url=service_url).get_hostname()['data'] | |
11fdf7f2 TL |
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: | |
11fdf7f2 TL |
46 | IscsiGatewaysConfig.remove_gateway(name) |
47 | return 0, 'Success', '' | |
11fdf7f2 TL |
48 | except IscsiGatewayDoesNotExist as ex: |
49 | return -errno.ENOENT, '', str(ex) | |
50 | except ManagedByOrchestratorException as ex: | |
51 | return -errno.EINVAL, '', str(ex) |