add mcclient sample

This commit is contained in:
Qiu Jian
2020-09-29 14:24:23 +08:00
parent ccb174bd2f
commit a4bedc7e2e

View File

@@ -1,2 +1,43 @@
Yunion CMP API go library
==========================
Yunion OneCloud API go library
===============================
Sample code
:::golang
package main
import (
"context"
"fmt"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
)
func main() {
client := mcclient.NewClient("https://<onecloud_controller_ip>:30500/v3",
60,
true,
true,
"",
"")
token, err := client.Authenticate("sysadmin", "<password>", "Default", "system", "Default")
if err != nil {
panic(err)
}
s := client.NewSession(context.Background(),
"region0",
"",
"PublicURL",
token,
"")
result, err := modules.Servers.List(s, nil)
if err != nil {
panic(err)
}
fmt.Printf("%#v\n", result)
}