Copyright | (c) Nickolay Kudasov 2014 |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | nickolay.kudasov@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Internal module to provide a set of functions to create,
control and manage LXC containers.
Normally you should import System.LXC
module only.
- type ContainerCreateFn = Ptr C'lxc_container -> CString -> CString -> Ptr C'bdev_specs -> CInt -> Ptr CString -> IO CBool
- mkCreateFn :: FunPtr ContainerCreateFn -> ContainerCreateFn
- type ContainerCloneFn = Ptr C'lxc_container -> CString -> CString -> CInt -> CString -> CString -> C'uint64_t -> Ptr CString -> IO (Ptr C'lxc_container)
- mkCloneFn :: FunPtr ContainerCloneFn -> ContainerCloneFn
- type ContainerBoolFn = Ptr C'lxc_container -> IO CBool
- mkBoolFn :: FunPtr ContainerBoolFn -> ContainerBoolFn
- type ContainerStringFn = Ptr C'lxc_container -> IO CString
- mkStringFn :: FunPtr ContainerStringFn -> ContainerStringFn
- type ContainerProcessIDFn = Ptr C'lxc_container -> IO C'pid_t
- mkProcessIDFn :: FunPtr ContainerProcessIDFn -> ContainerProcessIDFn
- type ContainerStringBoolFn = Ptr C'lxc_container -> CString -> IO CBool
- mkStringBoolFn :: FunPtr ContainerStringBoolFn -> ContainerStringBoolFn
- type ContainerBoolBoolFn = Ptr C'lxc_container -> CBool -> IO CBool
- mkBoolBoolFn :: FunPtr ContainerBoolBoolFn -> ContainerBoolBoolFn
- type ContainerStartFn = Ptr C'lxc_container -> CInt -> Ptr CString -> IO CBool
- mkStartFn :: FunPtr ContainerStartFn -> ContainerStartFn
- type ContainerShutdownFn = Ptr C'lxc_container -> CInt -> IO CBool
- mkShutdownFn :: FunPtr ContainerShutdownFn -> ContainerShutdownFn
- type ContainerClearConfigFn = Ptr C'lxc_container -> IO ()
- mkClearConfigFn :: FunPtr ContainerClearConfigFn -> ContainerClearConfigFn
- type ContainerGetRunningConfigItemFn = Ptr C'lxc_container -> CString -> IO CString
- mkGetRunningConfigItemFn :: FunPtr ContainerGetRunningConfigItemFn -> ContainerGetRunningConfigItemFn
- type ContainerGetItemFn = Ptr C'lxc_container -> CString -> CString -> CInt -> IO CInt
- mkGetItemFn :: FunPtr ContainerGetItemFn -> ContainerGetItemFn
- type ContainerSetItemFn = Ptr C'lxc_container -> CString -> CString -> IO CBool
- mkSetItemFn :: FunPtr ContainerSetItemFn -> ContainerSetItemFn
- type ContainerGetInterfacesFn = Ptr C'lxc_container -> IO (Ptr CString)
- mkGetInterfacesFn :: FunPtr ContainerGetInterfacesFn -> ContainerGetInterfacesFn
- type ContainerGetIPsFn = Ptr C'lxc_container -> CString -> CString -> CInt -> IO (Ptr CString)
- mkGetIPsFn :: FunPtr ContainerGetIPsFn -> ContainerGetIPsFn
- type ContainerWaitFn = Ptr C'lxc_container -> CString -> CInt -> IO CBool
- mkWaitFn :: FunPtr ContainerWaitFn -> ContainerWaitFn
- type ContainerSnapshotFn = Ptr C'lxc_container -> CString -> IO CInt
- mkSnapshotFn :: FunPtr ContainerSnapshotFn -> ContainerSnapshotFn
- type ContainerSnapshotListFn = Ptr C'lxc_container -> Ptr (Ptr C'lxc_snapshot) -> IO CInt
- mkSnapshotListFn :: FunPtr ContainerSnapshotListFn -> ContainerSnapshotListFn
- type ContainerConsoleGetFDFn = Ptr C'lxc_container -> Ptr CInt -> Ptr CInt -> IO CInt
- mkConsoleGetFDFn :: FunPtr ContainerConsoleGetFDFn -> ContainerConsoleGetFDFn
- type ContainerConsoleFn = Ptr C'lxc_container -> CInt -> CInt -> CInt -> CInt -> CInt -> IO CInt
- mkConsoleFn :: FunPtr ContainerConsoleFn -> ContainerConsoleFn
- type ContainerAttachFn = Ptr C'lxc_container -> C_lxc_attach_exec_t -> Ptr () -> Ptr C'lxc_attach_options_t -> Ptr C'pid_t -> IO CInt
- mkAttachFn :: FunPtr ContainerAttachFn -> ContainerAttachFn
- type ContainerAttachRunWaitFn = Ptr C'lxc_container -> Ptr C'lxc_attach_options_t -> CString -> Ptr CString -> IO CInt
- mkAttachRunWaitFn :: FunPtr ContainerAttachRunWaitFn -> ContainerAttachRunWaitFn
- type SnapshotFreeFn = Ptr C'lxc_snapshot -> IO ()
- mkFreeFn :: FunPtr SnapshotFreeFn -> SnapshotFreeFn
- data LXCError = LXCError {}
- prettyLXCError :: LXCError -> String
- data CloneOption
- data CreateOption
- cloneFlag :: Num a => CloneOption -> a
- createFlag :: Num a => CreateOption -> a
- data Snapshot = Snapshot {}
- newtype Container = Container {}
- data ContainerState
- parseState :: String -> ContainerState
- printState :: ContainerState -> String
- data BDevSpecs = BDevSpecs {}
- withC'bdev_specs :: BDevSpecs -> (Ptr C'bdev_specs -> IO a) -> IO a
- mkContainer :: String -> Maybe FilePath -> IO Container
- type Field s a = Ptr s -> Ptr a
- mkFn :: (t -> Ptr s) -> (FunPtr (Ptr s -> a) -> Ptr s -> a) -> Field s (FunPtr (Ptr s -> a)) -> t -> IO a
- boolFn :: Field C'lxc_container (FunPtr ContainerBoolFn) -> Container -> IO Bool
- stringBoolFn :: Field C'lxc_container (FunPtr ContainerStringBoolFn) -> Container -> Maybe String -> IO Bool
- boolBoolFn :: Field C'lxc_container (FunPtr ContainerBoolBoolFn) -> Container -> Bool -> IO Bool
- getItemFn :: Field C'lxc_container (FunPtr ContainerGetItemFn) -> Container -> String -> IO (Maybe String)
- setItemFn :: Field C'lxc_container (FunPtr ContainerSetItemFn) -> Container -> String -> Maybe String -> IO Bool
- setItemFn' :: Field C'lxc_container (FunPtr ContainerSetItemFn) -> Container -> String -> String -> IO Bool
- getDaemonize :: Container -> IO Bool
- getLastError :: Container -> IO (Maybe LXCError)
- isDefined :: Container -> IO Bool
- isRunning :: Container -> IO Bool
- state :: Container -> IO ContainerState
- freeze :: Container -> IO Bool
- unfreeze :: Container -> IO Bool
- initPID :: Container -> IO (Maybe ProcessID)
- loadConfig :: Container -> Maybe FilePath -> IO Bool
- start :: Container -> Bool -> [String] -> IO Bool
- stop :: Container -> IO Bool
- wantDaemonize :: Container -> Bool -> IO Bool
- wantCloseAllFDs :: Container -> Bool -> IO Bool
- configFileName :: Container -> IO (Maybe FilePath)
- wait :: Container -> ContainerState -> Int -> IO Bool
- setConfigItem :: Container -> String -> String -> IO Bool
- destroy :: Container -> IO Bool
- saveConfig :: Container -> FilePath -> IO Bool
- rename :: Container -> String -> IO Bool
- reboot :: Container -> IO Bool
- shutdown :: Container -> Int -> IO Bool
- clearConfig :: Container -> IO ()
- getConfigItem :: Container -> String -> IO (Maybe String)
- getRunningConfigItem :: Container -> String -> IO (Maybe String)
- getKeys :: Container -> String -> IO [String]
- getInterfaces :: Container -> IO [String]
- getIPs :: Container -> String -> String -> Word32 -> IO [String]
- getCGroupItem :: Container -> String -> IO (Maybe String)
- setCGroupItem :: Container -> String -> String -> IO Bool
- clearConfigItem :: Container -> String -> IO Bool
- getConfigPath :: Container -> IO FilePath
- setConfigPath :: Container -> FilePath -> IO Bool
- clone :: Container -> Maybe String -> Maybe FilePath -> [CloneOption] -> Maybe String -> Maybe String -> Maybe Word64 -> [String] -> IO Container
- 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)
- peekC'lxc_snapshot :: Ptr C'lxc_snapshot -> IO Snapshot
- snapshotList :: Container -> IO [Snapshot]
- snapshotRestore :: Container -> String -> String -> IO Bool
- snapshotDestroy :: Container -> String -> IO Bool
- mayControl :: Container -> IO Bool
- addDeviceNode :: Container -> FilePath -> Maybe FilePath -> IO Bool
- removeDeviceNode :: Container -> FilePath -> Maybe FilePath -> IO Bool
- create :: Container -> String -> Maybe String -> Maybe BDevSpecs -> [CreateOption] -> [String] -> IO Bool
- getRef :: Container -> IO Bool
- dropRef :: Container -> IO (Maybe Bool)
- getWaitStates :: IO [ContainerState]
- getGlobalConfigItem :: String -> IO (Maybe String)
- getVersion :: IO String
- listContainersFn :: (CString -> Ptr (Ptr CString) -> Ptr (Ptr (Ptr C'lxc_container)) -> IO CInt) -> Maybe String -> IO [(String, Container)]
- listDefinedContainers :: Maybe String -> IO [(String, Container)]
- listActiveContainers :: Maybe String -> IO [(String, Container)]
- listAllContainers :: Maybe String -> IO [(String, Container)]
- logClose :: IO ()
Documentation
type ContainerCreateFn = Ptr C'lxc_container -> CString -> CString -> Ptr C'bdev_specs -> CInt -> Ptr CString -> IO CBool Source
type ContainerCloneFn = Ptr C'lxc_container -> CString -> CString -> CInt -> CString -> CString -> C'uint64_t -> Ptr CString -> IO (Ptr C'lxc_container) Source
type ContainerBoolFn = Ptr C'lxc_container -> IO CBool Source
type ContainerStringFn = Ptr C'lxc_container -> IO CString Source
type ContainerProcessIDFn = Ptr C'lxc_container -> IO C'pid_t Source
type ContainerStringBoolFn = Ptr C'lxc_container -> CString -> IO CBool Source
type ContainerBoolBoolFn = Ptr C'lxc_container -> CBool -> IO CBool Source
type ContainerStartFn = Ptr C'lxc_container -> CInt -> Ptr CString -> IO CBool Source
type ContainerShutdownFn = Ptr C'lxc_container -> CInt -> IO CBool Source
type ContainerClearConfigFn = Ptr C'lxc_container -> IO () Source
type ContainerGetRunningConfigItemFn = Ptr C'lxc_container -> CString -> IO CString Source
mkGetRunningConfigItemFn :: FunPtr ContainerGetRunningConfigItemFn -> ContainerGetRunningConfigItemFn Source
type ContainerGetItemFn = Ptr C'lxc_container -> CString -> CString -> CInt -> IO CInt Source
type ContainerSetItemFn = Ptr C'lxc_container -> CString -> CString -> IO CBool Source
type ContainerGetInterfacesFn = Ptr C'lxc_container -> IO (Ptr CString) Source
type ContainerGetIPsFn = Ptr C'lxc_container -> CString -> CString -> CInt -> IO (Ptr CString) Source
type ContainerWaitFn = Ptr C'lxc_container -> CString -> CInt -> IO CBool Source
type ContainerSnapshotFn = Ptr C'lxc_container -> CString -> IO CInt Source
type ContainerSnapshotListFn = Ptr C'lxc_container -> Ptr (Ptr C'lxc_snapshot) -> IO CInt Source
type ContainerConsoleGetFDFn = Ptr C'lxc_container -> Ptr CInt -> Ptr CInt -> IO CInt Source
type ContainerConsoleFn = Ptr C'lxc_container -> CInt -> CInt -> CInt -> CInt -> CInt -> IO CInt Source
type ContainerAttachFn = Ptr C'lxc_container -> C_lxc_attach_exec_t -> Ptr () -> Ptr C'lxc_attach_options_t -> Ptr C'pid_t -> IO CInt Source
type ContainerAttachRunWaitFn = Ptr C'lxc_container -> Ptr C'lxc_attach_options_t -> CString -> Ptr CString -> IO CInt Source
type SnapshotFreeFn = Ptr C'lxc_snapshot -> IO () Source
LXC error structure.
LXCError | |
|
prettyLXCError :: LXCError -> String Source
Pretty print LXC error message.
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.
An LXC container snapshot.
Snapshot | |
|
Container object.
Container | |
|
data ContainerState Source
Container state.
ContainerStopped | Container is stopped. |
ContainerStarting | Container is starting. |
ContainerRunning | Container is running. |
ContainerStopping | Container is stopping. |
ContainerAborting | Container is aborting. |
ContainerFreezing | Container is freezing. |
ContainerFrozen | Container is frozen. |
ContainerThawed | Container is thawed. |
ContainerOtherState String | Container is in some other state. |
parseState :: String -> ContainerState Source
Parse state as string representation.
printState :: ContainerState -> String Source
Get string representation of a state.
Specifications for how to create a new backing store.
BDevSpecs | |
|
withC'bdev_specs :: BDevSpecs -> (Ptr C'bdev_specs -> IO a) -> IO a Source
Marshal Haskell BDevSpecs
into C structure using temporary storage.
- the memory is freed when the subcomputation terminates (either normally or via an exception), so the pointer to the temporary storage must not be used after this.
:: 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.
mkFn :: (t -> Ptr s) -> (FunPtr (Ptr s -> a) -> Ptr s -> a) -> Field s (FunPtr (Ptr s -> a)) -> t -> IO a Source
boolFn :: Field C'lxc_container (FunPtr ContainerBoolFn) -> Container -> IO Bool Source
stringBoolFn :: Field C'lxc_container (FunPtr ContainerStringBoolFn) -> Container -> Maybe String -> IO Bool Source
boolBoolFn :: Field C'lxc_container (FunPtr ContainerBoolBoolFn) -> Container -> Bool -> IO Bool Source
getItemFn :: Field C'lxc_container (FunPtr ContainerGetItemFn) -> Container -> String -> IO (Maybe String) Source
setItemFn :: Field C'lxc_container (FunPtr ContainerSetItemFn) -> Container -> String -> Maybe String -> IO Bool Source
setItemFn' :: Field C'lxc_container (FunPtr ContainerSetItemFn) -> Container -> String -> String -> IO Bool Source
getDaemonize :: Container -> IO Bool Source
Whether container wishes to be daemonized.
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 | Container. |
-> Maybe FilePath | Full path to alternate configuration file, or |
-> IO Bool |
|
Load the specified configuration for the container.
:: Container | Container. |
-> Bool | Use |
-> [String] | Array of arguments to pass to init. |
-> IO Bool |
|
Start the container.
:: 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.
:: 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.
:: Container | Container. |
-> String | Name of option to set. |
-> String | Value to set. |
-> IO Bool |
|
Set a key/value configuration option.
destroy :: Container -> IO Bool Source
Delete the container.
True
on success, else False
.
- NOTE: Container must be stopped and have no dependent snapshots.
:: Container | Container. |
-> FilePath | Full path to file to save configuration in. |
-> IO Bool |
|
Save configuaration to a file.
:: Container | Container. |
-> String | New name to be used for the container. |
-> IO Bool |
|
Rename a 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
.
clearConfig :: Container -> IO () Source
Completely clear the containers in-memory configuration.
:: 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.
Retrieve a list of config item keys given a key prefix.
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.
Clear a configuration item.
Analog of setConfigItem
.
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 | 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. |
-> 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.
:: 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.
:: Container | Container. |
-> FilePath | Full path to file containing a description of the snapshot. |
-> IO (Maybe Int) |
|
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
.
Destroy the specified snapshot.
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.
:: 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.
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.
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.
listContainersFn :: (CString -> Ptr (Ptr CString) -> Ptr (Ptr (Ptr C'lxc_container)) -> IO CInt) -> Maybe String -> IO [(String, Container)] Source
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.