Skip to content

Commit

Permalink
Merge pull request #5 from innodreamer/main
Browse files Browse the repository at this point in the history
Update Example usage of SDK go
  • Loading branch information
innodreamer authored Oct 14, 2021
2 parents 38252ab + b022b3c commit be6bc5f
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
cs := ktcloudsdk.KtCloudClient{}.New(apiUrl, apiKey, secretKey)

vmId := "19d2acfb-e281-4a13-8d62-e04ab501271d"
zoneId := "XXXXXX"
zoneId := "XXXXXXXXXXXXXXXXXXXX"
vmId := "XXXXXXXXXXXXXXXXXXXX"

vmListReqInfo := ktsdk.ListVMReqInfo{
ZoneId: zoneId,
Expand All @@ -47,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)
}

Expand All @@ -56,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)
}

}
Expand Down

0 comments on commit be6bc5f

Please sign in to comment.