forked from rancher/rke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudprovider.go
42 lines (38 loc) · 1.3 KB
/
cloudprovider.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 cloudprovider
import (
"github.com/rancher/rke/cloudprovider/aws"
"github.com/rancher/rke/cloudprovider/azure"
"github.com/rancher/rke/cloudprovider/custom"
"github.com/rancher/rke/cloudprovider/openstack"
"github.com/rancher/rke/cloudprovider/vsphere"
v3 "github.com/rancher/rke/types"
)
type CloudProvider interface {
Init(cloudProviderConfig v3.CloudProvider) error
GenerateCloudConfigFile() (string, error)
GetName() string
}
func InitCloudProvider(cloudProviderConfig v3.CloudProvider) (CloudProvider, error) {
var p CloudProvider
if cloudProviderConfig.AWSCloudProvider != nil || cloudProviderConfig.Name == aws.AWSCloudProviderName {
p = aws.GetInstance()
}
if cloudProviderConfig.AzureCloudProvider != nil || cloudProviderConfig.Name == azure.AzureCloudProviderName {
p = azure.GetInstance()
}
if cloudProviderConfig.OpenstackCloudProvider != nil || cloudProviderConfig.Name == openstack.OpenstackCloudProviderName {
p = openstack.GetInstance()
}
if cloudProviderConfig.VsphereCloudProvider != nil || cloudProviderConfig.Name == vsphere.VsphereCloudProviderName {
p = vsphere.GetInstance()
}
if cloudProviderConfig.CustomCloudProvider != "" {
p = custom.GetInstance()
}
if p != nil {
if err := p.Init(cloudProviderConfig); err != nil {
return nil, err
}
}
return p, nil
}