-
Notifications
You must be signed in to change notification settings - Fork 51
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
Remove associated NLBs with MCIS del #1201
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1655,26 +1655,28 @@ func AttachDetachDataDisk(nsId string, mcisId string, vmId string, command strin | |
// [Delete MCIS and VM object] | ||
|
||
// DelMcis is func to delete MCIS object | ||
func DelMcis(nsId string, mcisId string, option string) error { | ||
func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { | ||
|
||
option = common.ToLower(option) | ||
deletedResources := common.IdList{} | ||
deleteStatus := " [Done]" | ||
|
||
err := common.CheckString(nsId) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return err | ||
return deletedResources, err | ||
} | ||
|
||
err = common.CheckString(mcisId) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return err | ||
return deletedResources, err | ||
} | ||
check, _ := CheckMcis(nsId, mcisId) | ||
|
||
if !check { | ||
err := fmt.Errorf("The mcis " + mcisId + " does not exist.") | ||
return err | ||
return deletedResources, err | ||
} | ||
|
||
fmt.Println("[Delete MCIS] " + mcisId) | ||
|
@@ -1685,7 +1687,7 @@ func DelMcis(nsId string, mcisId string, option string) error { | |
err := fmt.Errorf("MCIS " + mcisId + " status nil, Deletion is not allowed (use option=force for force deletion)") | ||
common.CBLog.Error(err) | ||
if option != "force" { | ||
return err | ||
return deletedResources, err | ||
} | ||
} | ||
|
||
|
@@ -1698,14 +1700,14 @@ func DelMcis(nsId string, mcisId string, option string) error { | |
_, err := HandleMcisAction(nsId, mcisId, ActionRefine, true) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return err | ||
return deletedResources, err | ||
} | ||
|
||
// ActionTerminate | ||
_, err = HandleMcisAction(nsId, mcisId, ActionTerminate, true) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return err | ||
return deletedResources, err | ||
} | ||
// for deletion, need to wait until termination is finished | ||
// Sleep for 5 seconds | ||
|
@@ -1721,7 +1723,7 @@ func DelMcis(nsId string, mcisId string, option string) error { | |
err := fmt.Errorf("MCIS " + mcisId + " is " + mcisStatus.Status + " and not " + StatusTerminated + "/" + StatusUndefined + "/" + StatusFailed + ", Deletion is not allowed (use option=force for force deletion)") | ||
common.CBLog.Error(err) | ||
if option != "force" { | ||
return err | ||
return deletedResources, err | ||
} | ||
} | ||
|
||
|
@@ -1731,7 +1733,7 @@ func DelMcis(nsId string, mcisId string, option string) error { | |
vmList, err := ListVmId(nsId, mcisId) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return err | ||
return deletedResources, err | ||
} | ||
|
||
// delete vms info | ||
|
@@ -1743,13 +1745,13 @@ func DelMcis(nsId string, mcisId string, option string) error { | |
vmInfo, err := GetVmObject(nsId, mcisId, v) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return err | ||
return deletedResources, err | ||
} | ||
|
||
err = common.CBStore.Delete(vmKey) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return err | ||
return deletedResources, err | ||
} | ||
|
||
_, err = mcir.UpdateAssociatedObjectList(nsId, common.StrImage, vmInfo.ImageId, common.StrDelete, vmKey) | ||
|
@@ -1768,32 +1770,47 @@ func DelMcis(nsId string, mcisId string, option string) error { | |
for _, v2 := range vmInfo.DataDiskIds { | ||
mcir.UpdateAssociatedObjectList(nsId, common.StrDataDisk, v2, common.StrDelete, vmKey) | ||
} | ||
deletedResources.IdList = append(deletedResources.IdList, "VM: "+v+deleteStatus) | ||
} | ||
|
||
// delete vm group info | ||
vmGroupList, err := ListVmGroupId(nsId, mcisId) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return err | ||
return deletedResources, err | ||
} | ||
for _, v := range vmGroupList { | ||
vmGroupKey := common.GenMcisVmGroupKey(nsId, mcisId, v) | ||
fmt.Println(vmGroupKey) | ||
err := common.CBStore.Delete(vmGroupKey) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return err | ||
return deletedResources, err | ||
} | ||
deletedResources.IdList = append(deletedResources.IdList, "vmGroup: "+v+deleteStatus) | ||
} | ||
|
||
// delete associated CSP NLBs | ||
forceFlag := "false" | ||
if option == "force" { | ||
forceFlag = "true" | ||
} | ||
output, err := DelAllNLB(nsId, mcisId, "", forceFlag) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return deletedResources, err | ||
} | ||
Comment on lines
+1798
to
1802
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분에서, 예를 들어 MCIS 내에 3개의 NLB가 있었는데 output: [
"NLB: nlb01 [Done]",
"NLB: nlb02 [Done]",
"NLB: nlb03 <Some error>"
] err: nil 이후 L1803부터 다시 진행되어 저는 이것(↑)도 괜찮은 것 같습니다.. ㅎㅎ |
||
deletedResources.IdList = append(deletedResources.IdList, output.IdList...) | ||
|
||
// delete mcis info | ||
err = common.CBStore.Delete(key) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return err | ||
return deletedResources, err | ||
} | ||
deletedResources.IdList = append(deletedResources.IdList, "MCIS: "+mcisId+deleteStatus) | ||
|
||
return nil | ||
return deletedResources, nil | ||
} | ||
|
||
// DelMcisVm is func to delete VM object | ||
|
@@ -1890,7 +1907,7 @@ func CoreDelAllMcis(nsId string, option string) (string, error) { | |
} | ||
|
||
for _, v := range mcisList { | ||
err := DelMcis(nsId, v, option) | ||
_, err := DelMcis(nsId, v, option) | ||
if err != nil { | ||
common.CBLog.Error(err) | ||
return "", fmt.Errorf("Failed to delete All MCISs") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'vmList 의 vm들을 하나씩 지우는 for 문' 을 돌다가
특정 vm 삭제에 실패하면
return deletedResources, err
하는 것이 아니라deletedResources.IdList = append(deletedResources.IdList, "VM: "+v+" [Failed]")
하는 것이 어떨까 싶기도 했었는데(option=force 경우가 아닌 일반적인 경우에는)
DelMcis 함수는 Running VM이 있는 경우에는 삭제를 수행하지 않고
Terminated / Failed 등의 VM이 있는 경우에만 삭제를 수행하며
이 삭제 동작이 내부적으로 수행하는 것은
CBStore.Delete
인데이전 코드들을 고려하면 이 동작이 실패할 확률은 거의 없어서
현재 로직도 괜찮을 것 같습니다. 😊