コード例 #1
0
ファイル: volume.go プロジェクト: kjplatz/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(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
}
コード例 #2
0
ファイル: volume.go プロジェクト: 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
}
コード例 #3
0
ファイル: metadata.go プロジェクト: kjplatz/vic
// 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
}
コード例 #4
0
ファイル: metadata.go プロジェクト: kjplatz/vic
// Read the metadata from the given dir
func getMetadata(ctx context.Context, ds *datastore.Helper, dir string) (map[string][]byte, error) {

	res, err := ds.Ls(ctx, dir)
	if err != nil {
		return nil, err
	}

	if len(res.File) == 0 {
		log.Infof("No meta found for %s", dir)
		return nil, nil
	}

	meta := make(map[string][]byte)
	for _, f := range res.File {
		finfo, ok := f.(*types.FileInfo)
		if !ok {
			continue
		}

		p := path.Join(dir, finfo.Path)
		log.Infof("Getting metadata %s", p)
		rc, err := ds.Download(ctx, p)
		if err != nil {
			return nil, err
		}
		defer rc.Close()

		buf, err := ioutil.ReadAll(rc)
		if err != nil {
			return nil, err
		}

		meta[finfo.Path] = buf
	}

	return meta, nil
}