Esempio n. 1
0
// AddStore adds a volumestore by uri.
//
// ds is the Datastore (+ path) volumes will be created under.
//       The resulting path will be parentDir/VIC/volumes.
// storeName is the name used to refer to the datastore + path (ds above).
//
// returns the URL used to refer to the volume store
func (v *VolumeStore) AddStore(ctx context.Context, ds *datastore.Helper, storeName string) (*url.URL, error) {
	u, err := util.VolumeStoreNameToURL(storeName)
	if err != nil {
		return nil, err
	}

	if _, ok := v.ds[*u]; ok {
		return nil, fmt.Errorf("volumestore (%s) already added", u.String())
	}

	if _, err = ds.Mkdir(ctx, true, volumesDir); err != nil {
		return nil, err
	}

	v.ds[*u] = ds
	return u, nil
}
Esempio n. 2
0
File: volume.go Progetto: vmware/vic
// AddStore adds a volumestore by uri.
//
// ds is the Datastore (+ path) volumes will be created under.
//       The resulting path will be parentDir/VIC/volumes.
// storeName is the name used to refer to the datastore + path (ds above).
//
// returns the URL used to refer to the volume store
func (v *VolumeStore) AddStore(op trace.Operation, ds *datastore.Helper, storeName string) (*url.URL, error) {
	v.dsLock.Lock()
	defer v.dsLock.Unlock()

	u, err := util.VolumeStoreNameToURL(storeName)
	if err != nil {
		return nil, err
	}

	if _, ok := v.ds[*u]; ok {
		return nil, fmt.Errorf("volumestore (%s) already added", u.String())
	}

	if _, err = ds.Mkdir(op, true, VolumesDir); err != nil && !os.IsExist(err) {
		return nil, err
	}

	v.ds[*u] = ds
	return u, nil
}
Esempio n. 3
0
// Write the opaque metadata blobs (by name).
// Each blob in the metadata map is written to a file with the corresponding
// name.  Likewise, when we read it back (on restart) we populate the map
// accordingly.
func writeMetadata(ctx context.Context, ds *datastore.Helper, dir string, meta map[string][]byte) error {
	// XXX this should be done via disklib so this meta follows the disk in
	// case of motion.

	if meta != nil && len(meta) != 0 {
		for name, value := range meta {
			r := bytes.NewReader(value)
			pth := path.Join(dir, name)
			log.Infof("Writing metadata %s", pth)
			if err := ds.Upload(ctx, r, pth); err != nil {
				return err
			}
		}
	} else {
		if _, err := ds.Mkdir(ctx, false, dir); err != nil {
			return err
		}
	}

	return nil
}