コード例 #1
0
ファイル: handlers.go プロジェクト: cloudstrack/volplugin
func getPath(master string) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		vr, err := unmarshalRequest(r.Body)
		if err != nil {
			httpError(w, "Could not unmarshal request", err)
			return
		}

		if vr.Name == "" {
			httpError(w, "Name is empty", nil)
			return
		}

		log.Infof("Returning mount path to docker for volume: %q", vr.Name)

		pool, name, err := splitPath(vr.Name)
		if err != nil {
			httpError(w, "Configuring volume", err)
			return
		}

		// FIXME need to ensure that the mount exists before returning to docker
		driver := cephdriver.NewCephDriver()

		content, err := marshalResponse(VolumeResponse{Mountpoint: driver.MountPath(pool, name)})
		if err != nil {
			httpError(w, "Reply could not be marshalled", err)
			return
		}

		w.Write(content)
	}
}
コード例 #2
0
ファイル: handlers.go プロジェクト: ekuric/volplugin
func getPath(master, tenantName string) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		vr, err := unmarshalRequest(r.Body)
		if err != nil {
			httpError(w, "Could not unmarshal request", err)
			return
		}

		if vr.Name == "" {
			httpError(w, "Name is empty", nil)
			return
		}

		log.Infof("Returning mount path to docker for volume: %q", vr.Name)

		config, err := requestTenantConfig(master, tenantName, vr.Name)
		if err != nil {
			httpError(w, "Could not determine tenant configuration", err)
			return
		}

		driver := cephdriver.NewCephDriver(config.Pool)

		content, err := marshalResponse(VolumeResponse{Mountpoint: driver.MountPath(vr.Name)})
		if err != nil {
			httpError(w, "Reply could not be marshalled", err)
			return
		}

		w.Write(content)
	}
}
コード例 #3
0
ファイル: snapshot_intent.go プロジェクト: dockware/volplugin
func wrapSnapshotAction(config config, action func(config config, tenant string, volume *cephdriver.CephVolume)) {
	for tenant, value := range config {
		mutex.Lock()
		duration, err := time.ParseDuration(config[tenant].Snapshot.Frequency)
		if err != nil {
			panic(fmt.Sprintf("Runtime configuration incorrect; cannot use %q as a snapshot frequency", config[tenant].Snapshot.Frequency))
		}

		if value.UseSnapshots && time.Now().Unix()%int64(duration.Seconds()) == 0 {
			for _, volumes := range volumeMap {
				rbdConfig, err := librbd.ReadConfig("/etc/rbdconfig.json")
				if err != nil {
					log.Errorf("Cannot read RBD configuration: %v", err)
					break
				}
				driver, err := cephdriver.NewCephDriver(rbdConfig, config[tenant].Pool)
				if err != nil {
					log.Errorf("Cannot snap volumes for tenant %q: %v", tenant, err)
					break
				}
				for volName := range volumes {
					volume := driver.NewVolume(volName, config[tenant].Size)
					action(config, tenant, volume)
				}
			}
		}
		mutex.Unlock()
	}
}
コード例 #4
0
ファイル: snapshots.go プロジェクト: hankerepo/volplugin
func runSnapshot(config *config.TopLevelConfig, pool string, volume *config.VolumeConfig) {
	now := time.Now()
	cephVol := cephdriver.NewCephDriver().NewVolume(pool, strings.Join([]string{volume.TenantName, volume.VolumeName}, "."), volume.Options.Size)
	log.Infof("Snapping volume %q at %v", volume, now)
	if err := cephVol.CreateSnapshot(now.String()); err != nil {
		log.Errorf("Cannot snap volume: %q: %v", volume.VolumeName, err)
	}
}
コード例 #5
0
ファイル: image.go プロジェクト: ekuric/volplugin
func createImage(config configTenant, name string, size uint64) error {
	driver := cephdriver.NewCephDriver(config.Pool)

	if err := driver.NewVolume(name, config.Size).Create(); err != nil {
		return err
	}

	return nil
}
コード例 #6
0
ファイル: handlers.go プロジェクト: jainvipin/volplugin
func mount(master, host string) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		vr, err := unmarshalRequest(r.Body)
		if err != nil {
			httpError(w, "Could not unmarshal request", err)
			return
		}

		if vr.Name == "" {
			httpError(w, "Name is empty", nil)
			return
		}

		// FIXME check if we're holding the mount already
		log.Infof("Mounting volume %q", vr.Name)

		tenant, name, err := splitPath(vr.Name)
		if err != nil {
			httpError(w, "Configuring volume", err)
			return
		}

		volConfig, err := requestVolumeConfig(master, tenant, name)
		if err != nil {
			httpError(w, "Could not determine tenant configuration", err)
			return
		}

		driver := cephdriver.NewCephDriver()

		mt := &config.MountConfig{
			Volume:     volConfig.VolumeName,
			Pool:       volConfig.Options.Pool,
			MountPoint: driver.MountPath(volConfig.Options.Pool, name),
			Host:       host,
		}

		if err := reportMount(master, mt); err != nil {
			httpError(w, "Reporting mount to master", err)
			return
		}

		if err := driver.NewVolume(volConfig.Options.Pool, name, volConfig.Options.Size).Mount(volConfig.Options.FileSystem); err != nil {
			httpError(w, "Volume could not be mounted", err)
			return
		}

		content, err := marshalResponse(VolumeResponse{Mountpoint: driver.MountPath(volConfig.Options.Pool, name)})
		if err != nil {
			httpError(w, "Reply could not be marshalled", err)
			return
		}

		w.Write(content)
	}
}
コード例 #7
0
ファイル: image.go プロジェクト: hankerepo/volplugin
func createImage(tenant *config.TenantConfig, config *config.VolumeConfig) error {
	var (
		fscmd string
		ok    bool
	)

	if tenant.FileSystems == nil {
		fscmd = defaultFsCmd
	} else {
		fscmd, ok = tenant.FileSystems[config.Options.FileSystem]
		if !ok {
			return fmt.Errorf("Invalid filesystem %q", config.Options.FileSystem)
		}
	}

	return cephdriver.NewCephDriver().NewVolume(config.Options.Pool, joinVolumeName(config), config.Options.Size).Create(fscmd)
}
コード例 #8
0
ファイル: handlers.go プロジェクト: dockware/volplugin
func create(tenantName string, rbdConfig librbd.RBDConfig) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		vr, err := unmarshalRequest(r.Body)
		if err != nil {
			httpError(w, "Could not unmarshal request", err)
			return
		}

		if vr.Name == "" {
			httpError(w, "Image name is empty", nil)
			return
		}

		config, err := requestTenantConfig(tenantName, vr.Name)
		if err != nil {
			httpError(w, "Could not determine tenant configuration", err)
			return
		}

		driver, err := cephdriver.NewCephDriver(rbdConfig, config.Pool)
		if err != nil {
			httpError(w, "Error creating ceph driver", err)
			return
		}

		vol := driver.NewVolume(vr.Name, config.Size)

		log.Infof("Creating volume with parameters: %v", vol)

		if err := vol.Create(); err != nil {
			httpError(w, "Could not make new image", err)
			return
		}

		content, err := marshalResponse(VolumeResponse{Mountpoint: vr.Name, Err: ""})
		if err != nil {
			httpError(w, "Could not marshal response", err)
			return
		}

		w.Write(content)
	}
}
コード例 #9
0
ファイル: handlers.go プロジェクト: dockware/volplugin
func unmount(tenantName string, rbdConfig librbd.RBDConfig) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		vr, err := unmarshalRequest(r.Body)
		if err != nil {
			httpError(w, "Could not unmarshal request", err)
			return
		}

		if vr.Name == "" {
			httpError(w, "Name is empty", nil)
			return
		}

		log.Infof("Unmounting volume %q", vr.Name)

		config, err := requestTenantConfig(tenantName, vr.Name)
		if err != nil {
			httpError(w, "Could not determine tenant configuration", err)
			return
		}

		driver, err := cephdriver.NewCephDriver(rbdConfig, config.Pool)
		if err != nil {
			httpError(w, "Error creating ceph driver", err)
			return
		}

		if err := driver.NewVolume(vr.Name, config.Size).Unmount(); err != nil {
			httpError(w, "Could not mount image", err)
			return
		}

		content, err := marshalResponse(VolumeResponse{Mountpoint: driver.MountPath(vr.Name)})
		if err != nil {
			httpError(w, "Reply could not be marshalled", err)
			return
		}

		w.Write(content)
	}
}
コード例 #10
0
ファイル: snapshots.go プロジェクト: hankerepo/volplugin
func runSnapshotPrune(config *config.TopLevelConfig, pool string, volume *config.VolumeConfig) {
	cephVol := cephdriver.NewCephDriver().NewVolume(pool, strings.Join([]string{volume.TenantName, volume.VolumeName}, "."), volume.Options.Size)
	log.Debugf("starting snapshot prune for %q", volume.VolumeName)
	list, err := cephVol.ListSnapshots()
	if err != nil {
		log.Errorf("Could not list snapshots for volume %q", volume)
		return
	}

	toDeleteCount := len(list) - int(volume.Options.Snapshot.Keep)
	if toDeleteCount < 0 {
		return
	}

	for i := 0; i < toDeleteCount; i++ {
		log.Infof("Removing snapshot %q for  volume %q", list[i], volume)
		if err := cephVol.RemoveSnapshot(list[i]); err != nil {
			log.Errorf("Removing snapshot %q for volume %q failed: %v", list[i], volume, err)
		}
	}
}
コード例 #11
0
ファイル: image.go プロジェクト: hankerepo/volplugin
func removeImage(config *config.VolumeConfig) error {
	return cephdriver.NewCephDriver().NewVolume(config.Options.Pool, joinVolumeName(config), 0).Remove()
}
コード例 #12
0
ファイル: handlers.go プロジェクト: hankerepo/volplugin
func unmount(master string) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		vr, err := unmarshalRequest(r.Body)
		if err != nil {
			httpError(w, "Could not unmarshal request", err)
			return
		}

		if vr.Name == "" {
			httpError(w, "Name is empty", nil)
			return
		}

		log.Infof("Unmounting volume %q", vr.Name)

		tenant, name, err := splitPath(vr.Name)
		if err != nil {
			httpError(w, "Configuring volume", err)
			return
		}

		volConfig, err := requestVolumeConfig(master, tenant, name)
		if err != nil {
			httpError(w, "Could not determine tenant configuration", err)
			return
		}

		driver := cephdriver.NewCephDriver()

		if err := driver.NewVolume(volConfig.Options.Pool, joinPath(tenant, name), volConfig.Options.Size).Unmount(); err != nil {
			httpError(w, "Could not unmount image", err)
			return
		}

		hostname, err := os.Hostname()
		if err != nil {
			httpError(w, "Retrieving hostname", err)
			return
		}

		mt := &config.MountConfig{
			Volume:     name,
			MountPoint: driver.MountPath(volConfig.Options.Pool, joinPath(tenant, name)),
			Pool:       volConfig.Options.Pool,
			Host:       hostname,
		}

		if err := reportUnmount(master, mt); err != nil {
			httpError(w, "Reporting unmount to master", err)
			return
		}

		content, err := marshalResponse(VolumeResponse{Mountpoint: driver.MountPath(volConfig.Options.Pool, joinPath(tenant, name))})
		if err != nil {
			httpError(w, "Reply could not be marshalled", err)
			return
		}

		w.Write(content)
	}
}
コード例 #13
0
ファイル: image.go プロジェクト: cloudstrack/volplugin
func createImage(config *config.TenantConfig, pool, name string) error {
	return cephdriver.NewCephDriver().NewVolume(pool, name, config.Size).Create()
}
コード例 #14
0
ファイル: image.go プロジェクト: cloudstrack/volplugin
func removeImage(pool, name string) error {
	return cephdriver.NewCephDriver().NewVolume(pool, name, 0).Remove()
}