// RunFloatingIPList runs floating IP create. func RunFloatingIPList(ns string, out io.Writer) error { client := doit.DoitConfig.GetGodoClient() f := func(opt *godo.ListOptions) ([]interface{}, *godo.Response, error) { list, resp, err := client.FloatingIPs.List(opt) if err != nil { return nil, nil, err } si := make([]interface{}, len(list)) for i := range list { si[i] = list[i] } return si, resp, err } si, err := doit.PaginateResp(f) if err != nil { return err } list := make([]godo.FloatingIP, len(si)) for i := range si { list[i] = si[i].(godo.FloatingIP) } return doit.DisplayOutput(list, out) }
func listDroplets(client *godo.Client) ([]godo.Droplet, error) { f := func(opt *godo.ListOptions) ([]interface{}, *godo.Response, error) { list, resp, err := client.Droplets.List(opt) if err != nil { return nil, nil, err } si := make([]interface{}, len(list)) for i := range list { si[i] = list[i] } return si, resp, err } si, err := doit.PaginateResp(f) if err != nil { return nil, err } list := make([]godo.Droplet, len(si)) for i := range si { list[i] = si[i].(godo.Droplet) } return list, nil }
// RunRecordList list records for a domain. func RunRecordList(ns string, out io.Writer) error { client := doit.DoitConfig.GetGodoClient() name := doit.DoitConfig.GetString(ns, doit.ArgDomainName) if len(name) < 1 { return errors.New("domain name is missing") } f := func(opt *godo.ListOptions) ([]interface{}, *godo.Response, error) { list, resp, err := client.Domains.Records(name, opt) if err != nil { return nil, nil, err } si := make([]interface{}, len(list)) for i := range list { si[i] = list[i] } return si, resp, err } si, err := doit.PaginateResp(f) if err != nil { return err } list := make([]godo.DomainRecord, len(si)) for i := range si { list[i] = si[i].(godo.DomainRecord) } return doit.DisplayOutput(list, out) }
func listImages(ns string, config doit.Config, out io.Writer, lFn listFn) error { public, err := config.GetBool(ns, doit.ArgImagePublic) if err != nil { return err } fn := func(opt *godo.ListOptions) ([]interface{}, *godo.Response, error) { list, resp, err := lFn(opt) if err != nil { return nil, nil, err } si := []interface{}{} for _, i := range list { if (public && i.Public) || !public { si = append(si, i) } } return si, resp, err } si, err := doit.PaginateResp(fn) if err != nil { return err } list := make([]godo.Image, len(si)) for i := range si { list[i] = si[i].(godo.Image) } return doit.DisplayOutput(list, out) }
// RunDropletActions returns a list of actions for a droplet. func RunDropletActions(ns string, out io.Writer) error { client := doit.DoitConfig.GetGodoClient() id := doit.DoitConfig.GetInt(ns, doit.ArgDropletID) f := func(opt *godo.ListOptions) ([]interface{}, *godo.Response, error) { list, resp, err := client.Droplets.Actions(id, opt) if err != nil { return nil, nil, err } si := make([]interface{}, len(list)) for i := range list { si[i] = list[i] } return si, resp, err } si, err := doit.PaginateResp(f) if err != nil { return err } list := make([]godo.Action, len(si)) for i := range si { list[i] = si[i].(godo.Action) } return doit.DisplayOutput(list, out) }