mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #14678 from zexi/update-mcclient-readme
fix(mcclient): update readme
This commit is contained in:
+49
-32
@@ -2,42 +2,59 @@ Yunion OneCloud API go library
|
||||
===============================
|
||||
|
||||
|
||||
Login to first controlplane node of your cluster and execute `ocadm cluster rcadmin` to get auth info.
|
||||
|
||||
For example:
|
||||
|
||||
```bash
|
||||
$ ocadm cluster rcadmin
|
||||
export OS_AUTH_URL=https://10.127.100.2:30500/v3
|
||||
export OS_USERNAME=sysadmin
|
||||
export OS_PASSWORD=7AQMP9H2umQvbxxx
|
||||
export OS_PROJECT_DOMAIN=default
|
||||
export OS_PROJECT_NAME=system
|
||||
export YUNION_INSECURE=true
|
||||
export OS_REGION_NAME=region0
|
||||
export OS_ENDPOINT_TYPE=publicURL
|
||||
```
|
||||
|
||||
Sample code
|
||||
|
||||
:::golang
|
||||
package main
|
||||
```golang
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
)
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
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)
|
||||
}
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := mcclient.NewClient("https://10.127.100.2:30500/v3",
|
||||
60,
|
||||
true,
|
||||
true,
|
||||
"",
|
||||
"")
|
||||
token, err := client.Authenticate("sysadmin", "7AQMP9H2umQvbxxx", "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("%s", jsonutils.Marshal(result).PrettyString())
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user