コード例 #1
0
ファイル: gui.py プロジェクト: hlakhdari/conjure-up
 def _handle_exception(self, tag, exc):
     if app.showing_error:
         return
     app.showing_error = True
     track_exception(exc.args[0])
     app.ui.show_exception_message(exc)
     EventLoop.remove_alarms()
コード例 #2
0
async def shutdown_watcher():
    app.log.info('Watching for shutdown')
    try:
        await Shutdown.wait()
    except asyncio.CancelledError:
        pass

    app.log.info('Shutting down')
    if app.headless:
        utils.warning('Shutting down')
    else:
        app.ui.show_shutdown_message()

    try:
        if app.juju.authenticated:
            app.log.info('Disconnecting model')
            await app.juju.client.disconnect()
            app.log.info('Disconnected')

        if not app.headless:
            EventLoop.remove_alarms()

        for task in asyncio.Task.all_tasks(app.loop):
            # cancel all other tasks
            if getattr(task, '_coro', None) is not shutdown_watcher:
                task.cancel()
        app.loop.stop()
    except Exception:
        app.log.exception('Error in cleanup code')
        raise
コード例 #3
0
ファイル: gui.py プロジェクト: mnama/conjure-up
    def finish(self, step_model, step_widget, done=False):
        """ handles processing step with input data

        Arguments:
        step_model: step_model returned from widget
        done: if True continues on to the summary view
        """
        if done:
            EventLoop.remove_alarms()
            return controllers.use('summary').render(self.results)

        # Set next button focus here now that the step is complete.
        self.view.steps.popleft()
        if len(self.view.steps) > 0:
            next_step = self.view.steps[0]
            next_step.generate_additional_input()
            self.view.step_pile.focus_position = self.view.step_pile.focus_position + 1  # noqa
        else:
            app.log.debug("End of step list setting the view "
                          "summary button in focus.")
            index = self.view.current_summary_button_index
            app.log.debug("Next focused button: {}".format(index))
            self.view.step_pile.focus_position = index

        future = async .submit(
            partial(common.do_step,
                    step_model,
                    step_widget,
                    app.ui.set_footer,
                    gui=True), partial(self.__handle_exception, 'E002'))
        future.add_done_callback(self.get_result)
コード例 #4
0
ファイル: gui.py プロジェクト: graywen24/conjure-up
    def finish(self, step_model, step_widget, done=False):
        """ handles processing step with input data

        Arguments:
        step_model: step_model returned from widget
        done: if True continues on to the summary view
        """
        if done:
            EventLoop.remove_alarms()
            return controllers.use('summary').render(self.results)

        # Set next button focus here now that the step is complete.
        self.view.steps.popleft()
        if len(self.view.steps) > 0:
            next_step = self.view.steps[0]
            next_step.generate_additional_input()
            self.view.step_pile.focus_position = self.view.step_pile.focus_position + 1  # noqa
        else:
            app.log.debug(
                "End of step list setting the view "
                "summary button in focus.")
            index = self.view.current_summary_button_index
            app.log.debug("Next focused button: {}".format(index))
            self.view.step_pile.focus_position = index

        future = async.submit(partial(common.do_step,
                                      step_model,
                                      step_widget,
                                      app.ui.set_footer,
                                      gui=True),
                              partial(self.__handle_exception, 'E002'))
        future.add_done_callback(self.get_result)
コード例 #5
0
async def shutdown_watcher():
    app.log.info('Watching for shutdown')
    try:
        try:
            await Shutdown.wait()
        except asyncio.CancelledError:
            pass

        app.log.info('Shutting down')
        if app.headless:
            utils.warning('Shutting down')

        # Store application configuration state
        await app.save()

        if app.juju.authenticated:
            app.log.info('Disconnecting model')
            await app.juju.client.disconnect()
            app.log.info('Disconnected')

        if not app.headless:
            EventLoop.remove_alarms()

        for task in asyncio.Task.all_tasks(app.loop):
            # cancel all other tasks
            coro = getattr(task, '_coro', None)
            cr_code = getattr(coro, 'cr_code', None)
            if cr_code is not shutdown_watcher.__code__:
                app.log.debug('Cancelling pending task: {}'.format(task))
                task.cancel()
        await asyncio.sleep(0.1)  # give tasks a chance to see the cancel
    except Exception as e:
        app.log.exception('Error in cleanup code: {}'.format(e))
    app.loop.stop()
