diff --git a/topo/node/arista/arista.go b/topo/node/arista/arista.go index e75cdddf..dac0eb56 100644 --- a/topo/node/arista/arista.go +++ b/topo/node/arista/arista.go @@ -335,12 +335,7 @@ func defaults(pb *tpb.Node) *tpb.Node { Name: "default_ceos_node", } } - if pb.Constraints == nil { - pb.Constraints = map[string]string{ - "cpu": "0.5", - "memory": "1Gi", - } - } + pb = constraints(pb) if pb.Services == nil { pb.Services = map[uint32]*tpb.Service{ 443: { @@ -394,6 +389,19 @@ func defaults(pb *tpb.Node) *tpb.Node { return pb } +func constraints(pb *tpb.Node) *tpb.Node { + if pb.Constraints == nil { + pb.Constraints = map[string]string{} + } + if pb.Constraints["cpu"] == "" { + pb.Constraints["cpu"] = "0.5" + } + if pb.Constraints["memory"] == "" { + pb.Constraints["memory"] = "1Gi" + } + return pb +} + func (n *Node) FixInterfaces() error { for k, v := range n.Proto.Interfaces { switch { diff --git a/topo/node/juniper/juniper.go b/topo/node/juniper/juniper.go index a3685d41..63b827c7 100644 --- a/topo/node/juniper/juniper.go +++ b/topo/node/juniper/juniper.go @@ -507,10 +507,13 @@ func defaults(pb *tpb.Node) *tpb.Node { switch pb.Model { case ModelNCPTX: if pb.Constraints == nil { - pb.Constraints = map[string]string{ - "cpu": "4", - "memory": "4Gi", - } + pb.Constraints = map[string]string{} + } + if pb.Constraints["cpu"] == "" { + pb.Constraints["cpu"] = "4" + } + if pb.Constraints["memory"] == "" { + pb.Constraints["memory"] = "4Gi" } if len(pb.Config.GetCommand()) == 0 { pb.Config.Command = []string{ @@ -522,10 +525,13 @@ func defaults(pb *tpb.Node) *tpb.Node { } default: if pb.Constraints == nil { - pb.Constraints = map[string]string{ - "cpu": "8", - "memory": "8Gi", - } + pb.Constraints = map[string]string{} + } + if pb.Constraints["cpu"] == "" { + pb.Constraints["cpu"] = "8" + } + if pb.Constraints["memory"] == "" { + pb.Constraints["memory"] = "8Gi" } if len(pb.Config.GetCommand()) == 0 { pb.Config.Command = []string{ diff --git a/topo/node/nokia/nokia.go b/topo/node/nokia/nokia.go index a660aa7d..ab651a80 100644 --- a/topo/node/nokia/nokia.go +++ b/topo/node/nokia/nokia.go @@ -378,6 +378,15 @@ func defaults(pb *tpb.Node) *tpb.Node { pb.Config.ConfigFile = "config" + ext } + if pb.Constraints == nil { + pb.Constraints = map[string]string{} + } + if pb.Constraints["cpu"] == "" { + pb.Constraints["cpu"] = "0.5" + } + if pb.Constraints["memory"] == "" { + pb.Constraints["memory"] = "1Gi" + } return pb } diff --git a/topo/node/nokia/nokia_test.go b/topo/node/nokia/nokia_test.go index a6595964..5bd8e14a 100644 --- a/topo/node/nokia/nokia_test.go +++ b/topo/node/nokia/nokia_test.go @@ -139,6 +139,10 @@ func TestNew(t *testing.T) { Inside: 9559, }, }, + Constraints: map[string]string{ + "cpu": "0.5", + "memory": "1Gi", + }, }, }, { desc: "json config file", @@ -188,6 +192,10 @@ func TestNew(t *testing.T) { Inside: 9559, }, }, + Constraints: map[string]string{ + "cpu": "0.5", + "memory": "1Gi", + }, }, }, } diff --git a/topo/node/openconfig/openconfig.go b/topo/node/openconfig/openconfig.go index 45e3435d..c1328f3b 100644 --- a/topo/node/openconfig/openconfig.go +++ b/topo/node/openconfig/openconfig.go @@ -245,10 +245,13 @@ func lemmingDefaults(pb *tpb.Node) *tpb.Node { } } if pb.Constraints == nil { - pb.Constraints = map[string]string{ - "cpu": "0.5", - "memory": "1Gi", - } + pb.Constraints = map[string]string{} + } + if pb.Constraints["cpu"] == "" { + pb.Constraints["cpu"] = "0.5" + } + if pb.Constraints["memory"] == "" { + pb.Constraints["memory"] = "1Gi" } if pb.Labels == nil { pb.Labels = map[string]string{} diff --git a/topo/node/openconfig/openconfig_test.go b/topo/node/openconfig/openconfig_test.go index 8976bcfc..d3feeb17 100644 --- a/topo/node/openconfig/openconfig_test.go +++ b/topo/node/openconfig/openconfig_test.go @@ -388,7 +388,8 @@ func TestNew(t *testing.T) { Cert: &tpb.CertificateCfg{}, }, Constraints: map[string]string{ - "cpu": "10", + "cpu": "10", + "memory": "1Gi", }, Labels: map[string]string{ "custom": "value",