/
resolve_vlan.go
61 lines (49 loc) · 1.68 KB
/
resolve_vlan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package steps
import (
"fmt"
"github.com/DimensionDataResearch/packer-plugins-ddcloud/builders/customerimage/config"
"github.com/DimensionDataResearch/packer-plugins-ddcloud/helpers"
"github.com/mitchellh/multistep"
)
// ResolveVLAN is the step that resolves the target VLAN by name from CloudControl.
type ResolveVLAN struct{}
// Run is called to perform the step's action.
//
// The return value determines whether multi-step sequences should continue or halt.
func (step *ResolveVLAN) Run(stateBag multistep.StateBag) multistep.StepAction {
state := helpers.ForStateBag(stateBag)
ui := state.GetUI()
settings := state.GetSettings().(*config.Settings)
client := state.GetClient()
networkDomain := state.GetNetworkDomain()
vlan, err := client.GetVLANByName(
settings.VLANName,
networkDomain.ID,
)
if err != nil {
ui.Error(err.Error())
return multistep.ActionHalt
}
if vlan == nil {
ui.Error(fmt.Sprintf(
"Unable to find VLAN '%s' in network domain '%s' ('%s') in datacenter '%s'.",
settings.VLANName,
networkDomain.Name,
networkDomain.ID,
settings.DatacenterID,
))
return multistep.ActionHalt
}
state.SetVLAN(vlan)
return multistep.ActionContinue
}
// Cleanup is called in reverse order of the steps that have run
// and allow steps to clean up after themselves. Do not assume if this
// ran that the entire multi-step sequence completed successfully. This
// method can be ran in the face of errors and cancellations as well.
//
// The parameter is the same "state bag" as Run, and represents the
// state at the latest possible time prior to calling Cleanup.
func (step *ResolveVLAN) Cleanup(state multistep.StateBag) {
}
var _ multistep.Step = &ResolveVLAN{}