23
23
from .proto import gateway_pb2_grpc as pb2_grpc
24
24
from .proto import gateway_pb2 as pb2
25
25
from .config import GatewayConfig
26
- from .config import GatewayEnumUtils
26
+ from .utils import GatewayUtils
27
+ from .utils import GatewayEnumUtils
27
28
28
29
BASE_GATEWAY_VERSION = "0.0.7"
29
30
@@ -187,7 +188,7 @@ def stub(self):
187
188
def connect (self , host , port , client_key , client_cert , server_cert ):
188
189
"""Connects to server and sets stub."""
189
190
# We need to enclose IPv6 addresses in brackets before concatenating a colon and port number to it
190
- host = GatewayConfig .escape_address_if_ipv6 (host )
191
+ host = GatewayUtils .escape_address_if_ipv6 (host )
191
192
server = f"{ host } :{ port } "
192
193
193
194
if client_key and client_cert :
@@ -550,15 +551,15 @@ def subsystem_add(self, args):
550
551
out_func , err_func = self .get_output_functions (args )
551
552
if args .max_namespaces == None :
552
553
args .max_namespaces = 256
553
- if args .max_namespaces < 0 :
554
+ if args .max_namespaces <= 0 :
554
555
self .cli .parser .error ("--max-namespaces value must be positive" )
555
556
if not args .subsystem :
556
557
self .cli .parser .error ("--subsystem argument is mandatory for add command" )
557
558
if args .force :
558
559
self .cli .parser .error ("--force argument is not allowed for add command" )
559
560
if args .enable_ha and not args .ana_reporting :
560
561
self .cli .parser .error ("ANA reporting must be enabled when HA is active" )
561
- if args .subsystem == GatewayConfig .DISCOVERY_NQN :
562
+ if args .subsystem == GatewayUtils .DISCOVERY_NQN :
562
563
self .cli .parser .error ("Can't add a discovery subsystem" )
563
564
564
565
req = pb2 .create_subsystem_req (subsystem_nqn = args .subsystem ,
@@ -608,7 +609,7 @@ def subsystem_del(self, args):
608
609
self .cli .parser .error ("--ana-reporting argument is not allowed for del command" )
609
610
if args .enable_ha :
610
611
self .cli .parser .error ("--enable-ha argument is not allowed for del command" )
611
- if args .subsystem == GatewayConfig .DISCOVERY_NQN :
612
+ if args .subsystem == Utils .DISCOVERY_NQN :
612
613
self .cli .parser .error ("Can't delete a discovery subsystem" )
613
614
614
615
req = pb2 .delete_subsystem_req (subsystem_nqn = args .subsystem , force = args .force )
@@ -743,16 +744,16 @@ def listener_add(self, args):
743
744
if not args .traddr :
744
745
self .cli .parser .error ("--traddr argument is mandatory for add command" )
745
746
746
- if not args .trsvcid :
747
+ if args .trsvcid == None :
747
748
args .trsvcid = 4420
748
- elif args .trsvcid < 0 :
749
+ elif args .trsvcid <= 0 :
749
750
self .cli .parser .error ("trsvcid value must be positive" )
750
751
if not args .trtype :
751
752
args .trtype = "TCP"
752
753
if not args .adrfam :
753
754
args .adrfam = "IPV4"
754
755
755
- traddr = GatewayConfig .escape_address_if_ipv6 (args .traddr )
756
+ traddr = GatewayUtils .escape_address_if_ipv6 (args .traddr )
756
757
trtype = None
757
758
adrfam = None
758
759
if args .trtype :
@@ -807,16 +808,16 @@ def listener_del(self, args):
807
808
self .cli .parser .error ("--gateway-name argument is mandatory for del command" )
808
809
if not args .traddr :
809
810
self .cli .parser .error ("--traddr argument is mandatory for del command" )
810
- if not args .trsvcid :
811
+ if args .trsvcid == None :
811
812
self .cli .parser .error ("--trsvcid argument is mandatory for del command" )
812
- if args .trsvcid < 0 :
813
+ if args .trsvcid <= 0 :
813
814
self .cli .parser .error ("trsvcid value must be positive" )
814
815
if not args .trtype :
815
816
args .trtype = "TCP"
816
817
if not args .adrfam :
817
818
args .adrfam = "IPV4"
818
819
819
- traddr = GatewayConfig .escape_address_if_ipv6 (args .traddr )
820
+ traddr = GatewayUtils .escape_address_if_ipv6 (args .traddr )
820
821
trtype = None
821
822
adrfam = None
822
823
if args .trtype :
@@ -874,7 +875,7 @@ def listener_list(self, args):
874
875
self .cli .parser .error ("--trtype argument is not allowed for list command" )
875
876
if args .adrfam :
876
877
self .cli .parser .error ("--adrfam argument is not allowed for list command" )
877
- if args .trsvcid :
878
+ if args .trsvcid != None :
878
879
self .cli .parser .error ("--trsvcid argument is not allowed for list command" )
879
880
880
881
listeners_info = None
@@ -1161,9 +1162,9 @@ def ns_add(self, args):
1161
1162
args .block_size = 512
1162
1163
if args .load_balancing_group == None :
1163
1164
args .load_balancing_group = 1
1164
- if args .load_balancing_group and args . load_balancing_group < 0 :
1165
+ if args .load_balancing_group <= 0 :
1165
1166
self .cli .parser .error ("load-balancing-group value must be positive" )
1166
- if args .nsid and args .nsid <= 0 :
1167
+ if args .nsid != None and args .nsid <= 0 :
1167
1168
self .cli .parser .error ("nsid value must be positive" )
1168
1169
if args .size != None :
1169
1170
self .cli .parser .error ("--size argument is not allowed for add command" )
@@ -1173,8 +1174,6 @@ def ns_add(self, args):
1173
1174
self .cli .parser .error ("--rbd-image argument is mandatory for add command" )
1174
1175
if args .block_size <= 0 :
1175
1176
self .cli .parser .error ("block-size value must be positive" )
1176
- if args .load_balancing_group <= 0 :
1177
- self .cli .parser .error ("load-balancing-group value must be positive" )
1178
1177
if args .rw_ios_per_second != None :
1179
1178
self .cli .parser .error ("--rw-ios-per-second argument is not allowed for add command" )
1180
1179
if args .rw_megabytes_per_second != None :
@@ -1227,9 +1226,9 @@ def ns_del(self, args):
1227
1226
"""Deletes a namespace from a subsystem."""
1228
1227
1229
1228
out_func , err_func = self .get_output_functions (args )
1230
- if not args .nsid and not args .uuid :
1229
+ if args .nsid == None and args .uuid == None :
1231
1230
self .cli .parser .error ("At least one of --nsid or --uuid arguments is mandatory for del command" )
1232
- if args .nsid and args .nsid < 0 :
1231
+ if args .nsid != None and args .nsid <= 0 :
1233
1232
self .cli .parser .error ("nsid value must be positive" )
1234
1233
if args .size != None :
1235
1234
self .cli .parser .error ("--size argument is not allowed for del command" )
@@ -1239,7 +1238,7 @@ def ns_del(self, args):
1239
1238
self .cli .parser .error ("--rbd-pool argument is not allowed for del command" )
1240
1239
if args .rbd_image != None :
1241
1240
self .cli .parser .error ("--rbd-image argument is not allowed for del command" )
1242
- if args .load_balancing_group :
1241
+ if args .load_balancing_group != None :
1243
1242
self .cli .parser .error ("--load-balancing-group argument is not allowed for del command" )
1244
1243
if args .rw_ios_per_second != None :
1245
1244
self .cli .parser .error ("--rw-ios-per-second argument is not allowed for del command" )
@@ -1288,13 +1287,13 @@ def ns_resize(self, args):
1288
1287
"""Resizes a namespace."""
1289
1288
1290
1289
out_func , err_func = self .get_output_functions (args )
1291
- if not args .nsid and not args .uuid :
1290
+ if args .nsid == None and args .uuid == None :
1292
1291
self .cli .parser .error ("At least one of --nsid or --uuid arguments is mandatory for resize command" )
1293
- if args .nsid and args .nsid < 0 :
1292
+ if args .nsid != None and args .nsid <= 0 :
1294
1293
self .cli .parser .error ("nsid value must be positive" )
1295
- if not args .size :
1294
+ if args .size == None :
1296
1295
self .cli .parser .error ("--size argument is mandatory for resize command" )
1297
- if args .size < 0 :
1296
+ if args .size <= 0 :
1298
1297
self .cli .parser .error ("size value must be positive" )
1299
1298
if args .block_size != None :
1300
1299
self .cli .parser .error ("--block-size argument is not allowed for resize command" )
@@ -1379,7 +1378,7 @@ def ns_list(self, args):
1379
1378
"""Lists namespaces on a subsystem."""
1380
1379
1381
1380
out_func , err_func = self .get_output_functions (args )
1382
- if args .nsid and args .nsid < 0 :
1381
+ if args .nsid != None and args .nsid <= 0 :
1383
1382
self .cli .parser .error ("nsid value must be positive" )
1384
1383
if args .size != None :
1385
1384
self .cli .parser .error ("--size argument is not allowed for list command" )
@@ -1486,9 +1485,9 @@ def ns_get_io_stats(self, args):
1486
1485
"""Get namespace IO statistics."""
1487
1486
1488
1487
out_func , err_func = self .get_output_functions (args )
1489
- if not args .nsid and not args .uuid :
1488
+ if args .nsid == None and args .uuid == None :
1490
1489
self .cli .parser .error ("At least one of --nsid or --uuid arguments is mandatory for get_io_stats command" )
1491
- if args .nsid and args .nsid < 0 :
1490
+ if args .nsid != None and args .nsid <= 0 :
1492
1491
self .cli .parser .error ("nsid value must be positive" )
1493
1492
if args .size != None :
1494
1493
self .cli .parser .error ("--size argument is not allowed for get_io_stats command" )
@@ -1587,9 +1586,9 @@ def ns_change_load_balancing_group(self, args):
1587
1586
"""Change namespace load balancing group."""
1588
1587
1589
1588
out_func , err_func = self .get_output_functions (args )
1590
- if not args .nsid and not args .uuid :
1589
+ if args .nsid == None and args .uuid == None :
1591
1590
self .cli .parser .error ("At least one of --nsid or --uuid arguments is mandatory for change_load_balancing_group command" )
1592
- if args .nsid and args .nsid < 0 :
1591
+ if args .nsid != None and args .nsid <= 0 :
1593
1592
self .cli .parser .error ("nsid value must be positive" )
1594
1593
if args .load_balancing_group == None :
1595
1594
self .cli .parser .error ("--load-balancing-group argument is mandatory for change_load_balancing_group command" )
@@ -1659,9 +1658,9 @@ def ns_set_qos(self, args):
1659
1658
"""Set namespace QOS limits."""
1660
1659
1661
1660
out_func , err_func = self .get_output_functions (args )
1662
- if not args .nsid and not args .uuid :
1661
+ if args .nsid == None and args .uuid == None :
1663
1662
self .cli .parser .error ("At least one of --nsid or --uuid arguments is mandatory for set_qos command" )
1664
- if args .nsid and args .nsid < 0 :
1663
+ if args .nsid != None and args .nsid <= 0 :
1665
1664
self .cli .parser .error ("nsid value must be positive" )
1666
1665
if args .load_balancing_group != None :
1667
1666
self .cli .parser .error ("--load-balancing-group argument is not allowed for set_qos command" )
0 commit comments