From 35848030ca9961a9521b0b76fcbbf599c6a780d3 Mon Sep 17 00:00:00 2001 From: Kanji Nakano Date: Mon, 2 Oct 2023 18:44:43 +0000 Subject: [PATCH 1/2] nexthop group cli support Signed-off-by: Kanji Nakano --- CLI/actioner/sonic-cli-feature.py | 86 +++++++++++++++++++++++++++ CLI/clitree/cli-xml/sonic-feature.xml | 45 ++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 CLI/actioner/sonic-cli-feature.py create mode 100644 CLI/clitree/cli-xml/sonic-feature.xml diff --git a/CLI/actioner/sonic-cli-feature.py b/CLI/actioner/sonic-cli-feature.py new file mode 100644 index 0000000000..29d68e99e2 --- /dev/null +++ b/CLI/actioner/sonic-cli-feature.py @@ -0,0 +1,86 @@ +#!/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 invoke(func, enable): + body = None + aa = cc.ApiClient() + + feature = "nexthop_group" + + if enable == "1": + + keypath = cc.Path("/restconf/data/sonic-feature:sonic-feature") + + body = { + "sonic-feature": { + "FEATURE": {"FEATURE_LIST": [{"name": feature, "state": "enabled"}]} + } + } + return aa.patch(keypath, body) + + else: + + keypath = cc.Path( + "/restconf/data/sonic-feature:sonic-feature/FEATURE/FEATURE_LIST={}".format( + feature + ) + ) + + return aa.delete(keypath) + + +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]) diff --git a/CLI/clitree/cli-xml/sonic-feature.xml b/CLI/clitree/cli-xml/sonic-feature.xml new file mode 100644 index 0000000000..fe1dede2c3 --- /dev/null +++ b/CLI/clitree/cli-xml/sonic-feature.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + python3 $SONIC_CLI_ROOT/sonic-cli-feature.py configure_sonic_nexthop_groups 1 + + + + + + + python3 $SONIC_CLI_ROOT/sonic-cli-feature.py configure_sonic_nexthop_groups 0 + + + + + From 1163b640101c1945d881c8a79822a7d8b2d3db78 Mon Sep 17 00:00:00 2001 From: Kanji Nakano Date: Thu, 9 Nov 2023 20:10:07 +0000 Subject: [PATCH 2/2] update CLI Signed-off-by: Kanji Nakano --- CLI/actioner/sonic-cli-feature.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/CLI/actioner/sonic-cli-feature.py b/CLI/actioner/sonic-cli-feature.py index 29d68e99e2..2a7e22f63a 100644 --- a/CLI/actioner/sonic-cli-feature.py +++ b/CLI/actioner/sonic-cli-feature.py @@ -22,34 +22,30 @@ import re -def invoke(func, enable): +def config_nhg_feature(enable): body = None aa = cc.ApiClient() - feature = "nexthop_group" - - if enable == "1": - - keypath = cc.Path("/restconf/data/sonic-feature:sonic-feature") - + if enable: + keypath = cc.Path("/restconf/data/sonic-device_metadata:sonic-device_metadata") body = { - "sonic-feature": { - "FEATURE": {"FEATURE_LIST": [{"name": feature, "state": "enabled"}]} + "sonic-device_metadata": { + "DEVICE_METADATA": {"localhost": {"nexthop_group": "enabled"}} } } return aa.patch(keypath, body) - else: - keypath = cc.Path( - "/restconf/data/sonic-feature:sonic-feature/FEATURE/FEATURE_LIST={}".format( - feature - ) + "/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")