Run go fmt on files

This commit is contained in:
Taliesin Sisson 2016-11-06 16:02:00 +00:00
parent 44f73fa75f
commit 335615408a
15 changed files with 229 additions and 230 deletions

View File

@ -2,9 +2,9 @@ package common
import (
"fmt"
"os"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/template/interpolate"
"os"
)
type OutputConfig struct {

View File

@ -30,10 +30,10 @@ func (s *StepCreateTempDir) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
s.dirPath = packerTempDir;
s.dirPath = packerTempDir
state.Put("packerTempDir", packerTempDir)
// ui.Say("packerTempDir = '" + packerTempDir + "'")
// ui.Say("packerTempDir = '" + packerTempDir + "'")
return multistep.ActionContinue
}

View File

@ -28,9 +28,9 @@ func (s *StepMountFloppydrive) Run(state multistep.StateBag) multistep.StepActio
if s.Generation > 1 {
return multistep.ActionContinue
}
driver := state.Get("driver").(Driver)
// Determine if we even have a floppy disk to attach
var floppyPath string
if floppyPathRaw, ok := state.GetOk("floppy_path"); ok {
@ -69,7 +69,7 @@ func (s *StepMountFloppydrive) Run(state multistep.StateBag) multistep.StepActio
func (s *StepMountFloppydrive) Cleanup(state multistep.StateBag) {
if s.Generation > 1 {
return
}
}
driver := state.Get("driver").(Driver)
if s.floppyPath == "" {
return

View File

@ -1,96 +1,96 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
type StepMountGuestAdditions struct {
GuestAdditionsMode string
GuestAdditionsPath string
Generation uint
}
func (s *StepMountGuestAdditions) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
if s.GuestAdditionsMode != "attach" {
ui.Say("Skipping mounting Integration Services Setup Disk...")
return multistep.ActionContinue
}
driver := state.Get("driver").(Driver)
ui.Say("Mounting Integration Services Setup Disk...")
vmName := state.Get("vmName").(string)
// should be able to mount up to 60 additional iso images using SCSI
// but Windows would only allow a max of 22 due to available drive letters
// Will Windows assign DVD drives to A: and B: ?
// For IDE, there are only 2 controllers (0,1) with 2 locations each (0,1)
var dvdControllerProperties DvdControllerProperties
controllerNumber, controllerLocation, err := driver.CreateDvdDrive(vmName, s.GuestAdditionsPath, s.Generation)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
dvdControllerProperties.ControllerNumber = controllerNumber
dvdControllerProperties.ControllerLocation = controllerLocation
dvdControllerProperties.Existing = false
state.Put("guest.dvd.properties", dvdControllerProperties)
ui.Say(fmt.Sprintf("Mounting Integration Services dvd drive %s ...", s.GuestAdditionsPath))
err = driver.MountDvdDrive(vmName, s.GuestAdditionsPath, controllerNumber, controllerLocation)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
log.Println(fmt.Sprintf("ISO %s mounted on DVD controller %v, location %v", s.GuestAdditionsPath, controllerNumber, controllerLocation))
return multistep.ActionContinue
}
func (s *StepMountGuestAdditions) Cleanup(state multistep.StateBag) {
if s.GuestAdditionsMode != "attach" {
return
}
dvdControllerState := state.Get("guest.dvd.properties")
if dvdControllerState == nil {
return
}
dvdController := dvdControllerState.(DvdControllerProperties)
ui := state.Get("ui").(packer.Ui)
driver := state.Get("driver").(Driver)
vmName := state.Get("vmName").(string)
errorMsg := "Error unmounting Integration Services dvd drive: %s"
ui.Say("Cleanup Integration Services dvd drive...")
if dvdController.Existing {
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
if err != nil {
log.Print(fmt.Sprintf(errorMsg, err))
}
} else {
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
if err != nil {
log.Print(fmt.Sprintf(errorMsg, err))
}
}
}
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
type StepMountGuestAdditions struct {
GuestAdditionsMode string
GuestAdditionsPath string
Generation uint
}
func (s *StepMountGuestAdditions) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
if s.GuestAdditionsMode != "attach" {
ui.Say("Skipping mounting Integration Services Setup Disk...")
return multistep.ActionContinue
}
driver := state.Get("driver").(Driver)
ui.Say("Mounting Integration Services Setup Disk...")
vmName := state.Get("vmName").(string)
// should be able to mount up to 60 additional iso images using SCSI
// but Windows would only allow a max of 22 due to available drive letters
// Will Windows assign DVD drives to A: and B: ?
// For IDE, there are only 2 controllers (0,1) with 2 locations each (0,1)
var dvdControllerProperties DvdControllerProperties
controllerNumber, controllerLocation, err := driver.CreateDvdDrive(vmName, s.GuestAdditionsPath, s.Generation)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
dvdControllerProperties.ControllerNumber = controllerNumber
dvdControllerProperties.ControllerLocation = controllerLocation
dvdControllerProperties.Existing = false
state.Put("guest.dvd.properties", dvdControllerProperties)
ui.Say(fmt.Sprintf("Mounting Integration Services dvd drive %s ...", s.GuestAdditionsPath))
err = driver.MountDvdDrive(vmName, s.GuestAdditionsPath, controllerNumber, controllerLocation)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
log.Println(fmt.Sprintf("ISO %s mounted on DVD controller %v, location %v", s.GuestAdditionsPath, controllerNumber, controllerLocation))
return multistep.ActionContinue
}
func (s *StepMountGuestAdditions) Cleanup(state multistep.StateBag) {
if s.GuestAdditionsMode != "attach" {
return
}
dvdControllerState := state.Get("guest.dvd.properties")
if dvdControllerState == nil {
return
}
dvdController := dvdControllerState.(DvdControllerProperties)
ui := state.Get("ui").(packer.Ui)
driver := state.Get("driver").(Driver)
vmName := state.Get("vmName").(string)
errorMsg := "Error unmounting Integration Services dvd drive: %s"
ui.Say("Cleanup Integration Services dvd drive...")
if dvdController.Existing {
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
if err != nil {
log.Print(fmt.Sprintf(errorMsg, err))
}
} else {
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
if err != nil {
log.Print(fmt.Sprintf(errorMsg, err))
}
}
}

