Skip to content

Commit 89a229c

Browse files
committed
MB-68871 Add --ipv6only and --ipv4only options to init-node
Change-Id: I5487e588b5f26ff7a83512bcc48c69447eb49df2 Reviewed-on: https://review.couchbase.org/c/couchbase-cli/+/239988 Reviewed-by: Matt Hall <matt.hall@couchbase.com> Tested-by: Build Bot <build@couchbase.com> Well-Formed: Restriction Checker
1 parent cb0ed4c commit 89a229c

5 files changed

Lines changed: 61 additions & 6 deletions

File tree

cbmgr.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,28 +2262,42 @@ def __init__(self):
22622262
help="Configure the node to communicate via ipv6")
22632263
group.add_argument("--ipv4", dest="ipv4", action="store_true", default=False,
22642264
help="Configure the node to communicate via ipv4")
2265+
group.add_argument("--ipv6only", dest="ipv6_only", action="store_true", default=False,
2266+
help="Configure the node to only use ipv6")
2267+
group.add_argument("--ipv4only", dest="ipv4_only", action="store_true", default=False,
2268+
help="Configure the node to only use ipv4")
22652269

22662270
@rest_initialiser(credentials_required=False)
22672271
def execute(self, opts):
22682272
# Cluster does not need to be initialized for this command
22692273

22702274
if (opts.data_path is None and opts.index_path is None and opts.analytics_path is None
22712275
and opts.eventing_path is None and opts.java_home is None and opts.hostname is None
2272-
and opts.ipv6 is None and opts.ipv4 is None):
2276+
and opts.ipv6 is None and opts.ipv4 is None and opts.ipv6_only is None and opts.ipv4_only is None):
22732277
_exit_if_errors(["No node initialization parameters specified"])
22742278

2275-
if opts.ipv4 and opts.ipv6:
2276-
_exit_if_errors(["Use either --ipv4 or --ipv6"])
2279+
flags_used = sum([opts.ipv4, opts.ipv6, opts.ipv6_only, opts.ipv4_only])
2280+
if flags_used > 1:
2281+
_exit_if_errors(["--ipv4, --ipv6, --ipv4only, and --ipv6only are mutually exclusive"])
2282+
2283+
afamily_only = None
22772284

22782285
if opts.ipv4:
22792286
afamily = 'ipv4'
22802287
elif opts.ipv6:
22812288
afamily = 'ipv6'
2289+
elif opts.ipv4_only:
2290+
afamily = 'ipv4'
2291+
afamily_only = True
2292+
elif opts.ipv6_only:
2293+
afamily = 'ipv6'
2294+
afamily_only = True
22822295
else:
22832296
afamily = None
22842297

