Skip to content

Commit 0454945

Browse files
committed
dev
1 parent 41c7209 commit 0454945

File tree

9 files changed

+7827
-124
lines changed

9 files changed

+7827
-124
lines changed

go.mod

+27-16
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,61 @@
11
module github.com/asadarafat/topoViewer
22

3-
go 1.19
3+
go 1.21.1
4+
5+
toolchain go1.21.6
46

57
require (
68
github.com/buger/jsonparser v1.1.1
79
github.com/creack/pty v1.1.18
8-
github.com/google/uuid v1.3.0
10+
github.com/google/uuid v1.6.0
911
github.com/gorilla/mux v1.8.0
1012
github.com/gorilla/websocket v1.5.0
13+
github.com/openconfig/gnmic/pkg/api v0.1.2
1114
github.com/prometheus/client_golang v1.14.0
1215
github.com/sirupsen/logrus v1.9.3
1316
github.com/spf13/viper v1.16.0
14-
golang.org/x/crypto v0.12.0
17+
golang.org/x/crypto v0.14.0
1518
)
1619

1720
require (
21+
cloud.google.com/go/compute v1.23.0 // indirect
22+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
23+
github.com/AlekSi/pointer v1.2.0 // indirect
1824
github.com/Microsoft/go-winio v0.6.1 // indirect
25+
github.com/bufbuild/protocompile v0.6.0 // indirect
1926
github.com/docker/distribution v2.8.2+incompatible // indirect
2027
github.com/docker/go-units v0.5.0 // indirect
2128
github.com/gogo/protobuf v1.3.2 // indirect
29+
github.com/jhump/protoreflect v1.15.3 // indirect
2230
github.com/klauspost/cpuid v1.3.1 // indirect
23-
github.com/kylelemons/godebug v1.1.0 // indirect
2431
github.com/mackerelio/go-osstat v0.2.4 // indirect
32+
github.com/morikuni/aec v1.0.0 // indirect
2533
github.com/openconfig/gnmi v0.10.0 // indirect
34+
github.com/openconfig/gnmic/pkg/path v0.1.1 // indirect
35+
github.com/openconfig/gnmic/pkg/target v0.1.4 // indirect
36+
github.com/openconfig/gnmic/pkg/types v0.1.2 // indirect
37+
github.com/openconfig/gnmic/pkg/utils v0.1.0 // indirect
38+
github.com/openconfig/grpctunnel v0.1.0 // indirect
2639
github.com/opencontainers/go-digest v1.0.0 // indirect
2740
github.com/opencontainers/image-spec v1.1.0-rc3 // indirect
2841
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
2942
github.com/pkg/errors v0.9.1 // indirect
3043
golang.org/x/mod v0.12.0 // indirect
31-
golang.org/x/term v0.11.0 // indirect
44+
golang.org/x/oauth2 v0.13.0 // indirect
45+
golang.org/x/term v0.13.0 // indirect
3246
golang.org/x/tools v0.9.3 // indirect
33-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
47+
google.golang.org/appengine v1.6.7 // indirect
48+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
49+
google.golang.org/grpc v1.59.0 // indirect
3450
gopkg.in/yaml.v2 v2.4.0 // indirect
51+
gotest.tools/v3 v3.5.1 // indirect
3552
)
3653

