Skip to content

Commit

Permalink
Merge pull request #1306 from MZC-CSC/master
Browse files Browse the repository at this point in the history
[Tencent] Include tag information when get Resources (disk, keypair, myImage, vm)
  • Loading branch information
powerkimhub authored Aug 27, 2024
2 parents b864bc3 + d580128 commit 7419878
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ func convertDiskInfo(diskResp *cbs.Disk) (irs.DiskInfo, error) {
diskInfo.Status = convertTenStatusToDiskStatus(diskResp)
diskInfo.Zone = *diskResp.Placement.Zone

if diskResp.Tags != nil {
var tagList []irs.KeyValue
for _, tag := range diskResp.Tags {
tagList = append(tagList, irs.KeyValue{
Key: *tag.Key,
Value: *tag.Value,
})
diskInfo.TagList = tagList
}
}

return diskInfo, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ func ExtractKeyPairDescribeInfo(keyPair *cvm.KeyPair) (irs.KeyPairInfo, error) {
IId: irs.IID{NameId: *keyPair.KeyName, SystemId: *keyPair.KeyId},
//PublicKey: *keyPair.PublicKey,
}
cblogger.Info(" keyPair.Tags", keyPair.Tags)
if keyPair.Tags != nil {
var tagList []irs.KeyValue
for _, tag := range keyPair.Tags {
tagList = append(tagList, irs.KeyValue{
Key: *tag.Key,
Value: *tag.Value,
})
}
keyPairInfo.TagList = tagList
}

//PrivateKey는 최초 생성시에만 존재하며 조회 시에는 PrivateKey는 Nil임.
// if !reflect.ValueOf(keyPair.PrivateKey).IsNil() {
Expand Down Expand Up @@ -174,7 +185,7 @@ func (keyPairHandler *TencentKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPai
if len(tags) > 0 {
request.TagSpecification = []*cvm.TagSpecification{
{
ResourceType: common.StringPtr("instance"),
ResourceType: common.StringPtr(string(irs.KEY)),
Tags: tags,
},
}
Expand All @@ -195,18 +206,26 @@ func (keyPairHandler *TencentKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPai
cblogger.Debug(response.ToJsonString())
callogger.Info(call.String(callLogInfo))

cblogger.Infof("Created [%s]key pair", *response.Response.KeyPair.KeyName)
cblogger.Infof("Created key pair", *response.Response.KeyPair)
//cblogger.Debug(result)
keyPairInfo := irs.KeyPairInfo{
//Name: *result.KeyName,
IId: irs.IID{NameId: keyPairReqInfo.IId.NameId, SystemId: *response.Response.KeyPair.KeyId},
PublicKey: *response.Response.KeyPair.PublicKey,
PrivateKey: *response.Response.KeyPair.PrivateKey,
KeyValueList: []irs.KeyValue{
{Key: "KeyId", Value: *response.Response.KeyPair.KeyId},
},
keyPairInfo, errKeyPair := ExtractKeyPairDescribeInfo(response.Response.KeyPair)
if errKeyPair != nil {
cblogger.Error(errKeyPair.Error())
return irs.KeyPairInfo{}, errKeyPair
}

// keyPairInfo := irs.KeyPairInfo{
// //Name: *result.KeyName,
// IId: irs.IID{NameId: keyPairReqInfo.IId.NameId, SystemId: *response.Response.KeyPair.KeyId},
// PublicKey: *response.Response.KeyPair.PublicKey,
// PrivateKey: *response.Response.KeyPair.PrivateKey,
// KeyValueList: []irs.KeyValue{
// {Key: "KeyId", Value: *response.Response.KeyPair.KeyId},
// },
// }

// //

//cblogger.Debug(keyPairInfo)

/* 2021-10-27 이슈#480에 의해 Local Key 로직 제거
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ func (myImageHandler *TencentMyImageHandler) SnapshotVM(snapshotReqInfo irs.MyIm
*
TODO : CommonHandlerm에 DescribeImages, DescribeImageById, DescribeImageStatus 추가할 것.
*/

// deprecated : web 위에서 호출할 때 spider에 저장된 MyImage IID 가지고 getMyImage()를 순환하여 호출하고 있음
func (myImageHandler *TencentMyImageHandler) ListMyImage() ([]*irs.MyImageInfo, error) {
hiscallInfo := GetCallLogScheme(myImageHandler.Region, call.MYIMAGE, "MyImage", "ListMyImage()")
start := call.Start()

imageTypes := []string{}
imageTypes := []string{"PRIVATE_IMAGE"}
myImageSet, err := DescribeImages(myImageHandler.Client, nil, imageTypes)
hiscallInfo.ElapsedTime = call.Elapsed(start)
if err != nil {
Expand Down Expand Up @@ -180,9 +182,9 @@ func (myImageHandler *TencentMyImageHandler) GetMyImage(myImageIID irs.IID) (irs
myImageInfo, myImageInfoErr := convertImageSetToMyImageInfo(&targetImage)
if myImageInfoErr != nil {
cblogger.Error(myImageInfoErr)
return irs.MyImageInfo{}, myImageInfoErr
}

return myImageInfo, nil
}
return myImageInfo, nil
}

Expand Down Expand Up @@ -262,9 +264,29 @@ func convertImageSetToMyImageInfo(tencentImage *cvm.Image) (irs.MyImageInfo, err
returnMyImageInfo := irs.MyImageInfo{}

returnMyImageInfo.IId = irs.IID{NameId: *tencentImage.ImageName, SystemId: *tencentImage.ImageId}
returnMyImageInfo.SourceVM = irs.IID{SystemId: *tencentImage.Tags[0].Value}
returnMyImageInfo.CreatedTime, _ = time.Parse(time.RFC3339, *tencentImage.CreatedTime)
returnMyImageInfo.Status = convertTenStatusToImageStatus(*tencentImage.ImageState)

if len(tencentImage.Tags) == 0 {
return returnMyImageInfo, errors.New("No tag in " + *tencentImage.ImageName)
}

if tencentImage.Tags != nil {
var tagList []irs.KeyValue
for _, tag := range tencentImage.Tags {
//
if IMAGE_TAG_SOURCE_VM == *tag.Key {
returnMyImageInfo.SourceVM = irs.IID{SystemId: *tencentImage.Tags[0].Value} // MyImage의 경우 Vm의 정보가 myimage의 태그로 들어간다
} else {
tagList = append(tagList, irs.KeyValue{
Key: *tag.Key,
Value: *tag.Value,
})
}
}
returnMyImageInfo.TagList = tagList
}

return returnMyImageInfo, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,17 @@ func (securityHandler *TencentSecurityHandler) GetSecurity(securityIID irs.IID)
securityInfo.VpcIID = irs.IID{NameId: "", SystemId: ""}
securityInfo.IId = irs.IID{NameId: *response.Response.SecurityGroupSet[0].SecurityGroupName, SystemId: *response.Response.SecurityGroupSet[0].SecurityGroupId}

if response.Response.SecurityGroupSet[0].TagSet != nil {
var tagList []irs.KeyValue
for _, tag := range response.Response.SecurityGroupSet[0].TagSet {
tagList = append(tagList, irs.KeyValue{
Key: *tag.Key,
Value: *tag.Value,
})
}
securityInfo.TagList = tagList
}

securityInfo.SecurityRules, err = securityHandler.GetSecurityRuleInfo(securityIID)
if err != nil {
cblogger.Error(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,17 @@ func (vmHandler *TencentVMHandler) ExtractDescribeInstances(curVm *cvm.Instance)
vmInfo.PrivateIP = *curVm.PrivateIpAddresses[0]
}

if !reflect.ValueOf(curVm.Tags).IsNil() {
var tagList []irs.KeyValue
for _, tag := range curVm.Tags {
tagList = append(tagList, irs.KeyValue{
Key: *tag.Key,
Value: *tag.Value,
})
}
vmInfo.TagList = tagList
}

keyValueList := []irs.KeyValue{
{Key: "InstanceState", Value: *curVm.InstanceState},
{Key: "OsName", Value: *curVm.OsName},
Expand Down

0 comments on commit 7419878

Please sign in to comment.