當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cephdriver.NewCephDriver函數代碼示例

本文整理匯總了Golang中github.com/contiv/volplugin/cephdriver.NewCephDriver函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewCephDriver函數的具體用法?Golang NewCephDriver怎麽用?Golang NewCephDriver使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewCephDriver函數的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getPath

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)
	}
}
開發者ID:cloudstrack,項目名稱:volplugin,代碼行數:33,代碼來源:handlers.go

示例2: getPath

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)
	}
}
開發者ID:ekuric,項目名稱:volplugin,代碼行數:32,代碼來源:handlers.go

示例3: wrapSnapshotAction

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()
	}
}
開發者ID:dockware,項目名稱:volplugin,代碼行數:29,代碼來源:snapshot_intent.go

示例4: runSnapshot

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)
	}
}
開發者ID:hankerepo,項目名稱:volplugin,代碼行數:8,代碼來源:snapshots.go

示例5: createImage

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
}
開發者ID:ekuric,項目名稱:volplugin,代碼行數:9,代碼來源:image.go

示例6: mount

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)
	}
}
開發者ID:jainvipin,項目名稱:volplugin,代碼行數:56,代碼來源:handlers.go

示例7: createImage

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)
}
開發者ID:hankerepo,項目名稱:volplugin,代碼行數:17,代碼來源:image.go

示例8: create

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)
	}
}
開發者ID:dockware,項目名稱:volplugin,代碼行數:43,代碼來源:handlers.go

示例9: unmount

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)
	}
}
開發者ID:dockware,項目名稱:volplugin,代碼行數:41,代碼來源:handlers.go

示例10: runSnapshotPrune

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)
		}
	}
}
開發者ID:hankerepo,項目名稱:volplugin,代碼行數:21,代碼來源:snapshots.go

示例11: removeImage

func removeImage(config *config.VolumeConfig) error {
	return cephdriver.NewCephDriver().NewVolume(config.Options.Pool, joinVolumeName(config), 0).Remove()
}
開發者ID:hankerepo,項目名稱:volplugin,代碼行數:3,代碼來源:image.go

示例12: unmount

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)
	}
}
開發者ID:hankerepo,項目名稱:volplugin,代碼行數:61,代碼來源:handlers.go

示例13: createImage

func createImage(config *config.TenantConfig, pool, name string) error {
	return cephdriver.NewCephDriver().NewVolume(pool, name, config.Size).Create()
}
開發者ID:cloudstrack,項目名稱:volplugin,代碼行數:3,代碼來源:image.go

示例14: removeImage

func removeImage(pool, name string) error {
	return cephdriver.NewCephDriver().NewVolume(pool, name, 0).Remove()
}
開發者ID:cloudstrack,項目名稱:volplugin,代碼行數:3,代碼來源:image.go


注:本文中的github.com/contiv/volplugin/cephdriver.NewCephDriver函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。