2019-03-26 08:29:15 -04:00
|
|
|
package yandex
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2019-04-09 10:46:41 -04:00
|
|
|
"github.com/yandex-cloud/go-genproto/yandex/cloud/compute/v1"
|
|
|
|
)
|
2019-03-26 08:29:15 -04:00
|
|
|
|
|
|
|
type Artifact struct {
|
|
|
|
config *Config
|
2019-04-09 10:46:41 -04:00
|
|
|
driver Driver
|
|
|
|
image *compute.Image
|
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-03-26 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//revive:disable:var-naming
|
|
|
|
func (*Artifact) BuilderId() string {
|
|
|
|
return BuilderID
|
|
|
|
}
|
|
|
|
|
2019-04-09 10:46:41 -04:00
|
|
|
func (a *Artifact) Id() string {
|
|
|
|
return a.image.Id
|
2019-03-26 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*Artifact) Files() []string {
|
2020-04-26 19:19:08 -04:00
|
|
|
return []string{""}
|
2019-03-26 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
2019-04-09 10:46:41 -04:00
|
|
|
//revive:enable:var-naming
|
2019-03-26 08:29:15 -04:00
|
|
|
func (a *Artifact) String() string {
|
2019-04-09 10:46:41 -04:00
|
|
|
return fmt.Sprintf("A disk image was created: %v (id: %v) with family name %v", a.image.Name, a.image.Id, a.image.Family)
|
2019-03-26 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) State(name string) interface{} {
|
2020-01-30 05:27:58 -05:00
|
|
|
if _, ok := a.StateData[name]; ok {
|
|
|
|
return a.StateData[name]
|
|
|
|
}
|
|
|
|
|
2019-03-26 08:29:15 -04:00
|
|
|
switch name {
|
|
|
|
case "ImageID":
|
2019-04-09 10:46:41 -04:00
|
|
|
return a.image.Id
|
2019-03-26 08:29:15 -04:00
|
|
|
case "FolderID":
|
2019-04-09 10:46:41 -04:00
|
|
|
return a.image.FolderId
|
2019-03-26 08:29:15 -04:00
|
|
|
}
|
|
|
|
return nil
|
2019-04-09 10:46:41 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) Destroy() error {
|
|
|
|
return a.driver.DeleteImage(a.image.Id)
|
2019-03-26 08:29:15 -04:00
|
|
|
}
|