func enableDropletIPv6(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	return doResourceAction(c, client.DropletActions.EnableIPv6)
}
func enableDropletPrivateNetworking(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	return doResourceAction(c, client.DropletActions.EnablePrivateNetworking)
}
Esempio n. 3
0
func listDropletBackups(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	return listDropletImages(c, client.Droplets.Backups)
}
func disableDropletBackups(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	return doResourceAction(c, client.DropletActions.DisableBackups)
}
func powerOnDroplet(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	return doResourceAction(c, client.DropletActions.PowerOn)
}
Esempio n. 6
0
func listDropletKernels(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	list := []godo.Kernel{}
	opt := &godo.ListOptions{}
	for {
		kernels, resp, err := client.Droplets.Kernels(id, opt)
		if err != nil {
			return Error(err)
		}
		list = append(list, kernels...)
		if resp.Links == nil || resp.Links.IsLastPage() {
			break
		}
		page, err := resp.Links.CurrentPage()
		if err != nil {
			return Error(err)
		}
		opt.Page = page + 1
	}
	return Respond(c, list, nil)
}
Esempio n. 7
0
func listDroplets(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	list, er := paginateDroplets(client.Droplets.List)
	return Respond(c, list, er)
}
Esempio n. 8
0
func deleteDroplet(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	_, er := client.Droplets.Delete(id)
	return RespondNoContent(c, er)
}
Esempio n. 9
0
func showAction(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	action, _, er := client.Actions.Get(id)
	return Respond(c, action, er)
}
Esempio n. 10
0
func showImage(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	image, _, er := client.Images.GetByID(id)
	return Respond(c, image, er)
}
func convertImage(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	transferReq := godo.ActionRequest{"type": "convert"}
	action, _, er := client.ImageActions.Transfer(id, &transferReq)
	return Respond(c, action, er)
}
Esempio n. 12
0
func listDropletActions(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	list, er := paginateActions(func(opt *godo.ListOptions) ([]godo.Action, *godo.Response, error) {
		return client.Droplets.Actions(id, opt)
	})
	return Respond(c, list, er)
}
Esempio n. 13
0
func createKey(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	req := godo.KeyCreateRequest{}
	if err = c.Bind(&req); err != nil {
		return err
	}
	key, _, er := client.Keys.Create(&req)
	if er == nil {
		c.Response.Header().Set("Location", keyHref(key.ID))
	}
	return RespondNoContent(c, er)
}
Esempio n. 14
0
func createDroplet(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	req := godo.DropletCreateRequest{}
	if err = c.Bind(&req); err != nil {
		return err
	}
	root, _, er := client.Droplets.Create(&req)
	if er == nil {
		c.Response.Header().Set("Location", dropletHref(root.Droplet.ID))
	}
	return RespondNoContent(c, er)
}
Esempio n. 15
0
func showKey(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	key, _, er := client.Keys.GetByID(id)
	if er != nil {
		return Error(er)
	}
	return Respond(c, key, er)
}
Esempio n. 16
0
func updateKey(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	req := godo.KeyUpdateRequest{}
	if err = c.Bind(&req); err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	_, _, er := client.Keys.UpdateByID(id, &req)
	return RespondNoContent(c, er)
}
func restoreDroplet(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	req := struct {
		ImageID int `json:"imageID"`
	}{}
	err = c.Bind(&req)
	if err != nil {
		return err
	}
	return doResourceAction(c, func(id int) (*godo.Action, *godo.Response, error) {
		return client.DropletActions.Restore(id, req.ImageID)
	})
}
func snapshotDroplet(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	req := struct {
		Name string `json:"name"`
	}{}
	err = c.Bind(&req)
	if err != nil {
		return err
	}
	return doResourceAction(c, func(id int) (*godo.Action, *godo.Response, error) {
		return client.DropletActions.Snapshot(id, req.Name)
	})
}
Esempio n. 19
0
func showDroplet(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	root, _, er := client.Droplets.Get(id)
	var droplet *Droplet
	if err == nil {
		droplet = DropletFromApi(root.Droplet)
	}
	return Respond(c, droplet, er)
}
func changeDropletKernel(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	req := struct {
		KernelID int `json:"kernelID"`
	}{}
	err = c.Bind(&req)
	if err != nil {
		return err
	}
	return doResourceAction(c, func(id int) (*godo.Action, *godo.Response, error) {
		return client.DropletActions.ChangeKernel(id, req.KernelID)
	})
}
func resizeDroplet(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	req := struct {
		SizeSlug   string `json:"sizeSlug"`
		ResizeDisk bool   `json:"resizeDisk"`
	}{}
	err = c.Bind(&req)
	if err != nil {
		return err
	}
	return doResourceAction(c, func(id int) (*godo.Action, *godo.Response, error) {
		return client.DropletActions.Resize(id, req.SizeSlug, req.ResizeDisk)
	})
}
Esempio n. 22
0
func listDropletNeighbors(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	droplets, _, er := client.Droplets.Neighbors(id)
	var list []*Droplet
	if er == nil {
		for _, d := range droplets {
			list = append(list, DropletFromApi(&d))
		}
	}
	return Respond(c, list, er)
}
func transferImage(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	req := struct {
		Region string `json:"region"`
	}{}
	if err = c.Bind(&req); err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	transferReq := godo.ActionRequest{"type": "transfer", "region": req.Region}
	action, _, er := client.ImageActions.Transfer(id, &transferReq)
	return Respond(c, action, er)
}
func getDropletAction(c *echo.Context) *echo.HTTPError {
	client, err := middleware.GetDOClient(c)
	if err != nil {
		return err
	}
	id, err := getIDParam(c)
	if err != nil {
		return err
	}
	said := c.Param("actionId")
	if said == "" {
		return Error(fmt.Errorf("missing action id"))
	}
	aid, er := strconv.Atoi(said)
	if er != nil {
		return Error(fmt.Errorf("invalid action id '%s' - must be a number", said))
	}
	action, _, er := client.DropletActions.Get(id, aid)
	return Respond(c, action, er)
}