-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
124 lines (115 loc) · 3.35 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package eznc
import (
"fmt"
"github.com/Juniper/go-netconf/netconf"
)
// ExecConfigRPC is a func
func ExecConfigRPC(ns *netconf.Session, rpc string, attributes string, configuration string) (*netconf.RPCReply, error) {
if rpc == "lock-configuration" || rpc == "unlock-configuration" {
reply, err := ns.Exec(netconf.RawMethod(fmt.Sprintf("<%s/>", rpc)))
return reply, err
} else {
if rpc == "commit-configuration" {
if configuration != "" {
reply, err := ns.Exec(netconf.RawMethod(fmt.Sprintf("<%s>%s</%s>", rpc, configuration, rpc)))
if err != nil {
panic(err)
}
return reply, err
}
reply, err := ns.Exec(netconf.RawMethod(fmt.Sprintf("<%s/>", rpc)))
if err != nil {
panic(err)
}
return reply, err
} else if rpc == "load-configuration" {
if attributes != "" && configuration != "" {
reply, err := ns.Exec(netconf.RawMethod(fmt.Sprintf("<%s %s>%s</%s>", rpc, attributes, configuration, rpc)))
if err != nil {
panic(err)
}
return reply, err
} else if attributes != "" && configuration == "" {
reply, err := ns.Exec(netconf.RawMethod(fmt.Sprintf("<%s %s></%s>", rpc, attributes, rpc)))
if err != nil {
panic(err)
}
return reply, err
} else if attributes == "" && configuration != "" {
reply, err := ns.Exec(netconf.RawMethod(fmt.Sprintf("<%s>%s</%s>", rpc, configuration, rpc)))
if err != nil {
panic(err)
}
return reply, err
} else {
reply, err := ns.Exec(netconf.RawMethod(fmt.Sprintf("<%s/>", rpc)))
if err != nil {
panic(err)
}
return reply, err
}
} else if rpc == "get-configuration" {
if attributes != "" {
reply, err := ns.Exec(netconf.RawMethod(fmt.Sprintf("<%s %s></%s>", rpc, attributes, rpc)))
if err != nil {
panic(err)
}
return reply, err
} else {
reply, err := ns.Exec(netconf.RawMethod(fmt.Sprintf("<%s/>", rpc)))
if err != nil {
panic(err)
}
return reply, err
}
} else {
err := "Invalid RPC request!!"
panic(err)
}
}
}
func Get_configuration(ns *netconf.Session, attributes string) (*netconf.RPCReply, error) {
if ns == nil {
err := "Netconf connection handle missing!!"
panic(err)
} else {
reply, err := ExecConfigRPC(ns, "get-configuration", attributes, "")
return reply, err
}
}
func Commit_configuration(ns *netconf.Session, configuration string) (*netconf.RPCReply, error) {
if ns == nil {
err := "Netconf connection handle missing!!"
panic(err)
} else {
reply, err := ExecConfigRPC(ns, "commit-configuration", "", configuration)
return reply, err
}
}
func Load_configuration(ns *netconf.Session, attributes string, configuration string) (*netconf.RPCReply, error) {
if ns == nil {
err := "Netconf connection handle missing!!"
panic(err)
} else {
reply, err := ExecConfigRPC(ns, "load-configuration", attributes, configuration)
return reply, err
}
}
func Lock_configuration(ns *netconf.Session) (*netconf.RPCReply, error) {
if ns == nil {
err := "Netconf connection handle missing!!"
panic(err)
} else {
reply, err := ExecConfigRPC(ns, "lock-configuration", "", "")
return reply, err
}
}
func Unlock_configuration(ns *netconf.Session) (*netconf.RPCReply, error) {
if ns == nil {
err := "Netconf connection handle missing!!"
panic(err)
} else {
reply, err := ExecConfigRPC(ns, "unlock-configuration", "", "")
return reply, err
}
}