コード例 #1
0
ファイル: api.py プロジェクト: robvdl/lwp-pyramid
 def container_delete(self):
     """
     API to delete a container.
     """
     container = self.request.matchdict["container"]
     try:
         lxc.destroy(container)
         return {"status": "ok"}
     except lxc.ContainerDoesNotExist:
         self.request.response.status = 404
         return {"status": "error", "error": "Container doesn't exist"}
コード例 #2
0
ファイル: container.py プロジェクト: robvdl/lwp-pyramid
    def destroy_container(self):
        """
        Destroys LXC container.
        """
        # TODO: we should use pyramid permission for this
        if not self.request.user.is_superuser:
            return HTTPForbidden()
        try:
            if lxc.destroy(self.container) == 0:
                # TODO: delete machine from db
                self.session.flash('Container {} destroyed successfully'.format(self.container), queue='success')
            else:
                self.session.flash('Unable to destroy {}'.format(self.container), queue='error')
        except lxc.ContainerDoesNotExist:
            self.session.flash('The Container {} does not exists'.format(self.container), queue='error')

        return self._return_from_action()
コード例 #3
0
ファイル: lxc_lite.py プロジェクト: 62William/LXC-Web-Panel
 def test_06_destroy(self):
     lxc.destroy('test00')
     assert not os.path.exists('/tmp/lxc/test00')
コード例 #4
0
ファイル: api.py プロジェクト: wrestrtdr/LXC-Web-Panel-1
def delete_container(name):
    try:
        lxc.destroy(name)
        return jsonify(status="ok"), 200
    except lxc.ContainerDoesntExists:
        return jsonify(status="error", error="Container doesn' t exists"), 400
コード例 #5
0
ファイル: main.py プロジェクト: lukasraska/LXC-Web-Panel
def action():
    """
    manage all actions related to containers
    lxc-start, lxc-stop, etc...
    """
    act = request.args['action']
    name = request.args['name']

    # TODO: refactor this method, it's horrible to read
    if act == 'start':
        try:
            if lxc.start(name) == 0:
                time.sleep(
                    1
                )  # Fix bug : "the container is randomly not displayed in overview list after a boot"
                flash(u'Container %s started successfully!' % name, 'success')
            else:
                flash(u'Unable to start %s!' % name, 'error')
        except lxc.ContainerAlreadyRunning:
            flash(u'Container %s is already running!' % name, 'error')
    elif act == 'stop':
        try:
            if lxc.stop(name) == 0:
                flash(u'Container %s stopped successfully!' % name, 'success')
            else:
                flash(u'Unable to stop %s!' % name, 'error')
        except lxc.ContainerNotRunning:
            flash(u'Container %s is already stopped!' % name, 'error')
    elif act == 'freeze':
        try:
            if lxc.freeze(name) == 0:
                flash(u'Container %s frozen successfully!' % name, 'success')
            else:
                flash(u'Unable to freeze %s!' % name, 'error')
        except lxc.ContainerNotRunning:
            flash(u'Container %s not running!' % name, 'error')
    elif act == 'unfreeze':
        try:
            if lxc.unfreeze(name) == 0:
                flash(u'Container %s unfrozen successfully!' % name, 'success')
            else:
                flash(u'Unable to unfeeze %s!' % name, 'error')
        except lxc.ContainerNotRunning:
            flash(u'Container %s not frozen!' % name, 'error')
    elif act == 'destroy':
        if session['su'] != 'Yes':
            return abort(403)
        try:
            if lxc.destroy(name) == 0:
                flash(u'Container %s destroyed successfully!' % name,
                      'success')
            else:
                flash(u'Unable to destroy %s!' % name, 'error')
        except lxc.ContainerDoesntExists:
            flash(u'The Container %s does not exists!' % name, 'error')
    elif act == 'reboot' and name == 'host':
        if session['su'] != 'Yes':
            return abort(403)
        msg = '\v*** LXC Web Panel *** \
                \nReboot from web panel'

        try:
            subprocess.check_call('/sbin/shutdown -r now \'%s\'' % msg,
                                  shell=True)
            flash(u'System will now restart!', 'success')
        except subprocess.CalledProcessError:
            flash(u'System error!', 'error')
    elif act == 'push':
        # TODO: implement push action
        pass
    try:
        if request.args['from'] == 'edit':
            return redirect('../%s/edit' % name)
        else:
            return redirect(url_for('main.home'))
    except KeyError:
        return redirect(url_for('main.home'))
コード例 #6
0
ファイル: lxc_lite.py プロジェクト: wrestrtdr/LXC-Web-Panel-1
 def test_06_destroy(self):
     lxc.destroy('test00')
     assert not os.path.exists('/tmp/lxc/test00')
