it compiles :)
This commit is contained in:
parent
8aa716cd4c
commit
46c3113613
|
@ -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),
|
||||
},
|
||||
|
|
|
@ -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"`
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
},
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
@ -99,6 +101,7 @@ var Builders = map[string]packer.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),
|
||||
|
@ -111,6 +114,7 @@ var Builders = map[string]packer.Builder{
|
|||
"vmware-vmx": new(vmwarevmxbuilder.Builder),
|
||||
}
|
||||
|
||||
|
||||
var Provisioners = map[string]packer.Provisioner{
|
||||
"ansible": new(ansibleprovisioner.Provisioner),
|
||||
"ansible-local": new(ansiblelocalprovisioner.Provisioner),
|
||||
|
@ -128,6 +132,7 @@ var Provisioners = map[string]packer.Provisioner{
|
|||
"windows-shell": new(windowsshellprovisioner.Provisioner),
|
||||
}
|
||||
|
||||
|
||||
var PostProcessors = map[string]packer.PostProcessor{
|
||||
"alicloud-import": new(alicloudimportpostprocessor.PostProcessor),
|
||||
"amazon-import": new(amazonimportpostprocessor.PostProcessor),
|
||||
|
@ -148,6 +153,7 @@ var PostProcessors = map[string]packer.PostProcessor{
|
|||
"vsphere-template": new(vspheretemplatepostprocessor.PostProcessor),
|
||||
}
|
||||
|
||||
|
||||
var pluginRegexp = regexp.MustCompile("packer-(builder|post-processor|provisioner)-(.+)")
|
||||
|
||||
func (c *PluginCommand) Run(args []string) int {
|
||||
|
|
Loading…
Reference in New Issue