View File

@ -1,98 +1,98 @@
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
type StepMountSecondaryDvdImages struct {
IsoPaths []string
Generation uint
}
type DvdControllerProperties struct {
ControllerNumber uint
ControllerLocation uint
Existing bool
}
func (s *StepMountSecondaryDvdImages) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
ui.Say("Mounting secondary DVD images...")
vmName := state.Get("vmName").(string)
// should be able to mount up to 60 additional iso images using SCSI
// but Windows would only allow a max of 22 due to available drive letters
// Will Windows assign DVD drives to A: and B: ?
// For IDE, there are only 2 controllers (0,1) with 2 locations each (0,1)
var dvdProperties []DvdControllerProperties
for _, isoPath := range s.IsoPaths {
var properties DvdControllerProperties
controllerNumber, controllerLocation, err := driver.CreateDvdDrive(vmName, isoPath, s.Generation)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
properties.ControllerNumber = controllerNumber
properties.ControllerLocation = controllerLocation
properties.Existing = false
dvdProperties = append(dvdProperties, properties)
state.Put("secondary.dvd.properties", dvdProperties)
ui.Say(fmt.Sprintf("Mounting secondary dvd drive %s ...", isoPath))
err = driver.MountDvdDrive(vmName, isoPath, controllerNumber, controllerLocation)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
log.Println(fmt.Sprintf("ISO %s mounted on DVD controller %v, location %v", isoPath, controllerNumber, controllerLocation))
}
return multistep.ActionContinue
}
func (s *StepMountSecondaryDvdImages) Cleanup(state multistep.StateBag) {
dvdControllersState := state.Get("secondary.dvd.properties")
if dvdControllersState == nil {
return
}
dvdControllers := dvdControllersState.([]DvdControllerProperties)
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)
errorMsg := "Error unmounting secondary dvd drive: %s"
ui.Say("Clean up secondary dvd drives...")
for _, dvdController := range dvdControllers {
if dvdController.Existing {
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
if err != nil {
log.Print(fmt.Sprintf(errorMsg, err))
}
} else {
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
if err != nil {
log.Print(fmt.Sprintf(errorMsg, err))
}
}
}
}
// Copyright (c) Microsoft Open Technologies, Inc.
// All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
package common
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
type StepMountSecondaryDvdImages struct {
IsoPaths []string
Generation uint
}
type DvdControllerProperties struct {
ControllerNumber uint
ControllerLocation uint
Existing bool
}
func (s *StepMountSecondaryDvdImages) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
ui.Say("Mounting secondary DVD images...")
vmName := state.Get("vmName").(string)
// should be able to mount up to 60 additional iso images using SCSI
// but Windows would only allow a max of 22 due to available drive letters
// Will Windows assign DVD drives to A: and B: ?
// For IDE, there are only 2 controllers (0,1) with 2 locations each (0,1)
var dvdProperties []DvdControllerProperties
for _, isoPath := range s.IsoPaths {
var properties DvdControllerProperties
controllerNumber, controllerLocation, err := driver.CreateDvdDrive(vmName, isoPath, s.Generation)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
properties.ControllerNumber = controllerNumber
properties.ControllerLocation = controllerLocation
properties.Existing = false
dvdProperties = append(dvdProperties, properties)
state.Put("secondary.dvd.properties", dvdProperties)
ui.Say(fmt.Sprintf("Mounting secondary dvd drive %s ...", isoPath))
err = driver.MountDvdDrive(vmName, isoPath, controllerNumber, controllerLocation)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
log.Println(fmt.Sprintf("ISO %s mounted on DVD controller %v, location %v", isoPath, controllerNumber, controllerLocation))
}
return multistep.ActionContinue
}
func (s *StepMountSecondaryDvdImages) Cleanup(state multistep.StateBag) {
dvdControllersState := state.Get("secondary.dvd.properties")
if dvdControllersState == nil {
return
}
dvdControllers := dvdControllersState.([]DvdControllerProperties)
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)
errorMsg := "Error unmounting secondary dvd drive: %s"
ui.Say("Clean up secondary dvd drives...")
for _, dvdController := range dvdControllers {
if dvdController.Existing {
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
if err != nil {
log.Print(fmt.Sprintf(errorMsg, err))
}
} else {
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
if err != nil {
log.Print(fmt.Sprintf(errorMsg, err))
}
}
}
}