コード例 #6
0
ファイル: __init__.py プロジェクト: tomconte/conjure-up
    def show_exception_message(self, ex):
        errmsg = str(ex)
        errmsg += ("\n\n"
                   "Review log messages at ~/.cache/conjure-up/conjure-up.log "
                   "If appropriate, please submit a bug here: "
                   "https://github.com/conjure-up/conjure-up/issues/new")

        async .shutdown()
        EventLoop.remove_alarms()
        self.frame.body = ErrorView(errmsg)
        app.log.debug("Showing dialog for exception: {}".format(ex))
コード例 #7
0
    def show_exception_message(self, ex):
        _cache_dir = Path(app.argv.cache_dir) / 'conjure-up.log'
        errmsg = str(ex)
        errmsg += ("\n\n Review log messages at {} "
                   "If appropriate, please submit a bug here: "
                   "https://github.com/conjure-up/conjure-up/issues/new".
                   format(_cache_dir))

        async .shutdown()
        EventLoop.remove_alarms()
        self.frame.body = ErrorView(errmsg)
        # ensure error is shown, even if exception was inside urwid
        EventLoop.redraw_screen()
        app.log.debug("Showing dialog for exception: {}".format(ex))
コード例 #8
0
ファイル: gui.py プロジェクト: battlemidget/conjure-up
    def __handle_bootstrap_done(self, future):
        app.log.debug("handle bootstrap")
        result = future.result()
        if result.returncode < 0:
            # bootstrap killed via user signal, we're quitting
            return
        if result.returncode > 0:
            err = result.stderr.read().decode()
            app.log.error(err)
            return self.__handle_exception(Exception("error "))

        utils.pollinate(app.session_id, 'J004')
        EventLoop.remove_alarms()
        app.ui.set_footer('Bootstrap complete...')
        self.__post_bootstrap_exec()
コード例 #9
0
ファイル: gui.py プロジェクト: mnama/conjure-up
    def __handle_bootstrap_done(self, future):
        app.log.debug("handle bootstrap")
        result = future.result()
        if result.returncode < 0:
            # bootstrap killed via user signal, we're quitting
            return
        if result.returncode > 0:
            err = result.stderr.read().decode()
            app.log.error(err)
            return self.__handle_exception(Exception("error "))

        utils.pollinate(app.session_id, 'J004')
        EventLoop.remove_alarms()
        app.ui.set_footer('Bootstrap complete...')
        juju.switch_controller(app.current_controller)
        self.__post_bootstrap_exec()
コード例 #10
0
ファイル: gui.py プロジェクト: battlemidget/conjure-up
    def finish(self, needs_lxd_setup=False, lxdnetwork=None, back=False):
        """ Processes the new LXD setup and loads the controller to
        finish bootstrapping the model.

        Arguments:
        back: if true loads previous controller
        needs_lxd_setup: if true prompt user to run lxd init
        """
        if back:
            return controllers.use('clouds').render()

        if needs_lxd_setup:
            EventLoop.remove_alarms()
            EventLoop.exit(1)

        if lxdnetwork is None:
            return app.ui.show_exception_message(
                Exception("Unable to configure LXD network bridge."))

        formatted_network = self.__format_input(lxdnetwork)
        app.log.debug("LXD Config {}".format(formatted_network))

        out = self.__format_conf(formatted_network)

        with NamedTemporaryFile(mode="w", encoding="utf-8",
                                delete=False) as tempf:
            app.log.debug("Saving LXD config to {}".format(tempf.name))
            utils.spew(tempf.name, out)
            sh = utils.run('sudo mv {} /etc/default/lxd-bridge'.format(
                tempf.name), shell=True)
            if sh.returncode > 0:
                return app.ui.show_exception_message(
                    Exception("Problem saving config: {}".format(
                        sh.stderr.decode('utf8'))))

        app.log.debug("Restarting lxd-bridge")
        utils.run("sudo systemctl restart lxd-bridge.service", shell=True)

        utils.pollinate(app.session_id, 'L002')
        controllers.use('newcloud').render(
            cloud='localhost', bootstrap=True)
