Exemple #1
0
func removeVolume(cmd *cobra.Command, args []string, out io.Writer) error {
	dvol := api.NewDvolAPI(dvolAPIOptions)
	err := checkVolumeArgs(args)
	if err != nil {
		return err
	}
	volumeName := args[0]
	if !api.ValidName(volumeName) {
		return fmt.Errorf("Error: " + volumeName + " is not a valid name")
	}
	if !dvol.VolumeExists(volumeName) {
		msg := fmt.Sprintf("Volume '%s' does not exist, cannot remove it", volumeName)
		return fmt.Errorf(msg)
	}
	if forceRemoveVolume || userIsSure("This will remove all containers using the volume") {
		s := fmt.Sprintf("Deleting volume '%s'", volumeName)
		fmt.Fprintln(out, s)
		err = dvol.RemoveVolume(volumeName)
		if err != nil {
			return fmt.Errorf("Error removing volume")
		}
	} else {
		fmt.Fprintln(out, "Aborting.")
	}
	return nil
}
Exemple #2
0
func switchVolume(cmd *cobra.Command, args []string, out io.Writer) error {
	dvol := api.NewDvolAPI(dvolAPIOptions)
	err := checkVolumeArgs(args)
	if err != nil {
		return err
	}
	volumeName := args[0]
	if !api.ValidName(volumeName) {
		return fmt.Errorf("Error: " + volumeName + " is not a valid name")
	}
	if !dvol.VolumeExists(volumeName) {
		return fmt.Errorf("Error: " + volumeName + " does not exist")
	}
	err = dvol.SwitchVolume(volumeName)
	if err != nil {
		return fmt.Errorf("Error switching volume")
	}
	return nil
}
Exemple #3
0
func initVolume(cmd *cobra.Command, args []string, out io.Writer) error {
	dvol := api.NewDvolAPI(dvolAPIOptions)
	err := checkVolumeArgs(args)
	if err != nil {
		return err
	}
	volumeName := args[0]
	if !api.ValidName(volumeName) {
		return fmt.Errorf("Error: " + volumeName + " is not a valid name")
	}
	if dvol.VolumeExists(volumeName) {
		return fmt.Errorf("Error: volume " + volumeName + " already exists")
	}
	err = dvol.CreateVolume(volumeName)
	if err != nil {
		return fmt.Errorf("Error creating volume")
	}
	fmt.Fprintln(out, "Created volume", volumeName)
	fmt.Fprintf(out, "Created branch %s/%s\n", volumeName, api.DEFAULT_BRANCH)
	return nil
}