Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
asadarafat committed Feb 4, 2024
1 parent 41c7209 commit 0454945
Show file tree
Hide file tree
Showing 9 changed files with 7,827 additions and 124 deletions.
43 changes: 27 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,45 +1,61 @@
module github.com/asadarafat/topoViewer

go 1.19
go 1.21.1

toolchain go1.21.6

require (
github.com/buger/jsonparser v1.1.1
github.com/creack/pty v1.1.18
github.com/google/uuid v1.3.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
github.com/openconfig/gnmic/pkg/api v0.1.2
github.com/prometheus/client_golang v1.14.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/viper v1.16.0
golang.org/x/crypto v0.12.0
golang.org/x/crypto v0.14.0
)

require (
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/AlekSi/pointer v1.2.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/bufbuild/protocompile v0.6.0 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/jhump/protoreflect v1.15.3 // indirect
github.com/klauspost/cpuid v1.3.1 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mackerelio/go-osstat v0.2.4 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/openconfig/gnmi v0.10.0 // indirect
github.com/openconfig/gnmic/pkg/path v0.1.1 // indirect
github.com/openconfig/gnmic/pkg/target v0.1.4 // indirect
github.com/openconfig/gnmic/pkg/types v0.1.2 // indirect
github.com/openconfig/gnmic/pkg/utils v0.1.0 // indirect
github.com/openconfig/grpctunnel v0.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc3 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/tools v0.9.3 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.59.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gotest.tools/v3 v3.5.1 // indirect
)

