Ejemplo n.º 1
0
// Unmount will perform the steps to unmount and existing volume and detach
func (driver *Driver) Unmount(volumeName, volumeID string) error {
	if volumeName == "" && volumeID == "" {
		return errors.New("Missing volume name or ID")
	}

	instances, err := storage.GetInstance()
	if err != nil {
		return err
	}

	switch {
	case len(instances) == 0:
		return errors.New("No instances")
	case len(instances) > 1:
		return errors.New("Too many instances returned, limit the storagedrivers")
	}

	volumes, err := storage.GetVolume(volumeID, volumeName)
	if err != nil {
		return err
	}

	switch {
	case len(volumes) == 0:
		return errors.New("No volumes returned by name")
	case len(volumes) > 1:
		return errors.New("Multiple volumes returned by name")
	}

	volumeAttachment, err := storage.GetVolumeAttach(volumes[0].VolumeID, instances[0].InstanceID)
	if err != nil {
		return err
	}

	if len(volumeAttachment) == 0 {
		return nil
	}

	mounts, err := rros.GetMounts(volumeAttachment[0].DeviceName, "")
	if err != nil {
		return err
	}

	if len(mounts) == 0 {
		return nil
	}

	err = rros.Unmount(mounts[0].Mountpoint)
	if err != nil {
		return err
	}

	err = storage.DetachVolume(false, volumes[0].VolumeID, "")
	if err != nil {
		return err
	}
	return nil

}
Ejemplo n.º 2
0
// Remove will remove a remote volume
func (driver *Driver) Detach(volumeName, instanceID string) error {
	volume, err := storage.GetVolume("", volumeName)
	if err != nil {
		return err
	}

	return storage.DetachVolume(true, volume[0].VolumeID, instanceID)
}
Ejemplo n.º 3
0
			log.Fatal(err)
		}
		fmt.Printf(string(yamlOutput))

	},
}

var detachvolumeCmd = &cobra.Command{
	Use: "detach-volume",
	Run: func(cmd *cobra.Command, args []string) {

		if volumeID == "" {
			log.Fatalf("missing --volumeid")
		}

		err := storage.DetachVolume(runAsync, volumeID, instanceID)
		if err != nil {
			log.Fatal(err)
		}

	},
}

var copysnapshotCmd = &cobra.Command{
	Use: "copy-snapshot",
	Run: func(cmd *cobra.Command, args []string) {

		if snapshotID == "" && volumeID == "" && volumeName == "" {
			log.Fatalf("missing --volumeid or --snapshotid or --volumename")
		}