-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from hyokyungk/master
Azure, OpenStack, Cloudit 드라이버 추가
- Loading branch information
Showing
42 changed files
with
7,857 additions
and
0 deletions.
There are no files selected for viewing
195 changes: 195 additions & 0 deletions
195
cloud-control-manager/cloud-driver/drivers/azure/AzureDriver.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
// 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 azure | ||
|
||
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" | ||
"github.com/Azure/go-autorest/autorest/azure/auth" | ||
azcon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/azure/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" | ||
"time" | ||
) | ||
|
||
type AzureDriver struct{} | ||
|
||
func (AzureDriver) GetDriverVersion() string { | ||
return "AZURE DRIVER Version 1.0" | ||
} | ||
|
||
func (AzureDriver) GetDriverCapability() idrv.DriverCapabilityInfo { | ||
var drvCapabilityInfo idrv.DriverCapabilityInfo | ||
|
||
drvCapabilityInfo.ImageHandler = false | ||
drvCapabilityInfo.VNetworkHandler = false | ||
drvCapabilityInfo.SecurityHandler = false | ||
drvCapabilityInfo.KeyPairHandler = false | ||
drvCapabilityInfo.VNicHandler = false | ||
drvCapabilityInfo.PublicIPHandler = false | ||
drvCapabilityInfo.VMHandler = true | ||
|
||
return drvCapabilityInfo | ||
} | ||
|
||
func (driver *AzureDriver) 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. | ||
|
||
Ctx, VMClient, err := getVMClient(connectionInfo.CredentialInfo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
Ctx, imageClient, err := getImageClient(connectionInfo.CredentialInfo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
Ctx, publicIPClient, err := getPublicIPClient(connectionInfo.CredentialInfo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
Ctx, sgClient, err := getSecurityGroupClient(connectionInfo.CredentialInfo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
Ctx, vNicClient, err := getVNicClient(connectionInfo.CredentialInfo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
Ctx, SubnetClient, err := getSubnetClient(connectionInfo.CredentialInfo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
Ctx, VNetClient, err := getVNetworkClient(connectionInfo.CredentialInfo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
iConn := azcon.AzureCloudConnection{ | ||
Region: connectionInfo.RegionInfo, | ||
Ctx: Ctx, | ||
VMClient: VMClient, | ||
ImageClient: imageClient, | ||
PublicIPClient: publicIPClient, | ||
SecurityGroupClient: sgClient, | ||
VNetClient: VNetClient, | ||
VNicClient: vNicClient, | ||
SubnetClient: SubnetClient, | ||
} | ||
return &iConn, nil | ||
} | ||
|
||
func getVMClient(credential idrv.CredentialInfo) (context.Context, *compute.VirtualMachinesClient, error) { | ||
/*auth.NewClientCredentialsConfig() | ||
authorizer, err := auth.NewAuthorizerFromFile(azure.PublicCloud.ResourceManagerEndpoint) | ||
if err != nil { | ||
return nil, nil, err | ||
}*/ | ||
config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) | ||
authorizer, err := config.Authorizer() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
vmClient := compute.NewVirtualMachinesClient(credential.SubscriptionId) | ||
vmClient.Authorizer = authorizer | ||
ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) | ||
|
||
return ctx, &vmClient, nil | ||
} | ||
|
||
func getImageClient(credential idrv.CredentialInfo) (context.Context, *compute.ImagesClient, error) { | ||
config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) | ||
authorizer, err := config.Authorizer() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
imageClient := compute.NewImagesClient(credential.SubscriptionId) | ||
imageClient.Authorizer = authorizer | ||
ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) | ||
|
||
return ctx, &imageClient, nil | ||
} | ||
|
||
func getPublicIPClient(credential idrv.CredentialInfo) (context.Context, *network.PublicIPAddressesClient, error) { | ||
config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) | ||
authorizer, err := config.Authorizer() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
publicIPClient := network.NewPublicIPAddressesClient(credential.SubscriptionId) | ||
publicIPClient.Authorizer = authorizer | ||
ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) | ||
|
||
return ctx, &publicIPClient, nil | ||
} | ||
|
||
func getSecurityGroupClient(credential idrv.CredentialInfo) (context.Context, *network.SecurityGroupsClient, error) { | ||
config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) | ||
authorizer, err := config.Authorizer() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
sgClient := network.NewSecurityGroupsClient(credential.SubscriptionId) | ||
sgClient.Authorizer = authorizer | ||
ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) | ||
|
||
return ctx, &sgClient, nil | ||
} | ||
|
||
func getVNetworkClient(credential idrv.CredentialInfo) (context.Context, *network.VirtualNetworksClient, error) { | ||
config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) | ||
authorizer, err := config.Authorizer() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
vNetClient := network.NewVirtualNetworksClient(credential.SubscriptionId) | ||
vNetClient.Authorizer = authorizer | ||
ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) | ||
|
||
return ctx, &vNetClient, nil | ||
} | ||
|
||
func getVNicClient(credential idrv.CredentialInfo) (context.Context, *network.InterfacesClient, error) { | ||
config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) | ||
authorizer, err := config.Authorizer() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
vNicClient := network.NewInterfacesClient(credential.SubscriptionId) | ||
vNicClient.Authorizer = authorizer | ||
ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) | ||
|
||
return ctx, &vNicClient, nil | ||
} | ||
|
||
func getSubnetClient(credential idrv.CredentialInfo) (context.Context, *network.SubnetsClient, error) { | ||
config := auth.NewClientCredentialsConfig(credential.ClientId, credential.ClientSecret, credential.TenantId) | ||
authorizer, err := config.Authorizer() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
subnetClient := network.NewSubnetsClient(credential.SubscriptionId) | ||
subnetClient.Authorizer = authorizer | ||
ctx, _ := context.WithTimeout(context.Background(), 600*time.Second) | ||
|
||
return ctx, &subnetClient, nil | ||
} | ||
|
||
var TestDriver AzureDriver |
85 changes: 85 additions & 0 deletions
85
cloud-control-manager/cloud-driver/drivers/azure/connect/Azure_CloudConnection.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// 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 { | ||
Region idrv.RegionInfo | ||
Ctx context.Context | ||
VMClient *compute.VirtualMachinesClient | ||
ImageClient *compute.ImagesClient | ||
PublicIPClient *network.PublicIPAddressesClient | ||
SecurityGroupClient *network.SecurityGroupsClient | ||
VNetClient *network.VirtualNetworksClient | ||
VNicClient *network.InterfacesClient | ||
SubnetClient *network.SubnetsClient | ||
} | ||
|
||
func (cloudConn *AzureCloudConnection) CreateVNetworkHandler() (irs.VNetworkHandler, error) { | ||
cblogger.Info("Azure Cloud Driver: called CreateVNetworkHandler()!") | ||
vNetHandler := azrs.AzureVNetworkHandler{cloudConn.Region, cloudConn.Ctx, cloudConn.VNetClient} | ||
return &vNetHandler, nil | ||
} | ||
|
||
func (cloudConn *AzureCloudConnection) CreateImageHandler() (irs.ImageHandler, error) { | ||
cblogger.Info("Azure Cloud Driver: called CreateImageHandler()!") | ||
imageHandler := azrs.AzureImageHandler{cloudConn.Region, cloudConn.Ctx, cloudConn.ImageClient} | ||
return &imageHandler, 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 (AzureCloudConnection) CreateKeyPairHandler() (irs.KeyPairHandler, error) { | ||
return nil, nil | ||
} | ||
func (cloudConn *AzureCloudConnection) CreateVNicHandler() (irs.VNicHandler, error) { | ||
cblogger.Info("Azure Cloud Driver: called CreateVNicHandler()!") | ||
vNicHandler := azrs.AzureVNicHandler{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} | ||
return &publicIPHandler, nil | ||
} | ||
|
||
func (cloudConn *AzureCloudConnection) CreateVMHandler() (irs.VMHandler, error) { | ||
cblogger.Info("Azure Cloud Driver: called CreateVMHandler()!") | ||
vmHandler := azrs.AzureVMHandler{cloudConn.Region, cloudConn.Ctx, cloudConn.VMClient} | ||
return &vmHandler, nil | ||
} | ||
|
||
func (AzureCloudConnection) IsConnected() (bool, error) { | ||
return true, nil | ||
} | ||
func (AzureCloudConnection) Close() error { | ||
return nil | ||
} |
Oops, something went wrong.