github.com/getong/docker@v1.13.1/api/types/types.go (about)

     1  package types
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"io"
     7  	"os"
     8  	"strings"
     9  	"time"
    10  
    11  	"github.com/docker/docker/api/types/container"
    12  	"github.com/docker/docker/api/types/filters"
    13  	"github.com/docker/docker/api/types/mount"
    14  	"github.com/docker/docker/api/types/network"
    15  	"github.com/docker/docker/api/types/registry"
    16  	"github.com/docker/docker/api/types/swarm"
    17  	"github.com/docker/go-connections/nat"
    18  )
    19  
    20  // ContainerChange contains response of Engine API:
    21  // GET "/containers/{name:.*}/changes"
    22  type ContainerChange struct {
    23  	Kind int
    24  	Path string
    25  }
    26  
    27  // ImageHistory contains response of Engine API:
    28  // GET "/images/{name:.*}/history"
    29  type ImageHistory struct {
    30  	ID        string `json:"Id"`
    31  	Created   int64
    32  	CreatedBy string
    33  	Tags      []string
    34  	Size      int64
    35  	Comment   string
    36  }
    37  
    38  // ImageDelete contains response of Engine API:
    39  // DELETE "/images/{name:.*}"
    40  type ImageDelete struct {
    41  	Untagged string `json:",omitempty"`
    42  	Deleted  string `json:",omitempty"`
    43  }
    44  
    45  // GraphDriverData returns Image's graph driver config info
    46  // when calling inspect command
    47  type GraphDriverData struct {
    48  	Name string
    49  	Data map[string]string
    50  }
    51  
    52  // RootFS returns Image's RootFS description including the layer IDs.
    53  type RootFS struct {
    54  	Type      string
    55  	Layers    []string `json:",omitempty"`
    56  	BaseLayer string   `json:",omitempty"`
    57  }
    58  
    59  // ImageInspect contains response of Engine API:
    60  // GET "/images/{name:.*}/json"
    61  type ImageInspect struct {
    62  	ID              string `json:"Id"`
    63  	RepoTags        []string
    64  	RepoDigests     []string
    65  	Parent          string
    66  	Comment         string
    67  	Created         string
    68  	Container       string
    69  	ContainerConfig *container.Config
    70  	DockerVersion   string
    71  	Author          string
    72  	Config          *container.Config
    73  	Architecture    string
    74  	Os              string
    75  	OsVersion       string `json:",omitempty"`
    76  	Size            int64
    77  	VirtualSize     int64
    78  	GraphDriver     GraphDriverData
    79  	RootFS          RootFS
    80  }
    81  
    82  // Container contains response of Engine API:
    83  // GET "/containers/json"
    84  type Container struct {
    85  	ID         string `json:"Id"`
    86  	Names      []string
    87  	Image      string
    88  	ImageID    string
    89  	Command    string
    90  	Created    int64
    91  	Ports      []Port
    92  	SizeRw     int64 `json:",omitempty"`
    93  	SizeRootFs int64 `json:",omitempty"`
    94  	Labels     map[string]string
    95  	State      string
    96  	Status     string
    97  	HostConfig struct {
    98  		NetworkMode string `json:",omitempty"`
    99  	}
   100  	NetworkSettings *SummaryNetworkSettings
   101  	Mounts          []MountPoint
   102  }
   103  
   104  // CopyConfig contains request body of Engine API:
   105  // POST "/containers/"+containerID+"/copy"
   106  type CopyConfig struct {
   107  	Resource string
   108  }
   109  
   110  // ContainerPathStat is used to encode the header from
   111  // GET "/containers/{name:.*}/archive"
   112  // "Name" is the file or directory name.
   113  type ContainerPathStat struct {
   114  	Name       string      `json:"name"`
   115  	Size       int64       `json:"size"`
   116  	Mode       os.FileMode `json:"mode"`
   117  	Mtime      time.Time   `json:"mtime"`
   118  	LinkTarget string      `json:"linkTarget"`
   119  }
   120  
   121  // ContainerStats contains response of Engine API:
   122  // GET "/stats"
   123  type ContainerStats struct {
   124  	Body   io.ReadCloser `json:"body"`
   125  	OSType string        `json:"ostype"`
   126  }
   127  
   128  // ContainerProcessList contains response of Engine API:
   129  // GET "/containers/{name:.*}/top"
   130  type ContainerProcessList struct {
   131  	Processes [][]string
   132  	Titles    []string
   133  }
   134  
   135  // Ping contains response of Engine API:
   136  // GET "/_ping"
   137  type Ping struct {
   138  	APIVersion   string
   139  	Experimental bool
   140  }
   141  
   142  // Version contains response of Engine API:
   143  // GET "/version"
   144  type Version struct {
   145  	Version       string
   146  	APIVersion    string `json:"ApiVersion"`
   147  	MinAPIVersion string `json:"MinAPIVersion,omitempty"`
   148  	GitCommit     string
   149  	GoVersion     string
   150  	Os            string
   151  	Arch          string
   152  	KernelVersion string `json:",omitempty"`
   153  	Experimental  bool   `json:",omitempty"`
   154  	BuildTime     string `json:",omitempty"`
   155  }
   156  
   157  // Commit records a external tool actual commit id version along the
   158  // one expect by dockerd as set at build time
   159  type Commit struct {
   160  	ID       string
   161  	Expected string
   162  }
   163  
   164  // Info contains response of Engine API:
   165  // GET "/info"
   166  type Info struct {
   167  	ID                 string
   168  	Containers         int
   169  	ContainersRunning  int
   170  	ContainersPaused   int
   171  	ContainersStopped  int
   172  	Images             int
   173  	Driver             string
   174  	DriverStatus       [][2]string
   175  	SystemStatus       [][2]string
   176  	Plugins            PluginsInfo
   177  	MemoryLimit        bool
   178  	SwapLimit          bool
   179  	KernelMemory       bool
   180  	CPUCfsPeriod       bool `json:"CpuCfsPeriod"`
   181  	CPUCfsQuota        bool `json:"CpuCfsQuota"`
   182  	CPUShares          bool
   183  	CPUSet             bool
   184  	IPv4Forwarding     bool
   185  	BridgeNfIptables   bool
   186  	BridgeNfIP6tables  bool `json:"BridgeNfIp6tables"`
   187  	Debug              bool
   188  	NFd                int
   189  	OomKillDisable     bool
   190  	NGoroutines        int
   191  	SystemTime         string
   192  	LoggingDriver      string
   193  	CgroupDriver       string
   194  	NEventsListener    int
   195  	KernelVersion      string
   196  	OperatingSystem    string
   197  	OSType             string
   198  	Architecture       string
   199  	IndexServerAddress string
   200  	RegistryConfig     *registry.ServiceConfig
   201  	NCPU               int
   202  	MemTotal           int64
   203  	DockerRootDir      string
   204  	HTTPProxy          string `json:"HttpProxy"`
   205  	HTTPSProxy         string `json:"HttpsProxy"`
   206  	NoProxy            string
   207  	Name               string
   208  	Labels             []string
   209  	ExperimentalBuild  bool
   210  	ServerVersion      string
   211  	ClusterStore       string
   212  	ClusterAdvertise   string
   213  	Runtimes           map[string]Runtime
   214  	DefaultRuntime     string
   215  	Swarm              swarm.Info
   216  	// LiveRestoreEnabled determines whether containers should be kept
   217  	// running when the daemon is shutdown or upon daemon start if
   218  	// running containers are detected
   219  	LiveRestoreEnabled bool
   220  	Isolation          container.Isolation
   221  	InitBinary         string
   222  	ContainerdCommit   Commit
   223  	RuncCommit         Commit
   224  	InitCommit         Commit
   225  	SecurityOptions    []string
   226  }
   227  
   228  // KeyValue holds a key/value pair
   229  type KeyValue struct {
   230  	Key, Value string
   231  }
   232  
   233  // SecurityOpt contains the name and options of a security option
   234  type SecurityOpt struct {
   235  	Name    string
   236  	Options []KeyValue
   237  }
   238  
   239  // DecodeSecurityOptions decodes a security options string slice to a type safe
   240  // SecurityOpt
   241  func DecodeSecurityOptions(opts []string) ([]SecurityOpt, error) {
   242  	so := []SecurityOpt{}
   243  	for _, opt := range opts {
   244  		// support output from a < 1.13 docker daemon
   245  		if !strings.Contains(opt, "=") {
   246  			so = append(so, SecurityOpt{Name: opt})
   247  			continue
   248  		}
   249  		secopt := SecurityOpt{}
   250  		split := strings.Split(opt, ",")
   251  		for _, s := range split {
   252  			kv := strings.SplitN(s, "=", 2)
   253  			if len(kv) != 2 {
   254  				return nil, fmt.Errorf("invalid security option %q", s)
   255  			}
   256  			if kv[0] == "" || kv[1] == "" {
   257  				return nil, errors.New("invalid empty security option")
   258  			}
   259  			if kv[0] == "name" {
   260  				secopt.Name = kv[1]
   261  				continue
   262  			}
   263  			secopt.Options = append(secopt.Options, KeyValue{Key: kv[0], Value: kv[1]})
   264  		}
   265  		so = append(so, secopt)
   266  	}
   267  	return so, nil
   268  }
   269  
   270  // PluginsInfo is a temp struct holding Plugins name
   271  // registered with docker daemon. It is used by Info struct
   272  type PluginsInfo struct {
   273  	// List of Volume plugins registered
   274  	Volume []string
   275  	// List of Network plugins registered
   276  	Network []string
   277  	// List of Authorization plugins registered
   278  	Authorization []string
   279  }
   280  
   281  // ExecStartCheck is a temp struct used by execStart
   282  // Config fields is part of ExecConfig in runconfig package
   283  type ExecStartCheck struct {
   284  	// ExecStart will first check if it's detached
   285  	Detach bool
   286  	// Check if there's a tty
   287  	Tty bool
   288  }
   289  
   290  // HealthcheckResult stores information about a single run of a healthcheck probe
   291  type HealthcheckResult struct {
   292  	Start    time.Time // Start is the time this check started
   293  	End      time.Time // End is the time this check ended
   294  	ExitCode int       // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
   295  	Output   string    // Output from last check
   296  }
   297  
   298  // Health states
   299  const (
   300  	NoHealthcheck = "none"      // Indicates there is no healthcheck
   301  	Starting      = "starting"  // Starting indicates that the container is not yet ready
   302  	Healthy       = "healthy"   // Healthy indicates that the container is running correctly
   303  	Unhealthy     = "unhealthy" // Unhealthy indicates that the container has a problem
   304  )
   305  
   306  // Health stores information about the container's healthcheck results
   307  type Health struct {
   308  	Status        string               // Status is one of Starting, Healthy or Unhealthy
   309  	FailingStreak int                  // FailingStreak is the number of consecutive failures
   310  	Log           []*HealthcheckResult // Log contains the last few results (oldest first)
   311  }
   312  
   313  // ContainerState stores container's running state
   314  // it's part of ContainerJSONBase and will return by "inspect" command
   315  type ContainerState struct {
   316  	Status     string
   317  	Running    bool
   318  	Paused     bool
   319  	Restarting bool
   320  	OOMKilled  bool
   321  	Dead       bool
   322  	Pid        int
   323  	ExitCode   int
   324  	Error      string
   325  	StartedAt  string
   326  	FinishedAt string
   327  	Health     *Health `json:",omitempty"`
   328  }
   329  
   330  // ContainerNode stores information about the node that a container
   331  // is running on.  It's only available in Docker Swarm
   332  type ContainerNode struct {
   333  	ID        string
   334  	IPAddress string `json:"IP"`
   335  	Addr      string
   336  	Name      string
   337  	Cpus      int
   338  	Memory    int64
   339  	Labels    map[string]string
   340  }
   341  
   342  // ContainerJSONBase contains response of Engine API:
   343  // GET "/containers/{name:.*}/json"
   344  type ContainerJSONBase struct {
   345  	ID              string `json:"Id"`
   346  	Created         string
   347  	Path            string
   348  	Args            []string
   349  	State           *ContainerState
   350  	Image           string
   351  	ResolvConfPath  string
   352  	HostnamePath    string
   353  	HostsPath       string
   354  	LogPath         string
   355  	Node            *ContainerNode `json:",omitempty"`
   356  	Name            string
   357  	RestartCount    int
   358  	Driver          string
   359  	MountLabel      string
   360  	ProcessLabel    string
   361  	AppArmorProfile string
   362  	ExecIDs         []string
   363  	HostConfig      *container.HostConfig
   364  	GraphDriver     GraphDriverData
   365  	SizeRw          *int64 `json:",omitempty"`
   366  	SizeRootFs      *int64 `json:",omitempty"`
   367  }
   368  
   369  // ContainerJSON is newly used struct along with MountPoint
   370  type ContainerJSON struct {
   371  	*ContainerJSONBase
   372  	Mounts          []MountPoint
   373  	Config          *container.Config
   374  	NetworkSettings *NetworkSettings
   375  }
   376  
   377  // NetworkSettings exposes the network settings in the api
   378  type NetworkSettings struct {
   379  	NetworkSettingsBase
   380  	DefaultNetworkSettings
   381  	Networks map[string]*network.EndpointSettings
   382  }
   383  
   384  // SummaryNetworkSettings provides a summary of container's networks
   385  // in /containers/json
   386  type SummaryNetworkSettings struct {
   387  	Networks map[string]*network.EndpointSettings
   388  }
   389  
   390  // NetworkSettingsBase holds basic information about networks
   391  type NetworkSettingsBase struct {
   392  	Bridge                 string      // Bridge is the Bridge name the network uses(e.g. `docker0`)
   393  	SandboxID              string      // SandboxID uniquely represents a container's network stack
   394  	HairpinMode            bool        // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
   395  	LinkLocalIPv6Address   string      // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
   396  	LinkLocalIPv6PrefixLen int         // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
   397  	Ports                  nat.PortMap // Ports is a collection of PortBinding indexed by Port
   398  	SandboxKey             string      // SandboxKey identifies the sandbox
   399  	SecondaryIPAddresses   []network.Address
   400  	SecondaryIPv6Addresses []network.Address
   401  }
   402  
   403  // DefaultNetworkSettings holds network information
   404  // during the 2 release deprecation period.
   405  // It will be removed in Docker 1.11.
   406  type DefaultNetworkSettings struct {
   407  	EndpointID          string // EndpointID uniquely represents a service endpoint in a Sandbox
   408  	Gateway             string // Gateway holds the gateway address for the network
   409  	GlobalIPv6Address   string // GlobalIPv6Address holds network's global IPv6 address
   410  	GlobalIPv6PrefixLen int    // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
   411  	IPAddress           string // IPAddress holds the IPv4 address for the network
   412  	IPPrefixLen         int    // IPPrefixLen represents mask length of network's IPv4 address
   413  	IPv6Gateway         string // IPv6Gateway holds gateway address specific for IPv6
   414  	MacAddress          string // MacAddress holds the MAC address for the network
   415  }
   416  
   417  // MountPoint represents a mount point configuration inside the container.
   418  // This is used for reporting the mountpoints in use by a container.
   419  type MountPoint struct {
   420  	Type        mount.Type `json:",omitempty"`
   421  	Name        string     `json:",omitempty"`
   422  	Source      string
   423  	Destination string
   424  	Driver      string `json:",omitempty"`
   425  	Mode        string
   426  	RW          bool
   427  	Propagation mount.Propagation
   428  }
   429  
   430  // NetworkResource is the body of the "get network" http response message
   431  type NetworkResource struct {
   432  	Name       string                      // Name is the requested name of the network
   433  	ID         string                      `json:"Id"` // ID uniquely identifies a network on a single machine
   434  	Created    time.Time                   // Created is the time the network created
   435  	Scope      string                      // Scope describes the level at which the network exists (e.g. `global` for cluster-wide or `local` for machine level)
   436  	Driver     string                      // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
   437  	EnableIPv6 bool                        // EnableIPv6 represents whether to enable IPv6
   438  	IPAM       network.IPAM                // IPAM is the network's IP Address Management
   439  	Internal   bool                        // Internal represents if the network is used internal only
   440  	Attachable bool                        // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
   441  	Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
   442  	Options    map[string]string           // Options holds the network specific options to use for when creating the network
   443  	Labels     map[string]string           // Labels holds metadata specific to the network being created
   444  	Peers      []network.PeerInfo          `json:",omitempty"` // List of peer nodes for an overlay network
   445  }
   446  
   447  // EndpointResource contains network resources allocated and used for a container in a network
   448  type EndpointResource struct {
   449  	Name        string
   450  	EndpointID  string
   451  	MacAddress  string
   452  	IPv4Address string
   453  	IPv6Address string
   454  }
   455  
   456  // NetworkCreate is the expected body of the "create network" http request message
   457  type NetworkCreate struct {
   458  	CheckDuplicate bool
   459  	Driver         string
   460  	EnableIPv6     bool
   461  	IPAM           *network.IPAM
   462  	Internal       bool
   463  	Attachable     bool
   464  	Options        map[string]string
   465  	Labels         map[string]string
   466  }
   467  
   468  // NetworkCreateRequest is the request message sent to the server for network create call.
   469  type NetworkCreateRequest struct {
   470  	NetworkCreate
   471  	Name string
   472  }
   473  
   474  // NetworkCreateResponse is the response message sent by the server for network create call
   475  type NetworkCreateResponse struct {
   476  	ID      string `json:"Id"`
   477  	Warning string
   478  }
   479  
   480  // NetworkConnect represents the data to be used to connect a container to the network
   481  type NetworkConnect struct {
   482  	Container      string
   483  	EndpointConfig *network.EndpointSettings `json:",omitempty"`
   484  }
   485  
   486  // NetworkDisconnect represents the data to be used to disconnect a container from the network
   487  type NetworkDisconnect struct {
   488  	Container string
   489  	Force     bool
   490  }
   491  
   492  // Checkpoint represents the details of a checkpoint
   493  type Checkpoint struct {
   494  	Name string // Name is the name of the checkpoint
   495  }
   496  
   497  // Runtime describes an OCI runtime
   498  type Runtime struct {
   499  	Path string   `json:"path"`
   500  	Args []string `json:"runtimeArgs,omitempty"`
   501  }
   502  
   503  // DiskUsage contains response of Engine API:
   504  // GET "/system/df"
   505  type DiskUsage struct {
   506  	LayersSize int64
   507  	Images     []*ImageSummary
   508  	Containers []*Container
   509  	Volumes    []*Volume
   510  }
   511  
   512  // ContainersPruneReport contains the response for Engine API:
   513  // POST "/containers/prune"
   514  type ContainersPruneReport struct {
   515  	ContainersDeleted []string
   516  	SpaceReclaimed    uint64
   517  }
   518  
   519  // VolumesPruneReport contains the response for Engine API:
   520  // POST "/volumes/prune"
   521  type VolumesPruneReport struct {
   522  	VolumesDeleted []string
   523  	SpaceReclaimed uint64
   524  }
   525  
   526  // ImagesPruneReport contains the response for Engine API:
   527  // POST "/images/prune"
   528  type ImagesPruneReport struct {
   529  	ImagesDeleted  []ImageDelete
   530  	SpaceReclaimed uint64
   531  }
   532  
   533  // NetworksPruneReport contains the response for Engine API:
   534  // POST "/networks/prune"
   535  type NetworksPruneReport struct {
   536  	NetworksDeleted []string
   537  }
   538  
   539  // SecretCreateResponse contains the information returned to a client
   540  // on the creation of a new secret.
   541  type SecretCreateResponse struct {
   542  	// ID is the id of the created secret.
   543  	ID string
   544  }
   545  
   546  // SecretListOptions holds parameters to list secrets
   547  type SecretListOptions struct {
   548  	Filters filters.Args
   549  }