Skip to content

Commit

Permalink
Merge branch 'macsecCLI' into macsec_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Pterosaur committed Oct 25, 2021
2 parents 8ea834b + 766aaf9 commit 5eda315
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
92 changes: 92 additions & 0 deletions config/macsec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import click
import utilities_common.cli as clicommon

from time import sleep
from .utils import log

#
# 'macsec' group ('config macsec ...')
#
@click.group(cls=clicommon.AbbreviationGroup, name='macsec')
def macsec():
"""MACsec-related configuration tasks"""
pass

@macsec.group(cls=clicommon.AbbreviationGroup, name='port')
def macsec_port():
pass

@macsec_port.command('add')
@click.argument('port', metavar='<port_name>', required=True)
@click.argument('profile', metavar='<profile_name>', required=True)
@clicommon.pass_db
def add_port(db, port, profile):
"""
Add MACsec port
"""
ctx = click.get_current_context()

if clicommon.get_interface_naming_mode() == "alias":
alias = port
iface_alias_converter = clicommon.InterfaceAliasConverter(db)
port = iface_alias_converter.alias_to_name(alias)
if port is None:
ctx.fail("cannot find port name for alias {}".format(alias))

profile_entry = db.cfgdb.get_entry('MACSEC_PROFILE', profile)
if len(profile_entry) == 0:
ctx.fail("{} doesn't exist".format(profile))

db.cfgdb.set_entry("PORT", port, {'macsec': profile})

@macsec_port.command('del')
@click.argument('port', metavar='<port_name>', required=True)
@clicommon.pass_db
def del_port(db, port):
"""
Delete MACsec port
"""
ctx = click.get_current_context()

if clicommon.get_interface_naming_mode() == "alias":
alias = port
iface_alias_converter = clicommon.InterfaceAliasConverter(db)
port = iface_alias_converter.alias_to_name(alias)
if port is None:
ctx.fail("cannot find port name for alias {}".format(alias))

db.cfgdb.set_entry("PORT", port, {'macsec': ""})

@macsec.group(cls=clicommon.AbbreviationGroup, name='profile')
def macsec_profile():
pass

@macsec_profile.command('add')
@click.argument('profile', metavar='<profile_name>', required=True)
@clicommon.pass_db
def add_profile(db,profile):
"""
Add MACsec profile
"""
ctx = click.get_current_context()

if not len(profile_entry) == 0:
ctx.fail("{} already exists".format(profile))

db.cfgdb.set_entry("MACSEC_PROFILE", profile, {'NULL': 'NULL'})

@macsec_profile.command('del')
@click.argument('profile', metavar='<profile_name>', required=True)
@clicommon.pass_db
def del_profile(db, profile):
"""
Delete MACsec profile
"""
ctx = click.get_current_context()

profile_entry = db.cfgdb.get_entry('MACSEC_PROFILE', profile)
if len(profile_entry) == 0:
ctx.fail("{} doesn't exist".format(profile))

db.cfgdb.set_entry("MACSEC_PROFILE", profile, None)

2 changes: 2 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from . import feature
from . import kdump
from . import kube
from . import macsec
from . import muxcable
from . import nat
from . import vlan
Expand Down Expand Up @@ -1015,6 +1016,7 @@ def config(ctx):
config.add_command(feature.feature)
config.add_command(kdump.kdump)
config.add_command(kube.kubernetes)
config.add_command(macsec.macsec)
config.add_command(muxcable.muxcable)
config.add_command(nat.nat)
config.add_command(vlan.vlan)
Expand Down

0 comments on commit 5eda315

Please sign in to comment.