github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/uniter/operation/finishupgradecharmprofile.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package operation 5 6 import ( 7 "fmt" 8 9 "github.com/juju/errors" 10 "gopkg.in/juju/charm.v6" 11 ) 12 13 type finishUpgradeCharmProfile struct { 14 DoesNotRequireMachineLock 15 16 kind Kind 17 charmURL *charm.URL 18 callbacks Callbacks 19 } 20 21 // String is part of the Operation interface. 22 func (d *finishUpgradeCharmProfile) String() string { 23 return fmt.Sprintf("finish upgrade charm profile") 24 } 25 26 // Prepare is part of the Operation interface. 27 func (d *finishUpgradeCharmProfile) Prepare(state State) (*State, error) { 28 return d.getState(state, Pending), nil 29 } 30 31 // Execute is part of the Operation interface. 32 func (d *finishUpgradeCharmProfile) Execute(state State) (*State, error) { 33 // Ensure that we always clean up the LXD profile status. 34 if err := d.callbacks.RemoveUpgradeCharmProfileData(); err != nil { 35 return nil, errors.Trace(err) 36 } 37 return d.getState(state, Done), nil 38 } 39 40 // Commit is part of the Operation interface. 41 func (d *finishUpgradeCharmProfile) Commit(state State) (*State, error) { 42 // make no change to state 43 return &state, nil 44 } 45 46 func (d *finishUpgradeCharmProfile) getState(state State, step Step) *State { 47 return stateChange{ 48 Kind: d.kind, 49 Step: step, 50 CharmURL: d.charmURL, 51 }.apply(state) 52 }