Esempio n. 1
0
File: volume.go Progetto: vmware/vic
func (v *VolumeStore) VolumesList(op trace.Operation) ([]*storage.Volume, error) {
	volumes := []*storage.Volume{}

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

	for volStore, vols := range v.ds {

		store := volStore

		res, err := vols.Ls(op, VolumesDir)
		if err != nil {
			return nil, fmt.Errorf("error listing vols: %s", err)
		}

		for _, f := range res.File {
			file, ok := f.(*types.FileInfo)
			if !ok {
				continue
			}

			ID := file.Path

			// Get the path to the disk in datastore uri format
			volDiskDsURL, err := v.volDiskDsURL(&store, ID)
			if err != nil {
				return nil, err
			}

			dev, err := disk.NewVirtualDisk(volDiskDsURL)
			if err != nil {
				return nil, err
			}

			metaDataDir := v.volMetadataDirPath(ID)
			meta, err := getMetadata(op, vols, metaDataDir)
			if err != nil {
				return nil, err
			}

			vol, err := storage.NewVolume(&store, ID, meta, dev)
			if err != nil {
				return nil, err
			}

			volumes = append(volumes, vol)
		}

	}

	return volumes, nil
}
Esempio n. 2
0
File: volume.go Progetto: vmware/vic
func (v *VolumeStore) VolumeCreate(op trace.Operation, ID string, store *url.URL, capacityKB uint64, info map[string][]byte) (*storage.Volume, error) {

	// find the datastore
	dstore, err := v.getDatastore(store)
	if err != nil {
		return nil, err
	}

	// Create the volume directory in the store.
	_, err = dstore.Mkdir(op, false, v.volDirPath(ID))
	if err != nil {
		return nil, err
	}

	// Get the path to the disk in datastore uri format
	var volDiskDsURL string
	volDiskDsURL, err = v.volDiskDsURL(store, ID)
	if err != nil {
		return nil, err
	}

	// Create the disk
	vmdisk, err := v.dm.CreateAndAttach(op, volDiskDsURL, "", int64(capacityKB), os.O_RDWR)
	if err != nil {
		return nil, err
	}
	defer v.dm.Detach(op, vmdisk)

	vol, err := storage.NewVolume(store, ID, info, vmdisk)
	if err != nil {
		return nil, err
	}

	// Make the filesystem and set its label
	if err = vmdisk.Mkfs(vol.Label); err != nil {
		return nil, err
	}

	// Persist the metadata
	metaDataDir := v.volMetadataDirPath(ID)
	if err = writeMetadata(op, dstore, metaDataDir, info); err != nil {
		return nil, err
	}

	log.Infof("volumestore: %s (%s)", ID, vol.SelfLink)
	return vol, nil
}