-
Notifications
You must be signed in to change notification settings - Fork 47
/
AwsDriver.go
167 lines (139 loc) · 5.66 KB
/
AwsDriver.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Proof of Concepts of CB-Spider.
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// This is a Cloud Driver Example for PoC Test.
//
// by CB-Spider Team, 2019.06.
// https://docs.aws.amazon.com/sdk-for-go/api/service/elbv2
package aws
import (
acon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/aws/connect"
idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces"
icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect"
//icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect/AwsNewIfCloudConnect"
//icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect/connect"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/elbv2"
)
type AwsDriver struct {
}
func (AwsDriver) GetDriverVersion() string {
return "AWS DRIVER Version 1.0"
}
func (AwsDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
var drvCapabilityInfo idrv.DriverCapabilityInfo
drvCapabilityInfo.ImageHandler = true
drvCapabilityInfo.VPCHandler = true
drvCapabilityInfo.SecurityHandler = true
drvCapabilityInfo.KeyPairHandler = true
drvCapabilityInfo.VNicHandler = false
drvCapabilityInfo.PublicIPHandler = false
drvCapabilityInfo.VMHandler = true
drvCapabilityInfo.VMSpecHandler = true
drvCapabilityInfo.NLBHandler = true
return drvCapabilityInfo
}
//func getVMClient(regionInfo idrv.RegionInfo) (*ec2.EC2, error) {
func getVMClient(connectionInfo idrv.ConnectionInfo) (*ec2.EC2, error) {
// setup Region
fmt.Println("AwsDriver : getVMClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")
fmt.Println("AwsDriver : getVMClient() - Zone : [" + connectionInfo.RegionInfo.Zone + "]")
//fmt.Println("전달 받은 커넥션 정보")
//spew.Dump(connectionInfo)
sess, err := session.NewSession(&aws.Config{
Region: aws.String(connectionInfo.RegionInfo.Region),
//Region: aws.String("ap-northeast-2"),
Credentials: credentials.NewStaticCredentials(connectionInfo.CredentialInfo.ClientId, connectionInfo.CredentialInfo.ClientSecret, "")},
)
if err != nil {
fmt.Println("Could not create aws New Session", err)
return nil, err
}
// Create EC2 service client
svc := ec2.New(sess)
if err != nil {
fmt.Println("Could not create EC2 service client", err)
return nil, err
}
return svc, nil
}
//로드밸런서 처리를 위한 ELB 클라이언트 획득
func getNLBClient(connectionInfo idrv.ConnectionInfo) (*elbv2.ELBV2, error) {
//func getNLBClient(connectionInfo idrv.ConnectionInfo) (*elb.ELB, error) {
// setup Region
fmt.Println("AwsDriver : getVMClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")
fmt.Println("AwsDriver : getVMClient() - Zone : [" + connectionInfo.RegionInfo.Zone + "]")
//fmt.Println("전달 받은 커넥션 정보")
//spew.Dump(connectionInfo)
sess, err := session.NewSession(&aws.Config{
Region: aws.String(connectionInfo.RegionInfo.Region),
//Region: aws.String("ap-northeast-2"),
Credentials: credentials.NewStaticCredentials(connectionInfo.CredentialInfo.ClientId, connectionInfo.CredentialInfo.ClientSecret, "")},
)
if err != nil {
fmt.Println("Could not create aws New Session", err)
return nil, err
}
//svc := elb.New(sess)
// Create ELBv2 service client
svc := elbv2.New(sess)
if err != nil {
fmt.Println("Could not create ELBv2 service client", err)
return nil, err
}
return svc, nil
}
func (driver *AwsDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) {
// 1. get info of credential and region for Test A Cloud from connectionInfo.
// 2. create a client object(or service object) of Test A Cloud with credential info.
// 3. create CloudConnection Instance of "connect/TDA_CloudConnection".
// 4. return CloudConnection Interface of TDA_CloudConnection.
//fmt.Println("ConnectCloud의 전달 받은 idrv.ConnectionInfo 정보")
//spew.Dump(connectionInfo)
// sample code, do not user like this^^
//var iConn icon.CloudConnection
vmClient, err := getVMClient(connectionInfo)
nlbClient, err := getNLBClient(connectionInfo)
//vmClient, err := getVMClient(connectionInfo.RegionInfo)
if err != nil {
return nil, err
}
//iConn = acon.AwsCloudConnection{}
iConn := acon.AwsCloudConnection{
CredentialInfo: connectionInfo.CredentialInfo,
Region: connectionInfo.RegionInfo,
VMClient: vmClient,
KeyPairClient: vmClient,
VNetworkClient: vmClient,
//VNicClient: vmClient,
ImageClient: vmClient,
//PublicIPClient: vmClient,
SecurityClient: vmClient,
VmSpecClient: vmClient,
NLBClient: nlbClient,
DiskClient: vmClient,
MyImageClient: vmClient,
// Connection for AnyCall
AnyCallClient: vmClient,
}
return &iConn, nil // return type: (icon.CloudConnection, error)
}
/*
func (AwsDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) {
// 1. get info of credential and region for Test A Cloud from connectionInfo.
// 2. create a client object(or service object) of Test A Cloud with credential info.
// 3. create CloudConnection Instance of "connect/TDA_CloudConnection".
// 4. return CloudConnection Interface of TDA_CloudConnection.
// sample code, do not user like this^^
var iConn icon.CloudConnection
iConn = acon.AwsCloudConnection{}
return iConn, nil // return type: (icon.CloudConnection, error)
}
*/