本文整理汇总了Golang中github.com/docker/docker/api/client.NodeInspectWithRaw函数的典型用法代码示例。如果您正苦于以下问题:Golang NodeInspectWithRaw函数的具体用法?Golang NodeInspectWithRaw怎么用?Golang NodeInspectWithRaw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NodeInspectWithRaw函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runJoin
func runJoin(dockerCli *client.DockerCli, opts joinOptions) error {
client := dockerCli.Client()
ctx := context.Background()
req := swarm.JoinRequest{
JoinToken: opts.token,
ListenAddr: opts.listenAddr.String(),
RemoteAddrs: []string{opts.remote},
}
err := client.SwarmJoin(ctx, req)
if err != nil {
return err
}
info, err := client.Info(ctx)
if err != nil {
return err
}
_, _, err = client.NodeInspectWithRaw(ctx, info.Swarm.NodeID)
if err != nil {
// TODO(aaronl): is there a better way to do this?
if strings.Contains(err.Error(), "This node is not a swarm manager.") {
fmt.Fprintln(dockerCli.Out(), "This node joined a swarm as a worker.")
}
} else {
fmt.Fprintln(dockerCli.Out(), "This node joined a swarm as a manager.")
}
return nil
}
示例2: runTasks
func runTasks(dockerCli *client.DockerCli, opts tasksOptions) error {
client := dockerCli.Client()
ctx := context.Background()
nodeRef, err := nodeReference(client, ctx, opts.nodeID)
if err != nil {
return nil
}
node, _, err := client.NodeInspectWithRaw(ctx, nodeRef)
if err != nil {
return err
}
filter := opts.filter.Value()
filter.Add("node", node.ID)
if !opts.all && !filter.Include("desired-state") {
filter.Add("desired-state", string(swarm.TaskStateRunning))
filter.Add("desired-state", string(swarm.TaskStateAccepted))
}
tasks, err := client.TaskList(
ctx,
types.TaskListOptions{Filter: filter})
if err != nil {
return err
}
return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve))
}
示例3: updateNodes
func updateNodes(dockerCli *client.DockerCli, nodes []string, mergeNode func(node *swarm.Node) error, success func(nodeID string)) error {
client := dockerCli.Client()
ctx := context.Background()
for _, nodeID := range nodes {
node, _, err := client.NodeInspectWithRaw(ctx, nodeID)
if err != nil {
return err
}
err = mergeNode(&node)
if err != nil {
if err == errNoRoleChange {
continue
}
return err
}
err = client.NodeUpdate(ctx, node.ID, node.Version, node.Spec)
if err != nil {
return err
}
success(nodeID)
}
return nil
}
示例4: printJoinCommand
func printJoinCommand(ctx context.Context, dockerCli *client.DockerCli, nodeID string, worker bool, manager bool) error {
client := dockerCli.Client()
swarm, err := client.SwarmInspect(ctx)
if err != nil {
return err
}
node, _, err := client.NodeInspectWithRaw(ctx, nodeID)
if err != nil {
return err
}
if node.ManagerStatus != nil {
if worker {
fmt.Fprintf(dockerCli.Out(), "To add a worker to this swarm, run the following command:\n docker swarm join \\\n --token %s \\\n %s\n", swarm.JoinTokens.Worker, node.ManagerStatus.Addr)
}
if manager {
if worker {
fmt.Fprintln(dockerCli.Out())
}
fmt.Fprintf(dockerCli.Out(), "To add a manager to this swarm, run the following command:\n docker swarm join \\\n --token %s \\\n %s\n", swarm.JoinTokens.Manager, node.ManagerStatus.Addr)
}
}
return nil
}
示例5: runInspect
func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
client := dockerCli.Client()
ctx := context.Background()
getRef := func(ref string) (interface{}, []byte, error) {
nodeRef, err := Reference(client, ctx, ref)
if err != nil {
return nil, nil, err
}
node, _, err := client.NodeInspectWithRaw(ctx, nodeRef)
return node, nil, err
}
if !opts.pretty {
return inspect.Inspect(dockerCli.Out(), opts.nodeIds, opts.format, getRef)
}
return printHumanFriendly(dockerCli.Out(), opts.nodeIds, getRef)
}
示例6: runInit
func runInit(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts initOptions) error {
client := dockerCli.Client()
ctx := context.Background()
// If no secret was specified, we create a random one
if !flags.Changed("secret") {
opts.secret = generateRandomSecret()
fmt.Fprintf(dockerCli.Out(), "No --secret provided. Generated random secret:\n\t%s\n\n", opts.secret)
}
req := swarm.InitRequest{
ListenAddr: opts.listenAddr.String(),
ForceNewCluster: opts.forceNewCluster,
Spec: opts.swarmOptions.ToSpec(),
}
nodeID, err := client.SwarmInit(ctx, req)
if err != nil {
return err
}
fmt.Fprintf(dockerCli.Out(), "Swarm initialized: current node (%s) is now a manager.\n\n", nodeID)
// Fetch CAHash and Address from the API
info, err := client.Info(ctx)
if err != nil {
return err
}
node, _, err := client.NodeInspectWithRaw(ctx, nodeID)
if err != nil {
return err
}
if node.ManagerStatus != nil && info.Swarm.CACertHash != "" {
var secretArgs string
if opts.secret != "" {
secretArgs = "--secret " + opts.secret
}
fmt.Fprintf(dockerCli.Out(), "To add a worker to this swarm, run the following command:\n\tdocker swarm join %s \\\n\t--ca-hash %s \\\n\t%s\n", secretArgs, info.Swarm.CACertHash, node.ManagerStatus.Addr)
}
return nil
}
示例7: runPs
func runPs(dockerCli *client.DockerCli, opts psOptions) error {
client := dockerCli.Client()
ctx := context.Background()
nodeRef, err := Reference(ctx, client, opts.nodeID)
if err != nil {
return nil
}
node, _, err := client.NodeInspectWithRaw(ctx, nodeRef)
if err != nil {
return err
}
filter := opts.filter.Value()
filter.Add("node", node.ID)
tasks, err := client.TaskList(
ctx,
types.TaskListOptions{Filter: filter})
if err != nil {
return err
}
return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), opts.noTrunc)
}