implement ID and Type values in the provisioner template info sharing

This commit is contained in:
Megan Marsh 2019-12-13 11:57:01 -08:00
parent e1652696a6
commit 84063d2132
29 changed files with 103 additions and 4 deletions

View File

@ -77,6 +77,9 @@ func (s *stepCreateAlicloudInstance) Run(ctx context.Context, state multistep.St
ui.Message(fmt.Sprintf("Created instance: %s", instanceId))
s.instance = &instances.Instances.Instance[0]
state.Put("instance", s.instance)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", instanceId)
return multistep.ActionContinue
}

View File

@ -280,6 +280,9 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa
}
state.Put("instance", instance)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", instance.InstanceId)
// If we're in a region that doesn't support tagging on instance creation,
// do that now.

View File

@ -441,6 +441,9 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
}
state.Put("instance", instance)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", instance.InstanceId)
return multistep.ActionContinue
}

View File

@ -63,6 +63,9 @@ func (s *stepCreateDroplet) Run(ctx context.Context, state multistep.StateBag) m
// Store the droplet id for later
state.Put("droplet_id", droplet.ID)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", droplet.ID)
return multistep.ActionContinue
}

View File

@ -42,6 +42,9 @@ func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S
// Save the container ID
s.containerId = containerId
state.Put("container_id", s.containerId)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", s.containerId)
ui.Message(fmt.Sprintf("Container ID: %s", s.containerId))
return multistep.ActionContinue
}

View File

@ -176,6 +176,9 @@ func (s *StepCreateInstance) Run(ctx context.Context, state multistep.StateBag)
// Things succeeded, store the name so we can remove it later
state.Put("instance_name", name)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", name)
return multistep.ActionContinue
}

View File

@ -85,6 +85,9 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu
// Store the server id for later
state.Put("server_id", serverCreateResult.Server.ID)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", serverCreateResult.Server.ID)
if err := waitForAction(ctx, client, serverCreateResult.Action); err != nil {
err := fmt.Errorf("Error creating server: %s", err)

View File

@ -67,6 +67,9 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
s.vmID = vm.Id
state.Put("vm_id", vm.Id)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", vm.Id)
hdds, _, err := client.VmApi.VmListHdd(ctx, vm.Id)
if err != nil {

View File

@ -154,6 +154,9 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist
// Set the final name in the state bag so others can use it
state.Put("vmName", s.VMName)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", s.VMName)
return multistep.ActionContinue
}

View File

@ -166,6 +166,9 @@ func (s *StepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
// Set the final name in the state bag so others can use it
state.Put("vmName", s.VMName)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", s.VMName)
return multistep.ActionContinue
}

View File

@ -96,6 +96,9 @@ func (s *stepCreateJDCloudInstance) Run(_ context.Context, state multistep.State
"Hi, we have created the instance, its name=%v , "+
"its id=%v, "+
"and its eip=%v :) ", instance.InstanceName, s.InstanceSpecConfig.InstanceId, eip.Result.ElasticIp.ElasticIpAddress))
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", s.InstanceSpecConfig.InstanceId)
return multistep.ActionContinue
}

View File

@ -49,6 +49,9 @@ func (s *stepCreateLinode) Run(ctx context.Context, state multistep.StateBag) mu
return multistep.ActionHalt
}
state.Put("instance", instance)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", instance.ID)
}
disk, err := s.findDisk(ctx, instance.ID)

View File

@ -97,6 +97,9 @@ func (s *StepCreatePublicIPInstance) Run(ctx context.Context, state multistep.St
if err == nil {
state.Put("PublicIP", publicIPInstance.PublicIP)
state.Put("PublicIPInstance", publicIPInstance)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", publicIPInstance)
}
return processStepResult(err, s.Error, state)

View File

@ -96,6 +96,9 @@ func (s *StepCreateServerInstance) Run(ctx context.Context, state multistep.Stat
serverInstanceNo, err := s.CreateServerInstance(loginKey.KeyName, zoneNo, feeSystemTypeCode)
if err == nil {
state.Put("InstanceNo", serverInstanceNo)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", serverInstanceNo)
}
return processStepResult(err, s.Error, state)

View File

@ -94,6 +94,9 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu
}
state.Put("server_id", server_id)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", server_id)
state.Put("server_ip", server.Ips[0].Ip)

View File

@ -128,6 +128,9 @@ func (s *StepRunSourceServer) Run(ctx context.Context, state multistep.StateBag)
s.server = latestServer.(*servers.Server)
state.Put("server", s.server)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", s.server.ID)
return multistep.ActionContinue
}

View File

