[dhcp_server] add dhcp server show option (#17469)
* add show dhcp_server option * Option to option id
This commit is contained in:
parent
038ca267c8
commit
7011e00eba
@ -149,3 +149,28 @@ Vlan100 PORT 100.1.1.1 255.255.255.0 3600 enabled option6
|
||||
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
|
||||
assert result.stdout == expected_stdout
|
||||
|
||||
def test_show_dhcp_server_ipv4_option_without_name(self, mock_db):
|
||||
expected_stdout = """\
|
||||
Option Name Option ID Value Type
|
||||
------------- ----------- ----------- ------
|
||||
option60 60 dummy_value string
|
||||
"""
|
||||
runner = CliRunner()
|
||||
db = clicommon.Db()
|
||||
db.db = mock_db
|
||||
result = runner.invoke(show_dhcp_server.dhcp_server.commands["ipv4"].commands["option"], [], obj=db)
|
||||
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
|
||||
assert result.stdout == expected_stdout
|
||||
|
||||
def test_show_dhcp_server_ipv4_option_with_name(self, mock_db):
|
||||
expected_stdout = """\
|
||||
Option Name Option ID Value Type
|
||||
------------- ----------- ----------- ------
|
||||
option60 60 dummy_value string
|
||||
"""
|
||||
runner = CliRunner()
|
||||
db = clicommon.Db()
|
||||
db.db = mock_db
|
||||
result = runner.invoke(show_dhcp_server.dhcp_server.commands["ipv4"].commands["option"], ["option60"], obj=db)
|
||||
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
|
||||
assert result.stdout == expected_stdout
|
||||
|
@ -100,5 +100,21 @@ def info(db, dhcp_interface, with_customized_options):
|
||||
click.echo(tabulate(table, headers=headers))
|
||||
|
||||
|
||||
@ipv4.command()
|
||||
@click.argument("option_name", required=False)
|
||||
@clicommon.pass_db
|
||||
def option(db, option_name):
|
||||
if not option_name:
|
||||
option_name = "*"
|
||||
headers = ["Option Name", "Option ID", "Value", "Type"]
|
||||
table = []
|
||||
dbconn = db.db
|
||||
for key in dbconn.keys("CONFIG_DB", "DHCP_SERVER_IPV4_CUSTOMIZED_OPTIONS|" + option_name):
|
||||
entry = dbconn.get_all("CONFIG_DB", key)
|
||||
name = key.split("|")[1]
|
||||
table.append([name, entry["id"], entry["value"], entry["type"]])
|
||||
click.echo(tabulate(table, headers=headers))
|
||||
|
||||
|
||||
def register(cli):
|
||||
cli.add_command(dhcp_server)
|
||||
|
Loading…
Reference in New Issue
Block a user