示例#1
0
func (d *driver) VolumeDetach(
	ctx types.Context,
	volumeID string,
	opts *types.VolumeDetachOpts) (*types.Volume, error) {

	context.MustSession(ctx)

	vol, err := d.getVolumeByID(volumeID)
	if err != nil {
		return nil, err
	}

	iid := context.MustInstanceID(ctx)

	y := -1
	for x, att := range vol.Attachments {
		if att.InstanceID.ID == iid.ID {
			y = x
			break
		}
	}

	if y > -1 {
		vol.Attachments = append(vol.Attachments[:y], vol.Attachments[y+1:]...)
		if err := d.writeVolume(vol); err != nil {
			return nil, err
		}
	}

	vol.Attachments = nil
	return vol, nil
}
示例#2
0
func (d *driver) InstanceInspect(
	ctx types.Context,
	opts types.Store) (*types.Instance, error) {

	var err error
	if ctx, err = context.WithStorageSession(ctx); err != nil {
		return nil, err
	}

	context.MustSession(ctx)

	iid := context.MustInstanceID(ctx)
	if iid.ID != "" {
		return &types.Instance{Name: "vfsInstance", InstanceID: iid}, nil
	}

	var hostname string
	if err := iid.UnmarshalMetadata(&hostname); err != nil {
		return nil, err
	}

	return &types.Instance{
		Name: "vfsInstance",
		InstanceID: &types.InstanceID{
			ID:     hostname,
			Driver: iid.Driver,
		},
	}, nil
}
示例#3
0
func (d *driver) SnapshotCopy(
	ctx types.Context,
	snapshotID, snapshotName, destinationID string,
	opts types.Store) (*types.Snapshot, error) {

	context.MustSession(ctx)

	ogSnap, err := d.getSnapshotByID(snapshotID)
	if err != nil {
		return nil, err
	}

	newSnap := &types.Snapshot{
		ID:         d.newSnapshotID(ogSnap.VolumeID),
		VolumeID:   ogSnap.VolumeID,
		VolumeSize: ogSnap.VolumeSize,
		Name:       snapshotName,
		Status:     "online",
		StartTime:  time.Now().Unix(),
		Fields:     ogSnap.Fields,
	}

	if customFields := opts.GetStore("opts"); customFields != nil {
		for _, k := range customFields.Keys() {
			newSnap.Fields[k] = customFields.GetString(k)
		}
	}

	if err := d.writeSnapshot(newSnap); err != nil {
		return nil, err
	}

	return newSnap, nil
}
示例#4
0
func (d *driver) VolumeCopy(
	ctx types.Context,
	volumeID, volumeName string,
	opts types.Store) (*types.Volume, error) {

	context.MustSession(ctx)

	ogVol, err := d.getVolumeByID(volumeID)
	if err != nil {
		return nil, err
	}

	newVol := &types.Volume{
		ID:               d.newVolumeID(),
		Name:             volumeName,
		AvailabilityZone: ogVol.AvailabilityZone,
		IOPS:             ogVol.IOPS,
		Size:             ogVol.Size,
		Type:             ogVol.Type,
		Fields:           ogVol.Fields,
	}

	if customFields := opts.GetStore("opts"); customFields != nil {
		for _, k := range customFields.Keys() {
			newVol.Fields[k] = customFields.GetString(k)
		}
	}

	if err := d.writeVolume(newVol); err != nil {
		return nil, err
	}

	return newVol, nil
}
示例#5
0
func (d *driver) VolumeAttach(
	ctx types.Context,
	volumeID string,
	opts *types.VolumeAttachOpts) (*types.Volume, string, error) {

	context.MustSession(ctx)

	vol, err := d.getVolumeByID(volumeID)
	if err != nil {
		return nil, "", err
	}

	nextDevice := ""
	if opts.NextDevice != nil {
		nextDevice = *opts.NextDevice
	}

	att := &types.VolumeAttachment{
		VolumeID:   vol.ID,
		InstanceID: context.MustInstanceID(ctx),
		DeviceName: nextDevice,
		Status:     "attached",
	}

	vol.Attachments = append(vol.Attachments, att)
	if err := d.writeVolume(vol); err != nil {
		return nil, "", err
	}

	vol.Attachments = []*types.VolumeAttachment{att}

	return vol, nextDevice, nil
}
示例#6
0
func (d *driver) VolumeSnapshot(
	ctx types.Context,
	volumeID, snapshotName string,
	opts types.Store) (*types.Snapshot, error) {

	context.MustSession(ctx)

	v, err := d.getVolumeByID(volumeID)
	if err != nil {
		return nil, err
	}

	s := &types.Snapshot{
		ID:         d.newSnapshotID(v.ID),
		VolumeID:   v.ID,
		VolumeSize: v.Size,
		Name:       snapshotName,
		Status:     "online",
		StartTime:  time.Now().Unix(),
		Fields:     v.Fields,
	}

	if customFields := opts.GetStore("opts"); customFields != nil {
		for _, k := range customFields.Keys() {
			s.Fields[k] = customFields.GetString(k)
		}
	}

	if err := d.writeSnapshot(s); err != nil {
		return nil, err
	}

	return s, nil
}
示例#7
0
func (d *driver) Volumes(
	ctx types.Context,
	opts *types.VolumesOpts) ([]*types.Volume, error) {

	context.MustSession(ctx)

	iid, iidOK := context.InstanceID(ctx)
	if iidOK {
		if iid.ID == "" {
			return nil, goof.New("missing instance ID")
		}
	}

	volJSONPaths, err := d.getVolJSONs()
	if err != nil {
		return nil, err
	}

	volumes := []*types.Volume{}

	for _, volJSONPath := range volJSONPaths {
		v, err := readVolume(volJSONPath)
		if err != nil {
			return nil, err
		}
		if opts.Attachments > 0 {
			v.AttachmentState = 0
		}
		volumes = append(volumes, v)
	}

	return utils.SortVolumeByID(volumes), nil
}
示例#8
0
func (d *driver) SnapshotInspect(
	ctx types.Context,
	snapshotID string,
	opts types.Store) (*types.Snapshot, error) {

	context.MustSession(ctx)

	snap, err := d.getSnapshotByID(snapshotID)
	if err != nil {
		return nil, err
	}
	return snap, nil
}
示例#9
0
func (d *driver) VolumeCreateFromSnapshot(
	ctx types.Context,
	snapshotID, volumeName string,
	opts *types.VolumeCreateOpts) (*types.Volume, error) {

	context.MustSession(ctx)

	snap, err := d.getSnapshotByID(snapshotID)
	if err != nil {
		return nil, err
	}

	ogVol, err := d.getVolumeByID(snap.VolumeID)
	if err != nil {
		return nil, err
	}

	v := &types.Volume{
		ID:               d.newVolumeID(),
		Name:             volumeName,
		Fields:           ogVol.Fields,
		AvailabilityZone: ogVol.AvailabilityZone,
		IOPS:             ogVol.IOPS,
		Size:             ogVol.Size,
		Type:             ogVol.Type,
	}

	if opts.AvailabilityZone != nil {
		v.AvailabilityZone = *opts.AvailabilityZone
	}
	if opts.IOPS != nil {
		v.IOPS = *opts.IOPS
	}
	if opts.Size != nil {
		v.Size = *opts.Size
	}
	if opts.Type != nil {
		v.Type = *opts.Type
	}
	if customFields := opts.Opts.GetStore("opts"); customFields != nil {
		for _, k := range customFields.Keys() {
			v.Fields[k] = customFields.GetString(k)
		}
	}

	if err := d.writeVolume(v); err != nil {
		return nil, err
	}

	return v, nil
}
示例#10
0
func (d *driver) SnapshotRemove(
	ctx types.Context,
	snapshotID string,
	opts types.Store) error {

	context.MustSession(ctx)

	snapJSONPath := d.getSnapPath(snapshotID)
	if !gotil.FileExists(snapJSONPath) {
		return utils.NewNotFoundError(snapshotID)
	}
	os.Remove(snapJSONPath)
	return nil
}
示例#11
0
func (d *driver) VolumeRemove(
	ctx types.Context,
	volumeID string,
	opts types.Store) error {

	context.MustSession(ctx)

	volJSONPath := d.getVolPath(volumeID)
	if !gotil.FileExists(volJSONPath) {
		return utils.NewNotFoundError(volumeID)
	}
	os.Remove(volJSONPath)
	return nil
}
示例#12
0
func (d *driver) VolumeInspect(
	ctx types.Context,
	volumeID string,
	opts *types.VolumeInspectOpts) (*types.Volume, error) {

	context.MustSession(ctx)

	v, err := d.getVolumeByID(volumeID)
	if err != nil {
		return nil, err
	}
	if opts.Attachments > 0 {
		v.AttachmentState = 0
	}
	return v, nil
}
示例#13
0
func (d *driver) Snapshots(
	ctx types.Context,
	opts types.Store) ([]*types.Snapshot, error) {

	context.MustSession(ctx)

	snapJSONPaths, err := d.getSnapJSONs()
	if err != nil {
		return nil, err
	}

	snapshots := []*types.Snapshot{}

	for _, snapJSONPath := range snapJSONPaths {
		s, err := readSnapshot(snapJSONPath)
		if err != nil {
			return nil, err
		}
		snapshots = append(snapshots, s)
	}

	return snapshots, nil
}
示例#14
0
func (d *driver) VolumeCreate(
	ctx types.Context,
	name string,
	opts *types.VolumeCreateOpts) (*types.Volume, error) {

	context.MustSession(ctx)

	v := &types.Volume{
		ID:     d.newVolumeID(),
		Name:   name,
		Fields: map[string]string{},
	}

	if opts.AvailabilityZone != nil {
		v.AvailabilityZone = *opts.AvailabilityZone
	}
	if opts.IOPS != nil {
		v.IOPS = *opts.IOPS
	}
	if opts.Size != nil {
		v.Size = *opts.Size
	}
	if opts.Type != nil {
		v.Type = *opts.Type
	}
	if customFields := opts.Opts.GetStore("opts"); customFields != nil {
		for _, k := range customFields.Keys() {
			v.Fields[k] = customFields.GetString(k)
		}
	}

	if err := d.writeVolume(v); err != nil {
		return nil, err
	}

	return v, nil
}
示例#15
0
func mustSession(ctx types.Context) *awsefs.EFS {
	return context.MustSession(ctx).(*awsefs.EFS)
}
示例#16
0
func mustSession(ctx types.Context) *awsec2.EC2 {
	return context.MustSession(ctx).(*awsec2.EC2)
}