Пример #1
0
func getUUID(v interface{}, key string, required bool, err error) (string, error) {
	uuid, err := getLowerCaseFlag(v, key, required, err)
	if err != nil {
		return uuid, err
	}
	if !required && uuid == "" {
		return uuid, nil
	}
	if !util.ValidateUUID(uuid) {
		return "", fmt.Errorf("Invalid UUID %v", uuid)
	}
	return uuid, nil
}
Пример #2
0
func (s *Server) getDockerVolume(r *http.Request, create bool) (*Volume, error) {
	name, err := getDockerVolumeName(r)
	if err != nil {
		return nil, err
	}

	var (
		volume     *Volume
		volumeUUID string
		volumeName string
	)
	if util.ValidateUUID(name) {
		volumeUUID = name
		volume = s.loadVolume(name)
	} else 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 a valid UUID or only contains 0-9, a-z, understore(_) and dot(.)")
	}

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

			volume, err = s.processVolumeCreate(volumeUUID, volumeName, "", s.DefaultVolumeSize, true)
			if err != nil {
				return nil, err
			}
		} else {
			return nil, fmt.Errorf("Cannot find volume %v", name)
		}
	}

	return volume, nil
}