This repository has been archived by the owner on Oct 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chassis_zone_request.go
85 lines (70 loc) · 1.79 KB
/
chassis_zone_request.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
package request
import (
"net"
"time"
"github.com/Juniper/go-netconf/netconf"
log "github.com/Sirupsen/logrus"
)
const (
CHASSIS_ZONES_REQUEST_TMPL = "<get-chassis-zones-information></get-chassis-zones-information>"
)
type ChassisZonesRequest struct {
LoopBackIP net.IP
UserName string
Password string
Interval time.Duration
}
func (*ChassisZonesRequest) Method() netconf.RawMethod {
return netconf.RawMethod(CHASSIS_ZONES_REQUEST_TMPL)
}
func NewChassisZonesRequest(loopBackIP net.IP, interval time.Duration,
userName, password string) *ChassisZonesRequest {
return &ChassisZonesRequest{
LoopBackIP: loopBackIP,
UserName: userName,
Password: password,
Interval: interval,
}
}
func (zr *ChassisZonesRequest) Run(count int, replyChan chan<- *netconf.RPCReply) {
go func() {
ticker := time.NewTicker(zr.Interval)
for {
select {
case <-ticker.C:
// Get SSH/NETCONF session going for use throughout the life of this request.
if s, err := netconf.DialSSH(zr.LoopBackIP.String(),
netconf.SSHConfigPassword(zr.UserName, zr.Password)); err != nil {
log.Errorln(err)
s.Close()
close(replyChan)
} else if ncReply, err := s.Exec(zr.Method()); err != nil {
log.Errorln(err)
s.Close()
close(replyChan)
} else {
s.Close()
replyChan <- ncReply
}
count--
if count < 0 {
break
}
}
}
}()
/* cfg := config.GetConfig()
file, err := os.Create(cfg.ChassisZonesResultsFile)
if err != nil {
log.Fatalln(err)
}
for _ = range ticker.C {
if ncReply, err := s.Exec(zr.Method()); err != nil {
log.Error(err)
} else if chassisEnvResp, err := response.NewChassisEnvResponse(&ncReply.Data); err != nil {
log.Error(err)
} else {
chassisEnvResp.WriteCSV(file)
}
}*/
}