@mod.route('/action/clone-container', methods=['GET', 'POST'])
@if_logged_in()
def clone_container():
    """
    verify all forms to clone a container
    """
    if session['su'] != 'Yes':
        return abort(403)
    if request.method == 'POST':
        orig = request.form['orig']
        name = request.form['name']

        try:
            snapshot = request.form['snapshot']
            if snapshot == 'True':
                snapshot = True
        except KeyError:
            snapshot = False

        if re.match('^(?!^containers$)|[a-zA-Z0-9_-]+$', name):
            out = None

            try:
                out = lxc.clone(orig=orig, new=name, snapshot=snapshot)
            except lxc.ContainerAlreadyExists:
                flash(u'The Container %s already exists!' % name, 'error')
            except subprocess.CalledProcessError:
                flash(u'Can\'t snapshot a directory', 'error')

            if out and out == 0:
                flash(u'Container %s cloned into %s successfully!' % (orig, name), 'success')
            elif out and out != 0:
                flash(u'Failed to clone %s into %s!' % (orig, name), 'error')

        else:
            if name == '':
                flash(u'Please enter a container name!', 'error')
            else:
                flash(u'Invalid name for \"%s\"!' % name, 'error')

    return redirect(url_for('main.home'))
dataset/ETHPy150Open claudyus/LXC-Web-Panel/lwp/views/main.py/clone_container/original