コード例 #1
0
ファイル: refreshtoken.go プロジェクト: elodina/stack-deploy
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
}
コード例 #2
0
ファイル: add_layer.go プロジェクト: elodina/stack-deploy
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
}
コード例 #3
0
ファイル: remove.go プロジェクト: elodina/stack-deploy
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
}
コード例 #4
0
ファイル: adduser.go プロジェクト: elodina/stack-deploy
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
}
コード例 #5
0
ファイル: scheduled.go プロジェクト: elodina/stack-deploy
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
}
コード例 #6
0
ファイル: show.go プロジェクト: elodina/stack-deploy
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
}
コード例 #7
0
ファイル: run.go プロジェクト: elodina/stack-deploy
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
}
コード例 #8
0
ファイル: ping.go プロジェクト: elodina/stack-deploy
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
}
コード例 #9
0
ファイル: list.go プロジェクト: elodina/stack-deploy
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
}