Esempio n. 1
0
func (*RefreshTokenCommand) Run(args []string) int {
	var (
		flags  = flag.NewFlagSet("refreshtoken", flag.ExitOnError)
		apiUrl = flags.String("api", "", "Stack-deploy server address.")
		name   = flags.String("name", "", "New user name")
	)
	flags.Parse(args)

	stackDeployApi, err := resolveApi(*apiUrl)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}

	client := api.NewClient(stackDeployApi)
	key, err := client.RefreshToken(&api.RefreshTokenRequest{
		Name: *name,
	})
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}

	fmt.Printf("New key generated: %s\n", key)
	return 0
}
Esempio n. 2
0
func (asc *AddLayerCommand) Run(args []string) int {
	var (
		flags     = flag.NewFlagSet("add", flag.ExitOnError)
		apiUrl    = flags.String("api", "", "Stack-deploy server address.")
		stackFile = flags.String("file", "Stackfile", "Stackfile with Application Configs")
		level     = flags.String("level", "zone", "zone|cluster|datacenter")
		parent    = flags.String("parent", "", "Parent layer")
	)
	flags.Parse(args)

	stackDeployApi, err := resolveApi(*apiUrl)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}

	client := api.NewClient(stackDeployApi)
	stack, err := ioutil.ReadFile(*stackFile)
	if err != nil {
		fmt.Printf("Can't read file %s\n", *stackFile)
		return 1
	}
	err = client.CreateLayer(&api.CreateLayerRequest{
		Stackfile: string(stack),
		Layer:     *level,
		Parent:    *parent,
	})
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}

	fmt.Println("Stack added")
	return 0
}
Esempio n. 3
0
func (rsc *RemoveStackCommand) Run(args []string) int {
	if len(args) == 0 {
		fmt.Println("Stack name required to remove")
		return 1
	}

	var (
		flags  = flag.NewFlagSet("remove", flag.ExitOnError)
		apiUrl = flags.String("api", "", "Stack-deploy server address.")
		force  = flags.Bool("force", false, "Flag to force delete the stack with all children.")
	)
	flags.Parse(args[1:])

	name := args[0]

	stackDeployApi, err := resolveApi(*apiUrl)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}
	client := api.NewClient(stackDeployApi)

	fmt.Printf("Removing stack %s\n", name)
	err = client.RemoveStack(&api.RemoveStackRequest{
		Name:  name,
		Force: *force,
	})
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}

	fmt.Println("Stack removed")
	return 0
}
Esempio n. 4
0
func (auc *AddUserCommand) Run(args []string) int {
	var (
		flags  = flag.NewFlagSet("adduser", flag.ExitOnError)
		apiUrl = flags.String("api", "", "Stack-deploy server address.")
		name   = flags.String("name", "", "New user name")
		admin  = flags.Bool("admin", false, "Create admin")
	)
	flags.Parse(args)

	stackDeployApi, err := resolveApi(*apiUrl)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}

	client := api.NewClient(stackDeployApi)

	role := "regular"
	if *admin {
		role = "admin"
	}
	key, err := client.CreateUser(&api.CreateUserRequest{
		Name: *name,
		Role: role,
	})
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}

	fmt.Printf("User added. Key: %s\n", key)
	return 0
}
Esempio n. 5
0
func (*ScheduledCommand) Run(args []string) int {
	var (
		flags  = flag.NewFlagSet("scheduled", flag.ExitOnError)
		apiUrl = flags.String("api", "", "Stack-deploy server address.")
		remove = flags.Int64("remove", -1, "Remove scheduled task ID")
	)
	flags.Parse(args)

	stackDeployApi, err := resolveApi(*apiUrl)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}

	client := api.NewClient(stackDeployApi)
	if *remove == -1 {
		tasks, err := client.Scheduled()
		if err != nil {
			fmt.Printf("ERROR: %s\n", err)
			return 1
		}
		for _, task := range tasks {
			fmt.Printf("[%d] %s\n\tstart: '%s'\n\tschedule: '%s'\n", task.ID, task.Name, task.StartTime, task.TimeSchedule)
		}
		return 0
	}
	resp, err := client.RemoveScheduled(&api.RemoveScheduledRequest{ID: *remove})
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}
	fmt.Println(resp)
	return 0
}
Esempio n. 6
0
func (sc *ShowCommand) Run(args []string) int {
	if len(args) == 0 {
		fmt.Println("Stack name required to show")
		return 1
	}

	var (
		flags  = flag.NewFlagSet("run", flag.ExitOnError)
		apiUrl = flags.String("api", "", "Stack-deploy server address.")
	)
	flags.Parse(args[1:])

	name := args[0]

	stackDeployApi, err := resolveApi(*apiUrl)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}
	client := api.NewClient(stackDeployApi)

	stack, err := client.GetStack(&api.GetStackRequest{
		Name: name,
	})
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}

	fmt.Println(stack)
	return 0
}
Esempio n. 7
0
func (rc *RunCommand) Run(args []string) int {
	if len(args) == 0 {
		fmt.Println("Stack name required to run")
		return 1
	}

	var (
		flags            = flag.NewFlagSet("run", flag.ExitOnError)
		apiUrl           = flags.String("api", "", "Stack-deploy server address.")
		zone             = flags.String("zone", "", "Zone to run stack.")
		maxWait          = flags.Int("max.wait", defaultApplicationMaxWait, "Maximum time to wait for each application in a stack to become running and healthy.")
		variables        = make(vars)
		skipApplications = make(skipApplications, 0)
	)
	flags.Var(variables, "var", "Arbitrary variables to add to stack context. Multiple occurrences of this flag allowed.")
	flags.Var(&skipApplications, "skip", "Regular expression of applications to skip in stack. Multiple occurrences of this flag allowed.")
	flags.Parse(args[1:])

	name := args[0]
	stackDeployApi, err := resolveApi(*apiUrl)
	if err != nil {
		fmt.Printf("ERROR resolving API: %s\n", err)
		return 1
	}
	client := api.NewClient(stackDeployApi)

	fmt.Printf("Running stack %s\n", name)
	start := time.Now()
	err = client.Run(&api.RunRequest{
		Name:             name,
		Zone:             *zone,
		MaxWait:          *maxWait,
		Variables:        variables,
		SkipApplications: skipApplications,
	})
	if err != nil {
		fmt.Printf("ERROR running client request: %s\n", err)
		return 1
	}

	elapsed := time.Since(start)
	fmt.Printf("Done in %s\n", elapsed-elapsed%time.Second)
	return 0
}
Esempio n. 8
0
func (*PingCommand) Run(args []string) int {
	var (
		flags  = flag.NewFlagSet("ping", flag.ExitOnError)
		apiUrl = flags.String("api", "", "Stack-deploy server address.")
	)
	flags.Parse(args)

	stackDeployApi, err := resolveApi(*apiUrl)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}

	client := api.NewClient(stackDeployApi)
	err = client.Ping()
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}
	return 0
}
Esempio n. 9
0
func (lc *ListCommand) Run(args []string) int {
	var (
		flags  = flag.NewFlagSet("run", flag.ExitOnError)
		apiUrl = flags.String("api", "", "Stack-deploy server address.")
	)
	flags.Parse(args)

	stackDeployApi, err := resolveApi(*apiUrl)
	if err != nil {
		fmt.Printf("ERROR: %s\n", err)
		return 1
	}

	client := api.NewClient(stackDeployApi)

	stacks, err := client.List()
	if err != nil {
		fmt.Printf("ERROR getting list: %s\n", err)
		return 1
	}

	fmt.Println(strings.Join(stacks, "\n"))
	return 0
}