...

Source file src/github.com/Microsoft/hcsshim/cmd/runhcs/state.go

Documentation: github.com/Microsoft/hcsshim/cmd/runhcs

     1  //go:build windows
     2  
     3  package main
     4  
     5  import (
     6  	"encoding/json"
     7  	"os"
     8  
     9  	"github.com/Microsoft/hcsshim/internal/appargs"
    10  	"github.com/Microsoft/hcsshim/internal/runhcs"
    11  	"github.com/urfave/cli"
    12  )
    13  
    14  var stateCommand = cli.Command{
    15  	Name:  "state",
    16  	Usage: "output the state of a container",
    17  	ArgsUsage: `<container-id>
    18  
    19  Where "<container-id>" is your name for the instance of the container.`,
    20  	Description: `The state command outputs current state information for the
    21  instance of a container.`,
    22  	Before: appargs.Validate(argID),
    23  	Action: func(context *cli.Context) error {
    24  		id := context.Args().First()
    25  		c, err := getContainer(id, false)
    26  		if err != nil {
    27  			return err
    28  		}
    29  		defer c.Close()
    30  		status, err := c.Status()
    31  		if err != nil {
    32  			return err
    33  		}
    34  		cs := runhcs.ContainerState{
    35  			Version:        c.Spec.Version,
    36  			ID:             c.ID,
    37  			InitProcessPid: c.ShimPid,
    38  			Status:         string(status),
    39  			Bundle:         c.Bundle,
    40  			Rootfs:         c.Rootfs,
    41  			Created:        c.Created,
    42  			Annotations:    c.Spec.Annotations,
    43  		}
    44  		data, err := json.MarshalIndent(cs, "", "  ")
    45  		if err != nil {
    46  			return err
    47  		}
    48  		os.Stdout.Write(data)
    49  		return nil
    50  	},
    51  }
    52  

View as plain text