mirror of
https://github.com/rancher/rke.git
synced 2025-04-27 11:21:08 +00:00
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
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
|
|
}
|