コード例 #11
0
    def finish(self, needs_lxd_setup=False, lxdnetwork=None, back=False):
        """ Processes the new LXD setup and loads the controller to
        finish bootstrapping the model.

        Arguments:
        back: if true loads previous controller
        needs_lxd_setup: if true prompt user to run lxd init
        """
        if back:
            return controllers.use('clouds').render()

        if needs_lxd_setup:
            EventLoop.remove_alarms()
            EventLoop.exit(1)

        if lxdnetwork is None:
            return app.ui.show_exception_message(
                Exception("Unable to configure LXD network bridge."))

        formatted_network = self.__format_input(lxdnetwork)
        app.log.debug("LXD Config {}".format(formatted_network))

        out = self.__format_conf(formatted_network)

        with NamedTemporaryFile(mode="w", encoding="utf-8",
                                delete=False) as tempf:
            app.log.debug("Saving LXD config to {}".format(tempf.name))
            utils.spew(tempf.name, out)
            sh = run('sudo mv {} /etc/default/lxd-bridge'.format(
                tempf.name), shell=True)
            if sh.returncode > 0:
                return app.ui.show_exception_message(
                    Exception("Problem saving config: {}".format(
                        sh.stderr.decode('utf8'))))

        app.log.debug("Restarting lxd-bridge")
        run("sudo systemctl restart lxd-bridge.service", shell=True)

        utils.pollinate(app.session_id, 'L002')
        controllers.use('newcloud').render(
            cloud='localhost', bootstrap=True)
コード例 #12
0
    def __handle_bootstrap_done(self, future):
        app.log.debug("handle bootstrap")
        result = future.result()
        if result.returncode < 0:
            # bootstrap killed via user signal, we're quitting
            return
        if result.returncode > 0:
            pathbase = os.path.join(app.config['spell-dir'],
                                    '{}-bootstrap').format(
                                        app.current_controller)

            with open(pathbase + ".err") as errf:
                err = "\n".join(errf.readlines())
                app.log.error(err)
            e = Exception("Bootstrap error: {}".format(err))
            return self.__handle_exception(e)

        track_event("Juju Bootstrap", "Done", "")
        EventLoop.remove_alarms()
        app.ui.set_footer('Bootstrap complete...')
        self.__post_bootstrap_exec()
コード例 #13
0
    def finish(self, step_model, step_widget, done=False):
        """ handles processing step with input data

        Arguments:
        step_model: step_model returned from widget
        done: if True continues on to the summary view
        """
        if done:
            EventLoop.remove_alarms()
            return controllers.use('summary').render(self.results)

        if utils.is_linux() and step_model.needs_sudo:
            password = None
            if step_widget.sudo_input:
                password = step_widget.sudo_input.value
            if not step_model.can_sudo(password):
                step_widget.set_error(
                    'Sudo failed.  Please check your password and ensure that '
                    'your sudo timeout is not set to zero.')
                step_widget.show_button()
                return

        step_widget.clear_error()

        # Set next button focus here now that the step is complete.
        self.view.steps.popleft()

        if len(self.view.steps) > 0:
            next_step = self.view.steps[0]
            next_step.generate_additional_input()
            self.view.step_pile.focus_position = self.view.step_pile.focus_position + 1  # noqa

        future = async.submit(partial(common.do_step,
                                      step_model,
                                      step_widget,
                                      app.ui.set_footer,
                                      gui=True),
                              partial(self.__handle_exception, 'E002'))
        if future:
            future.add_done_callback(self.get_result)
コード例 #14
0
ファイル: __init__.py プロジェクト: graywen24/conjure-up
from conjureup import async
from conjureup.app_config import app
from ubuntui.ev import EventLoop
import macumba
import errno


class ConjureUI(Frame):
    def show_exception_message(self, ex):

        if isinstance(ex, async.ThreadCancelledException):
            pass
        elif isinstance(ex, macumba.errors.ServerError):
            errmsg = ex.args[1]
        elif hasattr(ex, 'errno') and ex.errno == errno.ENOENT:
            # handle oserror
            errmsg = ex.args[1]
        else:
            errmsg = ex.args[0]
        errmsg += ("\n\n"
                   "Review log messages at /var/log/conjure-up/combined.log "
                   "If appropriate, please submit a bug here: "
                   "https://bugs.launchpad.net/conjure-up/+filebug")

        self.frame.body = ErrorView(errmsg)
        app.log.exception("Showing dialog for exception:")
        EventLoop.remove_alarms()

    def show_error_message(self, msg):
        self.frame.body = ErrorView(msg)
