Files
cloudpods/pkg/mcclient
wanyaoqi 1570b17eb3 fix: gen copyright
Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
2022-08-28 13:52:25 +08:00
..
2022-05-06 23:22:50 +08:00
2022-08-28 13:52:25 +08:00
2022-08-28 13:52:25 +08:00
2019-10-28 06:22:17 +00:00
2020-07-21 16:13:18 +08:00
2019-03-29 14:47:48 +08:00
2020-07-21 16:13:18 +08:00
2018-08-01 14:13:23 +08:00
2020-07-21 16:13:18 +08:00
2020-07-21 16:13:18 +08:00
2022-07-19 17:51:43 +08:00
2020-07-21 16:13:18 +08:00
2021-12-02 07:43:10 +08:00
2021-12-02 07:43:10 +08:00
2021-12-02 07:43:10 +08:00
2021-12-02 07:43:10 +08:00

Yunion OneCloud API go library

Login to first controlplane node of your cluster and execute ocadm cluster rcadmin to get auth info.

For example:

$ 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

package main

import (
	"context"
	"fmt"

	"yunion.io/x/jsonutils"

	"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())
}