-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud.go
88 lines (78 loc) · 1.66 KB
/
cloud.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package cloud
import (
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
"github.com/wonderivan/logger"
)
const (
ALI = "ali"
TENCENT = "tencent"
)
var (
CloudConfig Config
CloudRequest Request
)
//Config is client config
type Config struct {
Provider string
Region string
AccessKey string
AccessSecret string
}
type Disk struct {
Name string
Size string
}
//Request is the create vm request
type Request struct {
//VM numbers
Num int
Image string
Flavor string
NamePrefix string
Passwd string
KeyPair string
FIP bool
Disks []Disk
ZoneID string
VPCID string // if not exist, create it
SwitchID string // if not exist, create it
SecuretyGroupID string // if not exist, create it
ExternalArgs map[string]string
}
//VM is
type VM struct {
ID string
IP string
FIP string
Name string
CPU int
Memory int
CreationTime string
}
//Response is
type Response struct {
VPCID string
SwitchID string
SecuretyGroupID string
VMs []VM
}
type Interface interface {
CreateNetwork(request Request) (*Response, error)
Create(request Request) (*Response, error)
Delete(...string) error
QueryFlavor(flavor string,zone string,charge string,strategy string) string
}
func NewProvider(config Config) Interface {
switch config.Provider {
case ALI:
client, err := ecs.NewClientWithAccessKey(config.Region, config.AccessKey, config.AccessSecret)
if err != nil {
logger.Error("create ali client failed")
return nil
}
return &AliProvider{config, client}
case TENCENT:
return &TencentProvider{config}
}
return nil
}