-
Notifications
You must be signed in to change notification settings - Fork 47
/
OpenStackDriver-lib.go
172 lines (144 loc) · 5.23 KB
/
OpenStackDriver-lib.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
168
169
170
171
172
// 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 hyokyung.kim@innogrid.co.kr, 2019.07.
package main
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
oscon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/openstack/connect"
osrs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/openstack/resources"
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"
)
type OpenStackDriver struct{}
func (OpenStackDriver) GetDriverVersion() string {
return "OPENSTACK DRIVER Version 1.0"
}
func (OpenStackDriver) 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
return drvCapabilityInfo
}
// modifiled by powerkim, 2019.07.29.
func (driver *OpenStackDriver) 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.
// Initialize Logger
osrs.InitLog()
Client, err := getServiceClient(connectionInfo)
if err != nil {
return nil, err
}
ImageClient, err := getImageClient(connectionInfo)
if err != nil {
return nil, err
}
NetworkClient, err := getNetworkClient(connectionInfo)
if err != nil {
return nil, err
}
VolumeClient, err := getVolumeClient(connectionInfo)
if err != nil {
return nil, err
}
iConn := oscon.OpenStackCloudConnection{Region: connectionInfo.RegionInfo, Client: Client, ImageClient: ImageClient, NetworkClient: NetworkClient, VolumeClient: VolumeClient}
return &iConn, nil
}
// moved by powerkim, 2019.07.29.
func getServiceClient(connInfo idrv.ConnectionInfo) (*gophercloud.ServiceClient, error) {
authOpts := gophercloud.AuthOptions{
IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint,
Username: connInfo.CredentialInfo.Username,
Password: connInfo.CredentialInfo.Password,
DomainName: connInfo.CredentialInfo.DomainName,
TenantID: connInfo.CredentialInfo.ProjectID,
}
provider, err := openstack.AuthenticatedClient(authOpts)
if err != nil {
return nil, err
}
client, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{
Region: connInfo.RegionInfo.Region,
})
if err != nil {
return nil, err
}
return client, err
}
func getImageClient(connInfo idrv.ConnectionInfo) (*gophercloud.ServiceClient, error) {
authOpts := gophercloud.AuthOptions{
IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint,
Username: connInfo.CredentialInfo.Username,
Password: connInfo.CredentialInfo.Password,
DomainName: connInfo.CredentialInfo.DomainName,
TenantID: connInfo.CredentialInfo.ProjectID,
}
provider, err := openstack.AuthenticatedClient(authOpts)
if err != nil {
return nil, err
}
c, err := openstack.NewImageServiceV2(provider, gophercloud.EndpointOpts{
Region: connInfo.RegionInfo.Region,
})
if err != nil {
return nil, err
}
return c, err
}
func getNetworkClient(connInfo idrv.ConnectionInfo) (*gophercloud.ServiceClient, error) {
authOpts := gophercloud.AuthOptions{
IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint,
Username: connInfo.CredentialInfo.Username,
Password: connInfo.CredentialInfo.Password,
DomainName: connInfo.CredentialInfo.DomainName,
TenantID: connInfo.CredentialInfo.ProjectID,
}
provider, err := openstack.AuthenticatedClient(authOpts)
if err != nil {
return nil, err
}
client, err := openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{
Name: "neutron",
Region: connInfo.RegionInfo.Region,
})
if err != nil {
return nil, err
}
return client, err
}
func getVolumeClient(connInfo idrv.ConnectionInfo) (*gophercloud.ServiceClient, error) {
authOpts := gophercloud.AuthOptions{
IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint,
Username: connInfo.CredentialInfo.Username,
Password: connInfo.CredentialInfo.Password,
DomainName: connInfo.CredentialInfo.DomainName,
TenantID: connInfo.CredentialInfo.ProjectID,
}
provider, err := openstack.AuthenticatedClient(authOpts)
if err != nil {
return nil, err
}
client, err := openstack.NewBlockStorageV2(provider, gophercloud.EndpointOpts{
Region: connInfo.RegionInfo.Region,
})
if err != nil {
return nil, err
}
return client, err
}
var CloudDriver OpenStackDriver