require (
github.com/containernetworking/plugins v1.3.0 // indirect
github.com/docker/go-connections v0.4.1-0.20210727194412-58542c764a11 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-resty/resty/v2 v2.7.0
github.com/google/go-cmp v0.5.9 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
Expand All @@ -55,23 +71,18 @@ require (
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/grpc v1.58.0-dev // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/RackSec/srslog v0.0.0-20180709174129-a4725f04ec91
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/docker/docker v24.0.6+incompatible
github.com/golang/glog v1.1.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/openconfig/goyang v1.4.1
github.com/openconfig/ygot v0.29.10
github.com/otiai10/copy v1.11.0
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
Expand All @@ -80,7 +91,7 @@ require (
github.com/spf13/cobra v1.7.0
github.com/srl-labs/containerlab v0.44.3
github.com/usvc/go-config v0.4.1
golang.org/x/sys v0.11.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
golang.org/x/sys v0.13.0 // indirect
google.golang.org/protobuf v1.32.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)
117 changes: 73 additions & 44 deletions go.sum

Large diffs are not rendered by default.

148 changes: 110 additions & 38 deletions go_cloudshellwrapper/cmdClab.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cloudshellwrapper

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -22,6 +23,9 @@ import (
cp "github.com/otiai10/copy"
log "github.com/sirupsen/logrus"

"github.com/openconfig/gnmic/pkg/api"
"google.golang.org/protobuf/encoding/prototext"

"github.com/gorilla/mux"
"github.com/gorilla/websocket"

Expand Down Expand Up @@ -157,43 +161,118 @@ func init() {
rootCommand.AddCommand(&clabCommand)
}

// define a reader which will listen for
// new messages being sent to our WebSocket
// endpoint
func reader(conn *websocket.Conn) {
defer conn.Close()
// test gMNIc
func SendGnmicToNodeCapabilities(targetName string, targetAddress string, targetUsername string, targetPassword string, skipVerifyFlag bool, insecureFlag bool) {
// create a target
tg, err := api.NewTarget(
api.Name(targetName),
api.Address(targetAddress+":57400"),
api.Username(targetUsername),
api.Password(targetPassword),
api.SkipVerify(skipVerifyFlag),
api.Insecure(insecureFlag),
)
if err != nil {
log.Fatal(err)
}

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

for {
// read in a message
messageType, p, err := conn.ReadMessage()
if err != nil {
// Check for specific close error codes indicating client-initiated closure
if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) {
log.Info("WebSocket connection closed by the client.")
} else {
log.Info("Error while reading from WebSocket:", err)
}
return
}
// print out that message for clarity
log.Info(string(p))
// create a gNMI client
err = tg.CreateGNMIClient(ctx)
if err != nil {
log.Fatal(err)
}
defer tg.Close()

if err := conn.WriteMessage(messageType, p); err != nil {
log.Info(err)
return
}
conn.SetReadDeadline(time.Now().Add(5 * time.Second))
// send a gNMI capabilities request to the created target
capResp, err := tg.Capabilities(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(prototext.Format(capResp))
}

func SendGnmicToNodeGet(targetName string, targetAddress string, targetUsername string, targetPassword string, skipVerifyFlag bool, insecureFlag bool, path string) {
// create a target
tg, err := api.NewTarget(
api.Name(targetName),
api.Address(targetAddress+":57400"),
api.Username(targetUsername),
api.Password(targetPassword),
api.SkipVerify(skipVerifyFlag),
api.Insecure(insecureFlag),
)
if err != nil {
log.Fatal(err)
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// create a gNMI client
err = tg.CreateGNMIClient(ctx)
if err != nil {
log.Fatal(err)
}
defer tg.Close()

// create a GetRequest
getReq, err := api.NewGetRequest(
api.Path(path),
api.Encoding("json_ietf"))
if err != nil {
log.Fatal(err)
}
fmt.Println(prototext.Format(getReq))

// send the created gNMI GetRequest to the created target
getResp, err := tg.Get(ctx, getReq)
if err != nil {
log.Fatal(err)
}
fmt.Println(prototext.Format(getResp))
}

// define a reader which will listen for
// new messages being sent to our WebSocket
// endpoint
// func reader(conn *websocket.Conn) {
// defer conn.Close()

// // Set the maximum allowed idle time for the WebSocket connection
// conn.SetReadDeadline(time.Now().Add(5 * time.Second)) // Adjust the duration as needed

// for {
// // read in a message
// messageType, p, err := conn.ReadMessage()
// if err != nil {
// // Check for specific close error codes indicating client-initiated closure
// if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) {
// log.Info("WebSocket connection closed by the client.")
// } else {
// log.Info("Error while reading from WebSocket:", err)
// }
// return
// }
// // print out that message for clarity
// log.Info(string(p))

// if err := conn.WriteMessage(messageType, p); err != nil {
// log.Info(err)
// return
// }
// conn.SetReadDeadline(time.Now().Add(5 * time.Second))
// }
// }

func checkSudoAccess() {
euid := syscall.Geteuid()

if euid == 0 {
log.Infof("Yo, this app is running with sudo access (as root).")

} else {
log.Infof("This app ain't got no sudo powers, bro.")
os.Exit(1)
Expand All @@ -205,6 +284,11 @@ func Clab(_ *cobra.Command, _ []string) error {

//check sudo
checkSudoAccess()
// SendGnmicToNodeCapabilities("srl", "10.2.1.121", "admin", "NokiaSrl1!", true, false)
// SendGnmicToNodeCapabilities("sros", "10.2.1.101", "admin", "admin", true, true)

// SendGnmicToNodeGet("srl", "10.2.1.121", "admin", "NokiaSrl1!", true, false, "/system/name")
// SendGnmicToNodeGet("sros", "10.2.1.101", "admin", "admin", true, true, "/system/name")

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

// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "index.tmpl", cyTopo.ClabTopoDataV2.Name+"/"+"index.html", "dataCytoMarshall-"+cyTopo.ClabTopoDataV2.Name+".json")

// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "index.tmpl", cyTopo.ClabTopoDataV2.Name+"/"+"index.html", cyTopo.ClabTopoDataV2.Name)
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "cy-style.tmpl", cyTopo.ClabTopoDataV2.Name+"/"+"cy-style.json", "")
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "cloudshell-index.tmpl", cyTopo.ClabTopoDataV2.Name+"/cloudshell/"+"index.html", "")
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "cloudshell-terminal-js.tmpl", cyTopo.ClabTopoDataV2.Name+"/cloudshell/"+"terminal.js", "")
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "tools-cloudshell-index.tmpl", cyTopo.ClabTopoDataV2.Name+"/cloudshell-tools/"+"index.html", "")
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "tools-cloudshell-terminal-js.tmpl", cyTopo.ClabTopoDataV2.Name+"/cloudshell-tools/"+"terminal.js", "")
// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "websocket-index.tmpl", cyTopo.ClabTopoDataV2.Name+"/ws/"+"index.html", "")

// createHtmlPublicFiles(htmlTemplatePath, htmlPublicPrefixPath, "button.tmpl", cyTopo.ClabTopoDataV2.Name+"/"+"button.html", cyTopo.ClabTopoDataV2.Name)

indexHtmldata := IndexHtmlStruct{
LabName: cyTopo.ClabTopoDataV2.Name,
DeploymentType: deploymentType,
Expand Down
3 changes: 2 additions & 1 deletion go_topoengine/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,9 @@ func main() {
// panic(err)
// }

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

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

Expand Down
Loading

0 comments on commit 0454945

Please sign in to comment.