Beispiel #1
0
func printTaskSummary(task *api.Task, res *common.Resolver) {
	w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
	defer w.Flush()

	fmt.Fprintf(w, "ID\t: %s\n", task.ID)
	fmt.Fprintf(w, "Slot\t: %d\n", task.Slot)
	fmt.Fprintf(w, "Service\t: %s\n", res.Resolve(api.Service{}, task.ServiceID))
	printTaskStatus(w, task)
	fmt.Fprintf(w, "Node\t: %s\n", res.Resolve(api.Node{}, task.NodeID))

	fmt.Fprintln(w, "Spec\t")
	ctr := task.Spec.GetContainer()
	common.FprintfIfNotEmpty(w, "  Image\t: %s\n", ctr.Image)
	common.FprintfIfNotEmpty(w, "  Command\t: %q\n", strings.Join(ctr.Command, " "))
	common.FprintfIfNotEmpty(w, "  Args\t: [%s]\n", strings.Join(ctr.Args, ", "))
	common.FprintfIfNotEmpty(w, "  Env\t: [%s]\n", strings.Join(ctr.Env, ", "))
	if len(ctr.Secrets) > 0 {
		fmt.Fprintln(w, "  Secrets:")
		for _, sr := range ctr.Secrets {
			var targetName, mode string
			if sr.GetFile() != nil {
				targetName = sr.GetFile().Name
				mode = "FILE"
			}
			fmt.Fprintf(w, "    [%s] %s:%s\n", mode, sr.SecretName, targetName)
		}
	}
}
Beispiel #2
0
func printClusterSummary(cluster *api.Cluster) {
	w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
	defer w.Flush()

	common.FprintfIfNotEmpty(w, "ID\t: %s\n", cluster.ID)
	common.FprintfIfNotEmpty(w, "Name\t: %s\n", cluster.Spec.Annotations.Name)
	if len(cluster.Spec.AcceptancePolicy.Policies) > 0 {
		fmt.Fprintf(w, "Acceptance Policies:\n")
		for _, policy := range cluster.Spec.AcceptancePolicy.Policies {
			fmt.Fprintf(w, "  Role\t: %v\n", policy.Role)
			fmt.Fprintf(w, "    Autoaccept\t: %v\n", policy.Autoaccept)
			if policy.Secret != nil {
				fmt.Fprintf(w, "    Secret\t: %v\n", string(policy.Secret.Data))
			}
		}
	}
	fmt.Fprintf(w, "Orchestration settings:\n")
	fmt.Fprintf(w, "  Task history entries: %d\n", cluster.Spec.Orchestration.TaskHistoryRetentionLimit)
	fmt.Fprintf(w, "Dispatcher settings:\n")
	fmt.Fprintf(w, "  Dispatcher heartbeat period: %d\n", cluster.Spec.Dispatcher.HeartbeatPeriod)
	if cluster.Spec.CAConfig.NodeCertExpiry != nil {
		fmt.Fprintf(w, "Certificate Authority settings:\n")
		clusterDuration, err := ptypes.Duration(cluster.Spec.CAConfig.NodeCertExpiry)
		if err != nil {
			fmt.Fprintf(w, "  Certificate Validity Duration: [ERROR PARSING DURATION]\n")
		} else {
			fmt.Fprintf(w, "  Certificate Validity Duration: %s\n", clusterDuration.String())
		}
	}
}
Beispiel #3
0
func printClusterSummary(cluster *api.Cluster) {
	w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
	defer w.Flush()

	common.FprintfIfNotEmpty(w, "ID\t: %s\n", cluster.ID)
	common.FprintfIfNotEmpty(w, "Name\t: %s\n", cluster.Spec.Annotations.Name)
	fmt.Fprintf(w, "Orchestration settings:\n")
	fmt.Fprintf(w, "  Task history entries: %d\n", cluster.Spec.Orchestration.TaskHistoryRetentionLimit)

	heartbeatPeriod, err := ptypes.Duration(cluster.Spec.Dispatcher.HeartbeatPeriod)
	if err == nil {
		fmt.Fprintf(w, "Dispatcher settings:\n")
		fmt.Fprintf(w, "  Dispatcher heartbeat period: %s\n", heartbeatPeriod.String())
	}

	fmt.Fprintf(w, "Certificate Authority settings:\n")
	if cluster.Spec.CAConfig.NodeCertExpiry != nil {
		clusterDuration, err := ptypes.Duration(cluster.Spec.CAConfig.NodeCertExpiry)
		if err != nil {
			fmt.Fprintf(w, "  Certificate Validity Duration: [ERROR PARSING DURATION]\n")
		} else {
			fmt.Fprintf(w, "  Certificate Validity Duration: %s\n", clusterDuration.String())
		}
	}
	if len(cluster.Spec.CAConfig.ExternalCAs) > 0 {
		fmt.Fprintf(w, "  External CAs:\n")
		for _, ca := range cluster.Spec.CAConfig.ExternalCAs {
			fmt.Fprintf(w, "    %s: %s\n", ca.Protocol, ca.URL)
		}
	}

	fmt.Fprintln(w, "  Join Tokens:")
	fmt.Fprintln(w, "    Worker:", cluster.RootCA.JoinTokens.Worker)
	fmt.Fprintln(w, "    Manager:", cluster.RootCA.JoinTokens.Manager)

	if cluster.Spec.TaskDefaults.LogDriver != nil {
		fmt.Fprintf(w, "Default Log Driver\t: %s\n", cluster.Spec.TaskDefaults.LogDriver.Name)
		var keys []string

		if len(cluster.Spec.TaskDefaults.LogDriver.Options) != 0 {
			for k := range cluster.Spec.TaskDefaults.LogDriver.Options {
				keys = append(keys, k)
			}
			sort.Strings(keys)

			for _, k := range keys {
				v := cluster.Spec.TaskDefaults.LogDriver.Options[k]
				if v != "" {
					fmt.Fprintf(w, "  %s\t: %s\n", k, v)
				} else {
					fmt.Fprintf(w, "  %s\t\n", k)

				}
			}
		}
	}
}
Beispiel #4
0
func printSecretSummary(secret *api.Secret) {
	w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
	defer w.Flush()

	common.FprintfIfNotEmpty(w, "ID\t: %s\n", secret.ID)
	common.FprintfIfNotEmpty(w, "Name\t: %s\n", secret.Spec.Annotations.Name)
	if len(secret.Spec.Annotations.Labels) > 0 {
		fmt.Fprintln(w, "Labels\t")
		for k, v := range secret.Spec.Annotations.Labels {
			fmt.Fprintf(w, "  %s\t: %s\n", k, v)
		}
	}

	common.FprintfIfNotEmpty(w, "Created\t: %s\n", ptypes.TimestampString(secret.Meta.CreatedAt))
}
Beispiel #5
0
func printTaskSummary(task *api.Task, res *common.Resolver) {
	w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
	defer w.Flush()

	fmt.Fprintf(w, "ID\t: %s\n", task.ID)
	fmt.Fprintf(w, "Slot\t: %d\n", task.Slot)
	fmt.Fprintf(w, "Service\t: %s\n", res.Resolve(api.Service{}, task.ServiceID))
	printTaskStatus(w, task)
	fmt.Fprintf(w, "Node\t: %s\n", res.Resolve(api.Node{}, task.NodeID))

	fmt.Fprintln(w, "Spec\t")
	ctr := task.Spec.GetContainer()
	common.FprintfIfNotEmpty(w, "  Image\t: %s\n", ctr.Image)
	common.FprintfIfNotEmpty(w, "  Command\t: %q\n", strings.Join(ctr.Command, " "))
	common.FprintfIfNotEmpty(w, "  Args\t: [%s]\n", strings.Join(ctr.Args, ", "))
	common.FprintfIfNotEmpty(w, "  Env\t: [%s]\n", strings.Join(ctr.Env, ", "))
}
Beispiel #6
0
func printNodeSummary(node *api.Node) {
	w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
	defer func() {
		// Ignore flushing errors - there's nothing we can do.
		_ = w.Flush()
	}()
	spec := &node.Spec
	desc := node.Description
	if desc == nil {
		desc = &api.NodeDescription{}
	}
	common.FprintfIfNotEmpty(w, "ID\t: %s\n", node.ID)
	common.FprintfIfNotEmpty(w, "Name\t: %s\n", spec.Annotations.Name)
	if node.Description != nil {
		common.FprintfIfNotEmpty(w, "Hostname\t: %s\n", node.Description.Hostname)
	}
	fmt.Fprintln(w, "Status:\t")
	common.FprintfIfNotEmpty(w, "  State\t: %s\n", node.Status.State.String())
	common.FprintfIfNotEmpty(w, "  Message\t: %s\n", node.Status.Message)
	common.FprintfIfNotEmpty(w, "  Availability\t: %s\n", spec.Availability.String())

	if node.ManagerStatus != nil {
		fmt.Fprintln(w, "Manager status:\t")
		common.FprintfIfNotEmpty(w, "  Address\t: %s\n", node.ManagerStatus.Addr)
		common.FprintfIfNotEmpty(w, "  Raft status\t: %s\n", node.ManagerStatus.Reachability.String())
		leader := "no"
		if node.ManagerStatus.Leader {
			leader = "yes"
		}
		common.FprintfIfNotEmpty(w, "  Leader\t: %s\n", leader)
	}

	if desc.Platform != nil {
		fmt.Fprintln(w, "Platform:\t")
		common.FprintfIfNotEmpty(w, "  Operating System\t: %s\n", desc.Platform.OS)
		common.FprintfIfNotEmpty(w, "  Architecture\t: %s\n", desc.Platform.Architecture)
	}

	if desc.Resources != nil {
		fmt.Fprintln(w, "Resources:\t")
		fmt.Fprintf(w, "  CPUs\t: %d\n", desc.Resources.NanoCPUs/1e9)
		fmt.Fprintf(w, "  Memory\t: %s\n", humanize.IBytes(uint64(desc.Resources.MemoryBytes)))
	}

	if desc.Engine != nil {
		fmt.Fprintln(w, "Plugins:\t")
		var pluginTypes []string
		pluginNamesByType := map[string][]string{}
		for _, p := range desc.Engine.Plugins {
			// append to pluginTypes only if not done previously
			if _, ok := pluginNamesByType[p.Type]; !ok {
				pluginTypes = append(pluginTypes, p.Type)
			}
			pluginNamesByType[p.Type] = append(pluginNamesByType[p.Type], p.Name)
		}

		sort.Strings(pluginTypes) // ensure stable output
		for _, pluginType := range pluginTypes {
			fmt.Fprintf(w, "  %s\t: %v\n", pluginType, pluginNamesByType[pluginType])
		}
	}

	if desc.Engine != nil {
		common.FprintfIfNotEmpty(w, "Engine Version\t: %s\n", desc.Engine.EngineVersion)

		if len(desc.Engine.Labels) != 0 {
			fmt.Fprintln(w, "Engine Labels:\t")
			for k, v := range desc.Engine.Labels {
				fmt.Fprintf(w, "  %s = %s", k, v)
			}
		}
	}
}
Beispiel #7
0
func printServiceSummary(service *api.Service, running int) {
	w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
	defer w.Flush()

	task := service.Spec.Task
	common.FprintfIfNotEmpty(w, "ID\t: %s\n", service.ID)
	common.FprintfIfNotEmpty(w, "Name\t: %s\n", service.Spec.Annotations.Name)
	if len(service.Spec.Annotations.Labels) > 0 {
		fmt.Fprintln(w, "Labels\t")
		for k, v := range service.Spec.Annotations.Labels {
			fmt.Fprintf(w, "  %s\t: %s\n", k, v)
		}
	}
	common.FprintfIfNotEmpty(w, "Replicas\t: %s\n", getServiceReplicasTxt(service, running))

	if service.UpdateStatus != nil {
		fmt.Fprintln(w, "Update Status\t")
		fmt.Fprintln(w, " State\t:", service.UpdateStatus.State)
		started, err := gogotypes.TimestampFromProto(service.UpdateStatus.StartedAt)
		if err == nil {
			fmt.Fprintln(w, " Started\t:", humanize.Time(started))
		}
		if service.UpdateStatus.State == api.UpdateStatus_COMPLETED {
			completed, err := gogotypes.TimestampFromProto(service.UpdateStatus.CompletedAt)
			if err == nil {
				fmt.Fprintln(w, " Completed\t:", humanize.Time(completed))
			}
		}
		fmt.Fprintln(w, " Message\t:", service.UpdateStatus.Message)
	}

	fmt.Fprintln(w, "Template\t")
	fmt.Fprintln(w, " Container\t")
	ctr := service.Spec.Task.GetContainer()
	common.FprintfIfNotEmpty(w, "  Image\t: %s\n", ctr.Image)
	common.FprintfIfNotEmpty(w, "  Command\t: %q\n", strings.Join(ctr.Command, " "))
	common.FprintfIfNotEmpty(w, "  Args\t: [%s]\n", strings.Join(ctr.Args, ", "))
	common.FprintfIfNotEmpty(w, "  Env\t: [%s]\n", strings.Join(ctr.Env, ", "))
	if task.Placement != nil {
		common.FprintfIfNotEmpty(w, "  Constraints\t: %s\n", strings.Join(task.Placement.Constraints, ", "))
	}

	if task.Resources != nil {
		res := task.Resources
		fmt.Fprintln(w, "  Resources\t")
		printResources := func(w io.Writer, r *api.Resources) {
			if r.NanoCPUs != 0 {
				fmt.Fprintf(w, "      CPU\t: %g\n", float64(r.NanoCPUs)/1e9)
			}
			if r.MemoryBytes != 0 {
				fmt.Fprintf(w, "      Memory\t: %s\n", humanize.IBytes(uint64(r.MemoryBytes)))
			}
		}
		if res.Reservations != nil {
			fmt.Fprintln(w, "    Reservations:\t")
			printResources(w, res.Reservations)
		}
		if res.Limits != nil {
			fmt.Fprintln(w, "    Limits:\t")
			printResources(w, res.Limits)
		}
	}
	if len(service.Spec.Task.Networks) > 0 {
		fmt.Fprintf(w, "  Networks:\t")
		for _, n := range service.Spec.Task.Networks {
			fmt.Fprintf(w, " %s", n.Target)
		}
	}

	if service.Endpoint != nil && len(service.Endpoint.Ports) > 0 {
		fmt.Fprintln(w, "\nPorts:")
		for _, port := range service.Endpoint.Ports {
			fmt.Fprintf(w, "    - Name\t= %s\n", port.Name)
			fmt.Fprintf(w, "      Protocol\t= %s\n", port.Protocol)
			fmt.Fprintf(w, "      Port\t= %d\n", port.TargetPort)
			fmt.Fprintf(w, "      SwarmPort\t= %d\n", port.PublishedPort)
		}
	}

	if len(ctr.Mounts) > 0 {
		fmt.Fprintln(w, "  Mounts:")
		for _, v := range ctr.Mounts {
			fmt.Fprintf(w, "    - target = %s\n", v.Target)
			fmt.Fprintf(w, "      source = %s\n", v.Source)
			fmt.Fprintf(w, "      readonly = %v\n", v.ReadOnly)
			fmt.Fprintf(w, "      type = %v\n", strings.ToLower(v.Type.String()))
		}
	}

	if len(ctr.Secrets) > 0 {
		fmt.Fprintln(w, "  Secrets:")
		for _, sr := range ctr.Secrets {
			var targetName, mode string
			if sr.GetFile() != nil {
				targetName = sr.GetFile().Name
				mode = "FILE"
			}
			fmt.Fprintf(w, "    [%s] %s@%s:%s\n", mode, sr.SecretName, sr.SecretID, targetName)
		}
	}

	if task.LogDriver != nil {
		fmt.Fprintf(w, "  LogDriver\t: %s\n", task.LogDriver.Name)
		var keys []string

		if task.LogDriver.Options != nil {
			for k := range task.LogDriver.Options {
				keys = append(keys, k)
			}
			sort.Strings(keys)

			for _, k := range keys {
				v := task.LogDriver.Options[k]
				if v != "" {
					fmt.Fprintf(w, "    %s\t: %s\n", k, v)
				} else {
					fmt.Fprintf(w, "    %s\t\n", k)

				}
			}
		}
	}
}
Beispiel #8
0
func printNetworkSummary(network *api.Network) {
	w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
	defer func() {
		// Ignore flushing errors - there's nothing we can do.
		_ = w.Flush()
	}()

	spec := &network.Spec
	common.FprintfIfNotEmpty(w, "ID\t: %s\n", network.ID)
	common.FprintfIfNotEmpty(w, "Name\t: %s\n", spec.Annotations.Name)

	fmt.Fprintln(w, "Spec:\t")
	if len(spec.Annotations.Labels) > 0 {
		fmt.Fprintln(w, "  Labels:\t")
		for k, v := range spec.Annotations.Labels {
			fmt.Fprintf(w, "    %s = %s\n", k, v)
		}
	}
	fmt.Fprintf(w, "  IPv6Enabled\t: %t\n", spec.Ipv6Enabled)
	fmt.Fprintf(w, "  Internal\t: %t\n", spec.Internal)

	driver := network.DriverState
	if driver != nil {
		fmt.Fprintln(w, "Driver:\t")
		common.FprintfIfNotEmpty(w, "  Name\t: %s\n", driver.Name)
		if len(driver.Options) > 0 {
			fmt.Fprintln(w, "  Options:\t")
			for k, v := range driver.Options {
				fmt.Fprintf(w, "    %s = %s\n", k, v)
			}
		}
	}

	ipam := network.IPAM
	if ipam != nil {
		fmt.Fprintln(w, "IPAM:\t")
		if ipam.Driver != nil {
			fmt.Fprintln(w, "  Driver:\t")
			common.FprintfIfNotEmpty(w, "    Name\t: %s\n", ipam.Driver.Name)
			if len(ipam.Driver.Options) > 0 {
				fmt.Fprintln(w, "    Options:\t")
				for k, v := range ipam.Driver.Options {
					fmt.Fprintf(w, "      %s = %s\n", k, v)
				}
			}
		}

		if len(ipam.Configs) > 0 {
			for _, config := range ipam.Configs {
				fmt.Fprintln(w, "  IPAM Config:\t")
				common.FprintfIfNotEmpty(w, "    Family\t: %s\n", config.Family.String())
				common.FprintfIfNotEmpty(w, "    Subnt\t: %s\n", config.Subnet)
				common.FprintfIfNotEmpty(w, "    Range\t: %s\n", config.Range)
				common.FprintfIfNotEmpty(w, "    Range\t: %s\n", config.Range)
				common.FprintfIfNotEmpty(w, "    Gateway\t: %s\n", config.Gateway)
				if len(config.Reserved) > 0 {
					fmt.Fprintln(w, "    Reserved:\t")
					for k, v := range config.Reserved {
						fmt.Fprintf(w, "      %s = %s\n", k, v)
					}
				}
			}
		}
	}
}
Beispiel #9
0
func printServiceSummary(service *api.Service, running int) {
	w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
	defer w.Flush()

	task := service.Spec.Task
	common.FprintfIfNotEmpty(w, "ID\t: %s\n", service.ID)
	common.FprintfIfNotEmpty(w, "Name\t: %s\n", service.Spec.Annotations.Name)
	if len(service.Spec.Annotations.Labels) > 0 {
		fmt.Fprintln(w, "Labels\t")
		for k, v := range service.Spec.Annotations.Labels {
			fmt.Fprintf(w, "  %s\t: %s\n", k, v)
		}
	}
	common.FprintfIfNotEmpty(w, "Replicas\t: %s\n", getServiceReplicasTxt(service, running))
	fmt.Fprintln(w, "Template\t")
	fmt.Fprintln(w, " Container\t")
	ctr := service.Spec.Task.GetContainer()
	common.FprintfIfNotEmpty(w, "  Image\t: %s\n", ctr.Image)
	common.FprintfIfNotEmpty(w, "  Command\t: %q\n", strings.Join(ctr.Command, " "))
	common.FprintfIfNotEmpty(w, "  Args\t: [%s]\n", strings.Join(ctr.Args, ", "))
	common.FprintfIfNotEmpty(w, "  Env\t: [%s]\n", strings.Join(ctr.Env, ", "))
	if task.Placement != nil {
		common.FprintfIfNotEmpty(w, "  Constraints\t: %s\n", strings.Join(task.Placement.Constraints, ", "))
	}

	if task.Resources != nil {
		res := task.Resources
		fmt.Fprintln(w, "  Resources\t")
		printResources := func(w io.Writer, r *api.Resources) {
			if r.NanoCPUs != 0 {
				fmt.Fprintf(w, "      CPU\t: %g\n", float64(r.NanoCPUs)/1e9)
			}
			if r.MemoryBytes != 0 {
				fmt.Fprintf(w, "      Memory\t: %s\n", humanize.IBytes(uint64(r.MemoryBytes)))
			}
		}
		if res.Reservations != nil {
			fmt.Fprintln(w, "    Reservations:\t")
			printResources(w, res.Reservations)
		}
		if res.Limits != nil {
			fmt.Fprintln(w, "    Limits:\t")
			printResources(w, res.Limits)
		}
	}
	if len(service.Spec.Networks) > 0 {
		fmt.Fprintf(w, "  Networks:\t")
		for _, n := range service.Spec.Networks {
			fmt.Fprintf(w, " %s", n.Target)
		}
	}

	if service.Endpoint != nil && len(service.Endpoint.Ports) > 0 {
		fmt.Fprintln(w, "\nPorts:")
		for _, port := range service.Endpoint.Ports {
			fmt.Fprintf(w, "    - Name\t= %s\n", port.Name)
			fmt.Fprintf(w, "      Protocol\t= %s\n", port.Protocol)
			fmt.Fprintf(w, "      Port\t= %d\n", port.TargetPort)
			fmt.Fprintf(w, "      SwarmPort\t= %d\n", port.PublishedPort)
		}
	}

	if len(ctr.Mounts) > 0 {
		fmt.Fprintln(w, "  Mounts:")
		for _, v := range ctr.Mounts {
			fmt.Fprintf(w, "    - target = %s\n", v.Target)
			fmt.Fprintf(w, "      source = %s\n", v.Source)
			fmt.Fprintf(w, "      writable = %v\n", v.Writable)
			fmt.Fprintf(w, "      type = %v\n", strings.ToLower(v.Type.String()))
		}
	}
}