How to send netconf xml
Opened this issue · 2 comments
sak0 commented
example help.
May i send this xml packet with go-netconf like this:
Could you please give an example to do it?
<rpc message-id ="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:h3c="http://www.h3c.com/netconf/base:1.0"> <get> <filter type="subtree"> <top xmlns="http://www.h3c.com/netconf/data:1.0"> <VLAN> <VLANs> <VLANID> <ID></ID> <Description></Description> <Name></Name> <RouteIfIndex></RouteIfIndex> <UntaggedPortList></UntaggedPortList> <TaggedPortList></TaggedPortList> <Shared></Shared> </VLANID> </VLANs> </VLAN> </top> </filter> </get> </rpc>]]>]]>
sak0 commented
package main
import (
"fmt"
"log"
"time"
"github.com/Juniper/go-netconf/netconf"
"golang.org/x/crypto/ssh"
)
func doRpc(s *netconf.Session, xml string) {
reply, err := s.Exec(netconf.RawMethod(xml))
if err != nil {
panic(err)
}
fmt.Printf("Reply: %+v", reply)
}
func main() {
var sshconfig ssh.Config
sshconfig.SetDefaults()
cipherOrder := sshconfig.Ciphers
sshconfig.Ciphers = append(cipherOrder, "aes128-cbc")
sshConfig := &ssh.ClientConfig{
Config: sshconfig,
User: "admin",
Auth: []ssh.AuthMethod{ssh.Password("admin")},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
Timeout: 5 * time.Second,
}
s, err := netconf.DialSSH("10.0.2.2:830", sshConfig)
if err != nil {
log.Fatal(err)
}
defer s.Close()
fmt.Println(s.ServerCapabilities)
fmt.Println(s.SessionID)
xml := `
<rpc message-id ="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:h3c="http://www.h3c.com/netconf/base:1.0">
<get>
<filter type="subtree">
<top xmlns="http://www.h3c.com/netconf/data:1.0">
<VLAN>
<VLANs>
<VLANID>
<ID></ID>
<Description></Description>
<Name></Name>
<RouteIfIndex></RouteIfIndex>
<UntaggedPortList></UntaggedPortList>
<TaggedPortList></TaggedPortList>
<Shared></Shared>
</VLANID>
</VLANs>
</VLAN>
</top>
</filter>
</get>
</rpc>
`
fmt.Printf("%s", xml)
doRpc(s, xml)
}
the code above will hung forever.