commands

package
v0.28.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2017 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DestroyCommand = cli.Command{
	Name:        "destroy",
	Usage:       "destroy --volume-path <path>",
	Description: "Destroys the qgroup for the given path.",

	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "volume-path",
			Usage: "Path to the volume",
		},
	},

	Action: func(ctx *cli.Context) error {
		logger := lager.NewLogger("drax")
		logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.DEBUG))

		commandRunner := linux_command_runner.New()
		limiter := limiterpkg.NewBtrfsLimiter(ctx.GlobalString("btrfs-bin"), commandRunner)
		err := limiter.DestroyQuotaGroup(logger, ctx.String("volume-path"))
		if err != nil {
			logger.Error("destroying-qgroup", err)
			return cli.NewExitError(err.Error(), 1)
		}

		return nil
	},
}
View Source
var LimitCommand = cli.Command{
	Name:        "limit",
	Usage:       "limit --disk-limit-bytes 102400 --volume-path <path>",
	Description: "Add disk limits to the volume.",

	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "volume-path",
			Usage: "Path to the volume",
		},
		cli.Int64Flag{
			Name:  "disk-limit-bytes",
			Usage: "Disk limit in bytes",
		},
		cli.BoolFlag{
			Name:  "exclude-image-from-quota",
			Usage: "Exclude base image from disk quota",
		},
	},

	Action: func(ctx *cli.Context) error {
		logger := lager.NewLogger("drax")
		logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.DEBUG))

		commandRunner := linux_command_runner.New()
		limiter := limiterpkg.NewBtrfsLimiter(ctx.GlobalString("btrfs-bin"), commandRunner)
		err := limiter.ApplyDiskLimit(
			logger,
			ctx.String("volume-path"),
			ctx.Int64("disk-limit-bytes"),
			ctx.Bool("exclude-image-from-quota"),
		)
		if err != nil {
			logger.Error("applying-limit-failed", err)
			return cli.NewExitError(err.Error(), 1)
		}

		return nil
	},
}
View Source
var ListCommand = cli.Command{
	Name:        "list",
	Usage:       "list <path>",
	Description: "List btrfs subvolumes inside the path",

	Flags: []cli.Flag{},

	Action: func(ctx *cli.Context) error {
		logger := lager.NewLogger("drax")
		logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.DEBUG))

		if len(ctx.Args()) != 1 {
			return cli.NewExitError("missing path argument", 1)
		}

		commandRunner := linux_command_runner.New()
		lister := lister.NewBtrfsLister(ctx.GlobalString("btrfs-bin"), commandRunner)
		volumes, err := lister.List(logger, ctx.Args()[0])
		if err != nil {
			logger.Error("listing-volumes", err)
			return cli.NewExitError(err.Error(), 1)
		}

		if _, err := os.Stdout.WriteString(strings.Join(volumes, "\n")); err != nil {
			logger.Error("encoding-stats", err)
			return cli.NewExitError(err.Error(), 1)
		}

		return nil
	},
}
View Source
var StatsCommand = cli.Command{
	Name:        "stats",
	Usage:       "stats --volume-path <path> [--force-sync]",
	Description: "Get stats for a volume",

	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "volume-path",
			Usage: "Path to the volume",
		},
		cli.BoolFlag{
			Name:  "force-sync",
			Usage: "Force BTRFS to update stats immediately",
		},
	},

	Action: func(ctx *cli.Context) error {
		logger := lager.NewLogger("drax")
		logger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.DEBUG))

		commandRunner := linux_command_runner.New()
		metrix := metrix.NewBtrfsStats(ctx.GlobalString("btrfs-bin"), commandRunner)
		stats, err := metrix.VolumeStats(
			logger,
			ctx.String("volume-path"),
			ctx.Bool("force-sync"),
		)

		if err != nil {
			logger.Error("fetching-volume-stats", err)
			return cli.NewExitError(err.Error(), 1)
		}

		if _, err := os.Stdout.Write(stats); err != nil {
			logger.Error("encoding-stats", err)
			return cli.NewExitError(err.Error(), 1)
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL