Beispiel #1
0
func decodeBackupURL(backupURL string) (string, string, error) {
	u, err := url.Parse(backupURL)
	if err != nil {
		return "", "", err
	}
	v := u.Query()
	volumeName := v.Get("volume")
	backupName := v.Get("backup")
	if !util.ValidateName(volumeName) || !util.ValidateName(backupName) {
		return "", "", fmt.Errorf("Invalid name parsed, got %v and %v", backupName, volumeName)
	}
	return backupName, volumeName, nil
}
Beispiel #2
0
func (s *daemon) doRequestUUID(version string, w http.ResponseWriter, r *http.Request, objs map[string]string) error {
	var err error
	key, err := util.GetName(r, api.KEY_NAME, true, err)
	if err != nil {
		return err
	}

	var uuid string
	resp := &api.UUIDResponse{}

	if util.ValidateName(key) {
		// It's probably a name
		uuid = s.NameUUIDIndex.Get(key)
	}

	if uuid == "" {
		// No luck with name, let's try uuid index
		uuid, _ = s.UUIDIndex.Get(key)
	}

	if uuid != "" {
		resp.UUID = uuid
	}
	return writeResponseOutput(w, resp)
}
Beispiel #3
0
func (s *daemon) getDockerVolume(r *http.Request, create bool) (*Volume, error) {
	request, err := getDockerVolumeRequest(r)
	if err != nil {
		return nil, err
	}

	name := request.Name
	var (
		volume     *Volume
		volumeName string
	)
	if util.ValidateName(name) {
		volumeName = name
		volume = s.loadVolumeByName(name)
	} else {
		// Not valid UUID or name
		return nil, fmt.Errorf("Invalid volume %s. Must be only contains 0-9, a-z, dash(-), underscore(_) and dot(.)", name)
	}

	if volume == nil {
		if create {
			log.Debugf("Create a new volume %v for docker", name)

			size, err := util.ParseSize(request.Opts["size"])
			if err != nil {
				return nil, err
			}
			iops := 0
			if request.Opts["iops"] != "" {
				iops, err = strconv.Atoi(request.Opts["iops"])
				if err != nil {
					return nil, err
				}
			}
			prepareForVM := false
			if request.Opts["vm"] != "" {
				prepareForVM, err = strconv.ParseBool(request.Opts["vm"])
				if err != nil {
					return nil, err
				}
			}
			request := &api.VolumeCreateRequest{
				Name:           volumeName,
				DriverName:     request.Opts["driver"],
				Size:           size,
				BackupURL:      request.Opts["backup"],
				DriverVolumeID: request.Opts["id"],
				Type:           request.Opts["type"],
				PrepareForVM:   prepareForVM,
				IOPS:           int64(iops),
			}
			volume, err = s.processVolumeCreate(request)
			if err != nil {
				return nil, err
			}
		}
	}

	return volume, nil
}
Beispiel #4
0
func (s *daemon) getDockerVolume(r *http.Request, create bool) (*Volume, error) {
	name, err := getDockerVolumeName(r)
	if err != nil {
		return nil, err
	}

	var (
		volume     *Volume
		volumeName string
	)
	if util.ValidateName(name) {
		volumeName = name
		volume = s.loadVolumeByName(name)
	} else {
		// Not valid UUID or name
		return nil, fmt.Errorf("Invalid volume name. Must be only contains 0-9, a-z, dash(-), underscore(_) and dot(.)")
	}

	if volume == nil {
		if create {
			log.Debugf("Create a new volume %v for docker", name)

			request := &api.VolumeCreateRequest{
				Name: volumeName,
			}
			volume, err = s.processVolumeCreate(request)
			if err != nil {
				return nil, err
			}
		} else {
			return nil, fmt.Errorf("Cannot find volume %v", name)
		}
	}

	return volume, nil
}