Skip to content

Commit

Permalink
Merge pull request #1225 from innodreamer/master
Browse files Browse the repository at this point in the history
[Domestic Cloud Drivers] Remove fmt.Print and spew.Dump statements
  • Loading branch information
powerkimhub authored Jul 4, 2024
2 parents 3742942 + 48136b3 commit 626a228
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,7 @@ import (
"fmt"
"sync"
"time"

// "reflect"
// "crypto/aes"
// "crypto/cipher"
// "crypto/rand"
// "io"
"os"
"os/exec"

// "errors"
// "encoding/hex"
// "encoding/base64"
// "hash"
// "hash/fnv"
// "github.com/davecgh/go-spew/spew"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -113,33 +100,6 @@ func logAndReturnError(callLogInfo call.CLOUDLOGSCHEMA, givenErrString string, v
return newErr
}

func RunCommand(cmdName string, cmdArgs []string) (string, error) {
/*
Ref)
var (
cmdOut []byte
cmdErr error
)
*/

cblogger.Infof("cmdName : %s", cmdName)
cblogger.Infof("cmdArgs : %s", cmdArgs)

//if cmdOut, cmdErr = exec.Command(cmdName, cmdArgs...).Output(); cmdErr != nil {
if cmdOut, cmdErr := exec.Command(cmdName, cmdArgs...).CombinedOutput(); cmdErr != nil {
fmt.Fprintln(os.Stderr, "There was an error running command: ", cmdErr)
//panic("Can't exec the command: " + cmdErr1.Error())
fmt.Println(fmt.Sprint(cmdErr) + ": " + string(cmdOut))
os.Exit(1)

return string(cmdOut), cmdErr
} else {
fmt.Println("cmdOut : ", string(cmdOut))

return string(cmdOut), nil
}
}

