Skip to content
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
15 changes: 15 additions & 0 deletions models/yang/annotations/sonic-file-mgmt-annot.yang
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
31 changes: 31 additions & 0 deletions models/yang/sonic/sonic-file-mgmt.yang
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
}
61 changes: 61 additions & 0 deletions translib/transformer/xfmr_sonic_file_mgmt.go
Original file line number Diff line number Diff line change
@@ -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
}