58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang"
|
|
)
|
|
|
|
func main() {
|
|
// Set Host and other parameters
|
|
configuration := garage.NewConfiguration()
|
|
configuration.Host = "127.0.0.1:3903"
|
|
|
|
|
|
// We can now generate a client
|
|
client := garage.NewAPIClient(configuration)
|
|
|
|
// Authentication is handled through the context pattern
|
|
ctx := context.WithValue(context.Background(), garage.ContextAccessToken, "s3cr3t")
|
|
|
|
// Send a request
|
|
resp, r, err := client.NodesApi.GetNodes(ctx).Execute()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error when calling `NodesApi.GetNodes`\n")
|
|
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
|
panic(err)
|
|
}
|
|
|
|
// Process the response
|
|
fmt.Fprintf(os.Stdout, "First hostname: %v\n", resp.KnownNodes[0].Hostname)
|
|
|
|
// Layout
|
|
capa := int64(1000000000)
|
|
change := []garage.NodeRoleChange{
|
|
garage.NodeRoleChange{NodeRoleUpdate: &garage.NodeRoleUpdate {
|
|
Id: *resp.KnownNodes[0].Id,
|
|
Zone: "dc1",
|
|
Capacity: *garage.NewNullableInt64(&capa),
|
|
Tags: []string{ "fast", "amd64" },
|
|
}},
|
|
}
|
|
staged, r, err := client.LayoutApi.AddLayout(ctx).NodeRoleChange(change).Execute()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error when calling `LayoutApi.AddLayout`\n")
|
|
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
|
panic(err)
|
|
}
|
|
msg, r, err := client.LayoutApi.ApplyLayout(ctx).LayoutVersion(*garage.NewLayoutVersion(staged.Version + 1)).Execute()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error when calling `LayoutApi.ApplyLayout`\n")
|
|
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
|
panic(err)
|
|
}
|
|
fmt.Printf(strings.Join(msg.Message, "\n"))
|
|
}
|