/
stemcells.go
42 lines (32 loc) · 1003 Bytes
/
stemcells.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cpi
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
apiv1 "github.com/cppforlife/bosh-cpi-go/apiv1"
bstem "github.com/cppforlife/bosh-virtualbox-cpi/stemcell"
)
type Stemcells struct {
importer bstem.Importer
finder bstem.Finder
}
func NewStemcells(importer bstem.Importer, finder bstem.Finder) Stemcells {
return Stemcells{importer, finder}
}
func (a Stemcells) CreateStemcell(
imagePath string, _ apiv1.StemcellCloudProps) (apiv1.StemcellCID, error) {
stemcell, err := a.importer.ImportFromPath(imagePath)
if err != nil {
return apiv1.StemcellCID{}, bosherr.WrapErrorf(err, "Importing stemcell from '%s'", imagePath)
}
return stemcell.ID(), nil
}
func (a Stemcells) DeleteStemcell(cid apiv1.StemcellCID) error {
stemcell, err := a.finder.Find(cid)
if err != nil {
return bosherr.WrapErrorf(err, "Finding stemcell '%s'", cid)
}
err = stemcell.Delete()
if err != nil {
return bosherr.WrapErrorf(err, "Deleting stemcell '%s'", cid)
}
return nil
}