Skip to content

Commit

Permalink
gcp convertDiskInfo modied
Browse files Browse the repository at this point in the history
  • Loading branch information
dogfootman committed Apr 12, 2024
1 parent c252409 commit 9bba7a6
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,9 @@ func (DiskHandler *GCPDiskHandler) AttachDisk(diskIID irs.IID, ownerVM irs.IID)
return irs.DiskInfo{}, err
}

diskZone := ""
index := strings.Index(attachDiskInfo.Zone, "zones/") // "zones/"의 인덱스를 찾음
if index != -1 {
diskZone = attachDiskInfo.Zone[index+len("zones/"):] // "zones/" 다음의 문자열을 추출
}
//https://www.googleapis.com/compute/v1/projects/csta-349809/zones/asia-northeast1-a
if vmInfo.Region.Zone != diskZone{
cblogger.Error("The disk and the VM must be in the same zone." + vmInfo.Region.Zone, diskZone)

if vmInfo.Region.Zone != attachDiskInfo.Zone{
cblogger.Error("The disk and the VM must be in the same zone." + vmInfo.Region.Zone, attachDiskInfo.Zone)
return irs.DiskInfo{}, errors.New(string("The disk and the VM must be in the same zone."))
}

Expand Down Expand Up @@ -509,7 +504,14 @@ func convertDiskInfo(diskResp *compute.Disk) (irs.DiskInfo, error) {
diskInfo.IId = irs.IID{NameId: diskResp.Name, SystemId: diskResp.Name}
diskInfo.DiskSize = strconv.FormatInt(diskResp.SizeGb, 10)
diskInfo.CreatedTime, _ = time.Parse(time.RFC3339, diskResp.CreationTimestamp)
diskInfo.Zone = diskResp.Zone
//diskInfo.Zone = diskResp.Zone // diskResp의 zone은 url 형태이므로 zone 만 추출
index := strings.Index(diskResp.Zone, "zones/") // "zones/"의 인덱스를 찾음
if index != -1 {
diskInfo.Zone = diskResp.Zone[index+len("zones/"):] // "zones/" 다음의 문자열을 추출
}else{
diskInfo.Zone = diskResp.Zone
}


// Users : the users of the disk (attached instances)
if diskResp.Users != nil {
Expand Down

0 comments on commit 9bba7a6

Please sign in to comment.