Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added destroy vifs step #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions builder/xenserver/common/common_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type CommonConfig struct {
RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"`
SSHWaitTimeout time.Duration

DestroyVIFs bool `mapstructure:"destroy_vifs"`

OutputDir string `mapstructure:"output_directory"`
Format string `mapstructure:"format"`
KeepVM string `mapstructure:"keep_vm"`
Expand Down
47 changes: 47 additions & 0 deletions builder/xenserver/common/step_destroy_vifs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package common

import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
xsclient "github.com/xenserver/go-xenserver-client"
)

type StepDestroyVIFs struct{}

func (self *StepDestroyVIFs) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("commonconfig").(CommonConfig)
if !config.DestroyVIFs {
return multistep.ActionContinue
}

ui := state.Get("ui").(packer.Ui)
client := state.Get("client").(xsclient.XenAPIClient)

ui.Say("Step: Destroy VIFs")

uuid := state.Get("instance_uuid").(string)
instance, err := client.GetVMByUuid(uuid)
if err != nil {
ui.Error(fmt.Sprintf("Unable to get VM from UUID '%s': %s", uuid, err.Error()))
return multistep.ActionHalt
}

vifs, err := instance.GetVIFs()
if err != nil {
ui.Error(fmt.Sprintf("Error getting VIFs: %s", err.Error()))
return multistep.ActionHalt
}

for _, vif := range vifs {
err = vif.Destroy()
if err != nil {
ui.Error(fmt.Sprintf("Error destroying VIF: %s", err.Error()))
return multistep.ActionHalt
}
}

return multistep.ActionContinue
}

func (self *StepDestroyVIFs) Cleanup(state multistep.StateBag) {}
1 change: 1 addition & 0 deletions builder/xenserver/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ func (self *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (pa
&xscommon.StepDetachVdi{
VdiUuidKey: "floppy_vdi_uuid",
},
new(xscommon.StepDestroyVIFs),
new(xscommon.StepExport),
}

Expand Down
1 change: 1 addition & 0 deletions builder/xenserver/xva/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func (self *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (pa
&xscommon.StepDetachVdi{
VdiUuidKey: "tools_vdi_uuid",
},
new(xscommon.StepDestroyVIFs),
new(xscommon.StepExport),
}

Expand Down
4 changes: 4 additions & 0 deletions docs/builders/xenserver-iso.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ each category, the available options are alphabetized and described.
run `xe template-list`. Setting the correct value hints to XenServer how to
optimize the virtual hardware to work best with that operating system.

* `destroy_vifs` (boolean) - Whether to destroy VIFs on the VM prior to
exporting. Removing them may make the image more generic and reusable.
Default is `false`.

* `disk_size` (integer) - The size, in megabytes, of the hard disk to create
for the VM. By default, this is 40000 (about 40 GB).

Expand Down