/
vsphere.go
63 lines (53 loc) · 1.61 KB
/
vsphere.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package vsphere
import (
"github.com/johandry/log"
"github.com/kraken/terraformer"
"github.com/kraken/ui"
)
// Platform implements the Provisioner interface for vSphere
type Platform struct {
name string
config *Config
t *terraformer.Terraformer
logger *log.Logger
ui *ui.UI
version string
}
// New creates a new Plaform with the given environment configuration
func New(clusterName string, envConfig map[string]string, ui *ui.UI, version string) (*Platform, error) {
config := &Config{}
if err := config.MergeWithEnv(envConfig, defaultConfig); err != nil {
return nil, err
}
config.ClusterName = clusterName
return &Platform{
name: "vsphere",
config: config,
ui: ui,
version: version,
}, nil
}
// CreateFrom creates a new Plaftorm with the given configuration for vSphere
func CreateFrom(clusterName string, config map[interface{}]interface{}, credentials []string, ui *ui.UI, version string) *Platform {
if config == nil {
return newPlatform(&defaultConfig, credentials, ui, version)
}
c := NewConfigFrom(config)
c.ClusterName = clusterName
return newPlatform(c, credentials, ui, version)
}
func newPlatform(c *Config, credentials []string, ui *ui.UI, version string) *Platform {
p := &Platform{
name: "vsphere",
config: c,
ui: ui,
version: version,
}
p.Credentials(credentials...)
return p
}
// MergeWithEnv implements the MergeWithEnv method from the interfase
// Provisioner. It merges the environment variables with the existing configuration
func (p *Platform) MergeWithEnv(envConfig map[string]string) error {
return p.config.MergeWithEnv(envConfig)
}