Skip to content

Commit

Permalink
Merge pull request #1270 from seokho-son/main
Browse files Browse the repository at this point in the history
Get access info in parallel
  • Loading branch information
seokho-son authored Nov 13, 2022
2 parents e7a1878 + 82c215e commit 3369bb5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
2 changes: 1 addition & 1 deletion conf/cloud_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ nlbsw:
commandNlbApplyConfig: "sudo ~/applyConfig.sh"
nlbMcisCommonSpec: "aws-ap-northeast-2-t2-small"
nlbMcisCommonImage: "ubuntu18.04"
nlbMcisSubGroupSize: "1"
nlbMcisSubGroupSize: "2"
61 changes: 43 additions & 18 deletions src/core/mcis/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ func GetMcisAccessInfo(nsId string, mcisId string, option string) (*McisAccessIn
return temp, err
}
// TODO: make in parallel

for _, groupId := range subGroupList {
subGroupAccessInfo := McisSubGroupAccessInfo{}
subGroupAccessInfo.SubGroupId = groupId
Expand All @@ -372,29 +373,46 @@ func GetMcisAccessInfo(nsId string, mcisId string, option string) (*McisAccessIn
common.CBLog.Error(err)
return temp, err
}
for _, vmId := range vmList {
vmInfo, err := GetVmCurrentPublicIp(nsId, mcisId, vmId)
if err != nil {
common.CBLog.Error(err)
return temp, err
}
vmAccessInfo := McisVmAccessInfo{}
vmAccessInfo.VmId = vmId
vmAccessInfo.PublicIP = vmInfo.PublicIp
vmAccessInfo.PrivateIP = vmInfo.PrivateIp
vmAccessInfo.SSHPort = vmInfo.SSHPort
var wg sync.WaitGroup
chanResults := make(chan McisVmAccessInfo)

_, verifiedUserName, privateKey := GetVmSshKey(nsId, mcisId, vmId)
for _, vmId := range vmList {
wg.Add(1)
go func(nsId string, mcisId string, vmId string, option string, chanResults chan McisVmAccessInfo) {
defer wg.Done()
vmInfo, err := GetVmCurrentPublicIp(nsId, mcisId, vmId)
vmAccessInfo := McisVmAccessInfo{}
if err != nil {
common.CBLog.Error(err)
vmAccessInfo.PublicIP = ""
vmAccessInfo.PrivateIP = ""
vmAccessInfo.SSHPort = ""
} else {
vmAccessInfo.PublicIP = vmInfo.PublicIp
vmAccessInfo.PrivateIP = vmInfo.PrivateIp
vmAccessInfo.SSHPort = vmInfo.SSHPort
}
vmAccessInfo.VmId = vmId

if strings.EqualFold(option, "showSshKey") {
vmAccessInfo.PrivateKey = privateKey
}
_, verifiedUserName, privateKey := GetVmSshKey(nsId, mcisId, vmId)

vmAccessInfo.VmUserAccount = verifiedUserName
//vmAccessInfo.VmUserPassword
if strings.EqualFold(option, "showSshKey") {
vmAccessInfo.PrivateKey = privateKey
}

subGroupAccessInfo.McisVmAccessInfo = append(subGroupAccessInfo.McisVmAccessInfo, vmAccessInfo)
vmAccessInfo.VmUserAccount = verifiedUserName
//vmAccessInfo.VmUserPassword
chanResults <- vmAccessInfo
}(nsId, mcisId, vmId, option, chanResults)
}
go func() {
wg.Wait()
close(chanResults)
}()
for result := range chanResults {
subGroupAccessInfo.McisVmAccessInfo = append(subGroupAccessInfo.McisVmAccessInfo, result)
}

output.McisSubGroupAccessInfo = append(output.McisSubGroupAccessInfo, subGroupAccessInfo)
}

Expand Down Expand Up @@ -1866,6 +1884,13 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) {
key := common.GenMcisKey(nsId, mcisId, "")
fmt.Println(key)

// delete associated MCIS Policy
err = DelMcisPolicy(nsId, mcisId)
if err == nil {
common.CBLog.Error(err)
deletedResources.IdList = append(deletedResources.IdList, "Policy: "+mcisId+deleteStatus)
}

vmList, err := ListVmId(nsId, mcisId)
if err != nil {
common.CBLog.Error(err)
Expand Down

0 comments on commit 3369bb5

Please sign in to comment.