示例#1
0
文件: volume.go 项目: vmware/vic
func validateDriverArgs(args map[string]string, req *models.VolumeRequest) error {
	// volumestore name validation
	req.Store = volumeStore(args)

	// capacity validation
	capstr, ok := args[OptsCapacityKey]
	if !ok {
		req.Capacity = -1
		return nil
	}

	//check if it is just a numerical value
	capacity, err := strconv.ParseInt(capstr, 10, 64)
	if err == nil {
		//input has no units in this case.
		if capacity < 1 {
			return fmt.Errorf("Invalid size: %s", capstr)
		}
		req.Capacity = capacity
		return nil
	}

	capacity, err = units.FromHumanSize(capstr)
	if err != nil {
		return err
	}

	if capacity < 1 {
		return fmt.Errorf("Capacity value too large: %s", capstr)
	}

	req.Capacity = int64(capacity) / int64(units.MB)
	return nil
}
示例#2
0
文件: volume.go 项目: jak-atx/vic
func translateInputsToPortlayerRequestModel(name, driverName string, opts, labels map[string]string) (models.VolumeRequest, error) {
	model := models.VolumeRequest{
		Driver:     driverName,
		DriverArgs: opts,
		Name:       name,
	}
	metadata := createVolumeMetadata(&model, labels)
	model.Metadata = make(map[string]string)
	model.Metadata["dockerMetaData"] = metadata
	if err := validateDriverArgs(opts, &model); err != nil {
		return model, err
	}
	return model, nil
}
示例#3
0
文件: volume.go 项目: jak-atx/vic
func validateDriverArgs(args map[string]string, model *models.VolumeRequest) error {
	//volumestore name validation
	storeName, ok := args[optsVolumeStoreKey]
	if !ok {
		storeName = "default"
	}
	model.Store = storeName

	//capacity validation
	capstr, ok := args[optsCapacityKey]
	if !ok {
		model.Capacity = -1
		return nil
	}
	capacity, convErr := strconv.ParseInt(capstr, 10, 64)
	if convErr != nil {
		model.Capacity = -1
		return fmt.Errorf("Capacity must be an integer value. The unit is GB.: %s", convErr)
	}
	model.Capacity = int64(capacity)
	return nil
}
示例#4
0
文件: volume.go 项目: kjplatz/vic
func validateDriverArgs(args map[string]string, model *models.VolumeRequest) error {
	// volumestore name validation
	storeName, ok := args[OptsVolumeStoreKey]
	if !ok {
		storeName = "default"
	}
	model.Store = storeName

	// capacity validation
	capstr, ok := args[OptsCapacityKey]
	if !ok {
		model.Capacity = -1
		return nil
	}

	capacity, err := units.FromHumanSize(capstr)
	if err != nil {
		return err
	}
	model.Capacity = int64(capacity) / bytesToMegabyte

	return nil
}
示例#5
0
func TestVolumeCreate(t *testing.T) {

	testStore := NewMockVolumeStore()
	op := trace.NewOperation(context.Background(), "test")
	volCache, err := spl.NewVolumeLookupCache(op, testStore)
	if !assert.NoError(t, err) {
		return
	}

	handler := StorageHandlersImpl{
		volumeCache: volCache,
	}

	model := models.VolumeRequest{}
	model.Store = "blah"
	model.Name = "testVolume"
	model.Capacity = 1
	model.Driver = "vsphere"
	model.DriverArgs = make(map[string]string)
	model.DriverArgs["stuff"] = "things"
	model.Metadata = make(map[string]string)
	params := storage.NewCreateVolumeParams()
	params.VolumeRequest = &model

	handler.CreateVolume(params)
	testVolume, err := testStore.VolumeGet(op, model.Name)
	if !assert.NoError(t, err) {
		return
	}

	if !assert.NotNil(t, testVolume) {
		return
	}
	testVolumeStoreName, err := util.VolumeStoreName(testVolume.Store)
	if !assert.NoError(t, err) {
		return
	}
	if !assert.Equal(t, "blah", testVolumeStoreName) {
		return
	}
	if !assert.Equal(t, "testVolume", testVolume.ID) {
		return
	}
}
示例#6
0
func TestVolumeCreate(t *testing.T) {

	var err error
	testStore := NewMockVolumeStore()
	storageVolumeLayer, err = spl.NewVolumeLookupCache(context.TODO(), testStore)
	if !assert.NoError(t, err) {
		return
	}

	model := models.VolumeRequest{}
	model.Store = "blah"
	model.Name = "testVolume"
	model.Capacity = 1
	model.Driver = "vsphere"
	model.DriverArgs = make(map[string]string)
	model.DriverArgs["stuff"] = "things"
	model.Metadata = make(map[string]string)
	params := storage.NewCreateVolumeParams()
	params.VolumeRequest = &model
	implementationHandler := StorageHandlersImpl{}

	implementationHandler.CreateVolume(params)
	testVolume, err := testStore.VolumeGet(context.TODO(), model.Name)
	if !assert.NoError(t, err) {
		return
	}

	if !assert.NotNil(t, testVolume) {
		return
	}
	testVolumeStoreName, err := util.VolumeStoreName(testVolume.Store)
	if !assert.NoError(t, err) {
		return
	}
	if !assert.Equal(t, "blah", testVolumeStoreName) {
		return
	}
	if !assert.Equal(t, "testVolume", testVolume.ID) {
		return
	}
}