Exemplo n.º 1
0
// TenantUpload uploads a Tenant intent from stdin.
func TenantUpload(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		errExit(ctx, fmt.Errorf("Invalid arguments"), true)
	}

	cfg, err := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	if err != nil {
		errExit(ctx, err, false)
	}

	content, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		errExit(ctx, err, false)
	}

	tenant := &config.TenantConfig{}

	if err := json.Unmarshal(content, tenant); err != nil {
		errExit(ctx, err, false)
	}

	if err := cfg.PublishTenant(ctx.Args()[0], tenant); err != nil {
		errExit(ctx, err, false)
	}
}
Exemplo n.º 2
0
// TenantGet retrieves tenant configuration, the name of which is supplied as
// an argument.
func TenantGet(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		errExit(ctx, fmt.Errorf("Invalid arguments"), true)
	}

	tenant := ctx.Args()[0]

	cfg := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	value, err := cfg.GetTenant(tenant)
	if err != nil {
		errExit(ctx, err, false)
	}

	// The following lines pretty-print the json by re-evaluating it. This is
	// purely a nicety for the CLI and is not necessary to use the tool.
	tenantObj := &config.TenantConfig{}

	if err := json.Unmarshal([]byte(value), tenantObj); err != nil {
		errExit(ctx, err, false)
	}

	content, err := ppJSON(tenantObj)
	if err != nil {
		errExit(ctx, err, false)
	}

	fmt.Println(string(content))
}
Exemplo n.º 3
0
// MountForceRemove deletes the mount entry from etcd; useful for clearing a
// stale mount.
func MountForceRemove(ctx *cli.Context) {
	if len(ctx.Args()) != 2 {
		errExit(ctx, fmt.Errorf("Invalid arguments"), true)
	}

	cfg := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	if err := cfg.RemoveMount(&config.MountConfig{Pool: ctx.Args()[0], Volume: ctx.Args()[1]}); err != nil {
		errExit(ctx, err, false)
	}
}
Exemplo n.º 4
0
func start(ctx *cli.Context) {
	if ctx.Bool("debug") {
		log.SetLevel(log.DebugLevel)
		log.Debug("Debug logging enabled")
	}

	cfg := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))

	daemon(cfg, ctx.Bool("debug"), ctx.String("listen"))
}
Exemplo n.º 5
0
// MountList returns a list of the mounts the volmaster knows about.
func MountList(ctx *cli.Context) {
	cfg := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	mounts, err := cfg.ListMounts()
	if err != nil {
		errExit(ctx, err, false)
	}

	for _, name := range mounts {
		fmt.Println(name)
	}
}
Exemplo n.º 6
0
// VolumeListAll returns a list of the pools the volmaster knows about.
func VolumeListAll(ctx *cli.Context) {
	cfg := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	pools, err := cfg.ListAllVolumes()
	if err != nil {
		errExit(ctx, err, false)
	}

	for _, name := range pools {
		fmt.Println(name)
	}
}
Exemplo n.º 7
0
func start(ctx *cli.Context) {
	if ctx.Bool("debug") {
		log.SetLevel(log.DebugLevel)
		log.Debug("Debug logging enabled")
	}

	cfg, err := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	if err != nil {
		log.Fatal(err)
	}

	volsupervisor.Daemon(cfg)
}
Exemplo n.º 8
0
// TenantDelete removes a tenant supplied as an argument.
func TenantDelete(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		errExit(ctx, fmt.Errorf("Invalid arguments"), true)
	}

	tenant := ctx.Args()[0]

	cfg := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	if err := cfg.DeleteTenant(tenant); err != nil {
		errExit(ctx, err, false)
	}

	fmt.Printf("%q removed!\n", tenant)
}
Exemplo n.º 9
0
// VolumeForceRemove removes a volume forcefully.
func VolumeForceRemove(ctx *cli.Context) {
	if len(ctx.Args()) != 2 {
		errExit(ctx, fmt.Errorf("Invalid arguments"), true)
	}

	cfg, err := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	if err != nil {
		errExit(ctx, err, false)
	}

	if err := cfg.RemoveVolume(ctx.Args()[0], ctx.Args()[1]); err != nil {
		errExit(ctx, err, false)
	}
}
Exemplo n.º 10
0
// TenantList provides a list of the tenant names.
func TenantList(ctx *cli.Context) {
	if len(ctx.Args()) != 0 {
		errExit(ctx, fmt.Errorf("Invalid arguments"), true)
	}

	cfg := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	tenants, err := cfg.ListTenants()
	if err != nil {
		errExit(ctx, err, false)
	}

	for _, tenant := range tenants {
		fmt.Println(path.Base(tenant))
	}
}
Exemplo n.º 11
0
// VolumeList prints the list of volumes for a pool.
func VolumeList(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		errExit(ctx, fmt.Errorf("Invalid arguments"), true)
	}

	cfg := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	vols, err := cfg.ListVolumes(ctx.Args()[0])
	if err != nil {
		errExit(ctx, err, false)
	}

	for name := range vols {
		fmt.Println(name)
	}
}
Exemplo n.º 12
0
// MountGet retrieves the JSON information for a mount.
func MountGet(ctx *cli.Context) {
	if len(ctx.Args()) != 2 {
		errExit(ctx, fmt.Errorf("Invalid arguments"), true)
	}

	cfg := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	mount, err := cfg.GetMount(ctx.Args()[0], ctx.Args()[1])
	if err != nil {
		errExit(ctx, err, false)
	}

	content, err := ppJSON(mount)
	if err != nil {
		errExit(ctx, err, false)
	}

	fmt.Println(string(content))
}
Exemplo n.º 13
0
// TenantGet retrieves tenant configuration, the name of which is supplied as
// an argument.
func TenantGet(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		errExit(ctx, fmt.Errorf("Invalid arguments"), true)
	}

	tenant := ctx.Args()[0]

	cfg := config.NewTopLevelConfig(ctx.String("prefix"), ctx.StringSlice("etcd"))
	value, err := cfg.GetTenant(tenant)
	if err != nil {
		errExit(ctx, err, false)
	}

	content, err := ppJSON(value)
	if err != nil {
		errExit(ctx, err, false)
	}

	fmt.Println(string(content))
}