-
Notifications
You must be signed in to change notification settings - Fork 47
/
NcpVpcCloudConnection.go
167 lines (124 loc) · 6.22 KB
/
NcpVpcCloudConnection.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 ETRI, 2020.12.
// by ETRI, 2022.10. updated
package connect
import (
"fmt"
"github.com/sirupsen/logrus"
cblog "github.com/cloud-barista/cb-log"
idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces"
irs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources"
vlb "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/vloadbalancer"
vpc "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/vpc"
vserver "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/vserver"
// ncpvpcrs "github.com/cloud-barista/ncpvpc/ncpvpc/resources" // For local testing
ncpvpcrs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/ncpvpc/resources"
)
type NcpVpcCloudConnection struct {
CredentialInfo idrv.CredentialInfo
RegionInfo idrv.RegionInfo
VmClient *vserver.APIClient
VpcClient *vpc.APIClient
VlbClient *vlb.APIClient
}
var cblogger *logrus.Logger
func init() {
// cblog is a global variable.
cblogger = cblog.GetLogger("NCP VPC Connect")
}
func (cloudConn *NcpVpcCloudConnection) CreateVMHandler() (irs.VMHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateVMHandler()!")
//NOTE Just for Test!!
// cblogger.Info("cloudConn.CredentialInfo.ClientId : ")
// spew.Dump(cloudConn.CredentialInfo.ClientId)
// cblogger.Info("cloudConn.RegionInfo : ")
// spew.Dump(cloudConn.RegionInfo)
vmHandler := ncpvpcrs.NcpVpcVMHandler{
CredentialInfo: cloudConn.CredentialInfo,
RegionInfo: cloudConn.RegionInfo,
VMClient: cloudConn.VmClient,
}
return &vmHandler, nil
}
func (cloudConn *NcpVpcCloudConnection) CreateVMSpecHandler() (irs.VMSpecHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateVMSpecHandler()!")
vmspecHandler := ncpvpcrs.NcpVpcVMSpecHandler{CredentialInfo: cloudConn.CredentialInfo, RegionInfo: cloudConn.RegionInfo, VMClient: cloudConn.VmClient}
return &vmspecHandler, nil
}
func (cloudConn *NcpVpcCloudConnection) CreateImageHandler() (irs.ImageHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateImagehandler()!")
imageHandler := ncpvpcrs.NcpVpcImageHandler{CredentialInfo: cloudConn.CredentialInfo, RegionInfo: cloudConn.RegionInfo, VMClient: cloudConn.VmClient}
return &imageHandler, nil
}
func (cloudConn *NcpVpcCloudConnection) CreateKeyPairHandler() (irs.KeyPairHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateKeyPairHandler()!")
keypairHandler := ncpvpcrs.NcpVpcKeyPairHandler{CredentialInfo: cloudConn.CredentialInfo, RegionInfo: cloudConn.RegionInfo, VMClient: cloudConn.VmClient}
return &keypairHandler, nil
}
func (cloudConn *NcpVpcCloudConnection) CreateSecurityHandler() (irs.SecurityHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateSecurityHandler()!")
sgHandler := ncpvpcrs.NcpVpcSecurityHandler{CredentialInfo: cloudConn.CredentialInfo, RegionInfo: cloudConn.RegionInfo, VMClient: cloudConn.VmClient}
return &sgHandler, nil
}
func (cloudConn *NcpVpcCloudConnection) CreateVPCHandler() (irs.VPCHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateVPCHandler()!")
vpcHandler := ncpvpcrs.NcpVpcVPCHandler{CredentialInfo: cloudConn.CredentialInfo, RegionInfo: cloudConn.RegionInfo, VPCClient: cloudConn.VpcClient}
return &vpcHandler, nil
}
func (cloudConn *NcpVpcCloudConnection) CreateNLBHandler() (irs.NLBHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateNLBHandler()!")
nlbHandler := ncpvpcrs.NcpVpcNLBHandler{CredentialInfo: cloudConn.CredentialInfo, RegionInfo: cloudConn.RegionInfo, VMClient: cloudConn.VmClient, VPCClient: cloudConn.VpcClient, VLBClient: cloudConn.VlbClient}
return &nlbHandler, nil
}
func (cloudConn *NcpVpcCloudConnection) CreateDiskHandler() (irs.DiskHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateDiskHandler()!")
// cblogger.Info("\n### cloudConn.RegionInfo : ")
// spew.Dump(cloudConn.RegionInfo)
// cblogger.Info("\n")
diskHandler := ncpvpcrs.NcpVpcDiskHandler{RegionInfo: cloudConn.RegionInfo, VMClient: cloudConn.VmClient}
return &diskHandler, nil
}
func (cloudConn *NcpVpcCloudConnection) CreateMyImageHandler() (irs.MyImageHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateMyImageHandler()!")
myimageHandler := ncpvpcrs.NcpVpcMyImageHandler{RegionInfo: cloudConn.RegionInfo, VMClient: cloudConn.VmClient}
return &myimageHandler, nil
}
func (cloudConn *NcpVpcCloudConnection) CreateClusterHandler() (irs.ClusterHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateClusterHandler()!")
return nil, fmt.Errorf("NCP VPC Cloud Driver does not support CreateClusterHandler yet.")
}
func (cloudConn *NcpVpcCloudConnection) CreateAnyCallHandler() (irs.AnyCallHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateAnyCallHandler()!")
return nil, fmt.Errorf("NCP VPC Cloud Driver does not support CreateAnyCallHandler yet.")
}
func (cloudConn *NcpVpcCloudConnection) CreateRegionZoneHandler() (irs.RegionZoneHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreateRegionZoneHandler()!")
regionZoneHandler := ncpvpcrs.NcpRegionZoneHandler{RegionInfo: cloudConn.RegionInfo, VMClient: cloudConn.VmClient}
return ®ionZoneHandler, nil
}
func (cloudConn *NcpVpcCloudConnection) CreatePriceInfoHandler() (irs.PriceInfoHandler, error) {
cblogger.Info("NCP VPC Cloud Driver: called CreatePriceInfoHandler()!")
priceInfoHandler := ncpvpcrs.NcpVpcPriceInfoHandler{CredentialInfo: cloudConn.CredentialInfo, RegionInfo: cloudConn.RegionInfo, VMClient: cloudConn.VmClient}
return &priceInfoHandler, nil
}
func (cloudConn *NcpVpcCloudConnection) IsConnected() (bool, error) {
cblogger.Info("NCP VPC Cloud Driver: called IsConnected()!")
if cloudConn == nil {
return false, nil
}
if cloudConn.VmClient.V2Api == nil {
return false, nil
}
return true, nil
}
func (cloudConn *NcpVpcCloudConnection) Close() error {
cblogger.Info("NCP VPC Cloud Driver: called Close()!")
return nil
}