github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/core/lxdprofile/status.go (about)

     1  // Copyright 2018 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package lxdprofile
     5  
     6  import (
     7  	"fmt"
     8  	"strings"
     9  )
    10  
    11  const (
    12  	// EmptyStatus represents the initial status
    13  	EmptyStatus = ""
    14  
    15  	// SuccessStatus defines if the lxd profile upgrade was a success
    16  	SuccessStatus = "Success"
    17  
    18  	// NotRequiredStatus defines when the lxd profile upgrade was not required
    19  	NotRequiredStatus = "Not Required"
    20  
    21  	// NotKnownStatus defines a state where the document for the lxd profile
    22  	// is removed, or never existed, but we don't know what the status should be.
    23  	NotKnownStatus = "Not known"
    24  
    25  	// ErrorStatus defines when the lxd profile is in an error state
    26  	ErrorStatus = "Error"
    27  
    28  	// NotSupportedStatus defines when a machine does not support lxd profiles.
    29  	NotSupportedStatus = "Not Supported"
    30  )
    31  
    32  // AnnotateErrorStatus annotates an existing error with the correct status
    33  func AnnotateErrorStatus(err error) string {
    34  	return fmt.Sprintf("%s: %s", ErrorStatus, err.Error())
    35  }
    36  
    37  // UpgradeStatusFinished defines if the upgrade has completed
    38  func UpgradeStatusFinished(status string) bool {
    39  	if status == SuccessStatus || status == NotRequiredStatus || status == NotSupportedStatus {
    40  		return true
    41  	}
    42  	return false
    43  }
    44  
    45  // UpgradeStatusTerminal defines if the status is in a terminal state. Success
    46  // or not required is also considered terminal.
    47  func UpgradeStatusTerminal(status string) bool {
    48  	if UpgradeStatusFinished(status) {
    49  		return true
    50  	}
    51  
    52  	return UpgradeStatusErrorred(status)
    53  }
    54  
    55  // UpgradeStatusErrorred defines if the status is in a error state.
    56  func UpgradeStatusErrorred(status string) bool {
    57  	return strings.HasPrefix(status, ErrorStatus)
    58  }