Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
- newtype Container = Container {}
- data Snapshot = Snapshot {}
- data BDevSpecs = BDevSpecs {}
- data ContainerState
- parseState :: String -> ContainerState
- printState :: ContainerState -> String
- mkContainer :: String -> Maybe FilePath -> IO Container
- data CloneOption
- data CreateOption
- cloneFlag :: Num a => CloneOption -> a
- createFlag :: Num a => CreateOption -> a
- isDefined :: Container -> IO Bool
- isRunning :: Container -> IO Bool
- state :: Container -> IO ContainerState
- initPID :: Container -> IO (Maybe ProcessID)
- configFileName :: Container -> IO (Maybe FilePath)
- getConfigPath :: Container -> IO FilePath
- setConfigPath :: Container -> FilePath -> IO Bool
- loadConfig :: Container -> Maybe FilePath -> IO Bool
- saveConfig :: Container -> FilePath -> IO Bool
- getKeys :: Container -> String -> IO [String]
- setConfigItem :: Container -> String -> String -> IO Bool
- getConfigItem :: Container -> String -> IO (Maybe String)
- getRunningConfigItem :: Container -> String -> IO (Maybe String)
- clearConfig :: Container -> IO ()
- clearConfigItem :: Container -> String -> IO Bool
- freeze :: Container -> IO Bool
- unfreeze :: Container -> IO Bool
- start :: Container -> Int -> [String] -> IO Bool
- stop :: Container -> IO Bool
- reboot :: Container -> IO Bool
- shutdown :: Container -> Int -> IO Bool
- wait :: Container -> ContainerState -> Int -> IO Bool
- create :: Container -> String -> Maybe String -> Maybe BDevSpecs -> [CreateOption] -> [String] -> IO Bool
- clone :: Container -> Maybe String -> Maybe FilePath -> [CloneOption] -> Maybe String -> Maybe String -> Maybe Word64 -> [String] -> IO Container
- rename :: Container -> String -> IO Bool
- destroy :: Container -> IO Bool
- consoleGetFD :: Container -> Maybe Int -> IO (Maybe (Int, Int, Int))
- console :: Container -> Maybe Int -> Fd -> Fd -> Fd -> Int -> IO Bool
- attach :: Container -> AttachExecFn -> AttachCommand -> AttachOptions -> IO (Maybe ProcessID)
- attachRunWait :: Container -> AttachOptions -> String -> [String] -> IO (Maybe ExitCode)
- snapshot :: Container -> FilePath -> IO (Maybe Int)
- snapshotList :: Container -> IO [Snapshot]
- snapshotRestore :: Container -> String -> String -> IO Bool
- wantDaemonize :: Container -> Bool -> IO Bool
- wantCloseAllFDs :: Container -> Bool -> IO Bool
- getInterfaces :: Container -> IO [String]
- getIPs :: Container -> String -> String -> Word32 -> IO [String]
- getCGroupItem :: Container -> String -> IO (Maybe String)
- setCGroupItem :: Container -> String -> String -> IO Bool
- mayControl :: Container -> IO Bool
- addDeviceNode :: Container -> FilePath -> Maybe FilePath -> IO Bool
- removeDeviceNode :: Container -> FilePath -> Maybe FilePath -> IO Bool
- getRef :: Container -> IO Bool
- dropRef :: Container -> IO (Maybe Bool)
- listDefinedContainers :: Maybe String -> IO [(String, Container)]
- listActiveContainers :: Maybe String -> IO [(String, Container)]
- listAllContainers :: Maybe String -> IO [(String, Container)]
- getWaitStates :: IO [ContainerState]
- getGlobalConfigItem :: String -> IO (Maybe String)
- getVersion :: IO String
- logClose :: IO ()
Data types
Container object.
Container | |
|
An LXC container snapshot.
Snapshot | |
|
Specifications for how to create a new backing store.
BDevSpecs | |
|
data ContainerState Source
parseState :: String -> ContainerState Source
printState :: ContainerState -> String Source
:: String | Name to use for the container. |
-> Maybe FilePath | Full path to configuration file to use. |
-> IO Container | Newly allocated container. |
Allocate a new container.
Flags
data CloneOption Source
Options for clone
operation.
CloneKeepName | Do not edit the rootfs to change the hostname. |
CloneKeepMacAddr | Do not change the MAC address on network interfaces. |
CloneSnapshot | Snapshot the original filesystem(s). |
CloneKeepBDevType | Use the same bdev type. |
CloneMaybeSnapshot | Snapshot only if bdev supports it, else copy. |
CloneMaxFlags | Number of |
data CreateOption Source
Options for create
operation.
CreateQuiet | Redirect |
CreateMaxFlags | Number of |
cloneFlag :: Num a => CloneOption -> a Source
Turn CloneOption
into a bit flag.
createFlag :: Num a => CreateOption -> a Source
Turn CreateOption
into a bit flag.
Container methods
Query container state.
isDefined :: Container -> IO Bool Source
Determine if /var/lib/lxc/$name/config
exists.
True
if container is defined, else False
.
isRunning :: Container -> IO Bool Source
Determine if container is running.
True
on success, else False
.
state :: Container -> IO ContainerState Source
Determine state of container.
initPID :: Container -> IO (Maybe ProcessID) Source
Determine process ID of the containers init process.
Container config
getConfigPath :: Container -> IO FilePath Source
Determine full path to the containers configuration file.
Each container can have a custom configuration path. However
by default it will be set to either the LXCPATH
configure
variable, or the lxcpath value in the LXC_GLOBAL_CONF
configuration
file (i.e. /etc/lxc/lxc.conf
).
The value for a specific container can be changed using
setConfigPath
.
:: Container | Container. |
-> FilePath | Full path to configuration file. |
-> IO Bool |
|
Set the full path to the containers configuration file.
:: Container | Container. |
-> Maybe FilePath | Full path to alternate configuration file, or |
-> IO Bool |
|
Load the specified configuration for the container.
:: Container | Container. |
-> FilePath | Full path to file to save configuration in. |
-> IO Bool |
|
Save configuaration to a file.
Retrieve a list of config item keys given a key prefix.
:: Container | Container. |
-> String | Name of option to set. |
-> String | Value to set. |
-> IO Bool |
|
Set a key/value configuration option.
:: Container | Container. |
-> String | Name of option to get. |
-> IO (Maybe String) | The item or |
Retrieve the value of a config item.
:: Container | Container. |
-> String | Name of option to get. |
-> IO (Maybe String) | The item or |
Retrieve the value of a config item from running container.
clearConfig :: Container -> IO () Source
Completely clear the containers in-memory configuration.
Clear a configuration item.
Analog of setConfigItem
.
Freeze/unfreeze
Control container state
:: Container | Container. |
-> Int | Use |
-> [String] | Array of arguments to pass to init. |
-> IO Bool |
|
Start the container.
reboot :: Container -> IO Bool Source
Request the container reboot by sending it SIGINT
.
True
if reboot request successful, else False
.
:: Container | Container. |
-> Int | Seconds to wait before returning false. ( |
-> IO Bool |
|
Request the container shutdown by sending it SIGPWR
.
:: Container | Container. |
-> ContainerState | State to wait for. |
-> Int | Timeout in seconds. |
-> IO Bool |
|
Wait for container to reach a particular state.
- A timeout of
-1
means wait forever. A timeout0
means do not wait.
Manage containers
:: Container | Container (with lxcpath, name and a starting configuration set). |
-> String | Template to execute to instantiate the root filesystem and adjust the configuration. |
-> Maybe String | Backing store type to use (if |
-> Maybe BDevSpecs | Additional parameters for the backing store (for example LVM volume group to use). |
-> [CreateOption] |
|
-> [String] | Arguments to pass to the template. |
-> IO Bool |
|
Create a container.
:: Container | Original container. |
-> Maybe String | New name for the container. If |
-> Maybe FilePath | lxcpath in which to create the new container. If |
-> [CloneOption] | Additional |
-> Maybe String | Optionally force the cloned bdevtype to a specified plugin. By default the original is used (subject to snapshot requirements). |
-> Maybe String | Information about how to create the new storage (i.e. fstype and fsdata). |
-> Maybe Word64 | In case of a block device backing store, an optional size. If |
-> [String] | Additional arguments to pass to the clone hook script. |
-> IO Container |
Copy a stopped container.
:: Container | Container. |
-> String | New name to be used for the container. |
-> IO Bool |
|
Rename a container.
destroy :: Container -> IO Bool Source
Delete the container.
True
on success, else False
.
- NOTE: Container must be stopped and have no dependent snapshots.
Console
:: Container | Container. |
-> Maybe Int | Terminal number to attempt to allocate, or |
-> IO (Maybe (Int, Int, Int)) | Tuple |
Allocate a console tty for the container.
- The returned file descriptor is used to keep the tty allocated. The caller should call close(2) on the returned file descriptor when no longer required so that it may be allocated by another caller.
:: Container | Container. |
-> Maybe Int | Terminal number to attempt to allocate, |
-> Fd | File descriptor to read input from. |
-> Fd | File descriptor to write output to. |
-> Fd | File descriptor to write error output to. |
-> Int | The escape character ( |
-> IO Bool |
|
Allocate and run a console tty.
Attach to container
:: Container | Container. |
-> AttachExecFn | Function to run. |
-> AttachCommand | Data to pass to |
-> AttachOptions | Attach options. |
-> IO (Maybe ProcessID) | Process ID of process running inside container |
Create a sub-process attached to a container and run a function inside it.
:: Container | Container. |
-> AttachOptions | Attach options. |
-> String | Full path inside container of program to run. |
-> [String] | Array of arguments to pass to program. |
-> IO (Maybe ExitCode) |
|
Run a program inside a container and wait for it to exit.
Snapshots
snapshot :: Container -> FilePath -> IO (Maybe Int) Source
Create a container snapshot.
Assuming default paths, snapshots will be created as
/var/lib/lxc/<c>/snaps/snap<n>
where <c>
represents the container name and <n>
represents the zero-based snapshot number.
snapshotList :: Container -> IO [Snapshot] Source
Obtain a list of container snapshots.
:: Container | Container. |
-> String | Name of snapshot. |
-> String | Name to be used for the restored snapshot. |
-> IO Bool |
|
Create a new container based on a snapshot.
The restored container will be a copy (not snapshot) of the snapshot, and restored in the lxcpath of the original container.
- WARNING: If new name is the same as the current container name, the container will be destroyed. However, this will fail if the snapshot is overlay-based, since the snapshots will pin the original container.
- NOTE: As an example, if the container exists as
/var/lib/lxc/c1
, snapname might be"snap0"
(representing/var/lib/lxc/c1/snaps/snap0
). If new name isc2
, thensnap0
will be copied to/var/lib/lxc/c2
.
Misc
:: Container | Container. |
-> Bool | Value for the daemonize bit. |
-> IO Bool |
|
Determine if the container wants to run disconnected from the terminal.
:: Container | Container. |
-> Bool | Value for the |
-> IO Bool |
|
Determine whether container wishes all file descriptors to be closed on startup.
getInterfaces :: Container -> IO [String] Source
Obtain a list of network interfaces.
:: Container | Container. |
-> String | Network interface name to consider. |
-> String | Network family (for example |
-> Word32 | IPv6 scope id (ignored if family is not "inet6"). |
-> IO [String] | A list of network interfaces. |
Determine the list of container IP addresses.
:: Container | Container. |
-> String |
|
-> IO (Maybe String) |
|
Retrieve the specified cgroup subsystem value for the container.
:: Container | Container. |
-> String |
|
-> String | Value to set. |
-> IO Bool |
|
Set the specified cgroup subsystem value for the container.
mayControl :: Container -> IO Bool Source
Determine if the caller may control the container.
False
if there is a control socket for the container monitor
and the caller may not access it, otherwise returns True
.
:: Container | Container. |
-> FilePath | Full path of the device. |
-> Maybe FilePath | Alternate path in the container (or |
-> IO Bool |
|
Add specified device to the container.
:: Container | Container. |
-> FilePath | Full path of the device. |
-> Maybe FilePath | Alternate path in the container (or |
-> IO Bool |
|
Remove specified device from the container.
dropRef :: Container -> IO (Maybe Bool) Source
Drop a reference to the specified container.
Just False
on success, Just True
if reference was successfully dropped
and container has been freed, and Nothing
on error.
Global LXC functions
List containers
Get a list of defined containers in a lxcpath.
Get a list of active containers for a given lxcpath.
Get a complete list of all containers for a given lxcpath.
Misc
getWaitStates :: IO [ContainerState] Source
Obtain a list of all container states.
:: String | The name of the config key. |
-> IO (Maybe String) | String representing the current value for the key. |
Get the value for a global config key.
getVersion :: IO String Source
Determine version of LXC.