1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# -*- coding: utf-8 -*-
import errno
import json
from mgr_module import CLICheckNonemptyFileInput, CLIReadCommand, CLIWriteCommand
from ..rest_client import RequestException
from .nvmeof_conf import ManagedByOrchestratorException, \
NvmeofGatewayAlreadyExists, NvmeofGatewaysConfig
@CLIReadCommand('dashboard nvmeof-gateway-list')
def list_nvmeof_gateways(_):
'''
List NVMe-oF gateways
'''
return 0, json.dumps(NvmeofGatewaysConfig.get_gateways_config()), ''
@CLIWriteCommand('dashboard nvmeof-gateway-add')
@CLICheckNonemptyFileInput(desc='NVMe-oF gateway configuration')
def add_nvmeof_gateway(_, inbuf, name: str, group: str, daemon_name: str):
'''
Add NVMe-oF gateway configuration. Gateway URL read from -i <file>
'''
service_url = inbuf
try:
NvmeofGatewaysConfig.add_gateway(name, service_url, group, daemon_name)
return 0, 'Success', ''
except NvmeofGatewayAlreadyExists as ex:
return -errno.EEXIST, '', str(ex)
except ManagedByOrchestratorException as ex:
return -errno.EINVAL, '', str(ex)
except RequestException as ex:
return -errno.EINVAL, '', str(ex)
@CLIWriteCommand('dashboard nvmeof-gateway-rm')
def remove_nvmeof_gateway(_, name: str, daemon_name: str = ''):
'''
Remove NVMe-oF gateway configuration
'''
try:
NvmeofGatewaysConfig.remove_gateway(name, daemon_name)
return 0, 'Success', ''
except ManagedByOrchestratorException as ex:
return -errno.EINVAL, '', str(ex)
|