2019-04-11 12:52:21 -04:00
|
|
|
package proxmox
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/Telmate/proxmox-api-go/proxmox"
|
2020-12-17 16:29:25 -05:00
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2019-04-11 12:52:21 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Artifact struct {
|
2020-09-04 17:53:09 -04:00
|
|
|
builderID string
|
2019-04-11 12:52:21 -04:00
|
|
|
templateID int
|
|
|
|
proxmoxClient *proxmox.Client
|
2020-01-30 05:27:58 -05:00
|
|
|
|
|
|
|
// StateData should store data such as GeneratedData
|
|
|
|
// to be shared with post-processors
|
|
|
|
StateData map[string]interface{}
|
2019-04-11 12:52:21 -04:00
|
|
|
}
|
|
|
|
|
2020-11-19 15:17:11 -05:00
|
|
|
// Artifact implements packersdk.Artifact
|
|
|
|
var _ packersdk.Artifact = &Artifact{}
|
2019-04-11 12:52:21 -04:00
|
|
|
|
2020-09-04 17:53:09 -04:00
|
|
|
func (a *Artifact) BuilderId() string {
|
|
|
|
return a.builderID
|
2019-04-11 12:52:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*Artifact) Files() []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) Id() string {
|
|
|
|
return strconv.Itoa(a.templateID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) String() string {
|
|
|
|
return fmt.Sprintf("A template was created: %d", a.templateID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) State(name string) interface{} {
|
2020-01-30 05:27:58 -05:00
|
|
|
return a.StateData[name]
|
2019-04-11 12:52:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) Destroy() error {
|
|
|
|
log.Printf("Destroying template: %d", a.templateID)
|
|
|
|
_, err := a.proxmoxClient.DeleteVm(proxmox.NewVmRef(a.templateID))
|
|
|
|
return err
|
|
|
|
}
|