50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package create_ecs
|
|
|
|
import schmod "gitlink.org.cn/cloudream/scheduler/common/models"
|
|
|
|
type CloudProvider interface {
|
|
CreateServer() (string, string, error)
|
|
RunCommand(commands []string, instanceID string, timeout int) (string, error)
|
|
DeleteInstance(instanceID string) (string, error)
|
|
StopInstance(instanceID string) (string, error)
|
|
RebootInstances(instanceID string) (string, error)
|
|
StartInstances(instanceID string) (string, error)
|
|
AvailableCheck(instanceID string) bool
|
|
}
|
|
|
|
type CloudFactory interface {
|
|
CreateProvider() CloudProvider
|
|
}
|
|
|
|
type HuaweiCloudFactory struct{}
|
|
|
|
func (f *HuaweiCloudFactory) CreateProvider() CloudProvider {
|
|
return &HuaweiCloud{}
|
|
}
|
|
|
|
type AliCloudFactory struct{}
|
|
|
|
func (f *AliCloudFactory) CreateProvider() CloudProvider {
|
|
return &AliCloud{}
|
|
}
|
|
|
|
type ShuGuangCloudFactory struct{}
|
|
|
|
func (f *ShuGuangCloudFactory) CreateProvider() CloudProvider {
|
|
return &SugonCloud{}
|
|
}
|
|
|
|
// GetFactory 根据云平台类型返回对应的工厂
|
|
func GetFactory(providerType string) CloudFactory {
|
|
switch providerType {
|
|
case schmod.HuaweiCloud:
|
|
return &HuaweiCloudFactory{}
|
|
case schmod.AliCloud:
|
|
return &AliCloudFactory{}
|
|
case schmod.SugonCloud:
|
|
return &ShuGuangCloudFactory{}
|
|
default:
|
|
return nil
|
|
}
|
|
}
|