2017-11-01 15:24:59 +00:00
|
|
|
package libpod
|
|
|
|
|
2018-07-30 13:42:35 +00:00
|
|
|
// State is a storage backend for libpod's current state.
|
|
|
|
// A State is only initialized once per instance of libpod.
|
|
|
|
// As such, initialization methods for State implementations may safely assume
|
|
|
|
// they will be run as a singleton.
|
|
|
|
// For all container and pod retrieval methods, a State must retrieve the
|
|
|
|
// Configuration struct of the container or pod and include it in the returned
|
|
|
|
// struct. The State of the container or pod may optionally be included as well,
|
|
|
|
// but this is not a requirement.
|
|
|
|
// As such, all containers and pods must be synced with the database via the
|
|
|
|
// UpdateContainer and UpdatePod calls before any state-specific information is
|
|
|
|
// retrieved after they are pulled from the database.
|
|
|
|
// Generally speaking, the syncContainer() call should be run at the beginning
|
|
|
|
// of all API operations, which will silently handle this.
|
2017-11-01 15:24:59 +00:00
|
|
|
type State interface {
|
2017-11-07 18:46:30 +00:00
|
|
|
// Close performs any pre-exit cleanup (e.g. closing database
|
|
|
|
// connections) that may be required
|
|
|
|
Close() error
|
|
|
|
|
2017-12-07 18:15:34 +00:00
|
|
|
// Refresh clears container and pod states after a reboot
|
|
|
|
Refresh() error
|
|
|
|
|
2018-06-26 03:39:11 +00:00
|
|
|
// SetNamespace() sets the namespace for the store, and will determine
|
2018-07-19 16:05:14 +00:00
|
|
|
// what containers are retrieved with container and pod retrieval calls.
|
|
|
|
// A namespace of "", the empty string, acts as no namespace, and
|
|
|
|
// containers and pods in all namespaces will be returned.
|
2018-06-26 03:39:11 +00:00
|
|
|
SetNamespace(ns string) error
|
|
|
|
|
2018-07-19 16:05:14 +00:00
|
|
|
// Return a container from the database from its full ID.
|
|
|
|
// If the container is not in the set namespace, an error will be
|
|
|
|
// returned.
|
2017-11-01 15:24:59 +00:00
|
|
|
Container(id string) (*Container, error)
|
2018-02-10 20:11:32 +00:00
|
|
|
// Return a container from the database by full or partial ID or full
|
2018-07-19 16:05:14 +00:00
|
|
|
// name.
|
|
|
|
// Containers not in the set namespace will be ignored.
|
2017-11-01 15:24:59 +00:00
|
|
|
LookupContainer(idOrName string) (*Container, error)
|
2018-07-19 16:05:14 +00:00
|
|
|
// Check if a container with the given full ID exists in the database.
|
|
|
|
// If the container exists but is not in the set namespace, false will
|
|
|
|
// be returned.
|
2017-11-01 15:24:59 +00:00
|
|
|
HasContainer(id string) (bool, error)
|
2018-07-19 16:05:14 +00:00
|
|
|
// Adds container to state.
|
|
|
|
// The container cannot be part of a pod.
|
2018-02-10 20:11:32 +00:00
|
|
|
// The container must have globally unique name and ID - pod names and
|
2018-07-19 16:05:14 +00:00
|
|
|
// IDs also conflict with container names and IDs.
|
|
|
|
// The container must be in the set namespace if a namespace has been
|
|
|
|
// set.
|
|
|
|
// All containers this container depends on must be part of the same
|
|
|
|
// namespace and must not be joined to a pod.
|
2017-11-01 15:24:59 +00:00
|
|
|
AddContainer(ctr *Container) error
|
2018-07-19 16:05:14 +00:00
|
|
|
// Removes container from state.
|
|
|
|
// Containers that are part of pods must use RemoveContainerFromPod.
|
|
|
|
// The container must be part of the set namespace.
|
2017-11-01 15:24:59 +00:00
|
|
|
RemoveContainer(ctr *Container) error
|
2018-07-19 16:05:14 +00:00
|
|
|
// UpdateContainer updates a container's state from the backing store.
|
|
|
|
// The container must be part of the set namespace.
|
2017-11-09 18:51:20 +00:00
|
|
|
UpdateContainer(ctr *Container) error
|
2018-07-19 16:05:14 +00:00
|
|
|
// SaveContainer saves a container's current state to the backing store.
|
|
|
|
// The container must be part of the set namespace.
|
2017-11-09 18:51:20 +00:00
|
|
|
SaveContainer(ctr *Container) error
|
2018-01-12 17:41:10 +00:00
|
|
|
// ContainerInUse checks if other containers depend upon a given
|
2018-07-19 16:05:14 +00:00
|
|
|
// container.
|
2018-01-12 17:41:10 +00:00
|
|
|
// It returns a slice of the IDs of containers which depend on the given
|
|
|
|
// container. If the slice is empty, no container depend on the given
|
|
|
|
// container.
|
2018-07-19 16:05:14 +00:00
|
|
|
// A container cannot be removed if other containers depend on it.
|
|
|
|
// The container being checked must be part of the set namespace.
|
2018-01-12 17:41:10 +00:00
|
|
|
ContainerInUse(ctr *Container) ([]string, error)
|
2018-07-19 16:05:14 +00:00
|
|
|
// Retrieves all containers presently in state.
|
|
|
|
// If a namespace is set, only containers within the namespace will be
|
|
|
|
// returned.
|
2017-11-01 15:24:59 +00:00
|
|
|
AllContainers() ([]*Container, error)
|
|
|
|
|
2018-07-19 16:05:14 +00:00
|
|
|
// Accepts full ID of pod.
|
|
|
|
// If the pod given is not in the set namespace, an error will be
|
|
|
|
// returned.
|
2017-11-01 15:24:59 +00:00
|
|
|
Pod(id string) (*Pod, error)
|
2018-07-19 16:05:14 +00:00
|
|
|
// Accepts full or partial IDs (as long as they are unique) and names.
|
|
|
|
// Pods not in the set namespace are ignored.
|
2017-11-01 15:24:59 +00:00
|
|
|
LookupPod(idOrName string) (*Pod, error)
|
2018-07-19 16:05:14 +00:00
|
|
|
// Checks if a pod with the given ID is present in the state.
|
|
|
|
// If the given pod is not in the set namespace, false is returned.
|
2017-11-01 15:24:59 +00:00
|
|
|
HasPod(id string) (bool, error)
|
2018-07-19 16:05:14 +00:00
|
|
|
// Check if a pod has a container with the given ID.
|
|
|
|
// The pod must be part of the set namespace.
|
2018-01-18 15:49:01 +00:00
|
|
|
PodHasContainer(pod *Pod, ctrID string) (bool, error)
|
2018-07-19 16:05:14 +00:00
|
|
|
// Get the IDs of all containers in a pod.
|
|
|
|
// The pod must be part of the set namespace.
|
2018-01-18 15:49:01 +00:00
|
|
|
PodContainersByID(pod *Pod) ([]string, error)
|
2018-07-19 16:05:14 +00:00
|
|
|
// Get all the containers in a pod.
|
|
|
|
// The pod must be part of the set namespace.
|
2018-01-18 15:49:01 +00:00
|
|
|
PodContainers(pod *Pod) ([]*Container, error)
|
2018-07-19 16:05:14 +00:00
|
|
|
// Adds pod to state.
|
|
|
|
// The pod must be part of the set namespace.
|
|
|
|
// The pod's name and ID must be globally unique.
|
2017-11-01 15:24:59 +00:00
|
|
|
AddPod(pod *Pod) error
|
2018-07-19 16:05:14 +00:00
|
|
|
// Removes pod from state.
|
|
|
|
// Only empty pods can be removed from the state.
|
|
|
|
// The pod must be part of the set namespace.
|
2017-11-01 15:24:59 +00:00
|
|
|
RemovePod(pod *Pod) error
|
2018-07-19 16:05:14 +00:00
|
|
|
// Remove all containers from a pod.
|
2018-05-25 00:50:37 +00:00
|
|
|
// Used to simultaneously remove containers that might otherwise have
|
2018-07-19 16:05:14 +00:00
|
|
|
// dependency issues.
|
|
|
|
// Will fail if a dependency outside the pod is encountered.
|
|
|
|
// The pod must be part of the set namespace.
|
2018-01-28 10:31:01 +00:00
|
|
|
RemovePodContainers(pod *Pod) error
|
2018-07-19 16:05:14 +00:00
|
|
|
// AddContainerToPod adds a container to an existing pod.
|
|
|
|
// The container given will be added to the state and the pod.
|
|
|
|
// The container and its dependencies must be part of the given pod,
|
|
|
|
// and the given pod's namespace.
|
|
|
|
// The pod must be part of the set namespace.
|
|
|
|
// The pod must already exist in the state.
|
|
|
|
// The container's name and ID must be globally unique.
|
2017-12-14 04:12:32 +00:00
|
|
|
AddContainerToPod(pod *Pod, ctr *Container) error
|
2018-07-19 16:05:14 +00:00
|
|
|
// RemoveContainerFromPod removes a container from an existing pod.
|
|
|
|
// The container will also be removed from the state.
|
|
|
|
// The container must be in the given pod, and the pod must be in the
|
|
|
|
// set namespace.
|
2017-12-14 04:12:32 +00:00
|
|
|
RemoveContainerFromPod(pod *Pod, ctr *Container) error
|
2018-07-19 16:05:14 +00:00
|
|
|
// UpdatePod updates a pod's state from the database.
|
|
|
|
// The pod must be in the set namespace.
|
2018-05-14 23:30:11 +00:00
|
|
|
UpdatePod(pod *Pod) error
|
2018-07-19 16:05:14 +00:00
|
|
|
// SavePod saves a pod's state to the database.
|
|
|
|
// The pod must be in the set namespace.
|
2018-05-14 23:30:11 +00:00
|
|
|
SavePod(pod *Pod) error
|
2018-07-19 16:05:14 +00:00
|
|
|
// Retrieves all pods presently in state.
|
|
|
|
// If a namespace has been set, only pods in that namespace will be
|
|
|
|
// returned.
|
2017-11-01 15:24:59 +00:00
|
|
|
AllPods() ([]*Pod, error)
|
|
|
|
}
|