Ejemplo n.º 1
0
func DescribeDeployment(remote config.Remote, id string) (prettycli.Output, error) {
	c := DefaultAgentClientFactory.New(remote)
	desc, err := c.DescribeDeployment(id)
	if err != nil {
		return prettycli.PlainOutput{}, err
	}

	do := prettycli.DetailOutput{
		Details: map[string]string{
			"Name":         desc.Name,
			"ID":           strconv.Itoa(desc.ID),
			"Redeployable": strconv.FormatBool(desc.Redeployable),
		},
		Order: []string{"ID", "Name", "Redeployable"},
	}

	lo := prettycli.ListOutput{Labels: []string{"ID", "State"}}
	for _, s := range desc.Status.Services {
		lo.AddRow(map[string]string{
			"ID":    s.ID,
			"State": s.ActualState,
		})
	}

	co := prettycli.CombinedOutput{}
	co.AddOutput("", do)
	co.AddOutput("Services", lo)
	return &co, nil
}
Ejemplo n.º 2
0
func List(options Options) (prettycli.Output, error) {

	endpoint, err := endpointFactory(options.EndpointOptions)
	if err != nil {
		return nil, err
	}

	output := prettycli.ListOutput{
		Labels: []string{"Active", "ID", "Deploy Date", "Services", "Message"},
	}

	reqs, err := collectRequests(options, true)
	if err != nil {
		return nil, err
	}

	// Get most recent deployment's manifests
	manifests, err := getDeploymentManifests(reqs, endpoint)
	if err != nil {
		return nil, err
	}

	// Iterate backwards from most recent mani to oldest
	for i := len(manifests) - 1; i >= 0; i-- {
		mani := manifests[i]
		var serviceList []string
		for _, svc := range mani.Services {
			serviceList = append(serviceList, svc.Name)
		}

		var isActive string
		if i == (len(manifests) - 1) {
			isActive = "*"
		}

		output.AddRow(map[string]string{
			"Active":      isActive,
			"ID":          strconv.Itoa(i + 1),
			"Deploy Date": mani.DeployedAt,
			"Services":    strings.Join(serviceList, ", "),
			"Message":     truncate(mani.Message, 72),
		})
	}

	return output, nil
}
Ejemplo n.º 3
0
func ListRemotes(config config.Config) prettycli.Output {
	agents := config.Remotes()
	if len(agents) == 0 {
		return prettycli.PlainOutput{"No remotes"}
	}

	output := prettycli.ListOutput{Labels: []string{"Active", "Name", "Endpoint"}}
	for _, r := range config.Remotes() {
		activeMarker := ""
		if config.Active() != nil && *config.Active() == r {
			activeMarker = "*"
		}

		output.AddRow(map[string]string{
			"Active":   activeMarker,
			"Name":     r.Name,
			"Endpoint": r.Endpoint,
		})
	}
	return &output
}
Ejemplo n.º 4
0
func ListDeployments(remote config.Remote) (prettycli.Output, error) {
	c := DefaultAgentClientFactory.New(remote)
	deps, err := c.ListDeployments()
	if err != nil {
		return prettycli.PlainOutput{}, err
	}

	if len(deps) == 0 {
		return prettycli.PlainOutput{"No Deployments"}, nil
	}

	o := prettycli.ListOutput{Labels: []string{"ID", "Name", "Services"}}
	for _, d := range deps {
		o.AddRow(map[string]string{
			"ID":       strconv.Itoa(d.ID),
			"Name":     d.Name,
			"Services": strconv.Itoa(len(d.ServiceIDs)),
		})
	}

	return &o, nil
}