XC4U
lxc4u的Python项目详细描述
警告!这项工作仍在进行中。
提供在Ubuntu12.04和Ubuntu12.04容器中管理LXC的工具。 不支持其他容器(还不支持?)
- 使用overlayfs创建容器
- 可以处理多个覆盖层
工作示例
创建名为test1:
的容器import lxc4u test1_lxc = lxc4u.create('test1') # Wait a long time... # Start the container test1_lxc.start()
创建覆盖test1:
的容器import lxc4u test1_overlay_lxc = lxc4u.create('test1_overlay', base='test1', overlays=['overlay_path']) # Start the container test1_overlay_lxc.start() test1_overlay_lxc.destroy()
创建一个包含多个test1覆盖的容器。最右边的覆盖 是最上面的覆盖目录:
import lxc4u test1_overlay_lxc = lxc4u.create('test1_overlay', base='test1', overlays=['overlay1_path', 'overlay2_path']) # Start the container test1_overlay_lxc.start()
这些例子尚未实施。很快!
正在启动名为test1的容器。这假设lxc配置正确 在您的系统中:
import lxc4u # Start container test1_lxc = lxc4u.start('test1') # Stop container test1_lxc.stop() # or lxc4u.stop('test1')
可能的接口示例
以test1为基础启动临时容器:
import lxc4u # Start container test1_ephemeral_lxc = lxc4u.start('test1', ephemeral=True) # Stop container test1_ephemeral_lxc.stop()
使用带有静态网络设置的test1启动临时容器:
import lxc4u network_settings = dict( ip="10.0.3.5", gateway="10.0.3.1", netmask="255.255.255.0", network="10.0.3.0", ) # Start container test1_ephemeral_lxc = lxc4u.start('test1', ephemeral=True, static_network=network_settings) # Stop container test1_ephemeral_lxc.stop()
使用startup命令启动临时容器(必须可用 在容器的路径上):
import lxc4u # Start container test1_ephemeral_lxc = lxc4u.start('test1', ephemeral=True, startup_command="/usr/local/bin/somecommand") # Stop container test1_ephemeral_lxc.stop()