5
5
6
6
import click
7
7
import utilities_common .cli as clicommon
8
- import netaddr
9
- from swsscommon .swsscommon import SonicV2Connector , ConfigDBConnector
8
+ from swsscommon .swsscommon import SonicV2Connector
10
9
from natsort import natsorted
11
10
import logging
12
11
@@ -53,33 +52,28 @@ def get_intf_list_in_vlan_member_table(config_db):
53
52
def is_valid_root_guard_timeout (ctx , root_guard_timeout ):
54
53
if root_guard_timeout not in range (STP_MIN_ROOT_GUARD_TIMEOUT , STP_MAX_ROOT_GUARD_TIMEOUT + 1 ):
55
54
ctx .fail ("STP root guard timeout must be in range 5-600" )
56
- pass
57
55
58
56
59
57
def is_valid_forward_delay (ctx , forward_delay ):
60
58
if forward_delay not in range (STP_MIN_FORWARD_DELAY , STP_MAX_FORWARD_DELAY + 1 ):
61
59
ctx .fail ("STP forward delay value must be in range 4-30" )
62
- pass
63
60
64
61
65
62
def is_valid_hello_interval (ctx , hello_interval ):
66
63
if hello_interval not in range (STP_MIN_HELLO_INTERVAL , STP_MAX_HELLO_INTERVAL + 1 ):
67
64
ctx .fail ("STP hello timer must be in range 1-10" )
68
- pass
69
65
70
66
71
67
def is_valid_max_age (ctx , max_age ):
72
68
if max_age not in range (STP_MIN_MAX_AGE , STP_MAX_MAX_AGE + 1 ):
73
69
ctx .fail ("STP max age value must be in range 6-40" )
74
- pass
75
70
76
71
77
72
def is_valid_bridge_priority (ctx , priority ):
78
73
if priority not in range (STP_MIN_BRIDGE_PRIORITY , STP_MAX_BRIDGE_PRIORITY + 1 ):
79
74
ctx .fail ("STP bridge priority must be in range 0-61440" )
80
75
if priority % 4096 != 0 :
81
76
ctx .fail ("STP bridge priority must be multiple of 4096" )
82
- pass
83
77
84
78
85
79
def validate_params (forward_delay , max_age , hello_time ):
@@ -129,15 +123,16 @@ def is_valid_stp_global_parameters(ctx, db, param_type, new_value):
129
123
parameter_bridge_priority = 4
130
124
131
125
def get_max_stp_instances ():
132
- state_db = SonicV2Connector (host = '127.0.0.1' )
133
- state_db .connect (state_db .STATE_DB , False )
134
- max_inst = state_db .get (state_db .STATE_DB , "STP_TABLE|GLOBAL" , "max_stp_inst" )
135
- #if max_inst == "":
136
126
return PVST_MAX_INSTANCES
137
- if max_inst != None and max_inst != 0 and max_inst < PVST_MAX_INSTANCES :
138
- return max_inst
139
- else :
140
- return PVST_MAX_INSTANCES
127
+ #state_db = SonicV2Connector(host='127.0.0.1')
128
+ #state_db.connect(state_db.STATE_DB, False)
129
+ #max_inst = state_db.get(state_db.STATE_DB, "STP_TABLE|GLOBAL", "max_stp_inst")
130
+ #if max_inst == "":
131
+ # return PVST_MAX_INSTANCES
132
+ #if max_inst != None and max_inst != 0 and max_inst < PVST_MAX_INSTANCES:
133
+ # return max_inst
134
+ #else:
135
+ # return PVST_MAX_INSTANCES
141
136
142
137
def update_stp_vlan_parameter (db , param_type , new_value ):
143
138
stp_global_entry = db .get_entry ('STP' , "GLOBAL" )
@@ -170,15 +165,13 @@ def update_stp_vlan_parameter(db, param_type, new_value):
170
165
current_vlan_value = vlan_entry .get ("priority" )
171
166
if current_global_value == current_vlan_value :
172
167
db .mod_entry ('STP_VLAN' , vlan , {'priority' : new_value })
173
- pass
174
168
175
169
176
170
def check_if_vlan_exist_in_db (db , ctx , vid ):
177
171
vlan_name = 'Vlan{}' .format (vid )
178
172
vlan = db .get_entry ('VLAN' , vlan_name )
179
173
if len (vlan ) == 0 :
180
174
ctx .fail ("{} doesn't exist" .format (vlan_name ))
181
- pass
182
175
183
176
184
177
def enable_stp_for_vlans (db ):
@@ -197,7 +190,6 @@ def enable_stp_for_vlans(db):
197
190
break
198
191
db .set_entry ('STP_VLAN' , vlan_key , fvs )
199
192
vlan_count += 1
200
- pass
201
193
202
194
203
195
def get_stp_enabled_vlan_count (db ):
@@ -312,7 +304,6 @@ def enable_stp_for_interfaces(db):
312
304
for po_ch_key in po_ch_dict :
313
305
if po_ch_key in intf_list_in_vlan_member_table :
314
306
db .set_entry ('STP_PORT' , po_ch_key , fvs )
315
- pass
316
307
317
308
318
309
def is_global_stp_enabled (db ):
@@ -391,7 +382,6 @@ def spanning_tree_enable(_db, mode):
391
382
# Enable STP for VLAN by default
392
383
enable_stp_for_interfaces (db )
393
384
enable_stp_for_vlans (db )
394
- pass
395
385
396
386
397
387
# cmd: STP disable
@@ -406,7 +396,6 @@ def stp_disable(_db, mode):
406
396
db .delete_table ('STP_VLAN' )
407
397
db .delete_table ('STP_PORT' )
408
398
db .delete_table ('STP_VLAN_PORT' )
409
- pass
410
399
411
400
412
401
# cmd: STP global root guard timeout
@@ -420,7 +409,6 @@ def stp_global_root_guard_timeout(_db, root_guard_timeout):
420
409
check_if_global_stp_enabled (db , ctx )
421
410
is_valid_root_guard_timeout (ctx , root_guard_timeout )
422
411
db .mod_entry ('STP' , "GLOBAL" , {'rootguard_timeout' : root_guard_timeout })
423
- pass
424
412
425
413
426
414
# cmd: STP global forward delay
@@ -436,7 +424,6 @@ def stp_global_forward_delay(_db, forward_delay):
436
424
is_valid_stp_global_parameters (ctx , db , parameter_forward_delay , forward_delay )
437
425
update_stp_vlan_parameter (db , parameter_forward_delay , forward_delay )
438
426
db .mod_entry ('STP' , "GLOBAL" , {'forward_delay' : forward_delay })
439
- pass
440
427
441
428
442
429
# cmd: STP global hello interval
@@ -452,7 +439,6 @@ def stp_global_hello_interval(_db, hello_interval):
452
439
is_valid_stp_global_parameters (ctx , db , parameter_hello_time , hello_interval )
453
440
update_stp_vlan_parameter (db , parameter_hello_time , hello_interval )
454
441
db .mod_entry ('STP' , "GLOBAL" , {'hello_time' : hello_interval })
455
- pass
456
442
457
443
458
444
# cmd: STP global max age
@@ -468,7 +454,6 @@ def stp_global_max_age(_db, max_age):
468
454
is_valid_stp_global_parameters (ctx , db , parameter_max_age , max_age )
469
455
update_stp_vlan_parameter (db , parameter_max_age , max_age )
470
456
db .mod_entry ('STP' , "GLOBAL" , {'max_age' : max_age })
471
- pass
472
457
473
458
474
459
# cmd: STP global bridge priority
@@ -483,7 +468,6 @@ def stp_global_priority(_db, priority):
483
468
is_valid_bridge_priority (ctx , priority )
484
469
update_stp_vlan_parameter (db , parameter_bridge_priority , priority )
485
470
db .mod_entry ('STP' , "GLOBAL" , {'priority' : priority })
486
- pass
487
471
488
472
489
473
###############################################
@@ -543,7 +527,6 @@ def stp_vlan_enable(_db, vid):
543
527
vlan_intf_key = "{}|{}" .format (vlan_name , intf )
544
528
vlan_intf_entry = db .get_entry ('STP_VLAN_PORT' , vlan_intf_key )
545
529
db .mod_entry ('STP_VLAN_PORT' , vlan_intf_key , vlan_intf_entry )
546
- pass
547
530
548
531
549
532
@spanning_tree_vlan .command ('disable' )
@@ -556,7 +539,6 @@ def stp_vlan_disable(_db, vid):
556
539
check_if_vlan_exist_in_db (db , ctx , vid )
557
540
vlan_name = 'Vlan{}' .format (vid )
558
541
db .mod_entry ('STP_VLAN' , vlan_name , {'enabled' : 'false' })
559
- pass
560
542
561
543
562
544
@spanning_tree_vlan .command ('forward_delay' )
@@ -573,7 +555,6 @@ def stp_vlan_forward_delay(_db, vid, forward_delay):
573
555
is_valid_forward_delay (ctx , forward_delay )
574
556
is_valid_stp_vlan_parameters (ctx , db , vlan_name , parameter_forward_delay , forward_delay )
575
557
db .mod_entry ('STP_VLAN' , vlan_name , {'forward_delay' : forward_delay })
576
- pass
577
558
578
559
579
560
@spanning_tree_vlan .command ('hello' )
@@ -590,7 +571,6 @@ def stp_vlan_hello_interval(_db, vid, hello_interval):
590
571
is_valid_hello_interval (ctx , hello_interval )
591
572
is_valid_stp_vlan_parameters (ctx , db , vlan_name , parameter_hello_time , hello_interval )
592
573
db .mod_entry ('STP_VLAN' , vlan_name , {'hello_time' : hello_interval })
593
- pass
594
574
595
575
596
576
@spanning_tree_vlan .command ('max_age' )
@@ -607,7 +587,6 @@ def stp_vlan_max_age(_db, vid, max_age):
607
587
is_valid_max_age (ctx , max_age )
608
588
is_valid_stp_vlan_parameters (ctx , db , vlan_name , parameter_max_age , max_age )
609
589
db .mod_entry ('STP_VLAN' , vlan_name , {'max_age' : max_age })
610
- pass
611
590
612
591
613
592
@spanning_tree_vlan .command ('priority' )
@@ -623,7 +602,6 @@ def stp_vlan_priority(_db, vid, priority):
623
602
check_if_stp_enabled_for_vlan (ctx , db , vlan_name )
624
603
is_valid_bridge_priority (ctx , priority )
625
604
db .mod_entry ('STP_VLAN' , vlan_name , {'priority' : priority })
626
- pass
627
605
628
606
629
607
###############################################
@@ -658,7 +636,6 @@ def check_if_interface_is_valid(ctx, db, interface_name):
658
636
ctx .fail (" {} is a portchannel member port - STP can't be configured" .format (interface_name ))
659
637
if not is_vlan_configured_interface (db , interface_name ):
660
638
ctx .fail (" {} has no VLAN configured - It's not a L2 interface" .format (interface_name ))
661
- pass
662
639
663
640
664
641
@spanning_tree .group ('interface' )
0 commit comments