launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/charm/hooks/hooks.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  // hooks provides types and constants that define the hooks known to Juju.
     5  package hooks
     6  
     7  // Kind enumerates the different kinds of hooks that exist.
     8  type Kind string
     9  
    10  const (
    11  	// None of these hooks are ever associated with a relation; each of them
    12  	// represents a change to the state of the unit as a whole. The values
    13  	// themselves are all valid hook names.
    14  	Install       Kind = "install"
    15  	Start         Kind = "start"
    16  	ConfigChanged Kind = "config-changed"
    17  	UpgradeCharm  Kind = "upgrade-charm"
    18  	Stop          Kind = "stop"
    19  
    20  	// These hooks require an associated relation, and the name of the relation
    21  	// unit whose change triggered the hook. The hook file names that these
    22  	// kinds represent will be prefixed by the relation name; for example,
    23  	// "db-relation-joined".
    24  	RelationJoined   Kind = "relation-joined"
    25  	RelationChanged  Kind = "relation-changed"
    26  	RelationDeparted Kind = "relation-departed"
    27  
    28  	// This hook requires an associated relation. The represented hook file name
    29  	// will be prefixed by the relation name, just like the other Relation* Kind
    30  	// values.
    31  	RelationBroken Kind = "relation-broken"
    32  )
    33  
    34  var unitHooks = []Kind{
    35  	Install,
    36  	Start,
    37  	ConfigChanged,
    38  	UpgradeCharm,
    39  	Stop,
    40  }
    41  
    42  // UnitHooks returns all known unit hook kinds.
    43  func UnitHooks() []Kind {
    44  	hooks := make([]Kind, len(unitHooks))
    45  	copy(hooks, unitHooks)
    46  	return hooks
    47  }
    48  
    49  var relationHooks = []Kind{
    50  	RelationJoined,
    51  	RelationChanged,
    52  	RelationDeparted,
    53  	RelationBroken,
    54  }
    55  
    56  // RelationHooks returns all known relation hook kinds.
    57  func RelationHooks() []Kind {
    58  	hooks := make([]Kind, len(relationHooks))
    59  	copy(hooks, relationHooks)
    60  	return hooks
    61  }
    62  
    63  // IsRelation returns whether the Kind represents a relation hook.
    64  func (kind Kind) IsRelation() bool {
    65  	switch kind {
    66  	case RelationJoined, RelationChanged, RelationDeparted, RelationBroken:
    67  		return true
    68  	}
    69  	return false
    70  }