本文整理汇总了Golang中github.com/rancher/convoy/util.ObjectLoad函数的典型用法代码示例。如果您正苦于以下问题:Golang ObjectLoad函数的具体用法?Golang ObjectLoad怎么用?Golang ObjectLoad使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectLoad函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetVolumeInfo
func (d *Driver) GetVolumeInfo(id string) (map[string]string, error) {
d.mutex.Lock()
defer d.mutex.Unlock()
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return nil, err
}
ebsVolume, err := d.ebsService.GetVolume(volume.EBSID)
if err != nil {
return nil, err
}
iops := ""
if ebsVolume.Iops != nil {
iops = strconv.FormatInt(*ebsVolume.Iops, 10)
}
info := map[string]string{
"Device": volume.Device,
"MountPoint": volume.MountPoint,
"UUID": volume.UUID,
"EBSVolumeID": volume.EBSID,
"AvailiablityZone": *ebsVolume.AvailabilityZone,
"CreatedTime": (*ebsVolume.CreateTime).Format(time.RubyDate),
"Size": strconv.FormatInt(*ebsVolume.Size*GB, 10),
"State": *ebsVolume.State,
"Type": *ebsVolume.VolumeType,
"IOPS": iops,
}
return info, nil
}
示例2: GetVolumeInfo
func (d *Driver) GetVolumeInfo(id string) (map[string]string, error) {
d.mutex.RLock()
defer d.mutex.RUnlock()
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return nil, err
}
gVolume := d.gVolumes[volume.VolumePool]
if gVolume == nil {
return nil, fmt.Errorf("Cannot find volume pool %v", volume.VolumePool)
}
size := "-1"
prepareForVM := strconv.FormatBool(volume.PrepareForVM)
if volume.PrepareForVM {
size = strconv.FormatInt(volume.Size, 10)
}
return map[string]string{
OPT_VOLUME_NAME: volume.Name,
"Path": volume.Path,
OPT_MOUNT_POINT: volume.MountPoint,
OPT_SIZE: size,
OPT_PREPARE_FOR_VM: prepareForVM,
OPT_VOLUME_CREATED_TIME: volume.CreatedTime,
"GlusterFSVolume": volume.VolumePool,
"GlusterFSServers": fmt.Sprintf("%v", gVolume.Servers),
}, nil
}
示例3: CreateSnapshot
func (d *Driver) CreateSnapshot(req Request) error {
d.mutex.Lock()
defer d.mutex.Unlock()
id := req.Name
volumeID, err := util.GetFieldFromOpts(OPT_VOLUME_NAME, req.Options)
if err != nil {
return err
}
volume := d.blankVolume(volumeID)
if err := util.ObjectLoad(volume); err != nil {
return err
}
if _, exists := volume.Snapshots[id]; exists {
return fmt.Errorf("Snapshot %v already exists for volume %v", id, volumeID)
}
snapFile := d.getSnapshotFilePath(id, volumeID)
if err := util.MkdirIfNotExists(filepath.Dir(snapFile)); err != nil {
return err
}
if err := util.CompressDir(volume.Path, snapFile); err != nil {
return err
}
volume.Snapshots[id] = Snapshot{
Name: id,
CreatedTime: util.Now(),
VolumeUUID: volumeID,
FilePath: snapFile,
}
return util.ObjectSave(volume)
}
示例4: CreateSnapshot
func (d *Driver) CreateSnapshot(id, volumeID string) error {
d.mutex.Lock()
defer d.mutex.Unlock()
volume := d.blankVolume(volumeID)
if err := util.ObjectLoad(volume); err != nil {
return err
}
if _, exists := volume.Snapshots[id]; exists {
return fmt.Errorf("Snapshot %v already exists for volume %v", id, volumeID)
}
snapFile := d.getSnapshotFilePath(id, volumeID)
if err := util.MkdirIfNotExists(filepath.Dir(snapFile)); err != nil {
return err
}
if err := util.CompressDir(volume.Path, snapFile); err != nil {
return err
}
volume.Snapshots[id] = Snapshot{
UUID: id,
VolumeUUID: volumeID,
FilePath: snapFile,
}
return util.ObjectSave(volume)
}
示例5: ListSnapshot
func (d *Driver) ListSnapshot(opts map[string]string) (map[string]map[string]string, error) {
var (
volumeIDs []string
err error
)
d.mutex.RLock()
defer d.mutex.RUnlock()
snapshots := make(map[string]map[string]string)
specifiedVolumeID, _ := util.GetFieldFromOpts(OPT_VOLUME_NAME, opts)
if specifiedVolumeID != "" {
volumeIDs = []string{
specifiedVolumeID,
}
} else {
volumeIDs, err = d.listVolumeNames()
if err != nil {
return nil, err
}
}
for _, volumeID := range volumeIDs {
volume := d.blankVolume(volumeID)
if err := util.ObjectLoad(volume); err != nil {
return nil, err
}
for snapshotID := range volume.Snapshots {
snapshots[snapshotID], err = d.getSnapshotInfo(snapshotID, volumeID)
if err != nil {
return nil, err
}
}
}
return snapshots, nil
}
示例6: MountVolume
func (d *Driver) MountVolume(id string, opts map[string]string) (string, error) {
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return "", err
}
dev, err := d.GetVolumeDevice(id)
if err != nil {
return "", err
}
specifiedPoint := opts[convoydriver.OPT_MOUNT_POINT]
mountPoint, err := d.getVolumeMountPoint(id, specifiedPoint)
if err != nil {
return "", err
}
if volume.MountPoint != "" && volume.MountPoint != mountPoint {
return "", fmt.Errorf("volume %v already mounted at %v, but asked to mount at %v", id, volume.MountPoint, mountPoint)
}
if !mounted(dev, mountPoint) {
log.Debugf("Volume %v is not mounted, mount it now to %v", id, mountPoint)
_, err = util.Execute(MOUNT_BINARY, []string{dev, mountPoint})
if err != nil {
return "", err
}
}
volume.MountPoint = mountPoint
if err := util.ObjectSave(volume); err != nil {
return "", err
}
return mountPoint, nil
}
示例7: deactivatePool
func (d *Driver) deactivatePool() error {
dev := d.Device
volumeIDs, err := dev.listVolumeIDs()
if err != nil {
return err
}
for _, id := range volumeIDs {
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return err
}
if err := d.removeDevice(id); err != nil {
return err
}
log.WithFields(logrus.Fields{
LOG_FIELD_EVENT: LOG_EVENT_ACTIVATE,
LOG_FIELD_VOLUME: id,
}).Debug("Deactivated volume device")
}
if err := removePool(dev.ThinpoolDevice); err != nil {
return err
}
log.Debug("Deactivate the pool ", dev.ThinpoolDevice)
return nil
}
示例8: MountPoint
func (d *Driver) MountPoint(id string) (string, error) {
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return "", err
}
return volume.MountPoint, nil
}
示例9: MountVolume
func (d *Driver) MountVolume(id string, opts map[string]string) (string, error) {
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return "", err
}
if err := volume.Stack(d).MoveController(); err != nil {
log.Errorf("Failed to move controller to %s", d.containerName)
return "", err
}
mountPoint, err := util.VolumeMount(volume, opts[convoydriver.OPT_MOUNT_POINT], false)
if err != nil {
return "", err
}
if volume.PrepareForVM {
if err := util.MountPointPrepareImageFile(mountPoint, volume.Size); err != nil {
return "", err
}
}
if err := util.ObjectSave(volume); err != nil {
return "", err
}
return mountPoint, nil
}
示例10: ListSnapshot
func (d *Driver) ListSnapshot(opts map[string]string) (map[string]map[string]string, error) {
var (
volumeIDs []string
err error
)
snapshots := make(map[string]map[string]string)
specifiedVolumeID := opts["VolumeID"]
if specifiedVolumeID != "" {
volumeIDs = []string{
specifiedVolumeID,
}
} else {
volumeIDs, err = d.listVolumeIDs()
if err != nil {
return nil, err
}
}
for _, volumeID := range volumeIDs {
volume := d.blankVolume(volumeID)
if err := util.ObjectLoad(volume); err != nil {
return nil, err
}
for snapshotID := range volume.Snapshots {
snapshots[snapshotID], err = d.GetSnapshotInfo(snapshotID, volumeID)
if err != nil {
return nil, err
}
}
}
return snapshots, nil
}
示例11: DeleteVolume
func (d *Driver) DeleteVolume(req Request) error {
d.mutex.Lock()
defer d.mutex.Unlock()
id := req.Name
opts := req.Options
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return err
}
if volume.MountPoint != "" {
return fmt.Errorf("Cannot delete volume %v. It is still mounted", id)
}
referenceOnly, _ := strconv.ParseBool(opts[OPT_REFERENCE_ONLY])
if !referenceOnly {
log.Debugf("Cleaning up volume %v", id)
gVolume := d.gVolumes[d.DefaultVolumePool]
if err := util.VolumeMountPointDirectoryRemove(gVolume, volume.Name); err != nil {
return err
}
}
return util.ObjectDelete(volume)
}
示例12: MountVolume
func (d *Driver) MountVolume(req Request) (string, error) {
d.mutex.Lock()
defer d.mutex.Unlock()
id := req.Name
opts := req.Options
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return "", err
}
specifiedPoint := opts[OPT_MOUNT_POINT]
if specifiedPoint != "" {
return "", fmt.Errorf("GlusterFS doesn't support specified mount point")
}
if volume.MountPoint == "" {
volume.MountPoint = volume.Path
}
if volume.PrepareForVM {
if err := util.MountPointPrepareImageFile(volume.MountPoint, volume.Size); err != nil {
return "", err
}
}
if err := util.ObjectSave(volume); err != nil {
return "", err
}
return volume.MountPoint, nil
}
示例13: DeleteVolume
func (d *Driver) DeleteVolume(id string, opts map[string]string) error {
d.mutex.Lock()
defer d.mutex.Unlock()
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return err
}
referenceOnly, _ := strconv.ParseBool(opts[convoydriver.OPT_REFERENCE_ONLY])
if err := d.ebsService.DetachVolume(volume.EBSID); err != nil {
if !referenceOnly {
return err
}
//Ignore the error, remove the reference
log.Warnf("Unable to detached %v(%v) due to %v, but continue with removing the reference",
id, volume.EBSID, err)
} else {
log.Debugf("Detached %v(%v) from %v", id, volume.EBSID, volume.Device)
}
if !referenceOnly {
if err := d.ebsService.DeleteVolume(volume.EBSID); err != nil {
return err
}
log.Debugf("Deleted %v(%v)", id, volume.EBSID)
}
return util.ObjectDelete(volume)
}
示例14: MountVolume
func (d *Driver) MountVolume(id string, opts map[string]string) (string, error) {
d.mutex.Lock()
defer d.mutex.Unlock()
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return "", err
}
specifiedPoint := opts[convoydriver.OPT_MOUNT_POINT]
if specifiedPoint != "" {
return "", fmt.Errorf("VFS doesn't support specified mount point")
}
if volume.MountPoint == "" {
volume.MountPoint = volume.Path
}
if volume.PrepareForVM {
if err := util.MountPointPrepareImageFile(volume.MountPoint, volume.Size); err != nil {
return "", err
}
}
if err := util.ObjectSave(volume); err != nil {
return "", err
}
return volume.MountPoint, nil
}
示例15: GetVolumeDevice
func (d *Driver) GetVolumeDevice(id string) (string, error) {
volume := d.blankVolume(id)
if err := util.ObjectLoad(volume); err != nil {
return "", err
}
return filepath.Join(DM_DIR, id), nil
}