Skip to content

Commit 2072a5a

Browse files
authored
Merge branch 'master' into breakout_cli_msft
2 parents 4f5f45e + 7e52ef9 commit 2072a5a

89 files changed

Lines changed: 13561 additions & 1069 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[![Total alerts](https://img.shields.io/lgtm/alerts/g/Azure/sonic-utilities.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Azure/sonic-utilities/alerts/)
2+
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Azure/sonic-utilities.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Azure/sonic-utilities/context:python)
3+
4+
[![Build](https://sonic-jenkins.westus2.cloudapp.azure.com/job/common/job/sonic-utilities-build/badge/icon)](https://sonic-jenkins.westus2.cloudapp.azure.com/job/common/job/sonic-utilities-build/)
5+
16
# SONiC: Software for Open Networking in the Cloud
27

38
## sonic-utilities
@@ -23,21 +28,21 @@ Guide for performing commits:
2328
* Use a standard commit message format:
2429

2530
> [component/folder touched]: Description intent of your changes
26-
>
31+
>
2732
> [List of changes]
28-
>
33+
>
2934
> Signed-off-by: Your Name [email protected]
30-
35+
3136
For example:
3237

3338
> swss-common: Stabilize the ConsumerTable
34-
>
39+
>
3540
> * Fixing autoreconf
3641
> * Fixing unit-tests by adding checkers and initialize the DB before start
3742
> * Adding the ability to select from multiple channels
38-
> * Health-Monitor - The idea of the patch is that if something went wrong with the notification channel,
43+
> * Health-Monitor - The idea of the patch is that if something went wrong with the notification channel,
3944
> we will have the option to know about it (Query the LLEN table length).
40-
>
45+
>
4146
> Signed-off-by: John Doe [email protected]
4247
4348

acl_loader/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,11 @@ def deny_rule(self, table_name):
474474
rule_props = {}
475475
rule_data = {(table_name, "DEFAULT_RULE"): rule_props}
476476
rule_props["PRIORITY"] = str(self.min_priority)
477-
rule_props["ETHER_TYPE"] = str(self.ethertype_map["ETHERTYPE_IPV4"])
478477
rule_props["PACKET_ACTION"] = "DROP"
478+
if 'v6' in table_name.lower():
479+
rule_props["ETHER_TYPE"] = str(self.ethertype_map["ETHERTYPE_IPV6"])
480+
else:
481+
rule_props["ETHER_TYPE"] = str(self.ethertype_map["ETHERTYPE_IPV4"])
479482
return rule_data
480483

481484
def convert_rules(self):

clear/bgp_frr_v6.py

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import click
2-
from clear.main import *
2+
from clear.main import ipv6, run_command
33

44

55
###############################################################################
@@ -9,40 +9,28 @@
99
###############################################################################
1010

1111

12-
@ipv6.group(cls=AliasedGroup, default_if_no_args=True,
13-
context_settings=CONTEXT_SETTINGS)
12+
@ipv6.group()
1413
def bgp():
1514
"""Clear IPv6 BGP (Border Gateway Protocol) information"""
1615
pass
1716

18-
19-
# Default 'bgp' command (called if no subcommands or their aliases were passed)
20-
@bgp.command(default=True)
21-
def default():
22-
"""Clear all BGP peers"""
23-
command = 'sudo vtysh -c "clear bgp ipv6 *"'
24-
run_command(command)
25-
26-
27-
@bgp.group(cls=AliasedGroup, default_if_no_args=True,
28-
context_settings=CONTEXT_SETTINGS)
17+
@bgp.group()
2918
def neighbor():
3019
"""Clear specific BGP peers"""
3120
pass
3221

33-
34-
@neighbor.command(default=True)
22+
# 'all' subcommand
23+
@neighbor.command('all')
3524
@click.argument('ipaddress', required=False)
36-
def default(ipaddress):
25+
def neigh_all(ipaddress):
3726
"""Clear all BGP peers"""
3827

3928
if ipaddress is not None:
40-
command = 'sudo vtysh -c "clear bgp ipv6 {} "'.format(ipaddress)
29+
command = 'sudo vtysh -c "clear bgp ipv6 {}"'.format(ipaddress)
4130
else:
4231
command = 'sudo vtysh -c "clear bgp ipv6 *"'
4332
run_command(command)
4433

45-
4634
# 'in' subcommand
4735
@neighbor.command('in')
4836
@click.argument('ipaddress', required=False)
@@ -69,25 +57,11 @@ def neigh_out(ipaddress):
6957
run_command(command)
7058

7159

72-
@neighbor.group(cls=AliasedGroup, default_if_no_args=True,
73-
context_settings=CONTEXT_SETTINGS)
60+
@neighbor.group()
7461
def soft():
7562
"""Soft reconfig BGP's inbound/outbound updates"""
7663
pass
7764

78-
79-
@soft.command(default=True)
80-
@click.argument('ipaddress', required=False)
81-
def default(ipaddress):
82-
"""Clear BGP neighbors soft configuration"""
83-
84-
if ipaddress is not None:
85-
command = 'sudo vtysh -c "clear bgp ipv6 {} soft "'.format(ipaddress)
86-
else:
87-
command = 'sudo vtysh -c "clear bgp ipv6 * soft"'
88-
run_command(command)
89-
90-
9165
# 'soft in' subcommand
9266
@soft.command('in')
9367
@click.argument('ipaddress', required=False)
@@ -101,6 +75,18 @@ def soft_in(ipaddress):
10175
run_command(command)
10276

10377

78+
# 'soft all' subcommand
79+
@neighbor.command('all')
80+
@click.argument('ipaddress', required=False)
81+
def soft_all(ipaddress):
82+
"""Clear BGP neighbors soft configuration"""
83+
84+
if ipaddress is not None:
85+
command = 'sudo vtysh -c "clear bgp ipv6 {} soft"'.format(ipaddress)
86+
else:
87+
command = 'sudo vtysh -c "clear bgp ipv6 * soft"'
88+
run_command(command)
89+
10490
# 'soft out' subcommand
10591
@soft.command('out')
10692
@click.argument('ipaddress', required=False)

clear/bgp_quagga_v4.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import click
2-
from clear.main import *
2+
from clear.main import ip, run_command
33

44

55
###############################################################################
@@ -9,35 +9,25 @@
99
###############################################################################
1010

1111

12-
@ip.group(cls=AliasedGroup, default_if_no_args=True,
13-
context_settings=CONTEXT_SETTINGS)
12+
@ip.group()
1413
def bgp():
1514
"""Clear BGP (Border Gateway Protocol) peers"""
1615
pass
1716

1817

19-
# Default 'bgp' command (called if no subcommands or their aliases were passed)
20-
@bgp.command(default=True)
21-
def default():
22-
"""Clear all BGP peers"""
23-
command = 'sudo vtysh -c "clear ip bgp *"'
24-
run_command(command)
25-
26-
27-
@bgp.group(cls=AliasedGroup, default_if_no_args=True,
28-
context_settings=CONTEXT_SETTINGS)
18+
@bgp.group()
2919
def neighbor():
3020
"""Clear specific BGP peers"""
3121
pass
3222

3323

34-
@neighbor.command(default=True)
24+
@neighbor.command('all')
3525
@click.argument('ipaddress', required=False)
36-
def default(ipaddress):
26+
def neigh_all(ipaddress):
3727
"""Clear all BGP peers"""
3828

3929
if ipaddress is not None:
40-
command = 'sudo vtysh -c "clear ip bgp {} "'.format(ipaddress)
30+
command = 'sudo vtysh -c "clear ip bgp {}"'.format(ipaddress)
4131
else:
4232
command = 'sudo vtysh -c "clear ip bgp *"'
4333
run_command(command)
@@ -69,20 +59,19 @@ def neigh_out(ipaddress):
6959
run_command(command)
7060

7161

72-
@neighbor.group(cls=AliasedGroup, default_if_no_args=True,
73-
context_settings=CONTEXT_SETTINGS)
62+
@neighbor.group()
7463
def soft():
7564
"""Soft reconfig BGP's inbound/outbound updates"""
7665
pass
7766

7867

79-
@soft.command(default=True)
68+
@soft.command('all')
8069
@click.argument('ipaddress', required=False)
81-
def default(ipaddress):
70+
def soft_all(ipaddress):
8271
"""Clear BGP neighbors soft configuration"""
8372

8473
if ipaddress is not None:
85-
command = 'sudo vtysh -c "clear ip bgp {} soft "'.format(ipaddress)
74+
command = 'sudo vtysh -c "clear ip bgp {} soft"'.format(ipaddress)
8675
else:
8776
command = 'sudo vtysh -c "clear ip bgp * soft"'
8877
run_command(command)

clear/bgp_quagga_v6.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import click
2-
from clear.main import *
2+
from clear.main import ipv6, run_command
33

44

55
###############################################################################
@@ -9,35 +9,23 @@
99
###############################################################################
1010

1111

12-
@ipv6.group(cls=AliasedGroup, default_if_no_args=True,
13-
context_settings=CONTEXT_SETTINGS)
12+
@ipv6.group()
1413
def bgp():
1514
"""Clear IPv6 BGP (Border Gateway Protocol) information"""
1615
pass
1716

18-
19-
# Default 'bgp' command (called if no subcommands or their aliases were passed)
20-
@bgp.command(default=True)
21-
def default():
22-
"""Clear all BGP peers"""
23-
command = 'sudo vtysh -c "clear ipv6 bgp *"'
24-
run_command(command)
25-
26-
27-
@bgp.group(cls=AliasedGroup, default_if_no_args=True,
28-
context_settings=CONTEXT_SETTINGS)
17+
@bgp.group()
2918
def neighbor():
3019
"""Clear specific BGP peers"""
3120
pass
3221

33-
34-
@neighbor.command(default=True)
22+
@neighbor.command('all')
3523
@click.argument('ipaddress', required=False)
36-
def default(ipaddress):
24+
def neigh_all(ipaddress):
3725
"""Clear all BGP peers"""
3826

3927
if ipaddress is not None:
40-
command = 'sudo vtysh -c "clear ipv6 bgp {} "'.format(ipaddress)
28+
command = 'sudo vtysh -c "clear ipv6 bgp {}"'.format(ipaddress)
4129
else:
4230
command = 'sudo vtysh -c "clear ipv6 bgp *"'
4331
run_command(command)
@@ -69,20 +57,19 @@ def neigh_out(ipaddress):
6957
run_command(command)
7058

7159

72-
@neighbor.group(cls=AliasedGroup, default_if_no_args=True,
73-
context_settings=CONTEXT_SETTINGS)
60+
@neighbor.group()
7461
def soft():
7562
"""Soft reconfig BGP's inbound/outbound updates"""
7663
pass
7764

7865

79-
@soft.command(default=True)
66+
@soft.command('all')
8067
@click.argument('ipaddress', required=False)
81-
def default(ipaddress):
68+
def soft_all(ipaddress):
8269
"""Clear BGP neighbors soft configuration"""
8370

8471
if ipaddress is not None:
85-
command = 'sudo vtysh -c "clear ipv6 bgp {} soft "'.format(ipaddress)
72+
command = 'sudo vtysh -c "clear ipv6 bgp {} soft"'.format(ipaddress)
8673
else:
8774
command = 'sudo vtysh -c "clear ipv6 bgp * soft"'
8875
run_command(command)

clear/main.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import click
44
import os
55
import subprocess
6-
from click_default_group import DefaultGroup
76

87
try:
98
# noinspection PyPep8Naming
@@ -35,12 +34,10 @@ def read_config(self, filename):
3534
_config = None
3635

3736

38-
# This aliased group has been modified from click examples to inherit from DefaultGroup instead of click.Group.
39-
# DefaultFroup is a superclass of click.Group which calls a default subcommand instead of showing
40-
# a help message if no subcommand is passed
41-
class AliasedGroup(DefaultGroup):
42-
"""This subclass of a DefaultGroup supports looking up aliases in a config
43-
file and with a bit of magic.
37+
38+
class AliasedGroup(click.Group):
39+
"""This subclass of click.Group supports abbreviations and
40+
looking up aliases in a config file with a bit of magic.
4441
"""
4542

4643
def get_command(self, ctx, cmd_name):
@@ -71,12 +68,9 @@ def get_command(self, ctx, cmd_name):
7168
matches = [x for x in self.list_commands(ctx)
7269
if x.lower().startswith(cmd_name.lower())]
7370
if not matches:
74-
# No command name matched. Issue Default command.
75-
ctx.arg0 = cmd_name
76-
cmd_name = self.default_cmd_name
77-
return DefaultGroup.get_command(self, ctx, cmd_name)
71+
return None
7872
elif len(matches) == 1:
79-
return DefaultGroup.get_command(self, ctx, matches[0])
73+
return click.Group.get_command(self, ctx, matches[0])
8074
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
8175

8276

@@ -95,7 +89,7 @@ def get_routing_stack():
9589
proc.wait()
9690
result = stdout.rstrip('\n')
9791

98-
except OSError, e:
92+
except OSError as e:
9993
raise OSError("Cannot detect routing-stack")
10094

10195
return (result)
@@ -380,5 +374,30 @@ def line(linenum):
380374
cmd = "consutil clear " + str(linenum)
381375
run_command(cmd)
382376

377+
#
378+
# 'nat' group ("clear nat ...")
379+
#
380+
381+
@cli.group(cls=AliasedGroup)
382+
def nat():
383+
"""Clear the nat info"""
384+
pass
385+
386+
# 'statistics' subcommand ("clear nat statistics")
387+
@nat.command()
388+
def statistics():
389+
""" Clear all NAT statistics """
390+
391+
cmd = "natclear -s"
392+
run_command(cmd)
393+
394+
# 'translations' subcommand ("clear nat translations")
395+
@nat.command()
396+
def translations():
397+
""" Clear all NAT translations """
398+
399+
cmd = "natclear -t"
400+
run_command(cmd)
401+
383402
if __name__ == '__main__':
384403
cli()

config/aaa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def is_ipaddress(val):
1111
return False
1212
try:
1313
netaddr.IPAddress(str(val))
14-
except:
14+
except ValueError:
1515
return False
1616
return True
1717

0 commit comments

Comments
 (0)