Exemplo n.º 1
0
// Print prints a list of tasks.
func Print(tasks []*api.Task, all bool, res *common.Resolver) {
	w := tabwriter.NewWriter(os.Stdout, 4, 4, 4, ' ', 0)
	defer w.Flush()

	common.PrintHeader(w, "Task ID", "Service", "Slot", "Image", "Desired State", "Last State", "Node")
	sort.Stable(tasksBySlot(tasks))
	for _, t := range tasks {
		if !all && t.DesiredState > api.TaskStateRunning {
			continue
		}
		c := t.Spec.GetContainer()
		fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s %s\t%s\n",
			t.ID,
			t.ServiceAnnotations.Name,
			t.Slot,
			c.Image,
			t.DesiredState.String(),
			t.Status.State.String(),
			common.TimestampAgo(t.Status.Timestamp),
			res.Resolve(api.Node{}, t.NodeID),
		)
	}
}
Exemplo n.º 2
0
				return err
			}
			r, err := c.ListClusters(common.Context(cmd), &api.ListClustersRequest{})
			if err != nil {
				return err
			}

			var output func(j *api.Cluster)

			if !quiet {
				w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
				defer func() {
					// Ignore flushing errors - there's nothing we can do.
					_ = w.Flush()
				}()
				common.PrintHeader(w, "ID", "Name")
				output = func(s *api.Cluster) {
					spec := s.Spec

					fmt.Fprintf(w, "%s\t%s\n",
						s.ID,
						spec.Annotations.Name,
					)
				}

			} else {
				output = func(j *api.Cluster) { fmt.Println(j.ID) }
			}

			for _, j := range r.Clusters {
				output(j)
Exemplo n.º 3
0
					return err
				}

				running := map[string]int{}
				for _, task := range tr.Tasks {
					if task.Status.State == api.TaskStateRunning {
						running[task.ServiceID]++
					}
				}

				w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
				defer func() {
					// Ignore flushing errors - there's nothing we can do.
					_ = w.Flush()
				}()
				common.PrintHeader(w, "ID", "Name", "Image", "Replicas")
				output = func(s *api.Service) {
					spec := s.Spec
					var reference string

					if spec.Task.GetContainer() != nil {
						reference = spec.Task.GetContainer().Image
					}

					fmt.Fprintf(w, "%s\t%s\t%s\t%s\n",
						s.ID,
						spec.Annotations.Name,
						reference,
						getServiceReplicasTxt(s, running[s.ID]),
					)
				}
Exemplo n.º 4
0
			}
			r, err := c.ListTasks(common.Context(cmd), &api.ListTasksRequest{})
			if err != nil {
				return err
			}
			res := common.NewResolver(cmd, c)

			var output func(t *api.Task)

			if !quiet {
				w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
				defer func() {
					// Ignore flushing errors - there's nothing we can do.
					_ = w.Flush()
				}()
				common.PrintHeader(w, "ID", "Service", "Desired State", "Last State", "Node")
				output = func(t *api.Task) {
					fmt.Fprintf(w, "%s\t%s.%d\t%s\t%s %s\t%s\n",
						t.ID,
						res.Resolve(api.Service{}, t.ServiceID),
						t.Slot,
						t.DesiredState.String(),
						t.Status.State.String(),
						common.TimestampAgo(t.Status.Timestamp),
						res.Resolve(api.Node{}, t.NodeID),
					)
				}
			} else {
				output = func(t *api.Task) { fmt.Println(t.ID) }
			}
Exemplo n.º 5
0
				return err
			}
			r, err := c.ListNodes(common.Context(cmd), &api.ListNodesRequest{})
			if err != nil {
				return err
			}

			var output func(n *api.Node)

			if !quiet {
				w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
				defer func() {
					// Ignore flushing errors - there's nothing we can do.
					_ = w.Flush()
				}()
				common.PrintHeader(w, "ID", "Name", "Membership", "Status", "Availability", "Manager Status")
				output = func(n *api.Node) {
					spec := &n.Spec
					name := spec.Annotations.Name
					availability := spec.Availability.String()
					membership := spec.Membership.String()

					if name == "" && n.Description != nil {
						name = n.Description.Hostname
					}
					reachability := ""
					if n.ManagerStatus != nil {
						reachability = n.ManagerStatus.Reachability.String()
						if n.ManagerStatus.Leader {
							reachability = reachability + " *"
						}
Exemplo n.º 6
0
				return err
			}
			r, err := c.ListNetworks(common.Context(cmd), &api.ListNetworksRequest{})
			if err != nil {
				return err
			}

			var output func(*api.Network)

			if !quiet {
				w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
				defer func() {
					// Ignore flushing errors - there's nothing we can do.
					_ = w.Flush()
				}()
				common.PrintHeader(w, "ID", "Name", "Driver")
				output = func(n *api.Network) {
					spec := n.Spec
					fmt.Fprintf(w, "%s\t%s\t%s\n",
						n.ID,
						spec.Annotations.Name,
						n.DriverState.Name,
					)
				}

			} else {
				output = func(n *api.Network) { fmt.Println(n.ID) }
			}

			for _, j := range r.Networks {
				output(j)
Exemplo n.º 7
0
			}

			resp, err := client.ListSecrets(common.Context(cmd), &api.ListSecretsRequest{})
			if err != nil {
				return err
			}

			var output func(*api.Secret)

			if !quiet {
				w := tabwriter.NewWriter(os.Stdout, 0, 4, 4, ' ', 0)
				defer func() {
					// Ignore flushing errors - there's nothing we can do.
					_ = w.Flush()
				}()
				common.PrintHeader(w, "ID", "Name", "Created")
				output = func(s *api.Secret) {
					created, err := gogotypes.TimestampFromProto(s.Meta.CreatedAt)
					if err != nil {
						panic(err)
					}
					fmt.Fprintf(w, "%s\t%s\t%s\n",
						s.ID,
						s.Spec.Annotations.Name,
						humanize.Time(created),
					)
				}

			} else {
				output = func(s *api.Secret) { fmt.Println(s.ID) }
			}