3754
require (
3855
github.com/containernetworking/plugins v1.3.0 // indirect
3956
github.com/docker/go-connections v0.4.1-0.20210727194412-58542c764a11 // indirect
4057
github.com/fsnotify/fsnotify v1.6.0 // indirect
4158
github.com/go-resty/resty/v2 v2.7.0
42-
github.com/google/go-cmp v0.5.9 // indirect
4359
github.com/hashicorp/hcl v1.0.0 // indirect
4460
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4561
github.com/joho/godotenv v1.5.1 // indirect
@@ -55,23 +71,18 @@ require (
5571
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
5672
github.com/vishvananda/netns v0.0.4 // indirect
5773
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect
58-
golang.org/x/net v0.14.0 // indirect
59-
golang.org/x/text v0.12.0 // indirect
60-
google.golang.org/grpc v1.58.0-dev // indirect
74+
golang.org/x/net v0.17.0 // indirect
75+
golang.org/x/text v0.13.0 // indirect
6176
gopkg.in/ini.v1 v1.67.0 // indirect
6277
gopkg.in/yaml.v3 v3.0.1 // indirect
6378
)
6479

6580
require (
66-
github.com/RackSec/srslog v0.0.0-20180709174129-a4725f04ec91
6781
github.com/beorn7/perks v1.0.1 // indirect
6882
github.com/cespare/xxhash/v2 v2.2.0 // indirect
6983
github.com/docker/docker v24.0.6+incompatible
70-
github.com/golang/glog v1.1.2 // indirect
7184
github.com/golang/protobuf v1.5.3 // indirect
7285
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
73-
github.com/openconfig/goyang v1.4.1
74-
github.com/openconfig/ygot v0.29.10
7586
github.com/otiai10/copy v1.11.0
7687
github.com/prometheus/client_model v0.3.0 // indirect
7788
github.com/prometheus/common v0.39.0 // indirect
@@ -80,7 +91,7 @@ require (
8091
github.com/spf13/cobra v1.7.0
8192
github.com/srl-labs/containerlab v0.44.3
8293
github.com/usvc/go-config v0.4.1
83-
golang.org/x/sys v0.11.0 // indirect
84-
google.golang.org/protobuf v1.31.0 // indirect
94+
golang.org/x/sys v0.13.0 // indirect
95+
google.golang.org/protobuf v1.32.0
8596
gopkg.in/natefinch/lumberjack.v2 v2.0.0
8697
)

go.sum

+73-44
Large diffs are not rendered by default.

go_cloudshellwrapper/cmdClab.go

+110-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cloudshellwrapper
22

33
import (
4+
"context"
45
"encoding/json"
56
"errors"
67
"fmt"
@@ -22,6 +23,9 @@ import (
2223
cp "github.com/otiai10/copy"
2324
log "github.com/sirupsen/logrus"
2425

26+
"github.com/openconfig/gnmic/pkg/api"
27+
"google.golang.org/protobuf/encoding/prototext"
28+
2529
"github.com/gorilla/mux"
2630
"github.com/gorilla/websocket"
2731

@@ -157,43 +161,118 @@ func init() {
157161
rootCommand.AddCommand(&clabCommand)
158162
}
159163

160-
// define a reader which will listen for
161-
// new messages being sent to our WebSocket
162-
// endpoint
163-
func reader(conn *websocket.Conn) {
164-
defer conn.Close()
164+
// test gMNIc
165+
func SendGnmicToNodeCapabilities(targetName string, targetAddress string, targetUsername string, targetPassword string, skipVerifyFlag bool, insecureFlag bool) {
166+
// create a target
167+
tg, err := api.NewTarget(
168+
api.Name(targetName),
169+
api.Address(targetAddress+":57400"),
170+
api.Username(targetUsername),
171+
api.Password(targetPassword),
172+
api.SkipVerify(skipVerifyFlag),
173+
api.Insecure(insecureFlag),
174+
)
175+
if err != nil {
176+
log.Fatal(err)
177+
}
165178

166-
// Set the maximum allowed idle time for the WebSocket connection
167-
conn.SetReadDeadline(time.Now().Add(5 * time.Second)) // Adjust the duration as needed
179+
ctx, cancel := context.WithCancel(context.Background())
180+
defer cancel()
168181

169-
for {
170-
// read in a message
171-
messageType, p, err := conn.ReadMessage()
172-
if err != nil {
173-
// Check for specific close error codes indicating client-initiated closure
174-
if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) {
175-
log.Info("WebSocket connection closed by the client.")
176-
} else {
177-
log.Info("Error while reading from WebSocket:", err)
178-
}
179-
return
180-
}
181-
// print out that message for clarity
182-
log.Info(string(p))
182+
// create a gNMI client
183+
err = tg.CreateGNMIClient(ctx)
184+
if err != nil {
185+
log.Fatal(err)
186+
}
187+
defer tg.Close()
183188

184-
if err := conn.WriteMessage(messageType, p); err != nil {
185-
log.Info(err)
186-
return
187-
}
188-
conn.SetReadDeadline(time.Now().Add(5 * time.Second))
189+
// send a gNMI capabilities request to the created target
190+
capResp, err := tg.Capabilities(ctx)
191+
if err != nil {
192+
log.Fatal(err)
189193
}
194+
fmt.Println(prototext.Format(capResp))
190195
}
191196

197+
func SendGnmicToNodeGet(targetName string, targetAddress string, targetUsername string, targetPassword string, skipVerifyFlag bool, insecureFlag bool, path string) {
198+
// create a target
199+
tg, err := api.NewTarget(
200+
api.Name(targetName),
201+
api.Address(targetAddress+":57400"),
202+
api.Username(targetUsername),
203+
api.Password(targetPassword),
204+
api.SkipVerify(skipVerifyFlag),
205+
api.Insecure(insecureFlag),
206+
)
207+
if err != nil {
208+
log.Fatal(err)
209+
}
210+
211+
ctx, cancel := context.WithCancel(context.Background())
212+
defer cancel()
213+
214+
// create a gNMI client
215+
err = tg.CreateGNMIClient(ctx)
216+
if err != nil {
217+
log.Fatal(err)
218+
}
219+
defer tg.Close()
220+
221+
// create a GetRequest
222+
getReq, err := api.NewGetRequest(
223+
api.Path(path),
224+
api.Encoding("json_ietf"))
225+
if err != nil {
226+
log.Fatal(err)
227+
}
228+
fmt.Println(prototext.Format(getReq))
229+
230+
// send the created gNMI GetRequest to the created target
231+
getResp, err := tg.Get(ctx, getReq)
232+
if err != nil {
233+
log.Fatal(err)
234+
}
235+
fmt.Println(prototext.Format(getResp))
236+
}
237+
238+
// define a reader which will listen for
239+
// new messages being sent to our WebSocket
240+
// endpoint
241+
// func reader(conn *websocket.Conn) {
242+
// defer conn.Close()
243+
244+
// // Set the maximum allowed idle time for the WebSocket connection
245+
// conn.SetReadDeadline(time.Now().Add(5 * time.Second)) // Adjust the duration as needed
246+
247+
// for {
248+
// // read in a message
249+
// messageType, p, err := conn.ReadMessage()
250+
// if err != nil {
251+
// // Check for specific close error codes indicating client-initiated closure
252+
// if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) {
253+
// log.Info("WebSocket connection closed by the client.")
254+
// } else {
255+
// log.Info("Error while reading from WebSocket:", err)
256+
// }
257+
// return
258+
// }
259+
// // print out that message for clarity
260+
// log.Info(string(p))
261+
262+
// if err := conn.WriteMessage(messageType, p); err != nil {
263+
// log.Info(err)
264+
// return
265+
// }
266+
// conn.SetReadDeadline(time.Now().Add(5 * time.Second))
267+
// }
268+
// }
269+
192270
func checkSudoAccess() {
193271
euid := syscall.Geteuid()
194272

195273
if euid == 0 {
196274
log.Infof("Yo, this app is running with sudo access (as root).")
275+
197276
} else {
198277
log.Infof("This app ain't got no sudo powers, bro.")
199278
os.Exit(1)
@@ -205,6 +284,11 @@ func Clab(_ *cobra.Command, _ []string) error {
205284

206285
//check sudo
207286
checkSudoAccess()
287+
// SendGnmicToNodeCapabilities("srl", "10.2.1.121", "admin", "NokiaSrl1!", true, false)
288+
// SendGnmicToNodeCapabilities("sros", "10.2.1.101", "admin", "admin", true, true)
289+
290+
// SendGnmicToNodeGet("srl", "10.2.1.121", "admin", "NokiaSrl1!", true, false, "/system/name")
291+
// SendGnmicToNodeGet("sros", "10.2.1.101", "admin", "admin", true, true, "/system/name")
208292

209293
// initialise the cloudshellLogger
210294
// tools.InitCloudShellLog(tools.Format(confClab.GetString("log-format")), tools.Level(confClab.GetString("log-level")))
@@ -633,18 +717,6 @@ func Clab(_ *cobra.Command, _ []string) error {
633717
err1 := cp.Copy(sourceClabClientFolder, destinationClabClientImageFolder)
634718
log.Debug("Copying clab-client folder error: ", err1)
635719

636-
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "index.tmpl", cyTopo.ClabTopoDataV2.Name+"/"+"index.html", "dataCytoMarshall-"+cyTopo.ClabTopoDataV2.Name+".json")
637-
638-
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "index.tmpl", cyTopo.ClabTopoDataV2.Name+"/"+"index.html", cyTopo.ClabTopoDataV2.Name)
639-
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "cy-style.tmpl", cyTopo.ClabTopoDataV2.Name+"/"+"cy-style.json", "")
640-
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "cloudshell-index.tmpl", cyTopo.ClabTopoDataV2.Name+"/cloudshell/"+"index.html", "")
641-
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "cloudshell-terminal-js.tmpl", cyTopo.ClabTopoDataV2.Name+"/cloudshell/"+"terminal.js", "")
642-
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "tools-cloudshell-index.tmpl", cyTopo.ClabTopoDataV2.Name+"/cloudshell-tools/"+"index.html", "")
643-
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "tools-cloudshell-terminal-js.tmpl", cyTopo.ClabTopoDataV2.Name+"/cloudshell-tools/"+"terminal.js", "")
644-
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "websocket-index.tmpl", cyTopo.ClabTopoDataV2.Name+"/ws/"+"index.html", "")
645-
646-
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "button.tmpl", cyTopo.ClabTopoDataV2.Name+"/"+"button.html", cyTopo.ClabTopoDataV2.Name)
647-
648720
indexHtmldata := IndexHtmlStruct{
649721
LabName: cyTopo.ClabTopoDataV2.Name,
650722
DeploymentType: deploymentType,

go_topoengine/cmd/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,9 @@ func main() {
820820
// panic(err)
821821
// }
822822

823-
tools.CommentProcessor("./html-public/nokia-MAGc-lab/button.html", "./html-static/template/clab/button.tmpl")
823+
// tools.CommentProcessor("./html-public/nokia-MAGc-lab/button.html", "./html-static/template/clab/button.tmpl")
824824
// tools.CommentProcessor("./html-public/demo/button.html", "./html-static/template/clab/button.tmpl")
825+
tools.CommentProcessor("./html-public/nokia-ServiceProvider/button.html", "./html-static/template/clab/button.tmpl")
825826

826827
// cytoUiGo.GetDockerNodeStatusViaUnixSocket("clab-3tierSmall-dcgw-1", "localhost")
827828

0 commit comments

Comments
 (0)