func CheckFolder(folderPath string) error {
// Check if the KeyPair Folder Exists
if _, err := os.Stat(folderPath); os.IsNotExist(err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"fmt"
"errors"
"strings"
"github.com/davecgh/go-spew/spew"
// "github.com/davecgh/go-spew/spew"

ktsdk "github.com/cloud-barista/ktcloud-sdk-go"

Expand Down Expand Up @@ -144,8 +144,9 @@ func (keyPairHandler *KtCloudKeyPairHandler) GetKey(keyIID irs.IID) (irs.KeyPair
cblogger.Infof("keyName : [%s]", keyIID.NameId)
result, err := keyPairHandler.Client.ListSSHKeyPairs(keyIID.NameId)
if err != nil {
cblogger.Errorf("Failed to Get the KeyPair with the keyName : ", err)
return irs.KeyPairInfo{}, err
newErr := fmt.Errorf("Failed to Get the KeyPair with the keyName : ", err)
cblogger.Error(newErr.Error())
return irs.KeyPairInfo{}, newErr
}
// spew.Dump(result)

Expand Down Expand Up @@ -180,16 +181,16 @@ func (keyPairHandler *KtCloudKeyPairHandler) DeleteKey(keyIID irs.IID) (bool, er
//It is necessary to check in advance because it succeeds unconditionally without Keypair.
_, keyError := keyPairHandler.GetKey(keyIID)
if keyError != nil {
cblogger.Errorf("Failed to Get the KeyPair : [%s]", keyIID.SystemId)
cblogger.Error(keyError)
return false, keyError
newErr := fmt.Errorf("Failed to Get the KeyPair : [%s], [%v]", keyIID.SystemId, keyError)
cblogger.Error(newErr.Error())
return false, newErr
}

result, err := keyPairHandler.Client.DeleteSSHKeyPair(keyIID.NameId)
if err != nil {
cblogger.Errorf("Failed to Delete the KeyPair : %s, %v", keyIID.NameId, err)
spew.Dump(err)
return false, err
newErr := fmt.Errorf("Failed to Delete the KeyPair : %s, %v", keyIID.NameId, err)
cblogger.Error(newErr.Error())
return false, newErr
}
cblogger.Infof("Deletion result on KT Cloud : %s", result.Deletesshkeypairresponse.Success)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import (
"fmt"
"strconv"
// "encoding/base64"
// "log"
"io"
"strings"
"time"
"github.com/davecgh/go-spew/spew"
// "github.com/davecgh/go-spew/spew"

call "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/call-log"
cblog "github.com/cloud-barista/cb-log"
Expand Down Expand Up @@ -308,15 +307,15 @@ func (vmHandler *KtCloudVMHandler) StartVM(vmReqInfo irs.VMReqInfo) (irs.VMInfo,
LoggingInfo(callLogInfo, callLogStart)
//spew.Dump(newVM)

jobResult, err := vmHandler.Client.QueryAsyncJobResult(newVM.Deployvirtualmachineresponse.JobId)
if err != nil {
cblogger.Errorf("Failed to Get the Job Result: [%v]", err)
return irs.VMInfo{}, err
// jobResult, queryErr := vmHandler.Client.QueryAsyncJobResult(newVM.Deployvirtualmachineresponse.JobId)
_, queryErr := vmHandler.Client.QueryAsyncJobResult(newVM.Deployvirtualmachineresponse.JobId)
if queryErr != nil {
newErr := fmt.Errorf("Failed to Get the Job Result: [%v]", queryErr)
cblogger.Error(newErr.Error())
return irs.VMInfo{}, newErr
}
cblogger.Info("\n### QueryAsyncJobResultResponse : ")
// spew.Dump(jobResult.Queryasyncjobresultresponse.JobResult.Virtualmachine[0])
spew.Dump(jobResult.Queryasyncjobresultresponse.JobResult)
// spew.Dump(jobResult)
// cblogger.Info("\n### QueryAsyncJobResultResponse : ")
// spew.Dump(jobResult.Queryasyncjobresultresponse.JobResult)

if strings.EqualFold(newVM.Deployvirtualmachineresponse.ID, "") {
newErr := fmt.Errorf("Failed to Find the VM Instance ID!!")
Expand Down Expand Up @@ -721,8 +720,9 @@ func (vmHandler *KtCloudVMHandler) GetVM(vmIID irs.IID) (irs.VMInfo, error) {

vmInfo, err := vmHandler.mappingVMInfo(&result.Listvirtualmachinesresponse.Virtualmachine[0])
if err != nil {
cblogger.Errorf("Failed to Map the VM info: [%v]", err)
return irs.VMInfo{}, err
newErr := fmt.Errorf("Failed to Map the VM info: [%v]", err)
cblogger.Error(newErr.Error())
return irs.VMInfo{}, newErr
}
return vmInfo, nil
}
Expand Down Expand Up @@ -772,12 +772,14 @@ func (vmHandler *KtCloudVMHandler) SuspendVM(vmIID irs.IID) (irs.VMStatus, error
return "", err
}

jobResult, err := vmHandler.Client.QueryAsyncJobResult(result.Stopvirtualmachineresponse.JobId)
if err != nil {
cblogger.Errorf("Failed to Get Job Result: [%v]", err)
return "", err
}
spew.Dump(jobResult.Queryasyncjobresultresponse.JobResult)
// jobResult, queryErr := vmHandler.Client.QueryAsyncJobResult(result.Stopvirtualmachineresponse.JobId)
_, queryErr := vmHandler.Client.QueryAsyncJobResult(result.Stopvirtualmachineresponse.JobId)
if queryErr != nil {
newErr := fmt.Errorf("Failed to Get Job Result: [%v]", queryErr)
cblogger.Error(newErr.Error())
return "", newErr
}
// spew.Dump(jobResult.Queryasyncjobresultresponse.JobResult)

//===================================
// 15-second wait for Suspending
Expand Down Expand Up @@ -858,12 +860,14 @@ func (vmHandler *KtCloudVMHandler) ResumeVM(vmIID irs.IID) (irs.VMStatus, error)
return "", err
}

jobResult, err := vmHandler.Client.QueryAsyncJobResult(result.Startvirtualmachineresponse.JobId)
if err != nil {
cblogger.Errorf("Failed to Get the Job Result : [%v]", err)
return "", err
}
spew.Dump(jobResult.Queryasyncjobresultresponse.JobResult)
// jobResult, queryErr := vmHandler.Client.QueryAsyncJobResult(result.Startvirtualmachineresponse.JobId)
_, queryErr := vmHandler.Client.QueryAsyncJobResult(result.Startvirtualmachineresponse.JobId)
if queryErr != nil {
newErr := fmt.Errorf("Failed to Get Job Result: [%v]", queryErr)
cblogger.Error(newErr.Error())
return "", newErr
}
// spew.Dump(jobResult.Queryasyncjobresultresponse.JobResult)

//===================================
// 60-second wait for Suspending
Expand Down Expand Up @@ -937,12 +941,14 @@ func (vmHandler *KtCloudVMHandler) RebootVM(vmIID irs.IID) (irs.VMStatus, error)
return "", err
}

jobResult, err := vmHandler.Client.QueryAsyncJobResult(result.Rebootvirtualmachineresponse.JobId)
if err != nil {
cblogger.Errorf("Failed to Get the Job Result : [%v]", err)
return "", err
}
spew.Dump(jobResult.Queryasyncjobresultresponse.JobResult)
// jobResult, queryErr := vmHandler.Client.QueryAsyncJobResult(result.Rebootvirtualmachineresponse.JobId)
_, queryErr := vmHandler.Client.QueryAsyncJobResult(result.Rebootvirtualmachineresponse.JobId)
if queryErr != nil {
newErr := fmt.Errorf("Failed to Get Job Result: [%v]", queryErr)
cblogger.Error(newErr.Error())
return "", newErr
}
// spew.Dump(jobResult.Queryasyncjobresultresponse.JobResult)

// ===================================
// 15-second wait for Rebooting
Expand Down Expand Up @@ -1709,7 +1715,8 @@ func (vmHandler *KtCloudVMHandler) associateIpAddress() (string, string, error)
if len(resp.Listpublicipaddressesresponse.PublicIpAddress) > 0 {
publicIp = resp.Listpublicipaddressesresponse.PublicIpAddress[0].IpAddress
ipState := resp.Listpublicipaddressesresponse.PublicIpAddress[0].State
fmt.Printf("New Public IP : %s, IP State : %s\n", publicIp, ipState)

cblogger.Infof("New Public IP : %s, IP State : %s\n", publicIp, ipState)
} else {
return "", "", errors.New("Failed to Find the Public IP!!\n")
}
Expand Down Expand Up @@ -1817,15 +1824,17 @@ func (vmHandler *KtCloudVMHandler) createPortForwardingFirewallRules(sgSystemIDs
pfRulesReqInfo := ktsdk.ListPortForwardingRulesReqInfo {
ID: pfRuleResponse.Createportforwardingruleresponse.ID,
}
pfRulesResult, err := vmHandler.Client.ListPortForwardingRules(pfRulesReqInfo)
if err != nil {
cblogger.Errorf("Failed to Get PortForwarding Rule List : [%v]", err)
return false, err
// pfRulesResult, listErr := vmHandler.Client.ListPortForwardingRules(pfRulesReqInfo)
_, listErr := vmHandler.Client.ListPortForwardingRules(pfRulesReqInfo)
if listErr != nil {
newErr := fmt.Errorf("Failed to Get PortForwarding Rule List : [%v]", listErr)
cblogger.Error(newErr.Error())
return false, newErr
} else {
cblogger.Info("# Succeeded in Getting PortForwarding Rule List!!")
}
cblogger.Info("### PortForwarding Rule List : ")
spew.Dump(pfRulesResult.Listportforwardingrulesresponse.PortForwardingRule)
// cblogger.Info("### PortForwarding Rule List : ")
// spew.Dump(pfRulesResult.Listportforwardingrulesresponse.PortForwardingRule)
}

// ### KT Cloud 'Firewall Rules' Setting for 'ICMP' protocol
Expand Down Expand Up @@ -1855,14 +1864,16 @@ func (vmHandler *KtCloudVMHandler) createPortForwardingFirewallRules(sgSystemIDs
firewallListReqInfo := ktsdk.ListFirewallRulesReqInfo {
ID: firewallRuleResponse.Createfirewallruleresponse.ID,
}
firewallRulesResult, err := vmHandler.Client.ListFirewallRules(firewallListReqInfo)
if err != nil {
cblogger.Errorf("Failed to Get List of Firewall Rules : [%v]", err)
return false, err
// firewallRulesResult, listError := vmHandler.Client.ListFirewallRules(firewallListReqInfo)
_, listError := vmHandler.Client.ListFirewallRules(firewallListReqInfo)
if listError != nil {
newErr := fmt.Errorf("Failed to Get Firewall Rule List : [%v]", listError)
cblogger.Error(newErr.Error())
return false, newErr
} else {
cblogger.Info("# Succeeded in Getting List of Firewall Rules!!")
}
spew.Dump(firewallRulesResult.Listfirewallrulesresponse.FirewallRule)
// spew.Dump(firewallRulesResult.Listfirewallrulesresponse.FirewallRule)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
ktsdk "github.com/cloud-barista/ktcloud-sdk-go"

"errors"
"fmt"
"strings"
"strconv"
// "github.com/davecgh/go-spew/spew"
Expand Down Expand Up @@ -195,7 +194,7 @@ func mappingVMSpecInfo(ZoneId string, ImageId string, ktServerProductType ktsdk.
// Split 함수로 문자열을 " "(공백) 기준으로 분리
specSlice := strings.Split(ktVMSpecString, " ")
for _, str := range specSlice {
fmt.Println(str)
cblogger.Infof("Splited string : [%s]", str)
}

// KT Cloud에서 core 수를 '4vcore' or '16vCore'와 같은 형태로 제공함.(String 처리시 자리수, 대수문자 주의 필요)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package resources

import (
"os"
"os/exec"
"fmt"
"strings"
"sync"
Expand Down Expand Up @@ -181,32 +180,6 @@ func reverse(s string) (result string) {
return
}

func runCommand(cmdName string, cmdArgs []string) (string, error) {
/*
Ref)
var (
cmdOut []byte
cmdErr error
)
*/
cblogger.Infof("cmdName : %s", cmdName)
cblogger.Infof("cmdArgs : %s", cmdArgs)

//if cmdOut, cmdErr = exec.Command(cmdName, cmdArgs...).Output(); cmdErr != nil {
if cmdOut, cmdErr := exec.Command(cmdName, cmdArgs...).CombinedOutput(); cmdErr != nil {
fmt.Fprintln(os.Stderr, "There was an Error running command : ", cmdErr)
//panic("Can't exec the command: " + cmdErr1.Error())
fmt.Println(fmt.Sprint(cmdErr) + ": " + string(cmdOut))
os.Exit(1)

return string(cmdOut), cmdErr
} else {
fmt.Println("cmdOut : ", string(cmdOut))

return string(cmdOut), nil
}
}

// Convert Cloud Object to JSON String type
func convertJsonString(v interface{}) (string, error) {
jsonBytes, err := json.Marshal(v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func (diskHandler *KTVpcDiskHandler) mappingDiskInfo(volume volumes2.Volume) (ir
// fmt.Printf("Image Name: %s\n", imageName)
keyValue = irs.KeyValue{Key: "ImageName", Value: imageName}
} else {
fmt.Println("Image Name not found in volume info.")
cblogger.Info("Image Name not found in volume info.")
}
keyValueList = append(keyValueList, keyValue)
diskInfo.KeyValueList = keyValueList
Expand Down Expand Up @@ -613,13 +613,13 @@ func (diskHandler *KTVpcDiskHandler) getImageNameandIDWithDiskID(diskId string)
// Extract the image name
imageName, ok := diskResult.VolumeImageMetadata["image_name"]
if !ok {
fmt.Println("Image Name not found")
cblogger.Info("Image Name not found")
}

// Extract the image id
imageId, ok := diskResult.VolumeImageMetadata["image_id"]
if !ok {
fmt.Println("Image ID not found")
cblogger.Info("Image ID not found")
}

if !strings.EqualFold(imageName, "") && !strings.EqualFold(imageId, "") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"
"time"
_ "time/tzdata" // To prevent 'unknown time zone Asia/Seoul' error
"github.com/davecgh/go-spew/spew"
// "github.com/davecgh/go-spew/spew"

ktvpcsdk "github.com/cloud-barista/ktcloudvpc-sdk-go"
// volumes2 "github.com/cloud-barista/ktcloudvpc-sdk-go/openstack/blockstorage/v2/volumes"
Expand Down Expand Up @@ -68,9 +68,9 @@ func (myImageHandler *KTVpcMyImageHandler) SnapshotVM(snapshotReqInfo irs.MyImag
loggingInfo(callLogInfo, start)
cblogger.Infof("\n\n# snapShotImageId : [%s]\n", volumeImage.ImageID)

cblogger.Info("\n\n### volumeImage : ")
spew.Dump(volumeImage)
cblogger.Info("\n")
// cblogger.Info("\n\n### volumeImage : ")
// spew.Dump(volumeImage)
// cblogger.Info("\n")

// To Wait for Creating a Snapshot Image
newImageIID := irs.IID{SystemId: volumeImage.ImageID}
Expand Down Expand Up @@ -138,9 +138,9 @@ func (myImageHandler *KTVpcMyImageHandler) ListMyImage() ([]*irs.MyImageInfo, er
}
loggingInfo(callLogInfo, start)

cblogger.Info("\n\n### ktImageList : ")
spew.Dump(ktImageList)
cblogger.Info("# ktImage count : ", len(ktImageList))
// cblogger.Info("\n\n### ktImageList : ")
// spew.Dump(ktImageList)
// cblogger.Info("# ktImage count : ", len(ktImageList))

// Note) Public image : ktImage.Visibility == "public", MyImage : ktImage.Visibility == "shared"
var imageInfoList []*irs.MyImageInfo
Expand Down
Loading

0 comments on commit 626a228

Please sign in to comment.