it compiles :)

This commit is contained in:
Megan Marsh 2018-01-17 13:07:41 -08:00 committed by Matthew Hooker
parent 8aa716cd4c
commit 46c3113613
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
9 changed files with 131 additions and 178 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/go-oracle-terraform/compute"
"github.com/hashicorp/go-oracle-terraform/opc"
ocommon "github.com/hashicorp/packer/builder/oracle/common"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/packer"
@ -68,8 +69,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&stepCreateInstance{},
&communicator.StepConnect{
Config: &b.config.Comm,
Host: commHost,
SSHConfig: SSHConfig(
Host: ocommon.CommHost,
SSHConfig: ocommon.SSHConfig(
b.config.Comm.SSHUsername,
b.config.Comm.SSHPassword),
},

View File

@ -24,6 +24,7 @@ type Config struct {
apiEndpointURL *url.URL
// Image
ImageName string `mapstructure:"image_name"`
Shape string `mapstructure:"shape"`
ImageList string `json:"image_list"`

View File

@ -13,18 +13,14 @@ type stepCreateIPReservation struct{}
func (s *stepCreateIPReservation) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
ui.Say("Creating IP reservation...")
client := state.Get("client", client).(*compute.ComputeClient)
client := state.Get("client").(*compute.ComputeClient)
iprClient := client.IPReservations()
if err != nil {
log.Printf("Error getting IPReservations Client: %s", err)
return multistep.ActionHalt
}
// TODO: add optional Name and Tags
IPInput := &iprClient.CreateIPReservationInput{
IPInput := &compute.CreateIPReservationInput{
ParentPool: compute.PublicReservationPool,
Permanent: true,
}
ipRes, err := iprClient.CreateIPReservation(createIPReservation)
ipRes, err := iprClient.CreateIPReservation(IPInput)
if err != nil {
log.Printf("Error creating IP Reservation: %s", err)
return multistep.ActionHalt
@ -33,3 +29,7 @@ func (s *stepCreateIPReservation) Run(state multistep.StateBag) multistep.StepAc
log.Printf("debug: ipRes is %#v", ipRes)
return multistep.ActionContinue
}
func (s *stepCreateIPReservation) Cleanup(state multistep.StateBag) {
// Nothing to do
}

View File

@ -11,10 +11,9 @@ import (
type stepCreateInstance struct{}
func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction {
ui.Say("Creating Instance...")
// get variables from state
ui := state.Get("ui").(packer.Ui)
ui.Say("Creating Instance...")
config := state.Get("config").(Config)
client := state.Get("client").(*compute.ComputeClient)
sshPublicKey := state.Get("publicKey").(string)
@ -27,7 +26,7 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
Name: config.ImageName,
Shape: config.Shape,
ImageList: config.ImageList,
SSHKeys: []string{},
SSHKeys: []string{sshPublicKey},
Attributes: map[string]interface{}{},
}
@ -40,6 +39,10 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
}
state.Put("instance_id", instanceInfo.ID)
ui.Say(fmt.Sprintf("Created instance (%s).", instanceID))
ui.Say(fmt.Sprintf("Created instance (%s).", instanceInfo.ID))
return multistep.ActionContinue
}
func (s *stepCreateInstance) Cleanup(state multistep.StateBag) {
// Nothing to do
}

View File

@ -1,18 +0,0 @@
package classic
import (
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
)
type stepInstanceInfo struct{}
func (s *stepInstanceInfo) Run(state multistep.StateBag) multistep.StepAction {
ui.Say("Getting Instance Info...")
ui := state.Get("ui").(packer.Ui)
instanceID := state.Get("instance_id").(string)
endpoint_path := "/instance/%s", instanceID // GET
// https://docs.oracle.com/en/cloud/iaas/compute-iaas-cloud/stcsa/op-instance-%7Bname%7D-get.html
}

View File

@ -19,15 +19,15 @@ func (s *stepSnapshot) Run(state multistep.StateBag) multistep.StepAction {
instanceID := state.Get("instance_id").(string)
// get instances client
snapshotClient := client.SnapshotsClient()
snapshotClient := client.Snapshots()
// Instances Input
createSnapshotInput := &CreateSnapshotInput{
snapshotInput := &compute.CreateSnapshotInput{
Instance: instanceID,
MachineImage: config.ImageName,
}
snap, err := snapshotClient.CreateSnapshot(input)
snap, err := snapshotClient.CreateSnapshot(snapshotInput)
if err != nil {
err = fmt.Errorf("Problem creating snapshot: %s", err)
ui.Error(err.Error())
@ -36,4 +36,9 @@ func (s *stepSnapshot) Run(state multistep.StateBag) multistep.StepAction {
}
ui.Say(fmt.Sprintf("Created snapshot (%s).", snap.Name))
return multistep.ActionContinue
}
func (s *stepSnapshot) Cleanup(state multistep.StateBag) {
// Nothing to do
}

View File

@ -60,8 +60,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&stepInstanceInfo{},
&communicator.StepConnect{
Config: &b.config.Comm,
Host: commHost,
SSHConfig: SSHConfig(
Host: ocommon.CommHost,
SSHConfig: ocommon.SSHConfig(
b.config.Comm.SSHUsername,
b.config.Comm.SSHPassword),
},

View File

@ -1,45 +0,0 @@
package oci
import (
"fmt"
packerssh "github.com/hashicorp/packer/communicator/ssh"
"github.com/hashicorp/packer/helper/multistep"
"golang.org/x/crypto/ssh"
)
func commHost(state multistep.StateBag) (string, error) {
ipAddress := state.Get("instance_ip").(string)
return ipAddress, nil
}
// SSHConfig returns a function that can be used for the SSH communicator
// config for connecting to the instance created over SSH using the private key
// or password.
func SSHConfig(username, password string) func(state multistep.StateBag) (*ssh.ClientConfig, error) {
return func(state multistep.StateBag) (*ssh.ClientConfig, error) {
privateKey, hasKey := state.GetOk("privateKey")
if hasKey {
signer, err := ssh.ParsePrivateKey([]byte(privateKey.(string)))
if err != nil {
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
}
return &ssh.ClientConfig{
User: username,
Auth: []ssh.AuthMethod{ssh.PublicKeys(signer)},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}, nil
}
return &ssh.ClientConfig{
User: username,
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
Auth: []ssh.AuthMethod{
ssh.Password(password),
ssh.KeyboardInteractive(packerssh.PasswordKeyboardInteractive(password)),
},
}, nil
}
}

View File

@ -14,65 +14,67 @@ import (
"github.com/hashicorp/packer/packer/plugin"
alicloudecsbuilder "github.com/hashicorp/packer/builder/alicloud/ecs"
alicloudimportpostprocessor "github.com/hashicorp/packer/post-processor/alicloud-import"
amazonchrootbuilder "github.com/hashicorp/packer/builder/amazon/chroot"
amazonebsbuilder "github.com/hashicorp/packer/builder/amazon/ebs"
amazonebssurrogatebuilder "github.com/hashicorp/packer/builder/amazon/ebssurrogate"
amazonebsvolumebuilder "github.com/hashicorp/packer/builder/amazon/ebsvolume"
amazoninstancebuilder "github.com/hashicorp/packer/builder/amazon/instance"
azurearmbuilder "github.com/hashicorp/packer/builder/azure/arm"
cloudstackbuilder "github.com/hashicorp/packer/builder/cloudstack"
digitaloceanbuilder "github.com/hashicorp/packer/builder/digitalocean"
dockerbuilder "github.com/hashicorp/packer/builder/docker"
filebuilder "github.com/hashicorp/packer/builder/file"
googlecomputebuilder "github.com/hashicorp/packer/builder/googlecompute"
hypervisobuilder "github.com/hashicorp/packer/builder/hyperv/iso"
hypervvmcxbuilder "github.com/hashicorp/packer/builder/hyperv/vmcx"
lxcbuilder "github.com/hashicorp/packer/builder/lxc"
lxdbuilder "github.com/hashicorp/packer/builder/lxd"
nullbuilder "github.com/hashicorp/packer/builder/null"
oneandonebuilder "github.com/hashicorp/packer/builder/oneandone"
openstackbuilder "github.com/hashicorp/packer/builder/openstack"
oracleocibuilder "github.com/hashicorp/packer/builder/oracle/oci"
parallelsisobuilder "github.com/hashicorp/packer/builder/parallels/iso"
parallelspvmbuilder "github.com/hashicorp/packer/builder/parallels/pvm"
profitbricksbuilder "github.com/hashicorp/packer/builder/profitbricks"
qemubuilder "github.com/hashicorp/packer/builder/qemu"
tritonbuilder "github.com/hashicorp/packer/builder/triton"
virtualboxisobuilder "github.com/hashicorp/packer/builder/virtualbox/iso"
virtualboxovfbuilder "github.com/hashicorp/packer/builder/virtualbox/ovf"
vmwareisobuilder "github.com/hashicorp/packer/builder/vmware/iso"
vmwarevmxbuilder "github.com/hashicorp/packer/builder/vmware/vmx"
alicloudimportpostprocessor "github.com/hashicorp/packer/post-processor/alicloud-import"
amazonimportpostprocessor "github.com/hashicorp/packer/post-processor/amazon-import"
amazoninstancebuilder "github.com/hashicorp/packer/builder/amazon/instance"
ansiblelocalprovisioner "github.com/hashicorp/packer/provisioner/ansible-local"
ansibleprovisioner "github.com/hashicorp/packer/provisioner/ansible"
artificepostprocessor "github.com/hashicorp/packer/post-processor/artifice"
atlaspostprocessor "github.com/hashicorp/packer/post-processor/atlas"
azurearmbuilder "github.com/hashicorp/packer/builder/azure/arm"
checksumpostprocessor "github.com/hashicorp/packer/post-processor/checksum"
chefclientprovisioner "github.com/hashicorp/packer/provisioner/chef-client"
chefsoloprovisioner "github.com/hashicorp/packer/provisioner/chef-solo"
cloudstackbuilder "github.com/hashicorp/packer/builder/cloudstack"
compresspostprocessor "github.com/hashicorp/packer/post-processor/compress"
convergeprovisioner "github.com/hashicorp/packer/provisioner/converge"
digitaloceanbuilder "github.com/hashicorp/packer/builder/digitalocean"
dockerbuilder "github.com/hashicorp/packer/builder/docker"
dockerimportpostprocessor "github.com/hashicorp/packer/post-processor/docker-import"
dockerpushpostprocessor "github.com/hashicorp/packer/post-processor/docker-push"
dockersavepostprocessor "github.com/hashicorp/packer/post-processor/docker-save"
dockertagpostprocessor "github.com/hashicorp/packer/post-processor/docker-tag"
googlecomputeexportpostprocessor "github.com/hashicorp/packer/post-processor/googlecompute-export"
manifestpostprocessor "github.com/hashicorp/packer/post-processor/manifest"
shelllocalpostprocessor "github.com/hashicorp/packer/post-processor/shell-local"
vagrantpostprocessor "github.com/hashicorp/packer/post-processor/vagrant"
vagrantcloudpostprocessor "github.com/hashicorp/packer/post-processor/vagrant-cloud"
vspherepostprocessor "github.com/hashicorp/packer/post-processor/vsphere"
vspheretemplatepostprocessor "github.com/hashicorp/packer/post-processor/vsphere-template"
ansibleprovisioner "github.com/hashicorp/packer/provisioner/ansible"
ansiblelocalprovisioner "github.com/hashicorp/packer/provisioner/ansible-local"
chefclientprovisioner "github.com/hashicorp/packer/provisioner/chef-client"
chefsoloprovisioner "github.com/hashicorp/packer/provisioner/chef-solo"
convergeprovisioner "github.com/hashicorp/packer/provisioner/converge"
filebuilder "github.com/hashicorp/packer/builder/file"
fileprovisioner "github.com/hashicorp/packer/provisioner/file"
googlecomputebuilder "github.com/hashicorp/packer/builder/googlecompute"
googlecomputeexportpostprocessor "github.com/hashicorp/packer/post-processor/googlecompute-export"
hypervisobuilder "github.com/hashicorp/packer/builder/hyperv/iso"
hypervvmcxbuilder "github.com/hashicorp/packer/builder/hyperv/vmcx"
lxcbuilder "github.com/hashicorp/packer/builder/lxc"
lxdbuilder "github.com/hashicorp/packer/builder/lxd"
manifestpostprocessor "github.com/hashicorp/packer/post-processor/manifest"
nullbuilder "github.com/hashicorp/packer/builder/null"
oneandonebuilder "github.com/hashicorp/packer/builder/oneandone"
openstackbuilder "github.com/hashicorp/packer/builder/openstack"
oracleclassicbuilder "github.com/hashicorp/packer/builder/oracle/classic"
oracleocibuilder "github.com/hashicorp/packer/builder/oracle/oci"
parallelsisobuilder "github.com/hashicorp/packer/builder/parallels/iso"
parallelspvmbuilder "github.com/hashicorp/packer/builder/parallels/pvm"
powershellprovisioner "github.com/hashicorp/packer/provisioner/powershell"
profitbricksbuilder "github.com/hashicorp/packer/builder/profitbricks"
puppetmasterlessprovisioner "github.com/hashicorp/packer/provisioner/puppet-masterless"
puppetserverprovisioner "github.com/hashicorp/packer/provisioner/puppet-server"
qemubuilder "github.com/hashicorp/packer/builder/qemu"
saltmasterlessprovisioner "github.com/hashicorp/packer/provisioner/salt-masterless"
shellprovisioner "github.com/hashicorp/packer/provisioner/shell"
shelllocalpostprocessor "github.com/hashicorp/packer/post-processor/shell-local"
shelllocalprovisioner "github.com/hashicorp/packer/provisioner/shell-local"
shellprovisioner "github.com/hashicorp/packer/provisioner/shell"
tritonbuilder "github.com/hashicorp/packer/builder/triton"
vagrantcloudpostprocessor "github.com/hashicorp/packer/post-processor/vagrant-cloud"
vagrantpostprocessor "github.com/hashicorp/packer/post-processor/vagrant"
virtualboxisobuilder "github.com/hashicorp/packer/builder/virtualbox/iso"
virtualboxovfbuilder "github.com/hashicorp/packer/builder/virtualbox/ovf"
vmwareisobuilder "github.com/hashicorp/packer/builder/vmware/iso"
vmwarevmxbuilder "github.com/hashicorp/packer/builder/vmware/vmx"
vspherepostprocessor "github.com/hashicorp/packer/post-processor/vsphere"
vspheretemplatepostprocessor "github.com/hashicorp/packer/post-processor/vsphere-template"
windowsrestartprovisioner "github.com/hashicorp/packer/provisioner/windows-restart"
windowsshellprovisioner "github.com/hashicorp/packer/provisioner/windows-shell"
)
type PluginCommand struct {
@ -80,74 +82,78 @@ type PluginCommand struct {
}
var Builders = map[string]packer.Builder{
"alicloud-ecs": new(alicloudecsbuilder.Builder),
"amazon-chroot": new(amazonchrootbuilder.Builder),
"amazon-ebs": new(amazonebsbuilder.Builder),
"amazon-ebssurrogate": new(amazonebssurrogatebuilder.Builder),
"amazon-ebsvolume": new(amazonebsvolumebuilder.Builder),
"amazon-instance": new(amazoninstancebuilder.Builder),
"azure-arm": new(azurearmbuilder.Builder),
"cloudstack": new(cloudstackbuilder.Builder),
"digitalocean": new(digitaloceanbuilder.Builder),
"docker": new(dockerbuilder.Builder),
"file": new(filebuilder.Builder),
"googlecompute": new(googlecomputebuilder.Builder),
"hyperv-iso": new(hypervisobuilder.Builder),
"hyperv-vmcx": new(hypervvmcxbuilder.Builder),
"lxc": new(lxcbuilder.Builder),
"lxd": new(lxdbuilder.Builder),
"null": new(nullbuilder.Builder),
"oneandone": new(oneandonebuilder.Builder),
"openstack": new(openstackbuilder.Builder),
"oracle-oci": new(oracleocibuilder.Builder),
"parallels-iso": new(parallelsisobuilder.Builder),
"parallels-pvm": new(parallelspvmbuilder.Builder),
"profitbricks": new(profitbricksbuilder.Builder),
"qemu": new(qemubuilder.Builder),
"triton": new(tritonbuilder.Builder),
"virtualbox-iso": new(virtualboxisobuilder.Builder),
"virtualbox-ovf": new(virtualboxovfbuilder.Builder),
"vmware-iso": new(vmwareisobuilder.Builder),
"vmware-vmx": new(vmwarevmxbuilder.Builder),
"alicloud-ecs": new(alicloudecsbuilder.Builder),
"amazon-chroot": new(amazonchrootbuilder.Builder),
"amazon-ebs": new(amazonebsbuilder.Builder),
"amazon-ebssurrogate": new(amazonebssurrogatebuilder.Builder),
"amazon-ebsvolume": new(amazonebsvolumebuilder.Builder),
"amazon-instance": new(amazoninstancebuilder.Builder),
"azure-arm": new(azurearmbuilder.Builder),
"cloudstack": new(cloudstackbuilder.Builder),
"digitalocean": new(digitaloceanbuilder.Builder),
"docker": new(dockerbuilder.Builder),
"file": new(filebuilder.Builder),
"googlecompute": new(googlecomputebuilder.Builder),
"hyperv-iso": new(hypervisobuilder.Builder),
"hyperv-vmcx": new(hypervvmcxbuilder.Builder),
"lxc": new(lxcbuilder.Builder),
"lxd": new(lxdbuilder.Builder),
"null": new(nullbuilder.Builder),
"oneandone": new(oneandonebuilder.Builder),
"openstack": new(openstackbuilder.Builder),
"oracle-classic": new(oracleclassicbuilder.Builder),
"oracle-oci": new(oracleocibuilder.Builder),
"parallels-iso": new(parallelsisobuilder.Builder),
"parallels-pvm": new(parallelspvmbuilder.Builder),
"profitbricks": new(profitbricksbuilder.Builder),
"qemu": new(qemubuilder.Builder),
"triton": new(tritonbuilder.Builder),
"virtualbox-iso": new(virtualboxisobuilder.Builder),
"virtualbox-ovf": new(virtualboxovfbuilder.Builder),
"vmware-iso": new(vmwareisobuilder.Builder),
"vmware-vmx": new(vmwarevmxbuilder.Builder),
}
var Provisioners = map[string]packer.Provisioner{
"ansible": new(ansibleprovisioner.Provisioner),
"ansible-local": new(ansiblelocalprovisioner.Provisioner),
"chef-client": new(chefclientprovisioner.Provisioner),
"chef-solo": new(chefsoloprovisioner.Provisioner),
"converge": new(convergeprovisioner.Provisioner),
"file": new(fileprovisioner.Provisioner),
"powershell": new(powershellprovisioner.Provisioner),
"puppet-masterless": new(puppetmasterlessprovisioner.Provisioner),
"puppet-server": new(puppetserverprovisioner.Provisioner),
"ansible": new(ansibleprovisioner.Provisioner),
"ansible-local": new(ansiblelocalprovisioner.Provisioner),
"chef-client": new(chefclientprovisioner.Provisioner),
"chef-solo": new(chefsoloprovisioner.Provisioner),
"converge": new(convergeprovisioner.Provisioner),
"file": new(fileprovisioner.Provisioner),
"powershell": new(powershellprovisioner.Provisioner),
"puppet-masterless": new(puppetmasterlessprovisioner.Provisioner),
"puppet-server": new(puppetserverprovisioner.Provisioner),
"salt-masterless": new(saltmasterlessprovisioner.Provisioner),
"shell": new(shellprovisioner.Provisioner),
"shell-local": new(shelllocalprovisioner.Provisioner),
"shell": new(shellprovisioner.Provisioner),
"shell-local": new(shelllocalprovisioner.Provisioner),
"windows-restart": new(windowsrestartprovisioner.Provisioner),
"windows-shell": new(windowsshellprovisioner.Provisioner),
"windows-shell": new(windowsshellprovisioner.Provisioner),
}
var PostProcessors = map[string]packer.PostProcessor{
"alicloud-import": new(alicloudimportpostprocessor.PostProcessor),
"amazon-import": new(amazonimportpostprocessor.PostProcessor),
"artifice": new(artificepostprocessor.PostProcessor),
"atlas": new(atlaspostprocessor.PostProcessor),
"checksum": new(checksumpostprocessor.PostProcessor),
"compress": new(compresspostprocessor.PostProcessor),
"docker-import": new(dockerimportpostprocessor.PostProcessor),
"docker-push": new(dockerpushpostprocessor.PostProcessor),
"docker-save": new(dockersavepostprocessor.PostProcessor),
"docker-tag": new(dockertagpostprocessor.PostProcessor),
"googlecompute-export": new(googlecomputeexportpostprocessor.PostProcessor),
"manifest": new(manifestpostprocessor.PostProcessor),
"shell-local": new(shelllocalpostprocessor.PostProcessor),
"vagrant": new(vagrantpostprocessor.PostProcessor),
"vagrant-cloud": new(vagrantcloudpostprocessor.PostProcessor),
"vsphere": new(vspherepostprocessor.PostProcessor),
"vsphere-template": new(vspheretemplatepostprocessor.PostProcessor),
"alicloud-import": new(alicloudimportpostprocessor.PostProcessor),
"amazon-import": new(amazonimportpostprocessor.PostProcessor),
"artifice": new(artificepostprocessor.PostProcessor),
"atlas": new(atlaspostprocessor.PostProcessor),
"checksum": new(checksumpostprocessor.PostProcessor),
"compress": new(compresspostprocessor.PostProcessor),
"docker-import": new(dockerimportpostprocessor.PostProcessor),
"docker-push": new(dockerpushpostprocessor.PostProcessor),
"docker-save": new(dockersavepostprocessor.PostProcessor),
"docker-tag": new(dockertagpostprocessor.PostProcessor),
"googlecompute-export": new(googlecomputeexportpostprocessor.PostProcessor),
"manifest": new(manifestpostprocessor.PostProcessor),
"shell-local": new(shelllocalpostprocessor.PostProcessor),
"vagrant": new(vagrantpostprocessor.PostProcessor),
"vagrant-cloud": new(vagrantcloudpostprocessor.PostProcessor),
"vsphere": new(vspherepostprocessor.PostProcessor),
"vsphere-template": new(vspheretemplatepostprocessor.PostProcessor),
}
var pluginRegexp = regexp.MustCompile("packer-(builder|post-processor|provisioner)-(.+)")
func (c *PluginCommand) Run(args []string) int {