View File

@ -12,17 +12,17 @@ import (
)
type StepSleep struct {
Minutes time.Duration
Minutes time.Duration
ActionName string
}
func (s *StepSleep) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
if(len(s.ActionName)>0){
ui.Say(s.ActionName + "! Waiting for "+ fmt.Sprintf("%v",uint(s.Minutes)) + " minutes to let the action to complete...")
if len(s.ActionName) > 0 {
ui.Say(s.ActionName + "! Waiting for " + fmt.Sprintf("%v", uint(s.Minutes)) + " minutes to let the action to complete...")
}
time.Sleep(time.Minute*s.Minutes);
time.Sleep(time.Minute * s.Minutes)
return multistep.ActionContinue
}

View File

@ -19,15 +19,15 @@ func (s *StepUnmountDvdDrive) Run(state multistep.StateBag) multistep.StepAction
ui := state.Get("ui").(packer.Ui)
ui.Say("Unmount/delete os dvd drive...")
dvdControllerState := state.Get("os.dvd.properties")
if dvdControllerState == nil {
return multistep.ActionContinue
}
dvdController := dvdControllerState.(DvdControllerProperties)
dvdController := dvdControllerState.(DvdControllerProperties)
if dvdController.Existing {
ui.Say(fmt.Sprintf("Unmounting os dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation))
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
@ -47,9 +47,9 @@ func (s *StepUnmountDvdDrive) Run(state multistep.StateBag) multistep.StepAction
return multistep.ActionHalt
}
}
state.Put("os.dvd.properties", nil)
return multistep.ActionContinue
}

