Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ Use: "create [options] --name <name> --type <type>", Short: "Create a placement group", } cmd.Flags().String("name", "", "Name") cmd.MarkFlagRequired("name") cmd.Flags().StringToString("label", nil, "User-defined labels ('key=value') (can be specified multiple times)") cmd.Flags().String("type", "", "Type of the placement group") cmd.MarkFlagRequired("type") return cmd }, Run: func(s state.State, cmd *cobra.Command, args []string) (any, any, error) { name, _ := cmd.Flags().GetString("name") labels, _ := cmd.Flags().GetStringToString("label") placementGroupType, _ := cmd.Flags().GetString("type") opts := hcloud.PlacementGroupCreateOpts{ Name: name, Labels: labels, Type: hcloud.PlacementGroupType(placementGroupType), } result, _, err := s.Client().PlacementGroup().Create(s, opts) if err != nil { return nil, nil, err } if result.Action != nil { if err := s.ActionProgress(cmd, s, result.Action); err != nil { return nil, nil, err } } cmd.Printf("Placement group %d created\n", result.PlacementGroup.ID) return result.PlacementGroup, util.Wrap("placement_group", hcloud.SchemaFromPlacementGroup(result.PlacementGroup)), nil }, }
View Source
var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "placement group", ShortDescription: "Delete a placement group", NameSuggestions: func(c hcapi2.Client) func() []string { return c.PlacementGroup().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { return s.Client().PlacementGroup().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { placementGroup := resource.(*hcloud.PlacementGroup) if _, err := s.Client().PlacementGroup().Delete(s, placementGroup); err != nil { return err } return nil }, }
View Source
var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "placement group", ShortDescription: "Describe a placement group", JSONKeyGetByID: "placement_group", JSONKeyGetByName: "placement_groups", NameSuggestions: func(c hcapi2.Client) func() []string { return c.PlacementGroup().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { pg, _, err := s.Client().PlacementGroup().Get(s, idOrName) if err != nil { return nil, nil, err } return pg, hcloud.SchemaFromPlacementGroup(pg), nil }, PrintText: func(s state.State, cmd *cobra.Command, resource interface{}) error { placementGroup := resource.(*hcloud.PlacementGroup) cmd.Printf("ID:\t\t%d\n", placementGroup.ID) cmd.Printf("Name:\t\t%s\n", placementGroup.Name) cmd.Printf("Created:\t%s (%s)\n", util.Datetime(placementGroup.Created), humanize.Time(placementGroup.Created)) cmd.Print("Labels:\n") if len(placementGroup.Labels) == 0 { cmd.Print(" No labels\n") } else { for key, value := range placementGroup.Labels { cmd.Printf(" %s: %s\n", key, value) } } cmd.Print("Servers:\n") for _, serverID := range placementGroup.Servers { cmd.Printf(" - Server ID:\t\t%d\n", serverID) cmd.Printf(" Server Name:\t%s\n", s.Client().Server().ServerName(serverID)) } cmd.Printf("Type:\t\t%s\n", placementGroup.Type) return nil }, }
View Source
var LabelCmds = base.LabelCmds{ ResourceNameSingular: "placement group", ShortDescriptionAdd: "Add a label to a placement group", ShortDescriptionRemove: "Remove a label from a placement group", NameSuggestions: func(c hcapi2.Client) func() []string { return c.PlacementGroup().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.PlacementGroup().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { placementGroup, _, err := s.Client().PlacementGroup().Get(s, idOrName) if err != nil { return nil, 0, err } if placementGroup == nil { return nil, 0, fmt.Errorf("placement group not found: %s", idOrName) } return placementGroup.Labels, placementGroup.ID, nil }, SetLabels: func(s state.State, id int64, labels map[string]string) error { opts := hcloud.PlacementGroupUpdateOpts{ Labels: labels, } _, _, err := s.Client().PlacementGroup().Update(s, &hcloud.PlacementGroup{ID: id}, opts) return err }, }
View Source
var ListCmd = base.ListCmd{ ResourceNamePlural: "Placement Groups", JSONKeyGetByName: "placement_groups", DefaultColumns: []string{"id", "name", "servers", "type", "age"}, Fetch: func(s state.State, _ *pflag.FlagSet, listOpts hcloud.ListOpts, sorts []string) ([]interface{}, error) { opts := hcloud.PlacementGroupListOpts{ListOpts: listOpts} if len(sorts) > 0 { opts.Sort = sorts } placementGroups, err := s.Client().PlacementGroup().AllWithOpts(s, opts) var resources []interface{} for _, n := range placementGroups { resources = append(resources, n) } return resources, err }, OutputTable: func(client hcapi2.Client) *output.Table { return output.NewTable(). AddAllowedFields(hcloud.PlacementGroup{}). AddFieldFn("servers", output.FieldFn(func(obj interface{}) string { placementGroup := obj.(*hcloud.PlacementGroup) count := len(placementGroup.Servers) if count == 1 { return fmt.Sprintf("%d server", count) } return fmt.Sprintf("%d servers", count) })). AddFieldFn("created", output.FieldFn(func(obj interface{}) string { placementGroup := obj.(*hcloud.PlacementGroup) return util.Datetime(placementGroup.Created) })). AddFieldFn("age", output.FieldFn(func(obj interface{}) string { placementGroup := obj.(*hcloud.PlacementGroup) return util.Age(placementGroup.Created, time.Now()) })) }, Schema: func(resources []interface{}) interface{} { placementGroupSchemas := make([]schema.PlacementGroup, 0, len(resources)) for _, resource := range resources { placementGroup := resource.(*hcloud.PlacementGroup) placementGroupSchemas = append(placementGroupSchemas, hcloud.SchemaFromPlacementGroup(placementGroup)) } return placementGroupSchemas }, }
View Source
var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "placement group", ShortDescription: "Update a placement group", NameSuggestions: func(c hcapi2.Client) func() []string { return c.PlacementGroup().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { return s.Client().PlacementGroup().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "Placement group name") }, Update: func(s state.State, cmd *cobra.Command, resource interface{}, flags map[string]pflag.Value) error { placementGroup := resource.(*hcloud.PlacementGroup) updOpts := hcloud.PlacementGroupUpdateOpts{ Name: flags["name"].String(), } _, _, err := s.Client().PlacementGroup().Update(s, placementGroup, updOpts) if err != nil { return err } return nil }, }
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.