Beispiel #1
0
// Create will create a remote volume
func (driver *Driver) Create(volumeName string) error {
	if volumeName == "" {
		return errors.New("Missing volume name")
	}

	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("", volumeName)
	if err != nil {
		return err
	}

	switch {
	case len(volumes) == 1:
		return nil
	case len(volumes) > 1:
		return errors.New(fmt.Sprintf("Too many volumes returned by name of %s", volumeName))
	}

	volumeType := os.Getenv("REXRAY_DOCKER_VOLUMETYPE")
	IOPSi, _ := strconv.Atoi(os.Getenv("REXRAY_DOCKER_IOPS"))
	IOPS := int64(IOPSi)
	sizei, _ := strconv.Atoi(os.Getenv("REXRAY_DOCKER_SIZE"))
	size := int64(sizei)
	if size == 0 {
		size = defaultVolumeSize
	}
	availabilityZone := os.Getenv("REXRAY_DOCKER_AVAILABILITYZONE")

	_, err = storage.CreateVolume(false, volumeName, "", "", volumeType, IOPS, size, availabilityZone)
	if err != nil {
		return err
	}
	return nil
}
Beispiel #2
0
		if err != nil {
			log.Fatal(err)
		}

	},
}

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

		if size == 0 && snapshotID == "" && volumeID == "" {
			log.Fatalf("missing --size")
		}

		volume, err := storage.CreateVolume(runAsync, volumeName, volumeID, snapshotID, volumeType, IOPS, size, availabilityZone)
		if err != nil {
			log.Fatal(err)
		}

		yamlOutput, err := yaml.Marshal(&volume)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf(string(yamlOutput))

	},
}

var removevolumeCmd = &cobra.Command{
	Use: "remove-volume",