Exemple #1
0
func doVolumeCreate(c *cli.Context) error {
	var err error

	name := c.Args().First()
	size, err := getSize(c, err)
	driverName, err := util.GetLowerCaseFlag(c, "driver", false, err)
	backupURL, err := util.GetLowerCaseFlag(c, "backup", false, err)
	if err != nil {
		return err
	}

	driverVolumeID := c.String("id")
	volumeType := c.String("type")
	iops := c.Int("iops")

	request := &api.VolumeCreateRequest{
		Name:           name,
		DriverName:     driverName,
		Size:           size,
		BackupURL:      backupURL,
		DriverVolumeID: driverVolumeID,
		Type:           volumeType,
		IOPS:           int64(iops),
		Verbose:        c.GlobalBool(verboseFlag),
	}

	url := "/volumes/create"

	return sendRequestAndPrint("POST", url, request)
}
Exemple #2
0
func doVolumeCreate(c *cli.Context) error {
	var err error

	name := c.Args().First()
	size, err := getSize(c, err)
	driverName, err := util.GetLowerCaseFlag(c, "driver", false, err)
	backupURL, err := util.GetLowerCaseFlag(c, "backup", false, err)
	if err != nil {
		return err
	}

	if backupURL != "" && size != 0 {
		return fmt.Errorf("Cannot specify volume size with backup-url. It would be the same size of backup")
	}

	request := &api.VolumeCreateRequest{
		Name:       name,
		DriverName: driverName,
		Size:       size,
		BackupURL:  backupURL,
		Verbose:    c.GlobalBool(verboseFlag),
	}

	url := "/volumes/create"

	return sendRequestAndPrint("POST", url, request)
}
Exemple #3
0
func getSize(c *cli.Context, err error) (int64, error) {
	size, err := util.GetLowerCaseFlag(c, "size", false, err)
	if err != nil {
		return 0, err
	}
	return util.ParseSize(size)
}
Exemple #4
0
func doBackupDelete(c *cli.Context) error {
	var err error
	backupURL, err := util.GetLowerCaseFlag(c, "", true, err)
	if err != nil {
		return err
	}

	request := &api.BackupDeleteRequest{
		URL: backupURL,
	}
	url := "/backups"
	return sendRequestAndPrint("DELETE", url, request)
}
Exemple #5
0
func doBackupInspect(c *cli.Context) error {
	var err error

	backupURL, err := util.GetLowerCaseFlag(c, "", true, err)
	if err != nil {
		return err
	}

	request := &api.BackupListRequest{
		URL: backupURL,
	}
	url := "/backups/inspect"
	return sendRequestAndPrint("GET", url, request)
}
Exemple #6
0
func doBackupList(c *cli.Context) error {
	var err error

	destURL, err := util.GetLowerCaseFlag(c, "", true, err)
	volumeUUID, err := util.GetUUID(c, "volume-uuid", false, err)
	if err != nil {
		return err
	}

	request := &api.BackupListRequest{
		URL:        destURL,
		VolumeUUID: volumeUUID,
	}
	url := "/backups/list"
	return sendRequestAndPrint("GET", url, request)
}
Exemple #7
0
func doVolumeMount(c *cli.Context) error {
	var err error

	volumeUUID, err := getOrRequestUUID(c, "", true)
	mountPoint, err := util.GetLowerCaseFlag(c, "mountpoint", false, err)
	if err != nil {
		return err
	}

	request := &api.VolumeMountRequest{
		VolumeUUID: volumeUUID,
		MountPoint: mountPoint,
		Verbose:    c.GlobalBool(verboseFlag),
	}

	url := "/volumes/mount"
	return sendRequestAndPrint("POST", url, request)
}
Exemple #8
0
func doBackupCreate(c *cli.Context) error {
	var err error

	destURL, err := util.GetLowerCaseFlag(c, "dest", false, err)
	if err != nil {
		return err
	}

	snapshotUUID, err := getOrRequestUUID(c, "", true)
	if err != nil {
		return err
	}

	request := &api.BackupCreateRequest{
		URL:          destURL,
		SnapshotUUID: snapshotUUID,
		Verbose:      c.GlobalBool(verboseFlag),
	}

	url := "/backups/create"
	return sendRequestAndPrint("POST", url, request)
}
Exemple #9
0
func (s *daemon) doVolumeList(version string, w http.ResponseWriter, r *http.Request, objs map[string]string) error {
	s.GlobalLock.RLock()
	defer s.GlobalLock.RUnlock()

	driverSpecific, err := util.GetLowerCaseFlag(r, "driver", false, nil)
	if err != nil {
		return err
	}

	var data []byte
	if driverSpecific == "1" {
		result := make(map[string]map[string]string)
		for _, driver := range s.ConvoyDrivers {
			volOps, err := driver.VolumeOps()
			if err != nil {
				break
			}
			volumes, err := volOps.ListVolume(map[string]string{})
			if err != nil {
				break
			}
			for k, v := range volumes {
				v["Driver"] = driver.Name()
				result[k] = v
			}
		}
		data, err = api.ResponseOutput(&result)
	} else {
		data, err = s.listVolume()
	}
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	return err
}