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