Skip to content

Commit

Permalink
Added method to allow custom RPC commands
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdware committed Apr 17, 2015
1 parent 65f62e4 commit 2443d95
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions netconf/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ func MethodUnlock(target string) RawMethod {
func MethodGetConfig(source string) RawMethod {
return RawMethod(fmt.Sprintf("<get-config><source><%s/></source></get-config>", source))
}

func MethodRPC(command string) RawMethod {
return RawMethod(fmt.Sprintf("%s", command))
}

3 comments on commit 2443d95

@scottdware
Copy link
Author

Choose a reason for hiding this comment

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

MethodRPC() allows the user to define custom RPC calls.

package main

import (
    "fmt"
    "github.com/Juniper/go-netconf/netconf"
)

func main() {
    host := "junos-device"
    username := "myuser"
    password := "mypassword"

    s, err := netconf.DialSSH(host, netconf.SSHConfigPassword(username, password))
    if err != nil {
        panic(err)
    }
    defer s.Close()

    reply, err := s.Exec(netconf.MethodRPC("<get-software-information/>"))
    if err != nil {
        panic(err)
    }
    fmt.Printf("Reply: %+v", reply)
}

@charl
Copy link
Contributor

@charl charl commented on 2443d95 Apr 18, 2015

Choose a reason for hiding this comment

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

I generally add this wrapper to my code myself but it makes sense to support it here though.

I'd champion RawRPC() though for clarity and to keep in theme with the rest of the naming instead of MethodRPC().

@scottdware
Copy link
Author

Choose a reason for hiding this comment

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

Sounds great, thanks for the advice! I was going back-and-forth on the name, as I was worried about confusion with "RPCMethod" you list earlier ;)

Please sign in to comment.