22852298
_, errors = self.rest.node_init(hostname=opts.hostname,
22862299
afamily=afamily,
2300+
afamily_only=afamily_only,
22872301
data_path=opts.data_path,
22882302
index_path=opts.index_path,
22892303
cbas_path=opts.analytics_path,

cluster_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ def get_bucket(self, name):
13961396

13971397
return None, ["Bucket not found"]
13981398

1399-
def node_init(self, hostname=None, afamily=None, data_path=None,
1399+
def node_init(self, hostname=None, afamily=None, afamily_only=None, data_path=None,
14001400
index_path=None, cbas_path=None, eventing_path=None,
14011401
java_home=None):
14021402
url = f'{self.hostname}/nodeInit'
@@ -1408,6 +1408,9 @@ def node_init(self, hostname=None, afamily=None, data_path=None,
14081408
if afamily is not None:
14091409
params["afamily"] = afamily
14101410

1411+
if afamily_only is not None:
1412+
params["afamilyOnly"] = "true" if afamily_only else "false"
1413+
14111414
if data_path is not None:
14121415
params["dataPath"] = data_path
14131416

docs/modules/cli/pages/cbcli/couchbase-cli-node-init.adoc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ _couchbase-cli node-init_ [--cluster <url>] [--username <user>] [--password <pas
1717
[--client-key-password <password>] [--node-init-data-path <path>]
1818
[--node-init-index-path <path>] [--node-init-analytics-path <path>]
1919
[--node-init-eventing-path <path>] [--node-init-hostname <hostname>]
20-
[--node-init-java-home <path>] [--ipv4] [--ipv6]
20+
[--node-init-java-home <path>] [--ipv4] [--ipv6] [--ipv4only] [--ipv6only]
2121

2222
== DESCRIPTION
2323

@@ -66,6 +66,14 @@ include::{partialsdir}/cbcli/part-common-options.adoc[]
6666
--ipv6::
6767
Switch the node to use ipv6 for node to node communication
6868

69+
--ipv4only::
70+
Switch the node to use ipv4 only for node to node communication. The node
71+
will only listen on that address.
72+
73+
--ipv6only::
74+
Switch the node to use ipv6 only for node to node communication. The node
75+
will only listen on that address.
76+
6977
include::{partialsdir}/cbcli/part-host-formats.adoc[]
7078

7179
include::{partialsdir}/cbcli/part-certificate-authentication.adoc[]

jenkins/.aspell.en.pws

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ cbbackupwrapper
2828
cbcli
2929
cbcollect
3030
cbdatarecovery
31+
cbexport
32+
cbimport
3133
cblogredaction
3234
CBO
3335
cbrecovery

test/test_cli.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ def test_node_init(self):
11841184

11851185
def test_node_init_ipv6_and_ipv4(self):
11861186
self.system_exit_run(self.command + self.name_args + ['--ipv4', '--ipv6'], self.server_args)
1187-
self.assertIn('Use either --ipv4 or --ipv6', self.str_output)
1187+
self.assertIn('--ipv4, --ipv6, --ipv4only, and --ipv6only are mutually exclusive', self.str_output)
11881188

11891189
def test_node_init_ipv6(self):
11901190
self.no_error_run(self.command + self.name_args + ['--ipv6'], self.server_args)
@@ -1198,6 +1198,34 @@ def test_node_init_ipv4(self):
11981198
expected_params = ['hostname=foo', 'afamily=ipv4']
11991199
self.rest_parameter_match(expected_params)
12001200

1201+
def test_node_init_ipv6only(self):
1202+
self.no_error_run(self.command + self.name_args + ['--ipv6only'], self.server_args)
1203+
self.assertIn('POST:/nodeInit', self.server.trace)
1204+
expected_params = ['hostname=foo', 'afamily=ipv6', 'afamilyOnly=true']
1205+
self.rest_parameter_match(expected_params)
1206+
1207+
def test_node_init_ipv4only(self):
1208+
self.no_error_run(self.command + self.name_args + ['--ipv4only'], self.server_args)
1209+
self.assertIn('POST:/nodeInit', self.server.trace)
1210+
expected_params = ['hostname=foo', 'afamily=ipv4', 'afamilyOnly=true']
1211+
self.rest_parameter_match(expected_params)
1212+
1213+
def test_node_init_ipv6_and_ipv6only(self):
1214+
self.system_exit_run(self.command + self.name_args + ['--ipv6', '--ipv6only'], self.server_args)
1215+
self.assertIn('--ipv4, --ipv6, --ipv4only, and --ipv6only are mutually exclusive', self.str_output)
1216+
1217+
def test_node_init_ipv4_and_ipv6only(self):
1218+
self.system_exit_run(self.command + self.name_args + ['--ipv4', '--ipv6only'], self.server_args)
1219+
self.assertIn('--ipv4, --ipv6, --ipv4only, and --ipv6only are mutually exclusive', self.str_output)
1220+
1221+
def test_node_init_ipv4_and_ipv4only(self):
1222+
self.system_exit_run(self.command + self.name_args + ['--ipv4', '--ipv4only'], self.server_args)
1223+
self.assertIn('--ipv4, --ipv6, --ipv4only, and --ipv6only are mutually exclusive', self.str_output)
1224+
1225+
def test_node_init_ipv4only_and_ipv6only(self):
1226+
self.system_exit_run(self.command + self.name_args + ['--ipv4only', '--ipv6only'], self.server_args)
1227+
self.assertIn('--ipv4, --ipv6, --ipv4only, and --ipv6only are mutually exclusive', self.str_output)
1228+
12011229

12021230
class TestNodeReset(CommandTest):
12031231
def setUp(self):

0 commit comments

Comments
 (0)