Beispiel #1
0
func (v *VolumeStore) VolumeStoresList(op trace.Operation) (map[string]url.URL, error) {
	m := make(map[string]url.URL)

	v.dsLock.RLock()
	defer v.dsLock.RUnlock()

	for u, ds := range v.ds {

		// Get the ds:// URL given the datastore url ("[datastore] /path")
		dsurl, err := datastore.ToURL(ds.RootURL)
		if err != nil {
			return nil, err
		}

		// from the storage url, get the store name
		storeName, err := util.VolumeStoreName(&u)
		if err != nil {
			return nil, err
		}

		m[storeName] = *dsurl
	}

	return m, nil
}
Beispiel #2
0
func fillVolumeModel(volume *spl.Volume) (models.VolumeResponse, error) {
	storeName, err := util.VolumeStoreName(volume.Store)
	if err != nil {
		return models.VolumeResponse{}, err
	}

	metadata := createMetadataMap(volume)

	model := models.VolumeResponse{
		Name:     volume.ID,
		Driver:   "vsphere",
		Store:    storeName,
		Metadata: metadata,
		Label:    volume.Label,
	}

	return model, nil
}
Beispiel #3
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
	}
}
Beispiel #4
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
	}
}
Beispiel #5
0
// Creates a volume on the given volume store, of the given size, with the given metadata.
func (m *MockVolumeStore) VolumeCreate(op trace.Operation, ID string, store *url.URL, capacityKB uint64, info map[string][]byte) (*Volume, error) {
	storeName, err := util.VolumeStoreName(store)
	if err != nil {
		return nil, err
	}

	selfLink, err := util.VolumeURL(storeName, ID)
	if err != nil {
		return nil, err
	}

	vol := &Volume{
		ID:       ID,
		Store:    store,
		SelfLink: selfLink,
	}

	m.db[ID] = vol

	return vol, nil
}
Beispiel #6
0
func (v *VolumeStore) VolumeStoresList(ctx context.Context) (map[string]url.URL, error) {
	m := make(map[string]url.URL)
	for u, ds := range v.ds {

		// Get the ds:// URL given the datastore url ("[datastore] /path")
		dsurl, err := datastore.ToURL(ds.RootURL)
		if err != nil {
			return nil, err
		}

		// from the storage url, get the store name
		storeName, err := util.VolumeStoreName(&u)
		if err != nil {
			return nil, err
		}

		m[storeName] = *dsurl
	}

	return m, nil
}
Beispiel #7
0
// NewVolume creates a Volume
func NewVolume(store *url.URL, ID string, info map[string][]byte, device Disk) (*Volume, error) {
	storeName, err := util.VolumeStoreName(store)
	if err != nil {
		return nil, err
	}

	selflink, err := util.VolumeURL(storeName, ID)
	if err != nil {
		return nil, err
	}

	// Set the label to the md5 of the ID

	vol := &Volume{
		ID:       ID,
		Label:    label(ID),
		Store:    store,
		SelfLink: selflink,
		Device:   device,
		Info:     info,
	}

	return vol, nil
}