Skip to content

Commit

Permalink
load mycelium keys in the network, remove commented print, ue slices.…
Browse files Browse the repository at this point in the history
…Contains instead of loop
  • Loading branch information
rawdaGastan committed Oct 21, 2024
1 parent dbe67be commit ddf4b43
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
16 changes: 15 additions & 1 deletion grid-client/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,16 @@ func (st *State) LoadNetworkFromGrid(ctx context.Context, name string) (znet wor
nodes = append(nodes, net.Nodes...)
}

myceliumKeys := make(map[uint32][]byte)
for _, net := range zNets {
maps.Copy(myceliumKeys, net.MyceliumKeys)
nodes = append(nodes, net.Nodes...)
}

znet.NodeDeploymentID = nodeDeploymentsIDs
znet.Nodes = nodes
znet.NodesIPRange = nodesIPRange
znet.MyceliumKeys = myceliumKeys
znet.Keys = keys
znet.WGPort = wgPort

Expand Down Expand Up @@ -456,15 +463,22 @@ func (st *State) LoadNetworkLightFromGrid(ctx context.Context, name string) (zne

// merge networks
var nodes []uint32
nodesIPRange := map[uint32]zosTypes.IPNet{}
nodesIPRange := make(map[uint32]zosTypes.IPNet)
for _, net := range zNets {
maps.Copy(nodesIPRange, net.NodesIPRange)
nodes = append(nodes, net.Nodes...)
}

myceliumKeys := make(map[uint32][]byte)
for _, net := range zNets {
maps.Copy(myceliumKeys, net.MyceliumKeys)
nodes = append(nodes, net.Nodes...)
}

znet.NodeDeploymentID = nodeDeploymentsIDs
znet.Nodes = nodes
znet.NodesIPRange = nodesIPRange
znet.MyceliumKeys = myceliumKeys

st.Networks.UpdateNetworkSubnets(znet.Name, znet.NodesIPRange)
return znet, nil
Expand Down
2 changes: 0 additions & 2 deletions grid-client/workloads/network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ type Network interface {
endpoints map[uint32]net.IP,
nodeUsedPorts map[uint32][]uint16,
) (map[uint32]zos.Deployment, error)
generateDeployments(endpointIPs map[uint32]net.IP, usedPorts map[uint32][]uint16, publicNode, twinID uint32,
) (map[uint32]zos.Deployment, error)
ReadNodesConfig(ctx context.Context, nodeDeployments map[uint32]zos.Deployment) error

GetNodes() []uint32
Expand Down
4 changes: 2 additions & 2 deletions grid-client/zos/ipnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func ParseIPNet(txt string) (r IPNet, err error) {
//empty ip net value
return r, nil
}
//fmt.Println("parsing: ", string(text))

ip, net, err := net.ParseCIDR(txt)
if err != nil {
return r, err
Expand Down Expand Up @@ -52,7 +52,7 @@ func (i IPNet) MarshalJSON() ([]byte, error) {
return []byte(v), nil
}

// MarshalJSON dumps iprange as a string
// MarshalText dumps iprange as a string
func (i IPNet) MarshalText() ([]byte, error) {
if len(i.IPNet.IP) == 0 {
return []byte{}, nil
Expand Down
9 changes: 2 additions & 7 deletions grid-client/zos/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zos
import (
"encoding/json"
"io"
"slices"

"github.com/threefoldtech/zos/pkg/gridtypes"
gridtypes4 "github.com/threefoldtech/zos4/pkg/gridtypes"
Expand Down Expand Up @@ -56,13 +57,7 @@ func (r *Result) Unmarshal(v interface{}) error {
type ResultState string

func (s ResultState) IsAny(state ...ResultState) bool {
for _, in := range state {
if s == in {
return true
}
}

return false
return slices.Contains(state, s)
}

func (s ResultState) IsOkay() bool {
Expand Down

0 comments on commit ddf4b43

Please sign in to comment.