From dfcfa95535ef3ac48e78d797a7f7e46888200b02 Mon Sep 17 00:00:00 2001 From: Sean Oh Date: Thu, 14 Oct 2021 17:26:33 +0900 Subject: [PATCH 1/2] Update Example usage of SDK go --- README.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 01a3c05..3dd8098 100644 --- a/README.md +++ b/README.md @@ -18,27 +18,29 @@ import ( ) func main() { - - apiurl := os.Getenv("KTCLOUD_API_URL") - if len(apiurl) == 0 { - fmt.Println("Needed environment variable KTCLOUD_API_URL not found, exiting") + + apiKey := os.Getenv("KTCLOUD_API_KEY") + if len(apiKey) == 0 { + fmt.Println("Failed to Find KTCLOUD_API_KEY, exiting") os.Exit(1) } - apikey := os.Getenv("KTCLOUD_API_KEY") - if len(apikey) == 0 { - fmt.Println("Needed environment variable KTCLOUD_API_KEY not found, exiting") + secretKey := os.Getenv("KTCLOUD_SECRET_KEY") + if len(secretKey) == 0 { + fmt.Println("Failed to Find KTCLOUD_SECRET_KEY, exiting") os.Exit(1) } - secretkey := os.Getenv("KTCLOUD_SECRET_KEY") - if len(secret) == 0 { - fmt.Println("Needed environment variable KTCLOUD_SECRET_KEY not found, exiting") - os.Exit(1) + + // When Zone is "KOR-Seoul M2" => API v2, else API v1 + if zoneID == "d7d0177e-6cda-404a-a46f-a5b356d2874e" { + apiUrl := "https://api.ucloudbiz.olleh.com/server/v2/client/api" + } else { + apiUrl := "https://api.ucloudbiz.olleh.com/server/v1/client/api" } cs := ktcloudsdk.KtCloudClient{}.New(apiurl, apikey, secretkey) - vmId := "19d2acfb-e281-4a13-8d62-e04ab501271d" - zoneId := "XXXXXX" + zoneId := "XXXXXXXXXXXXXXXXXXXX" + vmId := "XXXXXXXXXXXXXXXXXXXX" vmListReqInfo := ktsdk.ListVMReqInfo{ ZoneId: zoneId, From b022b3cf134d66f4be09c2fe44ba4a3d3c8a8313 Mon Sep 17 00:00:00 2001 From: Sean Oh Date: Thu, 14 Oct 2021 17:31:38 +0900 Subject: [PATCH 2/2] Update Example usage of SDK go --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3dd8098..89b8488 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ func main() { apiUrl := "https://api.ucloudbiz.olleh.com/server/v1/client/api" } - cs := ktcloudsdk.KtCloudClient{}.New(apiurl, apikey, secretkey) + cs := ktcloudsdk.KtCloudClient{}.New(apiUrl, apiKey, secretKey) zoneId := "XXXXXXXXXXXXXXXXXXXX" vmId := "XXXXXXXXXXXXXXXXXXXX" @@ -49,7 +49,7 @@ func main() { response, err := cs.ListVirtualMachines(vmListReqInfo) if err != nil { - fmt.Errorf("Error listing virtual machine: %s", err) + fmt.Errorf("Failed to Find the List of Virtual Machine: %s", err) os.Exit(1) } @@ -58,7 +58,7 @@ func main() { state := response.Listvirtualmachinesresponse.Virtualmachine[0].State fmt.Printf("%s has IP : %s and state : %s\n", vmid, ip, state) } else { - fmt.Printf("No VM with UUID: %s found\n", vmid) + fmt.Printf("Failed to Find the VM with the ID: %s found\n", vmid) } }