forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
48 lines (41 loc) · 1.22 KB
/
factory.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
43
44
45
46
47
48
package cloud
import (
biinstall "github.com/cloudfoundry/bosh-cli/installation"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type Factory interface {
NewCloud(installation biinstall.Installation, directorID string) (Cloud, error)
}
type factory struct {
fs boshsys.FileSystem
cmdRunner boshsys.CmdRunner
logger boshlog.Logger
}
func NewFactory(
fs boshsys.FileSystem,
cmdRunner boshsys.CmdRunner,
logger boshlog.Logger,
) Factory {
return &factory{
fs: fs,
cmdRunner: cmdRunner,
logger: logger,
}
}
func (f *factory) NewCloud(installation biinstall.Installation, directorID string) (Cloud, error) {
cpiJob := installation.Job()
target := installation.Target()
cpi := CPI{
JobPath: cpiJob.Path,
JobsDir: target.JobsPath(),
PackagesDir: target.PackagesPath(),
}
cmdPath := cpi.ExecutablePath()
if !f.fs.FileExists(cmdPath) {
return nil, bosherr.Errorf("Installed CPI job '%s' does not contain the required executable '%s'", cpiJob.Name, cmdPath)
}
cpiCmdRunner := NewCPICmdRunner(f.cmdRunner, cpi, f.logger)
return NewCloud(cpiCmdRunner, directorID, f.logger), nil
}