コード例 #15
0
ファイル: gui.py プロジェクト: graywen24/conjure-up
 def _handle_exception(self, tag, exc):
     utils.pollinate(app.session_id, tag)
     app.ui.show_exception_message(exc)
     self.showing_error = True
     EventLoop.remove_alarms()
コード例 #16
0
ファイル: gui.py プロジェクト: mnama/conjure-up
 def __handle_exception(self, tag, exc):
     utils.pollinate(app.session_id, tag)
     EventLoop.remove_alarms()
     app.ui.show_exception_message(exc)
コード例 #17
0
ファイル: gui.py プロジェクト: johnsca/conjure-up
 def finish(self):
     EventLoop.remove_alarms()
     EventLoop.exit(0)
コード例 #18
0
ファイル: gui.py プロジェクト: conjure-up/conjure-up
 def __handle_exception(self, tag, exc):
     track_exception(exc.args[0], is_fatal=True)
     EventLoop.remove_alarms()
     app.ui.show_exception_message(exc)
コード例 #19
0
 def __handle_exception(self, tag, exc):
     track_exception(exc.args[0], is_fatal=True)
     EventLoop.remove_alarms()
     app.ui.show_exception_message(exc)
コード例 #20
0
ファイル: __init__.py プロジェクト: johnsca/conjure-up
from conjureup.app_config import app
from ubuntui.ev import EventLoop
import macumba
import errno


class ConjureUI(Frame):
    def show_exception_message(self, ex):

        if isinstance(ex, async .ThreadCancelledException):
            pass
        elif isinstance(ex, macumba.errors.ServerError):
            errmsg = ex.args[1]
        elif hasattr(ex, 'errno') and ex.errno == errno.ENOENT:
            # handle oserror
            errmsg = ex.args[1]
        else:
            errmsg = ex.args[0]
        errmsg += ("\n\n"
                   "Review log messages at ~/.cache/conjure-up/conjure-up.log "
                   "If appropriate, please submit a bug here: "
                   "https://github.com/conjure-up/conjure-up/issues/new")

        async .shutdown()
        EventLoop.remove_alarms()
        self.frame.body = ErrorView(errmsg)
        app.log.debug("Showing dialog for exception: {}".format(ex))

    def show_error_message(self, msg):
        self.frame.body = ErrorView(msg)
コード例 #21
0
ファイル: gui.py プロジェクト: mnama/conjure-up
 def finish(self, future):
     if not future.exception():
         return controllers.use('steps').render()
     EventLoop.remove_alarms()
コード例 #22
0
ファイル: gui.py プロジェクト: graywen24/conjure-up
 def __handle_exception(self, tag, exc):
     utils.pollinate(app.session_id, tag)
     EventLoop.remove_alarms()
     app.ui.show_exception_message(exc)
コード例 #23
0
ファイル: gui.py プロジェクト: conjure-up/conjure-up
 def _handle_exception(self, tag, exc):
     track_exception(exc.args[0])
     app.ui.show_exception_message(exc)
     self.showing_error = True
     EventLoop.remove_alarms()
コード例 #24
0
 def __handle_destroy_done(self, future):
     if not future.exception():
         app.ui.set_footer("")
         return controllers.use('destroy').render()
     EventLoop.remove_alarms()
コード例 #25
0
ファイル: gui.py プロジェクト: benluteijn/conjure-up
def finish():
    EventLoop.remove_alarms()
コード例 #26
0
ファイル: gui.py プロジェクト: graywen24/conjure-up
 def finish(self):
     EventLoop.remove_alarms()
     EventLoop.exit(0)
コード例 #27
0
ファイル: gui.py プロジェクト: mnama/conjure-up
 def _handle_exception(self, tag, exc):
     utils.pollinate(app.session_id, tag)
     app.ui.show_exception_message(exc)
     self.showing_error = True
     EventLoop.remove_alarms()