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

Added method to allow custom RPC commands #11

Closed
wants to merge 4 commits into from
Closed
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
8 changes: 7 additions & 1 deletion netconf/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/xml"
"fmt"
"strings"
)

type RPCMessage struct {
Expand Down Expand Up @@ -54,7 +55,7 @@ type RPCError struct {
}

func (re *RPCError) Error() string {
return fmt.Sprintf("netconf rpc [%s] '%s'", re.Severity, re.Message)
return fmt.Sprintf("netconf rpc [%s]: %s", re.Severity, strings.Trim(re.Message, "[\r\n]"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please show me some cases where you need to remove leading and trailing "[\r\n]"?

Copy link
Contributor

@jamesboswell jamesboswell Nov 10, 2016

Choose a reason for hiding this comment

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

@charl @scottdware I've just run into the trailing [\n] on some RawMethod output
Using spew, I can see raw output like this
Text: (string) (len=16) "\nAvailable port\n"

I'm not sure where the [\n] is getting introduced. Go1.7.3 xml package

Here is an example code and output

}

type RPCMethod interface {
Expand All @@ -78,3 +79,8 @@ func MethodUnlock(target string) RawMethod {
func MethodGetConfig(source string) RawMethod {
return RawMethod(fmt.Sprintf("<get-config><source><%s/></source></get-config>", source))
}

// RawRPC allows any RPC command to be run on the target.
func RawRPC(command string) RawMethod {
return RawMethod(fmt.Sprintf("%s", command))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you using fmt.Sprintf() here? command can only ever be a string and you're not doing any variable interpolation.

Copy link
Author

Choose a reason for hiding this comment

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

That's my bad, I should change that to just reflect return RawMethod(command)

}