View File

@ -24,7 +24,7 @@ func (s *StepUnmountFloppyDrive) Run(state multistep.StateBag) multistep.StepAct
vmName := state.Get("vmName").(string)
ui.Say("Unmount/delete floppy drive (Run)...")
errorMsg := "Error Unmounting floppy drive: %s"
err := driver.UnmountFloppyDrive(vmName)

View File

@ -21,13 +21,13 @@ func (s *StepUnmountGuestAdditions) Run(state multistep.StateBag) multistep.Step
ui.Say("Unmount/delete Integration Services dvd drive...")
dvdControllerState := state.Get("guest.dvd.properties")
if dvdControllerState == nil {
return multistep.ActionContinue
}
dvdController := dvdControllerState.(DvdControllerProperties)
if dvdController.Existing {
ui.Say(fmt.Sprintf("Unmounting Integration Services dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation))
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
@ -47,9 +47,9 @@ func (s *StepUnmountGuestAdditions) Run(state multistep.StateBag) multistep.Step
return multistep.ActionHalt
}
}
state.Put("guest.dvd.properties", nil)
return multistep.ActionContinue
}

View File

@ -19,13 +19,13 @@ func (s *StepUnmountSecondaryDvdImages) Run(state multistep.StateBag) multistep.
vmName := state.Get("vmName").(string)
ui.Say("Unmount/delete secondary dvd drives...")
dvdControllersState := state.Get("secondary.dvd.properties")
if dvdControllersState == nil {
return multistep.ActionContinue
}
dvdControllers := dvdControllersState.([]DvdControllerProperties)
for _, dvdController := range dvdControllers {
@ -47,9 +47,9 @@ func (s *StepUnmountSecondaryDvdImages) Run(state multistep.StateBag) multistep.
ui.Error(err.Error())
return multistep.ActionHalt
}
}
}
}
state.Put("secondary.dvd.properties", nil)
return multistep.ActionContinue

View File

@ -82,7 +82,7 @@ var Builders = map[string]packer.Builder{
"docker": new(dockerbuilder.Builder),
"file": new(filebuilder.Builder),
"googlecompute": new(googlecomputebuilder.Builder),
"hyperv-iso": new(hypervbuilder.Builder),
"hyperv-iso": new(hypervbuilder.Builder),
"null": new(nullbuilder.Builder),
"oneandone": new(oneandonebuilder.Builder),
"openstack": new(openstackbuilder.Builder),

View File

@ -56,7 +56,7 @@ func (s *StepConnect) Run(state multistep.StateBag) multistep.StepAction {
Config: s.Config,
Host: s.Host,
WinRMConfig: s.WinRMConfig,
WinRMPort: s.WinRMPort,
WinRMPort: s.WinRMPort,
},
}
for k, v := range s.CustomConnect {

View File

@ -96,7 +96,7 @@ func (s *StepConnectWinRM) waitForWinRM(state multistep.StateBag, cancel <-chan
log.Printf("[DEBUG] Error getting WinRM host: %s", err)
continue
}
port := s.Config.WinRMPort
if s.WinRMPort != nil {
port, err = s.WinRMPort(state)

View File

@ -9,14 +9,14 @@ type ScriptBuilder struct {
}
func (b *ScriptBuilder) WriteLine(s string) (n int, err error) {
n, err = b.buffer.WriteString(s);
n, err = b.buffer.WriteString(s)
b.buffer.WriteString("\n")
return n+1, err
return n + 1, err
}
func (b *ScriptBuilder) WriteString(s string) (n int, err error) {
n, err = b.buffer.WriteString(s);
n, err = b.buffer.WriteString(s)
return n, err
}
@ -27,4 +27,3 @@ func (b *ScriptBuilder) String() string {
func (b *ScriptBuilder) Reset() {
b.buffer.Reset()
}

View File

@ -322,4 +322,4 @@ func (p *Provisioner) createFlattenedEnvVars() (flattened string, err error) {
flattened += fmt.Sprintf(p.config.EnvVarFormat, key, envVars[key])
}
return
}
}