mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-11 01:30:06 -04:00
destroy artifact
This commit is contained in:
parent
a12ff09f0a
commit
f42df93e8d
2 changed files with 19 additions and 2 deletions
18
artifact.go
18
artifact.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue