Skip to content

Commit

Permalink
control/cli: add ip requirement for listener
Browse files Browse the repository at this point in the history
discovert controller need a specific ip/port.

fixes: #87

Signed-off-by: Yin Congmin <[email protected]>
  • Loading branch information
CongMinYin committed May 15, 2023
1 parent e783513 commit 4725d2a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Indicate the location of the keys and certificates in the config file:
$ python3 -m control.cli add_host -n nqn.2016-06.io.spdk:cnode1 -t '*'
INFO:root:Allowed open host access to nqn.2016-06.io.spdk:cnode1: True
$ python3 -m control.cli create_listener -n nqn.2016-06.io.spdk:cnode1 -s 5001
$ python3 -m control.cli create_listener -n nqn.2016-06.io.spdk:cnode1 -g gateway_name -a gateway_addr -s 5001
INFO:root:Created nqn.2016-06.io.spdk:cnode1 listener: True

3. On the storage client system (ubuntu-21.04):
Expand Down
8 changes: 4 additions & 4 deletions control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ def remove_host(self, args):

@cli.cmd([
argument("-n", "--subnqn", help="Subsystem NQN", required=True),
argument("-g", "--gateway-name", help="Gateway name", default=""),
argument("-g", "--gateway-name", help="Gateway name", required=True),
argument("-t", "--trtype", help="Transport type", default="TCP"),
argument("-f", "--adrfam", help="Address family", default="ipv4"),
argument("-a", "--traddr", help="NVMe host IP", default=""),
argument("-a", "--traddr", help="NVMe host IP", required=True),
argument("-s", "--trsvcid", help="Port number", required=True),
])
def create_listener(self, args):
Expand All @@ -295,10 +295,10 @@ def create_listener(self, args):

@cli.cmd([
argument("-n", "--subnqn", help="Subsystem NQN", required=True),
argument("-g", "--gateway-name", help="Gateway name", default=""),
argument("-g", "--gateway-name", help="Gateway name", required=True),
argument("-t", "--trtype", help="Transport type", default="TCP"),
argument("-f", "--adrfam", help="Address family", default="ipv4"),
argument("-a", "--traddr", help="NVMe host IP", default=""),
argument("-a", "--traddr", help="NVMe host IP", required=True),
argument("-s", "--trsvcid", help="Port number", required=True),
])
def delete_listener(self, args):
Expand Down
34 changes: 4 additions & 30 deletions control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,25 +330,12 @@ def create_listener(self, request, context=None):
f" {request.trtype} listener for {request.nqn} at"
f" {request.traddr}:{request.trsvcid}.")
try:
if (request.gateway_name and not request.traddr) or \
(not request.gateway_name and request.traddr):
raise Exception(
"both gateway_name and traddr or neither must be specified")

if not request.gateway_name or \
request.gateway_name == self.gateway_name:
if not request.traddr:
traddr = self.config.get("gateway", "addr")
if not traddr:
raise Exception("gateway.addr option is not set")
else:
traddr = request.traddr

if request.gateway_name == self.gateway_name:
ret = self.spdk_rpc.nvmf.nvmf_subsystem_add_listener(
self.spdk_rpc_client,
nqn=request.nqn,
trtype=request.trtype,
traddr=traddr,
traddr=request.traddr,
trsvcid=request.trsvcid,
adrfam=request.adrfam,
)
Expand Down Expand Up @@ -384,25 +371,12 @@ def delete_listener(self, request, context=None):
f" {request.trtype} listener for {request.nqn} at"
f" {request.traddr}:{request.trsvcid}.")
try:
if (request.gateway_name and not request.traddr) or \
(not request.gateway_name and request.traddr):
raise Exception(
"both gateway_name and traddr or neither must be specified")

if not request.gateway_name or \
request.gateway_name == self.gateway_name:
if not request.traddr:
traddr = self.config.get("gateway", "addr")
if not traddr:
raise Exception("gateway.addr option is not set")
else:
traddr = request.traddr

if request.gateway_name == self.gateway_name:
ret = self.spdk_rpc.nvmf.nvmf_subsystem_remove_listener(
self.spdk_rpc_client,
nqn=request.nqn,
trtype=request.trtype,
traddr=traddr,
traddr=request.traddr,
trsvcid=request.trsvcid,
adrfam=request.adrfam,
)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
trtype = "TCP"
gateway_name = socket.gethostname()
addr = "127.0.0.1"
listener_list = [["-g", gateway_name, "-a", addr, "-s", "5001"], ["-s", "5002"]]
listener_list = [["-g", gateway_name, "-a", addr, "-s", "5001"], \
["-g", gateway_name, "-a", addr, "-s", "5002"]]
config = "ceph-nvmeof.conf"


Expand Down

0 comments on commit 4725d2a

Please sign in to comment.