Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fpmsyncd] Added CLI for Fpmsyncd Next Hop Table Enhancement #122

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions CLI/actioner/sonic-cli-feature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/python
###########################################################################
#
# Copyright (C) 2023 NIPPON TELEGRAPH AND TELEPHONE CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################

import sys
import cli_client as cc
import re


def config_nhg_feature(enable):
body = None
aa = cc.ApiClient()

if enable:
keypath = cc.Path("/restconf/data/sonic-device_metadata:sonic-device_metadata")
body = {
"sonic-device_metadata": {
"DEVICE_METADATA": {"localhost": {"nexthop_group": "enabled"}}
}
}
return aa.patch(keypath, body)
else:
keypath = cc.Path(
"/restconf/data/sonic-device_metadata:sonic-device_metadata/DEVICE_METADATA/localhost/nexthop_group"
)
return aa.delete(keypath)


def invoke(func, enable):
if func == "configure_sonic_nexthop_groups":
return config_nhg_feature(enable == "1")


def run(func, enable):
if func != "configure_sonic_nexthop_groups":
print("%Error: Invalid function")
return

try:
api_response = invoke(func, enable)
except ValueError as err_msg:
print(
"%Error: An exception occurred while attempting to execute "
"the requested RPC call: {}".format(err_msg)
)

if not api_response.ok():
# Print the message for a failing return code
print("CLI transformer error: ")
print(" status code: {}".format(api_response.status_code))
if (
"error" in api_response.errors()
and len(api_response.errors()["error"]) >= 1
and "error-message" in api_response.errors()["error"][0]
):
print(
" error: {}".format(
api_response.errors()["error"][0]["error-message"]
)
)
return

print("Success")


if __name__ == "__main__":
run(sys.argv[1], sys.argv[2])
45 changes: 45 additions & 0 deletions CLI/clitree/cli-xml/sonic-feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2023 NIPPON TELEGRAPH AND TELEPHONE CORPORATION.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<CLISH_MODULE
xmlns="http://www.dellemc.com/sonic/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:schemaLocation="http://www.dellemc.com/sonic/XMLSchema
http://www.dellemc.com/sonic/XMLSchema/clish.xsd"
>
<!--=========================================================================-->

<VIEW name="configure-view">

<COMMAND name="feature" help="Configure additional feature"></COMMAND>
<COMMAND name="feature next-hop-group" help="Next-hop Groups feature"></COMMAND>
<COMMAND name="feature next-hop-group enable" help="Enable Next-hop Groups feature">
<ACTION>
python3 $SONIC_CLI_ROOT/sonic-cli-feature.py configure_sonic_nexthop_groups 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the HLD it is mentioned that the enable disable cannot be changed in run time. Then why do we have a CLI which can modify it? If it doesn't take effect we should have a log message asking the user to save and reboot

</ACTION>
</COMMAND>

<COMMAND name="no feature" help="Disable additional feature"></COMMAND>
<COMMAND name="no feature next-hop-group" help="Disable Next-hop Groups feature">
<ACTION>
python3 $SONIC_CLI_ROOT/sonic-cli-feature.py configure_sonic_nexthop_groups 0
</ACTION>
</COMMAND>

</VIEW>
</CLISH_MODULE>
Loading