def render_newcloud(self): """ Renders new cloud provider form """ try: creds = load_schema(app.current_cloud) except Exception as e: track_exception("Credentials Error: {}".format(e)) app.log.exception("Credentials Error: {}".format(e)) return app.ui.show_exception_message( Exception( "Unable to find credentials for {}, " "you can double check what credentials you " "do have available by running " "`juju credentials`. Please see `juju help " "add-credential` for more information.".format( app.current_cloud))) regions = [] # No regions for these providers if self.cloud_type not in ['maas', 'vsphere', 'localhost']: regions = sorted(juju.get_regions(app.current_cloud).keys()) view = NewCloudView(creds, regions, self.finish) app.ui.set_header( title="New cloud setup", ) app.ui.set_body(view) app.ui.set_footer("")
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()
def handle_exception(loop, context): exc = context.get('exception') if exc is None or isinstance(exc, CancelledError): return # not an error, cleanup message if isinstance(exc, ExitMainLoop): Shutdown.set() # use previously stored exit code return if Error.is_set(): return # already reporting an error Error.set() exc_info = (type(exc), exc, exc.__traceback__) if any(pred(exc) for pred in NOTRACK_EXCEPTIONS): app.log.debug('Would not track exception: {}'.format(exc)) if not (app.noreport or any(pred(exc) for pred in NOTRACK_EXCEPTIONS)): track_exception(str(exc)) utils.sentry_report(exc_info=exc_info) msg = 'Unhandled exception' if 'future' in context: msg += ' in {}'.format(context['future']) app.log.exception(msg, exc_info=exc) if app.headless: msg = str(exc) utils.error(msg) Shutdown.set(1) else: app.exit_code = 1 # store exit code for later app.ui.show_exception_message(exc) # eventually raises ExitMainLoop
def render(self): track_screen("Cloud Creation") if app.current_controller is None: app.current_controller = "conjure-up-{}-{}".format( app.current_cloud, utils.gen_hash()) if app.current_model is None: app.current_model = utils.gen_model() cloud_type = juju.get_cloud_types_by_name()[app.current_cloud] # LXD is a special case as we want to make sure a bridge # is configured. If not we'll bring up a new view to allow # a user to configure a LXD bridge with suggested network # information. if cloud_type == 'localhost': lxd = common.is_lxd_ready() if not lxd['ready']: return controllers.use('lxdsetup').render(lxd['msg']) # lxd doesn't require user-provided credentials, # so never show the editor for localhost return self.finish() creds = common.try_get_creds(app.current_cloud) try: endpoint = juju.get_cloud(app.current_cloud).get('endpoint', None) except LookupError: endpoint = None if creds and (endpoint or cloud_type != 'maas'): return self.finish() # show credentials editor otherwise try: creds = load_schema(app.current_cloud) except Exception as e: track_exception("Credentials Error: {}".format(e)) app.log.exception("Credentials Error: {}".format(e)) return app.ui.show_exception_message( Exception("Unable to find credentials for {}, " "you can double check what credentials you " "do have available by running " "`juju credentials`. Please see `juju help " "add-credential` for more information.".format( app.current_cloud))) regions = [] # No regions for these providers if cloud_type not in ['maas', 'vsphere']: regions = sorted(juju.get_regions(app.current_cloud).keys()) view = NewCloudView(creds, regions, self.finish) app.ui.set_header(title="New cloud setup", ) app.ui.set_body(view) app.ui.set_footer("")
def render(self): track_screen("Cloud Creation") if app.current_controller is None: app.current_controller = "conjure-up-{}-{}".format( app.current_cloud, utils.gen_hash()) if app.current_model is None: app.current_model = utils.gen_model() # LXD is a special case as we want to make sure a bridge # is configured. If not we'll bring up a new view to allow # a user to configure a LXD bridge with suggested network # information. cloud_type = juju.get_cloud_types_by_name()[app.current_cloud] try: if cloud_type == 'lxd': lxd = common.is_lxd_ready() if not lxd['ready']: return controllers.use('lxdsetup').render(lxd['msg']) self.__do_bootstrap() return except LookupError as e: # TODO: Add vsphere once lp bug 1671650 is resolved if cloud_type in ['maas']: app.log.debug("Not a cloud, using provider type: {}".format( app.current_cloud)) else: raise Exception(e) # XXX: always prompt for maas information for now as there is no way to # logically store the maas server ip for future sessions. creds = common.try_get_creds(app.current_cloud) if creds and cloud_type != 'maas': self.__do_bootstrap(credential=creds) return controllers.use('deploy').render() # show credentials editor otherwise try: creds = load_schema(app.current_cloud) except Exception as e: track_exception("Credentials Error: {}".format(e)) return app.ui.show_exception_message( Exception("Unable to find credentials for cloud " "looking for {}".format(app.current_cloud))) view = NewCloudView(creds, self.finish) app.ui.set_header(title="New cloud setup", ) app.ui.set_body(view) app.ui.set_footer("")
def __post_bootstrap_done(self, future): try: result = json.loads(future.result().decode('utf8')) except Exception as e: return self.__handle_exception(e) app.log.debug("post_bootstrap_done: {}".format(result)) if result['returnCode'] > 0: track_exception("Error in Post-Bootstrap") return self.__handle_exception(Exception( 'There was an error during the post ' 'bootstrap processing phase: {}.'.format(result))) track_event("Juju Post-Bootstrap", "Done", "") app.ui.set_footer('')
def __post_bootstrap_done(self, future): try: result = json.loads(future.result().decode('utf8')) except Exception as e: return self.__handle_exception(e) app.log.debug("post_bootstrap_done: {}".format(result)) if result['returnCode'] > 0: track_exception("Error in Post-Bootstrap") return self.__handle_exception( Exception('There was an error during the post ' 'bootstrap processing phase: {}.'.format(result))) track_event("Juju Post-Bootstrap", "Done", "") app.ui.set_footer('')
def render(self, cloud): """ Render Arguments: cloud: The cloud to create credentials for """ track_screen("Cloud Creation") self.cloud = cloud if app.current_controller is None: app.current_controller = petname.Name() if app.current_model is None: app.current_model = 'conjure-up' # LXD is a special case as we want to make sure a bridge # is configured. If not we'll bring up a new view to allow # a user to configure a LXD bridge with suggested network # information. if self.cloud == 'localhost': if not utils.check_bridge_exists(): return controllers.use('lxdsetup').render() app.log.debug("Found an IPv4 address, " "assuming LXD is configured.") self.__do_bootstrap() return controllers.use('deploy').render() # XXX: always prompt for maas information for now as there is no way to # logically store the maas server ip for future sessions. if common.try_get_creds(self.cloud) \ is not None and self.cloud != 'maas': self.__do_bootstrap(credential=common.try_get_creds(self.cloud)) return controllers.use('deploy').render() # show credentials editor otherwise try: creds = Schema[self.cloud] except KeyError as e: track_exception("Credentials Error") return app.ui.show_exception_message(e) view = NewCloudView(app, self.cloud, creds, self.finish) app.ui.set_header(title="New cloud setup", ) app.ui.set_body(view) app.ui.set_footer("")
def render(self): track_screen("Cloud Creation") if app.current_controller is None: app.current_controller = petname.Name() if app.current_model is None: app.current_model = 'conjure-up' # LXD is a special case as we want to make sure a bridge # is configured. If not we'll bring up a new view to allow # a user to configure a LXD bridge with suggested network # information. if app.current_cloud == 'localhost': if not utils.check_bridge_exists() or \ not utils.check_user_in_group('lxd'): return controllers.use('lxdsetup').render() app.log.debug("Found an IPv4 address, " "assuming LXD is configured.") self.__do_bootstrap() return controllers.use('deploy').render() # XXX: always prompt for maas information for now as there is no way to # logically store the maas server ip for future sessions. if common.try_get_creds(app.current_cloud) \ is not None and app.current_cloud != 'maas': self.__do_bootstrap( credential=common.try_get_creds(app.current_cloud)) return controllers.use('deploy').render() # show credentials editor otherwise try: creds = Schema[app.current_cloud] except KeyError as e: track_exception("Credentials Error") return app.ui.show_exception_message(e) view = NewCloudView(creds, self.finish) app.ui.set_header( title="New cloud setup", ) app.ui.set_body(view) app.ui.set_footer("")
def _pre_deploy_done(self, future): e = future.exception() if e: self._handle_exception('Pre Deploy', e) return result = future.result() app.log.debug("pre_deploy_done: {}".format(result)) if result['returnCode'] > 0: track_exception("Pre-deploy error") return self._handle_exception( 'E003', Exception('There was an error during the pre ' 'deploy processing phase: {}.'.format(result))) else: app.ui.set_footer("Pre-deploy processing done.")
def _pre_deploy_done(self, future): try: result = json.loads(future.result().stdout.decode()) except AttributeError: result = json.loads(future.result()) except: return self._handle_exception( 'E003', Exception( "Problem with pre-deploy: \n{}, ".format( future.result()))) app.log.debug("pre_deploy_done: {}".format(result)) if result['returnCode'] > 0: track_exception("Pre-deploy error") return self._handle_exception('E003', Exception( 'There was an error during the pre ' 'deploy processing phase: {}.'.format(result))) else: app.ui.set_footer("Pre-deploy processing done.")
def _pre_deploy_done(self, future): try: result = json.loads(future.result().stdout.decode()) except AttributeError: result = json.loads(future.result()) except: return self._handle_exception( 'E003', Exception("Problem with pre-deploy: \n{}, ".format( future.result()))) app.log.debug("pre_deploy_done: {}".format(result)) if result['returnCode'] > 0: track_exception("Pre-deploy error") return self._handle_exception( 'E003', Exception('There was an error during the pre ' 'deploy processing phase: {}.'.format(result))) else: app.ui.set_footer("Pre-deploy processing done.")
def handle_exception(loop, context): if 'exception' not in context: return # not an error, cleanup message if isinstance(context['exception'], ExitMainLoop): Shutdown.set() # use previously stored exit code return if Error.is_set(): return # already reporting an error Error.set() exc = context['exception'] if not (app.noreport or any(pred(exc) for pred in NOTRACK_EXCEPTIONS)): track_exception(str(exc)) try: exc_info = (type(exc), exc, exc.__traceback__) app.sentry.captureException(exc_info, tags={ 'spell': app.config.get('spell'), 'cloud_type': app.current_cloud_type, 'region': app.current_region, 'jaas': app.is_jaas, 'headless': app.headless, 'juju_version': utils.juju_version(), 'lxd_version': utils.lxd_version(), }) except Exception: app.log.exception('Error reporting error') app.log.exception('Unhandled exception', exc_info=exc) if app.headless: msg = str(exc) utils.error(msg) Shutdown.set(1) else: app.exit_code = 1 # store exit code for later app.ui.show_exception_message(exc) # eventually raises ExitMainLoop
def handle_exception(loop, context): if 'exception' not in context: return # not an error, cleanup message if isinstance(context['exception'], ExitMainLoop): Shutdown.set() # use previously stored exit code return if Error.is_set(): return # already reporting an error Error.set() exc = context['exception'] track_exception(str(exc)) # not sure of a cleaner way to log the exception instance try: raise exc except type(exc): app.log.exception('Unhandled exception') if app.headless: utils.error(exc) Shutdown.set(1) else: app.exit_code = 1 # store exit code for later app.ui.show_exception_message(exc) # eventually raises ExitMainLoop
def render(self): track_screen("Cloud Creation") if app.current_controller is None: app.current_controller = "conjure-up-{}-{}".format( app.current_cloud, utils.gen_hash()) if app.current_model is None: app.current_model = "conjure-up-{}-{}".format( app.env['CONJURE_UP_SPELL'], utils.gen_hash()) # LXD is a special case as we want to make sure a bridge # is configured. If not we'll bring up a new view to allow # a user to configure a LXD bridge with suggested network # information. if app.current_cloud == 'localhost': if not utils.check_bridge_exists(): return controllers.use('lxdsetup').render( "Unable to determine an existing LXD network bridge, " "please make sure you've run `sudo lxd init` to configure " "LXD.") if not utils.check_user_in_group('lxd'): return controllers.use('lxdsetup').render( "{} is not part of the LXD group. You will need " "to exit conjure-up and do one of the following: " " 1: Run `newgrp lxd` and re-launch conjure-up\n" " 2: Log out completely, Log in and " "re-launch conjure-up".format(os.environ['USER'])) if utils.lxd_has_ipv6(): return controllers.use('lxdsetup').render( "The LXD bridge has IPv6 enabled. Currently this is " "unsupported by conjure-up. Please disable IPv6 and " "re-launch conjure-up\n\n" "Visit http://conjure-up.io/docs/en/users/#_lxd for " "information on how to disable IPv6.") app.log.debug("Found an IPv4 address, " "assuming LXD is configured.") self.__do_bootstrap() return # XXX: always prompt for maas information for now as there is no way to # logically store the maas server ip for future sessions. if common.try_get_creds(app.current_cloud) \ is not None and app.current_cloud != 'maas': self.__do_bootstrap( credential=common.try_get_creds(app.current_cloud)) return controllers.use('deploy').render() # show credentials editor otherwise try: creds = Schema[app.current_cloud] except KeyError as e: track_exception("Credentials Error") return app.ui.show_exception_message(e) view = NewCloudView(creds, self.finish) app.ui.set_header(title="New cloud setup", ) app.ui.set_body(view) app.ui.set_footer("")
def __handle_exception(self, exc): track_exception(exc.args[0]) app.ui.set_footer("Problem destroying the deployment") return app.ui.show_exception_message(exc)
def __handle_exception(self, msg, exc): track_exception(msg) return app.ui.show_exception_message(exc)
def __handle_exception(self, exc): track_exception(exc.args[0]) return app.ui.show_exception_message(exc)
def __handle_exception(self, exc): if app.showing_error: return app.showing_error = True track_exception(exc.args[0]) app.ui.show_exception_message(exc)
def _handle_exception(self, tag, exc): track_exception(exc.args[0]) app.ui.show_exception_message(exc) self.showing_error = True EventLoop.remove_alarms()
def __handle_exception(self, tag, exc): track_exception(exc.args[0], is_fatal=True) EventLoop.remove_alarms() app.ui.show_exception_message(exc)
def __handle_exception(self, exc): track_exception(exc.args[0]) app.ui.show_exception_message(exc)