Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add commit confirm feature #585

Closed
NikitaPuglachenko opened this issue Dec 1, 2023 · 1 comment · Fixed by #601
Closed

Feature request: add commit confirm feature #585

NikitaPuglachenko opened this issue Dec 1, 2023 · 1 comment · Fixed by #601
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@NikitaPuglachenko
Copy link

Description

It would be great to keep the JunOS feature like commit confirm to avoid an outage if something wrong with config.

New or Affected Resource(s)

junos
internal/junos/netconf.go
...

Potential Terraform Configuration

junos:

provider "junos" {
  ...
  commitconfirm = 5 # minutes
}

internal/junos/netconf.go:

// netconfCommit commits the configuration.
func (sess *Session) netconfCommit(logMessage string, confirmCommit *int) (_warn []error, _err error) {
	if confirmCommit != nil {
		confirmReply, confirmErr := sess.netconf.Exec(netconf.RawMethod(fmt.Sprintf(rpcCommitConfirm, confirmCommit, logMessage)))
		if confirmErr != nil {
			return []error{}, fmt.Errorf("executing netconf confirm commit: %w", confirmErr)
		}

		// If there are errors in the confirm commit, return now.
		if confirmReply.Errors != nil {
			warnings := make([]error, 0)
			for _, m := range confirmReply.Errors {
				if m.Severity == errorSeverity {
					return warnings, errors.New(m.Error())
				}
				warnings = append(warnings, errors.New(m.Error()))
			}
			return warnings, nil
		}

		delay := *confirmCommit - 1
		if delay < 0 {
			delay = 0
		}

		// Wait for confirmCommit - 1 minutes before committing.
		time.Sleep(time.Duration(delay) * time.Minute)
	}
...

References

https://www.juniper.net/documentation/us/en/software/junos/junos-xml-protocol/topics/ref/tag/junos-xml-protocol-commit-configuration.html

@NikitaPuglachenko NikitaPuglachenko added the enhancement New feature or request label Dec 1, 2023
@jeremmfr
Copy link
Owner

Hi 👋

After a few tests, the feature is feasible. I'll take care of adding it.

@jeremmfr jeremmfr added this to the v2.4.0 milestone Dec 12, 2023
@jeremmfr jeremmfr self-assigned this Dec 12, 2023
jeremmfr added a commit that referenced this issue Dec 15, 2023
and commit_confirmed_wait_percent
Fix #585
jeremmfr added a commit that referenced this issue Dec 15, 2023
and commit_confirmed_wait_percent
Fix #585
jeremmfr added a commit that referenced this issue Dec 15, 2023
and commit_confirmed_wait_percent
Fix #585
jeremmfr added a commit that referenced this issue Dec 18, 2023
and commit_confirmed_wait_percent
Fix #585
jeremmfr added a commit that referenced this issue Dec 18, 2023
and commit_confirmed_wait_percent
Fix #585
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants