示例#1
0
文件: volume.go 项目: vmware/vic
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
}
示例#2
0
文件: store_files.go 项目: vmware/vic
// returns # of removed stores
func (d *Dispatcher) deleteVolumeStoreIfForced(conf *config.VirtualContainerHostConfigSpec) (removed int) {
	defer trace.End(trace.Begin(""))
	removed = 0

	if !d.force {
		if len(conf.VolumeLocations) == 0 {
			return 0
		}

		volumeStores := new(bytes.Buffer)
		for label, url := range conf.VolumeLocations {
			volumeStores.WriteString(fmt.Sprintf("\t%s: %s\n", label, url.Path))
		}
		log.Warnf("Since --force was not specified, the following volume stores will not be removed. Use the vSphere UI to delete content you do not wish to keep.\n%s", volumeStores.String())
		return 0
	}

	log.Infoln("Removing volume stores")
	for label, url := range conf.VolumeLocations {
		// FIXME: url is being encoded by the portlayer incorrectly, so we have to convert url.Path to the right url.URL object
		dsURL, err := datastore.ToURL(url.Path)
		if err != nil {
			log.Warnf("Didn't receive an expected volume store path format: %q", url.Path)
			continue
		}

		if dsURL.Path == vsphere.StorageParentDir {
			dsURL.Path = path.Join(dsURL.Path, vsphere.VolumesDir)
		}

		log.Debugf("Provided datastore URL: %q\nParsed volume store path: %q", url.Path, dsURL.Path)
		log.Infof("Deleting volume store %q on Datastore %q at path %q", label, dsURL.Host, dsURL.Path)

		datastores, err := d.session.Finder.DatastoreList(d.ctx, dsURL.Host)

		if err != nil {
			log.Errorf("Error finding datastore %q: %s", dsURL.Host, err)
			continue
		}
		if len(datastores) > 1 {
			foundDatastores := new(bytes.Buffer)
			for _, d := range datastores {
				foundDatastores.WriteString(fmt.Sprintf("\n%s\n", d.InventoryPath))
			}
			log.Errorf("Ambiguous datastore name (%q) provided. Results were: %q", dsURL.Host, foundDatastores)
			continue
		}

		datastore := datastores[0]
		if _, err := d.deleteDatastoreFiles(datastore, dsURL.Path, d.force); err != nil {
			log.Errorf("Failed to delete volume store %q on Datastore %q at path %q", label, dsURL.Host, dsURL.Path)
		} else {
			removed++
		}
	}
	return removed

}
示例#3
0
文件: portlayer.go 项目: vmware/vic
func Init(ctx context.Context, sess *session.Session) error {
	source, err := extraconfig.GuestInfoSource()
	if err != nil {
		return err
	}

	sink, err := extraconfig.GuestInfoSink()
	if err != nil {
		return err
	}

	// Grab the storage layer config blobs from extra config
	extraconfig.Decode(source, &storage.Config)
	log.Debugf("Decoded VCH config for storage: %#v", storage.Config)

	// create or restore a portlayer k/v store in the VCH's directory.
	vch, err := guest.GetSelf(ctx, sess)
	if err != nil {
		return err
	}

	vchvm := vm.NewVirtualMachineFromVM(ctx, sess, vch)
	vmPath, err := vchvm.VMPathName(ctx)
	if err != nil {
		return err
	}

	// vmPath is set to the vmx.  Grab the directory from that.
	vmFolder, err := datastore.ToURL(path.Dir(vmPath))
	if err != nil {
		return err
	}

	if err = store.Init(ctx, sess, vmFolder); err != nil {
		return err
	}

	if err := exec.Init(ctx, sess, source, sink); err != nil {
		return err
	}

	if err = network.Init(ctx, sess, source, sink); err != nil {
		return err
	}

	return nil
}
示例#4
0
文件: volume.go 项目: kjplatz/vic
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
}
示例#5
0
文件: storage.go 项目: kjplatz/vic
func (v *Validator) DatastoreHelper(ctx context.Context, path string, label string, flag string) (*url.URL, *object.Datastore, error) {
	defer trace.End(trace.Begin(path))

	dsURL, err := url.Parse(path)
	if err != nil {
		return nil, nil, errors.Errorf("error parsing datastore path: %s", err)
	}

	// url scheme does not contain ://, so remove it to make url work
	if dsURL.Scheme != "" && dsURL.Scheme != "ds" {
		return nil, nil, errors.Errorf("bad scheme %q provided for datastore", dsURL.Scheme)
	}

	dsURL.Scheme = "ds"

	// if a datastore name (e.g. "datastore1") is specifed with no decoration then this
	// is interpreted as the Path
	if dsURL.Host == "" && dsURL.Path != "" {
		pathElements := strings.SplitN(path, "/", 2)
		dsURL.Host = pathElements[0]
		if len(pathElements) > 1 {
			dsURL.Path = pathElements[1]
		} else {
			dsURL.Path = ""
		}
	}

	if dsURL.Host == "" {
		// see if we can find a default datastore
		store, err := v.Session.Finder.DatastoreOrDefault(ctx, "*")
		if err != nil {
			v.suggestDatastore("*", label, flag)
			return nil, nil, errors.New("datastore empty")
		}

		dsURL.Host = store.Name()
		log.Infof("Using default datastore: %s", dsURL.Host)
	}

	stores, err := v.Session.Finder.DatastoreList(ctx, dsURL.Host)
	if err != nil {
		log.Debugf("no such datastore %#v", dsURL)
		v.suggestDatastore(path, label, flag)
		// TODO: error message about no such match and how to get a datastore list
		// we return err directly here so we can check the type
		return nil, nil, err
	}
	if len(stores) > 1 {
		// TODO: error about required disabmiguation and list entries in stores
		v.suggestDatastore(path, label, flag)
		return nil, nil, errors.New("ambiguous datastore " + dsURL.Host)
	}

	// temporary until session is extracted
	// FIXME: commented out until components can consume moid
	// dsURL.Host = stores[0].Reference().Value

	// make sure the vsphere ds format fits the right format
	if _, err := datastore.ToURL(fmt.Sprintf("[%s] %s", dsURL.Host, dsURL.Path)); err != nil {
		return nil, nil, err
	}

	return dsURL, stores[0], nil
}