-
Notifications
You must be signed in to change notification settings - Fork 44
/
Azure_CloudConnection.go
117 lines (101 loc) · 4.75 KB
/
Azure_CloudConnection.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
// 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 connect
import (
"context"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-06-01/compute"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-04-01/network"
cblog "github.com/cloud-barista/cb-log"
azrs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/azure/resources"
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"
"github.com/sirupsen/logrus"
)
var cblogger *logrus.Logger
func init() {
// cblog is a global variable.
cblogger = cblog.GetLogger("CB-SPIDER")
}
type AzureCloudConnection struct {
CredentialInfo idrv.CredentialInfo
Region idrv.RegionInfo
Ctx context.Context
VMClient *compute.VirtualMachinesClient
ImageClient *compute.ImagesClient
VMImageClient *compute.VirtualMachineImagesClient
PublicIPClient *network.PublicIPAddressesClient
SecurityGroupClient *network.SecurityGroupsClient
VNetClient *network.VirtualNetworksClient
VNicClient *network.InterfacesClient
IPConfigClient *network.InterfaceIPConfigurationsClient
SubnetClient *network.SubnetsClient
DiskClient *compute.DisksClient
VmSpecClient *compute.VirtualMachineSizesClient
}
func (cloudConn *AzureCloudConnection) CreateImageHandler() (irs.ImageHandler, error) {
cblogger.Info("Azure Cloud Driver: called CreateImageHandler()!")
imageHandler := azrs.AzureImageHandler{cloudConn.Region, cloudConn.Ctx, cloudConn.ImageClient, cloudConn.VMImageClient}
return &imageHandler, nil
}
/*func (cloudConn *AzureCloudConnection) CreateVNetworkHandler() (irs.VNetworkHandler, error) {
cblogger.Info("Azure Cloud Driver: called CreateVNetworkHandler()!")
vNetHandler := azrs.AzureVPCHandler{cloudConn.Region, cloudConn.Ctx, cloudConn.VNetClient, cloudConn.SubnetClient}
return &vNetHandler, nil
}*/
func (cloudConn *AzureCloudConnection) CreateVPCHandler() (irs.VPCHandler, error) {
cblogger.Info("Azure Cloud Driver: called CreateVPCHandler()!")
vpcHandler := azrs.AzureVPCHandler{cloudConn.Region, cloudConn.Ctx, cloudConn.VNetClient, cloudConn.SubnetClient}
return &vpcHandler, nil
}
func (cloudConn *AzureCloudConnection) CreateSecurityHandler() (irs.SecurityHandler, error) {
cblogger.Info("Azure Cloud Driver: called CreateSecurityHandler()!")
sgHandler := azrs.AzureSecurityHandler{cloudConn.Region, cloudConn.Ctx, cloudConn.SecurityGroupClient}
return &sgHandler, nil
}
func (cloudConn *AzureCloudConnection) CreateKeyPairHandler() (irs.KeyPairHandler, error) {
cblogger.Info("Azure Cloud Driver: called CreateKeyPairHandler()!")
keypairHandler := azrs.AzureKeyPairHandler{cloudConn.CredentialInfo, cloudConn.Region}
return &keypairHandler, nil
}
/*func (cloudConn *AzureCloudConnection) CreateVNicHandler() (irs.VNicHandler, error) {
cblogger.Info("Azure Cloud Driver: called CreateVNicHandler()!")
vNicHandler := azrs.AzureVNicHandler{cloudConn.CredentialInfo, cloudConn.Region, cloudConn.Ctx, cloudConn.VNicClient, cloudConn.SubnetClient}
return &vNicHandler, nil
}*/
/*func (cloudConn *AzureCloudConnection) CreatePublicIPHandler() (irs.PublicIPHandler, error) {
cblogger.Info("Azure Cloud Driver: called CreatePublicIPHandler()!")
publicIPHandler := azrs.AzurePublicIPHandler{cloudConn.Region, cloudConn.Ctx, cloudConn.PublicIPClient, cloudConn.IPConfigClient}
return &publicIPHandler, nil
}*/
func (cloudConn *AzureCloudConnection) CreateVMHandler() (irs.VMHandler, error) {
cblogger.Info("Azure Cloud Driver: called CreateVMHandler()!")
vmHandler := azrs.AzureVMHandler{
CredentialInfo: cloudConn.CredentialInfo,
Region: cloudConn.Region,
Ctx: cloudConn.Ctx,
Client: cloudConn.VMClient,
SubnetClient: cloudConn.SubnetClient,
NicClient: cloudConn.VNicClient,
PublicIPClient: cloudConn.PublicIPClient,
DiskClient: cloudConn.DiskClient,
}
return &vmHandler, nil
}
func (cloudConn *AzureCloudConnection) CreateVMSpecHandler() (irs.VMSpecHandler, error) {
cblogger.Info("Azure Cloud Driver: called CreateVMSpecHandler()!")
vmSpecHandler := azrs.AzureVmSpecHandler{cloudConn.Region, cloudConn.Ctx, cloudConn.VmSpecClient}
return &vmSpecHandler, nil
}
func (cloudConn *AzureCloudConnection) IsConnected() (bool, error) {
return true, nil
}
func (cloudConn *AzureCloudConnection) Close() error {
return nil
}