diff --git a/models/yang/annotations/sonic-file-mgmt-annot.yang b/models/yang/annotations/sonic-file-mgmt-annot.yang new file mode 100644 index 000000000..d185e4868 --- /dev/null +++ b/models/yang/annotations/sonic-file-mgmt-annot.yang @@ -0,0 +1,15 @@ +module sonic-file-mgmt-annot { + yang-version "1"; + + namespace "http://openconfig.net/Azure/sonic-file-mgmt-annot"; + prefix "sfilemgmt-annot"; + + import sonic-extensions { prefix sonic-ext; } + import sonic-file-mgmt { prefix sfilemgmt; } + + deviation /sfilemgmt:remove { + deviate add { + sonic-ext:rpc-callback "rpc_file_remove_cb"; + } + } +} \ No newline at end of file diff --git a/models/yang/sonic/sonic-file-mgmt.yang b/models/yang/sonic/sonic-file-mgmt.yang new file mode 100644 index 000000000..c3d441336 --- /dev/null +++ b/models/yang/sonic/sonic-file-mgmt.yang @@ -0,0 +1,31 @@ +module sonic-file-mgmt { + namespace "http://github.com/Azure/sonic-file-mgmt"; + prefix sfilemgmt; + yang-version 1.1; + + organization + "SONiC"; + + contact + "SONiC"; + + description + "SONiC RPCs definition for file module"; + + revision 2025-01-23 { + description + "Initial revision."; + } + + rpc remove { + description + "Remove removes the specified file from the target"; + input { + leaf remote_file { + type string; + description + "Path of the file to remove"; + } + } + } +} \ No newline at end of file diff --git a/translib/transformer/xfmr_sonic_file_mgmt.go b/translib/transformer/xfmr_sonic_file_mgmt.go new file mode 100644 index 000000000..865cb5d4e --- /dev/null +++ b/translib/transformer/xfmr_sonic_file_mgmt.go @@ -0,0 +1,61 @@ +//////////////////////////////////////////////////////////////////////////////// +// // +// Copyright 2025 Cisco. // +// // +// 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. // +// // +//////////////////////////////////////////////////////////////////////////////// + +package transformer + +import ( + "encoding/json" + + "github.com/Azure/sonic-mgmt-common/translib/db" + "github.com/Azure/sonic-mgmt-common/translib/tlerr" + "github.com/golang/glog" +) + +func init() { + XlateFuncBind("rpc_file_remove_cb", rpc_file_remove_cb) +} + +var rpc_file_remove_cb RpcCallpoint = func(body []byte, _ [db.MaxDB]*db.DB) ([]byte, error) { + var err error + var output struct{} + var operand struct { + RemoteFile string `json:"remote_file"` + } + glog.Info("File Remove request - RPC callback") + + err = json.Unmarshal(body, &operand) + if err != nil { + glog.Errorf("Error: Failed to parse rpc input; err=%v", err) + return nil, tlerr.InvalidArgs("Invalid rpc input") + } + + result, _ := json.Marshal(&output) + + host_output := HostQuery("file.remove", operand.RemoteFile) + if host_output.Err != nil { + glog.Errorf("Error: File Remove host Query failed: err=%v", host_output.Err) + return nil, host_output.Err + } + if host_output.Body[0].(int32) != 0 { + err = tlerr.New(host_output.Body[1].(string)) + glog.Errorf("Error: File Remove host Query failed: err=%v", err) + return nil, err + } + + return result, nil +}