diff --git a/pkg/vendors/juniper-els/interfaces.go b/pkg/vendors/juniper-els/interfaces.go index bb332f8..a513ae9 100644 --- a/pkg/vendors/juniper-els/interfaces.go +++ b/pkg/vendors/juniper-els/interfaces.go @@ -3,7 +3,6 @@ package juniper_els import ( "bytes" "encoding/xml" - "errors" "fmt" "github.com/Juniper/go-netconf/netconf" "github.com/g-portal/switchmgr-go/pkg/models" @@ -134,27 +133,36 @@ func (s *JuniperELS) isUplink(inter string) bool { return false } -const EditPortConfigurationTemplate = ` - - {{ .Name }} - {{ .Description }} - {{if .UntaggedVLAN}}{{ .UntaggedVLAN }}{{end}} - - 0 - - - trunk - - {{range .TaggedVLANs }}{{ . }}{{end}} - - - default - - - - - -` +const EditPortConfigurationTemplate = ` + + + + merge + test-then-set + + + + + {{ .Name }} + {{ .Description }} + {{if .UntaggedVLAN}}{{ .UntaggedVLAN }}{{end}} + + 0 + + + trunk + {{if gt (len .TaggedVLANs) 0}} + {{range .TaggedVLANs }}{{ . }}{{end}} + {{end}} + + + + + + + + +` // ConfigureInterface configures a single interface. It returns true if the // configuration has changed. If the interface is an uplink, it will return @@ -171,6 +179,7 @@ func (j *JuniperELS) ConfigureInterface(update *models.UpdateInterface) (bool, e if err != nil { return false, err } + if !swport.Differs(update) { return false, nil } @@ -184,7 +193,7 @@ func (j *JuniperELS) ConfigureInterface(update *models.UpdateInterface) (bool, e update.TaggedVLANs = utils.UniqueVlanIDs(update.TaggedVLANs) if len(update.TaggedVLANs) == 0 && update.UntaggedVLAN != nil && *update.UntaggedVLAN == 0 { - return false, errors.New("switch port has no vlans to configure") + return false, fmt.Errorf("switch port has no vlans to configure") } var tpl bytes.Buffer diff --git a/pkg/vendors/juniper-els/interfaces_test.go b/pkg/vendors/juniper-els/interfaces_test.go index 1e543fc..67745f6 100644 --- a/pkg/vendors/juniper-els/interfaces_test.go +++ b/pkg/vendors/juniper-els/interfaces_test.go @@ -73,27 +73,36 @@ func TestGetInterface(t *testing.T) { } } -const EditPortConfigurationExpected = ` - - eth0 - example interface - 1337 - - 0 - - - trunk - - 123 - - - default - - - - - -` +const EditPortConfigurationExpected = ` + + + + merge + test-then-set + + + + + eth0 + example interface + 1337 + + 0 + + + trunk + + 123 + + + + + + + + + +` func TestConfigureInterfaceTemplate(t *testing.T) { var tpl bytes.Buffer