commands

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2016 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreateCommand = cli.Command{
	Name:        "create",
	Usage:       "create [options] <image> <id>",
	Description: "Creates a root filesystem for the provided image.",

	Flags: []cli.Flag{
		cli.Int64Flag{
			Name:  "disk-limit-size-bytes",
			Usage: "Inclusive disk limit (i.e: includes all layers in the filesystem)",
		},
		cli.StringSliceFlag{
			Name:  "uid-mapping",
			Usage: "UID mapping for image translation, e.g.: <Namespace UID>:<Host UID>:<Size>",
		},
		cli.StringSliceFlag{
			Name:  "gid-mapping",
			Usage: "GID mapping for image translation, e.g.: <Namespace UID>:<Host UID>:<Size>",
		},
		cli.StringSliceFlag{
			Name:  "insecure-registry",
			Usage: "Whitelist a private registry",
		},
		cli.BoolFlag{
			Name:  "exclude-image-from-quota",
			Usage: "Set disk limit to be exclusive (i.e.: exluding image layers)",
		},
	},

	Action: func(ctx *cli.Context) error {
		logger := ctx.App.Metadata["logger"].(lager.Logger)
		logger = logger.Session("create")

		if ctx.NArg() != 2 {
			logger.Error("parsing-command", errors.New("invalid arguments"), lager.Data{"args": ctx.Args()})
			return cli.NewExitError(fmt.Sprintf("invalid arguments - usage: %s", ctx.Command.Usage), 1)
		}

		storePath := ctx.GlobalString("store")
		image := ctx.Args().First()
		id := ctx.Args().Tail()[0]

		diskLimit := ctx.Int64("disk-limit-size-bytes")
		if diskLimit < 0 {
			err := errors.New("invalid argument: disk limit cannot be negative")
			logger.Error("parsing-command", err)
			return cli.NewExitError(err.Error(), 1)
		}

		uidMappings, err := parseIDMappings(ctx.StringSlice("uid-mapping"))
		if err != nil {
			err = fmt.Errorf("parsing uid-mapping: %s", err)
			logger.Error("parsing-command", err)
			return cli.NewExitError(err.Error(), 1)
		}
		gidMappings, err := parseIDMappings(ctx.StringSlice("gid-mapping"))
		if err != nil {
			err = fmt.Errorf("parsing gid-mapping: %s", err)
			logger.Error("parsing-command", err)
			return cli.NewExitError(err.Error(), 1)
		}

		btrfsVolumeDriver := volume_driver.NewBtrfs(ctx.GlobalString("drax-bin"), storePath)
		bundler := storepkg.NewBundler(btrfsVolumeDriver, storePath)

		runner := linux_command_runner.New()
		idMapper := unpackerpkg.NewIDMapper(runner)
		namespacedCmdUnpacker := unpackerpkg.NewNamespacedUnpacker(runner, idMapper)

		trustedRegistries := ctx.StringSlice("insecure-registry")
		dockerSrc := remote.NewDockerSource(trustedRegistries)

		cacheDriver := cache_driver.NewCacheDriver(storePath)
		remoteFetcher := remote.NewRemoteFetcher(dockerSrc, cacheDriver)

		localFetcher := local.NewLocalFetcher()

		locksmith := locksmithpkg.NewFileSystem(storePath)
		imgPuller := image_puller.NewImagePuller(localFetcher, remoteFetcher, namespacedCmdUnpacker, btrfsVolumeDriver)
		groot := grootpkg.IamGroot(bundler, imgPuller, locksmith)

		bundle, err := groot.Create(logger, grootpkg.CreateSpec{
			ID:                    id,
			Image:                 image,
			DiskLimit:             diskLimit,
			ExcludeImageFromQuota: ctx.Bool("exclude-image-from-quota"),
			UIDMappings:           uidMappings,
			GIDMappings:           gidMappings,
		})
		if err != nil {
			logger.Error("creating", err)

			humanizedError := tryHumanize(err)
			return cli.NewExitError(humanizedError, 1)
		}

		fmt.Println(bundle.Path())
		return nil
	},
}
View Source
var DeleteCommand = cli.Command{
	Name:        "delete",
	Usage:       "delete <id>",
	Description: "Deletes a container bundle",

	Action: func(ctx *cli.Context) error {
		logger := ctx.App.Metadata["logger"].(lager.Logger)
		logger = logger.Session("delete")

		storePath := ctx.GlobalString("store")
		if ctx.NArg() != 1 {
			logger.Error("parsing-command", errors.New("id was not specified"))
			return cli.NewExitError("id was not specified", 1)
		}
		id := ctx.Args().First()

		btrfsVolumeDriver := volume_driver.NewBtrfs(ctx.GlobalString("drax-bin"), storePath)

		bundler := store.NewBundler(btrfsVolumeDriver, storePath)
		groot := grootpkg.IamGroot(bundler, nil, nil)

		err := groot.Delete(logger, id)
		if err != nil {
			logger.Error("deleting-bundle-failed", err)
			return cli.NewExitError(err.Error(), 1)
		}

		fmt.Printf("Bundle %s deleted\n", id)
		return nil
	},
}
View Source
var MetricsCommand = cli.Command{
	Name:        "metrics",
	Usage:       "metrics [options] <id>",
	Description: "Return filesystem metrics",

	Action: func(ctx *cli.Context) error {
		logger := ctx.App.Metadata["logger"].(lager.Logger)
		logger = logger.Session("metrics")

		if ctx.NArg() != 1 {
			logger.Error("parsing-command", errors.New("invalid arguments"), lager.Data{"args": ctx.Args()})
			return cli.NewExitError(fmt.Sprintf("invalid arguments - usage: %s", ctx.Command.Usage), 1)
		}

		storePath := ctx.GlobalString("store")
		id := ctx.Args().First()

		btrfsVolumeDriver := volume_driver.NewBtrfs(ctx.GlobalString("drax-bin"), storePath)
		bundler := storepkg.NewBundler(btrfsVolumeDriver, storePath)

		groot := grootpkg.IamGroot(bundler, nil, nil)
		metrics, err := groot.Metrics(logger, id)
		if err != nil {
			logger.Error("fetching-metrics", err)
			return cli.NewExitError(err.Error(), 1)
		}

		json.NewEncoder(os.Stdout).Encode(metrics)
		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