39 lines
926 B
Go
39 lines
926 B
Go
package create_ecs
|
|
|
|
// CloudProvider 是一个接口,定义了创建服务器的方法
|
|
type CloudProvider interface {
|
|
CreateServer() (string, error)
|
|
RunCommand(commands []string, instanceID string) (string, error)
|
|
DestroyServer(instanceID string) (string, error)
|
|
}
|
|
|
|
type CloudFactory interface {
|
|
CreateProvider() CloudProvider
|
|
}
|
|
|
|
// HuaweiCloudFactory 实现了CloudFactory接口
|
|
type HuaweiCloudFactory struct{}
|
|
|
|
func (f *HuaweiCloudFactory) CreateProvider() CloudProvider {
|
|
return &HuaweiCloud{}
|
|
}
|
|
|
|
// AliCloudFactory 实现了CloudFactory接口
|
|
type AliCloudFactory struct{}
|
|
|
|
func (f *AliCloudFactory) CreateProvider() CloudProvider {
|
|
return &AliCloud{}
|
|
}
|
|
|
|
// GetFactory 根据云平台类型返回对应的工厂
|
|
func GetFactory(providerType string) CloudFactory {
|
|
switch providerType {
|
|
case "HuaweiCloud":
|
|
return &HuaweiCloudFactory{}
|
|
case "AliCloud":
|
|
return &AliCloudFactory{}
|
|
default:
|
|
return nil
|
|
}
|
|
}
|