コード例 #7
0
ファイル: main.py プロジェクト: romses/LXC-Web-Panel
def action():
    """
    manage all actions related to containers
    lxc-start, lxc-stop, etc...
    """
    act = request.args['action']
    name = request.args['name']

    # TODO: refactor this method, it's horrible to read
    if act == 'start':
        try:
            if lxc.start(name) == 0:
                time.sleep(1)  # Fix bug : "the container is randomly not displayed in overview list after a boot"
                flash(u'Container %s started successfully!' % name, 'success')
            else:
                flash(u'Unable to start %s!' % name, 'error')
        except lxc.ContainerAlreadyRunning:
            flash(u'Container %s is already running!' % name, 'error')
    elif act == 'stop':
        try:
            if lxc.stop(name) == 0:
                flash(u'Container %s stopped successfully!' % name, 'success')
            else:
                flash(u'Unable to stop %s!' % name, 'error')
        except lxc.ContainerNotRunning:
            flash(u'Container %s is already stopped!' % name, 'error')
    elif act == 'freeze':
        try:
            if lxc.freeze(name) == 0:
                flash(u'Container %s frozen successfully!' % name, 'success')
            else:
                flash(u'Unable to freeze %s!' % name, 'error')
        except lxc.ContainerNotRunning:
            flash(u'Container %s not running!' % name, 'error')
    elif act == 'unfreeze':
        try:
            if lxc.unfreeze(name) == 0:
                flash(u'Container %s unfrozen successfully!' % name, 'success')
            else:
                flash(u'Unable to unfeeze %s!' % name, 'error')
        except lxc.ContainerNotRunning:
            flash(u'Container %s not frozen!' % name, 'error')
    elif act == 'destroy':
        if session['su'] != 'Yes':
            return abort(403)
        try:
            if lxc.destroy(name) == 0:
                flash(u'Container %s destroyed successfully!' % name, 'success')
            else:
                flash(u'Unable to destroy %s!' % name, 'error')
        except lxc.ContainerDoesntExists:
            flash(u'The Container %s does not exists!' % name, 'error')
    elif act == 'reboot' and name == 'host':
        if session['su'] != 'Yes':
            return abort(403)
        msg = '\v*** LXC Web Panel *** \
                \nReboot from web panel'
        try:
            subprocess.check_call('/sbin/shutdown -r now \'%s\'' % msg, shell=True)
            flash(u'System will now restart!', 'success')
        except subprocess.CalledProcessError:
            flash(u'System error!', 'error')
    elif act == 'push':
        # TODO: implement push action
        pass
    try:
        if request.args['from'] == 'edit':
            return redirect(url_for('main.edit', container=name))
        else:
            return redirect(url_for('main.home'))
    except KeyError:
        return redirect(url_for('main.home'))
コード例 #8
0
ファイル: api.py プロジェクト: cvalenti/LXC-Web-Panel
def delete_container(name):
    try:
        lxc.destroy(name)
        return jsonify(status="ok"), 200
    except lxc.ContainerDoesntExists:
        return jsonify(status="error", error="Container doesn' t exists"), 400
コード例 #9
0
ファイル: main.py プロジェクト: jaags/LXC-Web-Panel
def action():
    """
    manage all actions related to containers
    lxc-start, lxc-stop, etc...
    """
    act = request.args["action"]
    name = request.args["name"]

    # TODO: refactor this method, it's horrible to read
    if act == "start":
        try:
            if lxc.start(name) == 0:
                time.sleep(1)  # Fix bug : "the container is randomly not displayed in overview list after a boot"
                flash(u"Container %s started successfully!" % name, "success")
            else:
                flash(u"Unable to start %s!" % name, "error")
        except lxc.ContainerAlreadyRunning:
            flash(u"Container %s is already running!" % name, "error")
    elif act == "stop":
        try:
            if lxc.stop(name) == 0:
                flash(u"Container %s stopped successfully!" % name, "success")
            else:
                flash(u"Unable to stop %s!" % name, "error")
        except lxc.ContainerNotRunning:
            flash(u"Container %s is already stopped!" % name, "error")
    elif act == "freeze":
        try:
            if lxc.freeze(name) == 0:
                flash(u"Container %s frozen successfully!" % name, "success")
            else:
                flash(u"Unable to freeze %s!" % name, "error")
        except lxc.ContainerNotRunning:
            flash(u"Container %s not running!" % name, "error")
    elif act == "unfreeze":
        try:
            if lxc.unfreeze(name) == 0:
                flash(u"Container %s unfrozen successfully!" % name, "success")
            else:
                flash(u"Unable to unfeeze %s!" % name, "error")
        except lxc.ContainerNotRunning:
            flash(u"Container %s not frozen!" % name, "error")
    elif act == "destroy":
        if session["su"] != "Yes":
            return abort(403)
        try:
            if lxc.destroy(name) == 0:
                flash(u"Container %s destroyed successfully!" % name, "success")
            else:
                flash(u"Unable to destroy %s!" % name, "error")
        except lxc.ContainerDoesntExists:
            flash(u"The Container %s does not exists!" % name, "error")
    elif act == "reboot" and name == "host":
        if session["su"] != "Yes":
            return abort(403)
        msg = "\v*** LXC Web Panel *** \
                \nReboot from web panel"
        try:
            subprocess.check_call("/sbin/shutdown -r now '%s'" % msg, shell=True)
            flash(u"System will now restart!", "success")
        except subprocess.CalledProcessError:
            flash(u"System error!", "error")
    elif act == "push":
        # TODO: implement push action
        pass
    try:
        if request.args["from"] == "edit":
            return redirect(url_for("main.edit", container=name))
        else:
            return redirect(url_for("main.home"))
    except KeyError:
        return redirect(url_for("main.home"))