/
resolve_network_domain.go
58 lines (46 loc) · 1.7 KB
/
resolve_network_domain.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
package steps
import (
"fmt"
"github.com/DimensionDataResearch/packer-plugins-ddcloud/builders/customerimage/config"
"github.com/DimensionDataResearch/packer-plugins-ddcloud/helpers"
"github.com/mitchellh/multistep"
)
// ResolveNetworkDomain is the step that resolves the target network domain by name from CloudControl.
type ResolveNetworkDomain struct{}
// Run is called to perform the step's action.
//
// The return value determines whether multi-step sequences should continue or halt.
func (step *ResolveNetworkDomain) Run(stateBag multistep.StateBag) multistep.StepAction {
state := helpers.ForStateBag(stateBag)
ui := state.GetUI()
settings := state.GetSettings().(*config.Settings)
client := state.GetClient()
networkDomain, err := client.GetNetworkDomainByName(
settings.NetworkDomainName,
settings.DatacenterID,
)
if err != nil {
ui.Error(err.Error())
return multistep.ActionHalt
}
if networkDomain == nil {
ui.Error(fmt.Sprintf(
"Unable to find network domain '%s' in datacenter '%s'.",
settings.NetworkDomainName,
settings.DatacenterID,
))
return multistep.ActionHalt
}
state.SetNetworkDomain(networkDomain)
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 *ResolveNetworkDomain) Cleanup(state multistep.StateBag) {
}
var _ multistep.Step = &ResolveNetworkDomain{}