Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion lxc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,32 @@ def create(name, config_file=None, template=None, backing_store=None, template_o
return 1


def clone(name, original, snapshot=False):
'''
Clones a container.
'''

if exists(name):
raise ContainerAlreadyExists("The Container %s is already created!" % name)
if not exists(original):
raise ContainerNotExists("The container (%s) does not exist!" % original)

cmd = "lxc-clone -n %s -o %s" % (name, original)

if snapshot:
cmd += ' -s'

if subprocess.check_call('%s >> /dev/null' % cmd, shell=True) == 0:
if not exists(name):
_logger.critical("The Container %s doesn't seem to be cloned! (name: %s)", original, name)
raise ContainerNotExists("The container (%s) does not exist!" % name)

_logger.info("Container %s has been cloned to %s", original, name)
return 0
else:
return 1


def exists(name):
'''
checks if a given container is defined or not
Expand Down Expand Up @@ -321,4 +347,4 @@ def th():
subprocess.check_call(cmd)
callback()
_logger.info("Waiting on states %s for container %s", states, name)
threading.Thread(target=th).start()
threading.Thread(target=th).start()