@ -253,6 +253,9 @@ func (s *StepRunSourceVm) Run(ctx context.Context, state multistep.StateBag) mul
}
state.Put("vm", vm)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", vmId)
// If we're in a region that doesn't support tagging on vm creation,
// do that now.

View File

@ -36,6 +36,9 @@ func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S
}
s.vmName = vmName
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", vmName)
return multistep.ActionContinue
}

View File

@ -147,6 +147,9 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu
state.Put("volume_id", server.Entities.Volumes.Items[0].Id)
server = profitbricks.GetServer(datacenter.Id, server.Id)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", server.Id)
state.Put("server_ip", server.Entities.Nics.Items[0].Properties.Ips[0])

View File

@ -76,6 +76,9 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist
// Store the vm id for later
state.Put("vmRef", vmRef)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", vmRef)
ui.Say("Starting VM")
_, err = client.StartVm(vmRef)

View File

@ -60,6 +60,9 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu
s.serverID = server
state.Put("server_id", server)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", s.serverID)
return multistep.ActionContinue
}

View File

@ -175,6 +175,9 @@ func (s *stepRunInstance) Run(ctx context.Context, state multistep.StateBag) mul
}
state.Put("instance", describeResp.Response.InstanceSet[0])
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", s.instanceId)
Message(state, s.instanceId, "Instance created")
return multistep.ActionContinue

View File

@ -43,6 +43,9 @@ func (s *StepCreateSourceMachine) Run(ctx context.Context, state multistep.State
}
state.Put("machine", machineId)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", machineId)
return multistep.ActionContinue
}

View File

@ -77,6 +77,9 @@ func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag)
s.instanceId = instanceId
state.Put("instance", instance)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", instance)
if instance.BootDiskState != ucloudcommon.BootDiskStateNormal {
ui.Say("Waiting for boot disk of instance initialized")

View File

@ -35,7 +35,11 @@ func (s *StepUp) Run(ctx context.Context, state multistep.StateBag) multistep.St
ui.Say("Calling Vagrant Up (this can take some time)...")
_, _, err := driver.Up(s.generateArgs())
args := s.generateArgs()
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", args[0])
_, _, err := driver.Up(args)
if err != nil {
state.Put("error", err)

View File

@ -57,6 +57,9 @@ func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S
}
s.vmName = vmName
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", s.vmName)
return multistep.ActionContinue
}

View File

@ -64,6 +64,10 @@ func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S
return multistep.ActionHalt
}
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", vmxPath)
return multistep.ActionContinue
}

View File

@ -249,6 +249,9 @@ runcmd:
}
state.Put("disk_id", instance.BootDisk.DiskId)
// instance_id is the generic term used so that users can have access to the
// instance id inside of the provisioners, used in step_provision.
state.Put("instance_id", instance.Id)
if s.Debug {
ui.Message(fmt.Sprintf("Instance ID %s started. Current instance status %s", instance.Id, instance.Status))

View File

@ -26,7 +26,7 @@ import (
// accidentally being interpolated into empty strings at prepare time.
func PlaceholderData() map[string]string {
placeholderData := map[string]string{}
placeholderData["ID"] = "{{.ID}}"
// The following correspond to communicator-agnostic functions that are
// part of the SSH and WinRM communicator implementations. These functions
// are not part of the communicator interface, but are stored on the
@ -38,6 +38,7 @@ func PlaceholderData() map[string]string {
placeholderData["Port"] = "{{.Port}}"
placeholderData["User"] = "{{.User}}"
placeholderData["Password"] = "{{.Password}}"
placeholderData["ConnType"] = "{{.Type}}"
// Backwards-compatability:
placeholderData["WinRMPassword"] = "{{.WinRMPassword}}"
@ -60,12 +61,24 @@ func PopulateProvisionHookData(state multistep.StateBag) map[string]interface{}
hookData["Port"] = commConf.Port()
hookData["User"] = commConf.User()
hookData["Password"] = commConf.Password()
hookData["ConnType"] = commConf.Type
// Backwards compatibility; in practice, WinRMPassword is fulfilled by
// Password.
hookData["WinRMPassword"] = commConf.WinRMPassword
// TODO
// state.GetOK("id")
// instance_id is placed in state by the builders.
// Not yet implemented in Chroot, lxc/lxd, Azure, Qemu.
// Implemented in most others including digitalOcean (droplet id),
// docker (container_id), and clouds which use "server" internally instead
// of instance.
id, ok := state.GetOk("instance_id")
if ok {
hookData["ID"] = id
} else {
// Warn user that the id isn't implemented
hookData["ID"] = "ERR_ID_NOT_IMPLEMENTED_BY_BUILDER"
}
return hookData
}