destroy artifact

This commit is contained in:
Michael Kuzmin 2017-06-30 01:08:49 +03:00 committed by Michael Kuzmin
parent a12ff09f0a
commit f42df93e8d
2 changed files with 19 additions and 2 deletions

View File

@ -1,9 +1,15 @@
package main
import (
"github.com/vmware/govmomi/object"
"context"
)
const BuilderId = "jetbrains.vsphere"
type Artifact struct {
VMName string `json:"vm_name"`
VMName string
Conn *object.VirtualMachine
}
func (a *Artifact) BuilderId() string {
@ -27,5 +33,15 @@ func (a *Artifact) State(name string) interface{} {
}
func (a *Artifact) Destroy() error {
ctx := context.TODO()
task, err := a.Conn.Destroy(ctx)
if err != nil {
return err
}
_, err = task.WaitForResult(ctx, nil)
if err != nil {
return err
}
return nil
}

View File

@ -14,6 +14,7 @@ import (
"context"
"net/url"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
)
type Builder struct {
@ -121,9 +122,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return nil, errors.New("Build was halted.")
}
// No errors, must've worked
artifact := &Artifact{
VMName: b.config.VMName,
Conn: state.Get("vm").(*object.VirtualMachine),
}
return artifact, nil
}