Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1차 IID 기반 로직 반영 #163

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cloud-control-manager/cloud-driver/drivers/aws/AwsDriver-lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (AwsDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
drvCapabilityInfo.VNetworkHandler = true
drvCapabilityInfo.SecurityHandler = true
drvCapabilityInfo.KeyPairHandler = true
drvCapabilityInfo.VNicHandler = true
drvCapabilityInfo.PublicIPHandler = true
drvCapabilityInfo.VNicHandler = false
drvCapabilityInfo.PublicIPHandler = false
drvCapabilityInfo.VMHandler = true
drvCapabilityInfo.VMSpecHandler = true

Expand Down Expand Up @@ -106,9 +106,9 @@ func (driver *AwsDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.
KeyPairClient: vmClient,

VNetworkClient: vmClient,
VNicClient: vmClient,
ImageClient: vmClient,
PublicIPClient: vmClient,
//VNicClient: vmClient,
ImageClient: vmClient,
//PublicIPClient: vmClient,
SecurityClient: vmClient,
VmSpecClient: vmClient,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ type AwsCloudConnection struct {
VMClient *ec2.EC2

VNetworkClient *ec2.EC2
VNicClient *ec2.EC2
ImageClient *ec2.EC2
PublicIPClient *ec2.EC2
//VNicClient *ec2.EC2
ImageClient *ec2.EC2
//PublicIPClient *ec2.EC2
SecurityClient *ec2.EC2
VmSpecClient *ec2.EC2
}
Expand Down Expand Up @@ -89,6 +89,7 @@ func (cloudConn *AwsCloudConnection) CreateSecurityHandler() (irs.SecurityHandle
return &handler, nil
}

/*
func (cloudConn *AwsCloudConnection) CreateVNicHandler() (irs.VNicHandler, error) {
cblogger.Info("Start")
handler := ars.AwsVNicHandler{cloudConn.Region, cloudConn.VNicClient}
Expand All @@ -102,6 +103,7 @@ func (cloudConn *AwsCloudConnection) CreatePublicIPHandler() (irs.PublicIPHandle

return &handler, nil
}
*/

func (cloudConn *AwsCloudConnection) CreateVMSpecHandler() (irs.VMSpecHandler, error) {
cblogger.Info("Start")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func handleSecurity() {
//result, err := handler.ListSecurity()

securityReqInfo := irs.SecurityReqInfo{
Name: securityId,
IId: irs.IID{NameId: securityId},
SecurityRules: &[]irs.SecurityRuleInfo{ //보안 정책 설정
{
FromPort: "20",
Expand Down Expand Up @@ -114,6 +114,7 @@ func handleSecurity() {
}
}

/*
// Test PublicIp
func handlePublicIP() {
cblogger.Debug("Start Publicip Resource Test")
Expand Down Expand Up @@ -191,21 +192,6 @@ func handlePublicIP() {

case 4:
fmt.Println("Start DeletePublicIP() ...")
/*
fmt.Print("삭제할 PublicIP를 입력하세요 : ")
inputCnt, err := fmt.Scan(&reqDelIP)
if err != nil {
panic(err)
}

if inputCnt == 1 {
cblogger.Info("삭제할 PublicIP : ", reqDelIP)
} else {
fmt.Println("삭제할 Public IP만 입력하세요.")
}
result, err := handler.DeletePublicIP(reqDelIP)
*/

result, err := handler.DeletePublicIP(reqPublicIP)
if err != nil {
cblogger.Error(reqDelIP, " PublicIP 삭제 실패 : ", err)
Expand All @@ -225,6 +211,7 @@ func handlePublicIP() {
}
}
}
*/

// Test KeyPair
func handleKeyPair() {
Expand Down Expand Up @@ -272,7 +259,8 @@ func handleKeyPair() {
case 2:
cblogger.Infof("[%s] 키 페어 생성 테스트", keyPairName)
keyPairReqInfo := irs.KeyPairReqInfo{
Name: keyPairName,
IId: irs.IID{NameId: keyPairName},
//Name: keyPairName,
}
result, err := KeyPairHandler.CreateKey(keyPairReqInfo)
if err != nil {
Expand All @@ -283,15 +271,15 @@ func handleKeyPair() {
}
case 3:
cblogger.Infof("[%s] 키 페어 조회 테스트", keyPairName)
result, err := KeyPairHandler.GetKey(keyPairName)
result, err := KeyPairHandler.GetKey(irs.IID{NameId: keyPairName})
if err != nil {
cblogger.Infof(keyPairName, " 키 페어 조회 실패 : ", err)
} else {
cblogger.Infof("[%s] 키 페어 조회 결과 : [%s]", keyPairName, result)
}
case 4:
cblogger.Infof("[%s] 키 페어 삭제 테스트", keyPairName)
result, err := KeyPairHandler.DeleteKey(keyPairName)
result, err := KeyPairHandler.DeleteKey(irs.IID{NameId: keyPairName})
if err != nil {
cblogger.Infof(keyPairName, " 키 페어 삭제 실패 : ", err)
} else {
Expand All @@ -313,11 +301,13 @@ func handleVNetwork() {

vNetworkReqInfo := irs.VNetworkReqInfo{
//Id: "subnet-044a2b57145e5afc5",
Name: "CB-VNet-Subnet", // 웹 도구 등 외부에서 전달 받지 않고 드라이버 내부적으로 자동 구현때문에 사용하지 않음.
//Name: "CB-VNet-Subnet", // 웹 도구 등 외부에서 전달 받지 않고 드라이버 내부적으로 자동 구현때문에 사용하지 않음.
IId: irs.IID{NameId: "CB-VNet-Subnet"},
//CidrBlock: "10.0.0.0/16",
//CidrBlock: "192.168.0.0/16",
}
reqSubnetId := "subnet-0b9ea37601d46d8fa"
//reqSubnetId := "subnet-0b9ea37601d46d8fa"
reqSubnetId := irs.IID{NameId: "subnet-0b9ea37601d46d8fa"}
//reqSubnetId = ""

for {
Expand Down Expand Up @@ -351,19 +341,19 @@ func handleVNetwork() {
// 내부적으로 1개만 존재함.
//조회및 삭제 테스트를 위해 리스트의 첫번째 서브넷 ID를 요청ID로 자동 갱신함.
if result != nil {
reqSubnetId = result[0].Id // 조회 및 삭제를 위해 생성된 ID로 변경
reqSubnetId = result[0].IId // 조회 및 삭제를 위해 생성된 ID로 변경
}
}

case 2:
cblogger.Infof("[%s] VNetwork 생성 테스트", vNetworkReqInfo.Name)
cblogger.Infof("[%s] VNetwork 생성 테스트", vNetworkReqInfo.IId.NameId)
//vNetworkReqInfo := irs.VNetworkReqInfo{}
result, err := vNetworkHandler.CreateVNetwork(vNetworkReqInfo)
if err != nil {
cblogger.Infof(reqSubnetId, " VNetwork 생성 실패 : ", err)
cblogger.Infof(reqSubnetId.NameId, " VNetwork 생성 실패 : ", err)
} else {
cblogger.Infof("VNetwork 생성 결과 : ", result)
reqSubnetId = result.Id // 조회 및 삭제를 위해 생성된 ID로 변경
reqSubnetId = result.IId // 조회 및 삭제를 위해 생성된 ID로 변경
spew.Dump(result)
}

Expand Down Expand Up @@ -403,8 +393,9 @@ func handleImage() {

//imageReqInfo := irs2.ImageReqInfo{
imageReqInfo := irs.ImageReqInfo{
Id: "ami-047f7b46bd6dd5d84",
Name: "Test OS Image",
IId: irs.IID{NameId: "Test OS Image", SystemId: "ami-047f7b46bd6dd5d84"},
//Id: "ami-047f7b46bd6dd5d84",
//Name: "Test OS Image",
}

for {
Expand Down Expand Up @@ -438,45 +429,46 @@ func handleImage() {

//조회및 삭제 테스트를 위해 리스트의 첫번째 정보의 ID를 요청ID로 자동 갱신함.
if result != nil {
imageReqInfo.Id = result[0].Id // 조회 및 삭제를 위해 생성된 ID로 변경
imageReqInfo.IId = result[0].IId // 조회 및 삭제를 위해 생성된 ID로 변경
}
}

case 2:
cblogger.Infof("[%s] Image 생성 테스트", imageReqInfo.Name)
cblogger.Infof("[%s] Image 생성 테스트", imageReqInfo.IId.NameId)
//vNetworkReqInfo := irs.VNetworkReqInfo{}
result, err := handler.CreateImage(imageReqInfo)
if err != nil {
cblogger.Infof(imageReqInfo.Id, " Image 생성 실패 : ", err)
cblogger.Infof(imageReqInfo.IId.NameId, " Image 생성 실패 : ", err)
} else {
cblogger.Infof("Image 생성 결과 : ", result)
imageReqInfo.Id = result.Id // 조회 및 삭제를 위해 생성된 ID로 변경
imageReqInfo.IId = result.IId // 조회 및 삭제를 위해 생성된 ID로 변경
spew.Dump(result)
}

case 3:
cblogger.Infof("[%s] Image 조회 테스트", imageReqInfo.Id)
result, err := handler.GetImage(imageReqInfo.Id)
cblogger.Infof("[%s] Image 조회 테스트", imageReqInfo.IId)
result, err := handler.GetImage(imageReqInfo.IId)
if err != nil {
cblogger.Infof("[%s] Image 조회 실패 : ", imageReqInfo.Id, err)
cblogger.Infof("[%s] Image 조회 실패 : ", imageReqInfo.IId.NameId, err)
} else {
cblogger.Infof("[%s] Image 조회 결과 : [%s]", imageReqInfo.Id, result)
cblogger.Infof("[%s] Image 조회 결과 : [%s]", imageReqInfo.IId.NameId, result)
spew.Dump(result)
}

case 4:
cblogger.Infof("[%s] Image 삭제 테스트", imageReqInfo.Id)
result, err := handler.DeleteImage(imageReqInfo.Id)
cblogger.Infof("[%s] Image 삭제 테스트", imageReqInfo.IId.NameId)
result, err := handler.DeleteImage(imageReqInfo.IId)
if err != nil {
cblogger.Infof("[%s] Image 삭제 실패 : ", imageReqInfo.Id, err)
cblogger.Infof("[%s] Image 삭제 실패 : ", imageReqInfo.IId.NameId, err)
} else {
cblogger.Infof("[%s] Image 삭제 결과 : [%s]", imageReqInfo.Id, result)
cblogger.Infof("[%s] Image 삭제 결과 : [%s]", imageReqInfo.IId.NameId, result)
}
}
}
}
}

/*
// Test VNic
func handleVNic() {
cblogger.Debug("Start VNicHandler Resource Test")
Expand Down Expand Up @@ -559,6 +551,7 @@ func handleVNic() {
}
}
}
*/

func testErr() error {
//return awserr.Error("")
Expand Down Expand Up @@ -742,14 +735,14 @@ func getResourceHandler(handlerType string) (interface{}, error) {
switch handlerType {
case "Image":
resourceHandler, err = cloudConnection.CreateImageHandler()
case "Publicip":
resourceHandler, err = cloudConnection.CreatePublicIPHandler()
//case "Publicip":
// resourceHandler, err = cloudConnection.CreatePublicIPHandler()
case "Security":
resourceHandler, err = cloudConnection.CreateSecurityHandler()
case "VNetwork":
resourceHandler, err = cloudConnection.CreateVNetworkHandler()
case "VNic":
resourceHandler, err = cloudConnection.CreateVNicHandler()
//case "VNic":
// resourceHandler, err = cloudConnection.CreateVNicHandler()
case "VMSpec":
resourceHandler, err = cloudConnection.CreateVMSpecHandler()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ func (vNetworkHandler *AwsVNetworkHandler) GetAutoCBNetworkInfo() (AwsCBNetworkI
awsCBNetworkInfo.VpcId = awsVpcInfo.Id
awsCBNetworkInfo.VpcName = awsVpcInfo.Name

awsSubnetInfo, _ := vNetworkHandler.GetVNetwork("")
awsSubnetInfo, _ := vNetworkHandler.GetVNetwork(irs.IID{})
spew.Dump(awsSubnetInfo)
awsCBNetworkInfo.SubnetId = awsSubnetInfo.Id
awsCBNetworkInfo.SubnetName = awsSubnetInfo.Name
//awsCBNetworkInfo.SubnetId = awsSubnetInfo.Id
//awsCBNetworkInfo.SubnetName = awsSubnetInfo.Name
awsCBNetworkInfo.SubnetId = awsSubnetInfo.IId.SystemId
awsCBNetworkInfo.SubnetName = awsSubnetInfo.IId.NameId

spew.Dump(awsCBNetworkInfo)

Expand Down Expand Up @@ -112,8 +114,9 @@ func (vNetworkHandler *AwsVNetworkHandler) GetMcloudBaristaDefaultVpcId() string
}
}

//@TODO : awsSubnetInfo.IId.SystemId를 리턴해야 하는지 NameId를 리턴해야 하는지 체크해야 함. -> 생성된 정보가 있는지만 체크 하므로 상관 없음.
func (vNetworkHandler *AwsVNetworkHandler) GetMcloudBaristaDefaultSubnetId() string {
awsSubnetInfo, err := vNetworkHandler.GetVNetwork("")
awsSubnetInfo, err := vNetworkHandler.GetVNetwork(irs.IID{})
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
Expand All @@ -127,8 +130,10 @@ func (vNetworkHandler *AwsVNetworkHandler) GetMcloudBaristaDefaultSubnetId() str
}

//기존 정보가 존재하면...
if awsSubnetInfo.Id != "" {
return awsSubnetInfo.Id
//if awsSubnetInfo.Id != "" {
// return awsSubnetInfo.Id
if awsSubnetInfo.IId.SystemId != "" {
return awsSubnetInfo.IId.SystemId
} else {
return ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ func (imageHandler *AwsImageHandler) ListImage() ([]*irs.ImageInfo, error) {
}

//Image 정보를 추출함
//@TODO : GuestOS 쳌크할 것
func ExtractImageDescribeInfo(image *ec2.Image) irs.ImageInfo {
//spew.Dump(image)
imageInfo := irs.ImageInfo{
Id: *image.ImageId,
Name: *image.Name,
IId: irs.IID{*image.Name, *image.ImageId},
//Id: *image.ImageId,
//Name: *image.Name,
Status: *image.State,
}

Expand Down Expand Up @@ -128,12 +130,14 @@ func ExtractImageDescribeInfo(image *ec2.Image) irs.ImageInfo {
return imageInfo
}

func (imageHandler *AwsImageHandler) GetImage(imageID string) (irs.ImageInfo, error) {
cblogger.Infof("imageID : [%s]", imageID)
//func (imageHandler *AwsImageHandler) GetImage(imageID string) (irs.ImageInfo, error) {
func (imageHandler *AwsImageHandler) GetImage(imageIID irs.IID) (irs.ImageInfo, error) {

cblogger.Infof("imageID : [%s]", imageIID.SystemId)

input := &ec2.DescribeImagesInput{
ImageIds: []*string{
aws.String(imageID),
aws.String(imageIID.SystemId),
},
}

Expand Down Expand Up @@ -165,6 +169,6 @@ func (imageHandler *AwsImageHandler) GetImage(imageID string) (irs.ImageInfo, er
}

//@TODO : 삭제 API 찾아야 함.
func (imageHandler *AwsImageHandler) DeleteImage(imageID string) (bool, error) {
func (imageHandler *AwsImageHandler) DeleteImage(imageIID irs.IID) (bool, error) {
return false, nil
}
Loading