Exemple #1
0
    def render(self):
        "Pick or create a cloud to bootstrap a new controller on"
        track_screen("Cloud Select")

        all_clouds = juju.get_clouds()
        compatible_clouds = juju.get_compatible_clouds()
        cloud_types = juju.get_cloud_types_by_name()
        # filter to only public clouds
        public_clouds = sorted(
            name for name, info in all_clouds.items()
            if info['defined'] == 'public' and
            cloud_types[name] in compatible_clouds)
        # filter to custom clouds
        # exclude localhost because we treat that as "configuring a new cloud"
        custom_clouds = sorted(
            name for name, info in all_clouds.items()
            if info['defined'] != 'public' and
            cloud_types[name] != 'localhost' and
            cloud_types[name] in compatible_clouds)

        excerpt = app.config.get(
            'description',
            "Where would you like to deploy?")
        view = CloudView(app,
                         public_clouds,
                         custom_clouds,
                         cb=self.finish)

        app.ui.set_header(
            title="Choose a Cloud",
            excerpt=excerpt
        )
        app.ui.set_body(view)
        app.ui.set_footer('Please press [ENTER] on highlighted '
                          'Cloud to proceed.')
Exemple #2
0
    def render(self):
        spells = []
        track_screen("Spell Picker")
        if app.endpoint_type is None:
            for _, kd in app.spells_index.items():
                spells += kd['spells']
        elif app.endpoint_type == EndpointType.LOCAL_SEARCH:
            spells = utils.find_spells_matching(app.argv.spell)
        else:
            e = Exception("Unexpected endpoint type {}".format(
                app.endpoint_type))
            app.ui.show_exception_message(e)

        # add subdir of spells-dir to spell dict for bundle readme view:
        for spell in spells:
            spell['spell-dir'] = os.path.join(app.config['spells-dir'],
                                              spell['key'])
        view = SpellPickerView(app,
                               sorted(spells, key=lambda kv: kv['name']),
                               self.finish)

        app.ui.set_header(
            title="Spell Selection",
            excerpt="Choose from this list of recommended spells"
        )
        app.ui.set_body(view)
Exemple #3
0
    def render(self):
        spells = []
        track_screen("Spell Picker")
        if app.endpoint_type is None:
            spells += utils.find_spells()
        elif app.endpoint_type == EndpointType.LOCAL_SEARCH:
            spells = utils.find_spells_matching(app.argv.spell)
        else:
            raise Exception("Unexpected endpoint type {}".format(
                app.endpoint_type))

        # add subdir of spells-dir to spell dict for bundle readme view:
        for category, spell in spells:
            spell['spell-dir'] = os.path.join(app.config['spells-dir'],
                                              spell['key'])

        def spellcatsorter(t):
            cat = t[0]
            name = t[1]['name']
            if cat == '_unassigned_spells':
                return ('z', name)
            return (cat, name)

        view = SpellPickerView(app, sorted(spells, key=spellcatsorter),
                               self.finish)

        app.ui.set_header(
            title="Spell Selection",
            excerpt="Choose from this list of recommended spells")
        app.ui.set_body(view)
Exemple #4
0
    def render(self):
        existing_controllers = juju.get_controllers()['controllers']
        if len(existing_controllers) == 0:
            return controllers.use('clouds').render()

        metadata = app.config['metadata']
        whitelisted_clouds = [c for c in metadata.get('cloud-whitelist', [])]
        blacklisted_clouds = [c for c in metadata.get('cloud-blacklist', [])]
        if len(whitelisted_clouds) > 0:
            filtered_controllers = {
                n: d
                for n, d in existing_controllers.items()
                if d['cloud'] in whitelisted_clouds
            }
        elif len(blacklisted_clouds) > 0:
            filtered_controllers = {
                n: d
                for n, d in existing_controllers.items()
                if d['cloud'] not in blacklisted_clouds
            }
        else:
            filtered_controllers = existing_controllers

        if len(filtered_controllers) == 0:
            return controllers.use('clouds').render()

        track_screen("Controller Picker")
        excerpt = app.config.get(
            'description', "Please select an existing controller,"
            " or choose to bootstrap a new one.")
        view = ControllerListView(app, filtered_controllers, self.finish)

        app.ui.set_header(title="Choose a Controller or Create new",
                          excerpt=excerpt)
        app.ui.set_body(view)
Exemple #5
0
 def render_interstitial(self):
     track_screen("JaaS Login Wait")
     app.ui.set_header(title="Waiting")
     self.view = BootstrapWaitView(
         app=app, message="Logging in to JaaS. Please wait.")
     app.ui.set_body(self.view)
     self.__refresh()
Exemple #6
0
    def render(self):
        "Pick or create a cloud to bootstrap a new controller on"
        track_screen("Cloud Select")

        all_clouds = juju.get_clouds()
        compatible_clouds = juju.get_compatible_clouds()
        cloud_types = juju.get_cloud_types_by_name()
        # filter to only public clouds
        public_clouds = sorted(name for name, info in all_clouds.items()
                               if info['defined'] == 'public')
        # filter to custom clouds
        # exclude localhost because we treat that as "configuring a new cloud"
        custom_clouds = sorted(name for name, info in all_clouds.items()
                               if info['defined'] != 'public'
                               and cloud_types[name] != 'localhost')

        excerpt = app.config.get('description',
                                 "Where would you like to deploy?")

        self.view = CloudView(app,
                              public_clouds,
                              custom_clouds,
                              compatible_clouds,
                              cb=self.finish)

        if 'localhost' in compatible_clouds:
            app.log.debug(
                "Starting watcher for verifying LXD server is available.")
            app.loop.create_task(
                self._monitor_localhost(LocalhostProvider(),
                                        self.view._enable_localhost_widget))

        app.ui.set_header(title="Choose a Cloud", excerpt=excerpt)
        app.ui.set_body(self.view)
        app.ui.set_footer('')
Exemple #7
0
    def render(self):
        existing_controllers = juju.get_controllers()['controllers']
        clouds = juju.get_compatible_clouds()
        cloud_types = juju.get_cloud_types_by_name()

        app.jaas_ok = set(clouds) & JAAS_CLOUDS
        jaas_controller = {
            n
            for n, c in existing_controllers.items()
            if JAAS_ENDPOINT in c['api-endpoints']
        }
        if jaas_controller:
            app.jaas_controller = jaas_controller.pop()

        filtered_controllers = {
            n: d
            for n, d in existing_controllers.items()
            if cloud_types.get(d['cloud']) in clouds
        }

        if not app.jaas_ok and len(filtered_controllers) == 0:
            return controllers.use('clouds').render()

        track_screen("Controller Picker")
        excerpt = app.config.get(
            'description', "Please select an existing controller,"
            " or choose to bootstrap a new one.")
        view = ControllerListView(app, filtered_controllers, self.finish)

        app.ui.set_header(title="Choose a Controller or Create new",
                          excerpt=excerpt)
        app.ui.set_body(view)
Exemple #8
0
    def render(self):
        track_screen("Steps")
        if len(self.step_metas) == 0:
            self.finish(None, None, done=True)
            return

        step_widgets = deque()
        self.n_completed_steps = 0
        for step_meta_path in self.step_metas:
            step_ex_path, ext = path.splitext(step_meta_path)
            if not path.isfile(step_ex_path) or \
               not os.access(step_ex_path, os.X_OK):
                app.log.error(
                    'Unable to process step, missing {}'.format(step_ex_path))
                continue
            step_metadata = {}
            with open(step_meta_path) as fp:
                step_metadata = yaml.load(fp.read())

            try:
                # Store step model and its widget
                model = StepModel(step_metadata, step_meta_path)
                step_widget = StepWidget(
                    app,
                    model,
                    self.finish)
                if not step_widget.model.viewable:
                    app.log.debug("Skipping step: {}".format(step_widget))
                    continue
                model.path = step_ex_path
                step_widgets.append(step_widget)
                app.log.debug("Queueing step: {}".format(step_widget))
            except Exception as e:
                self.__handle_exception('E002', e)
                return

        try:
            self.all_step_widgets = list(step_widgets)
            self.view = StepsView(app, step_widgets, self.finish)

            # Set initial step as active and viewable
            step_widgets[0].description.set_text((
                'body', step_widgets[0].model.description))
            step_widgets[0].icon.set_text((
                'pending_icon', step_widgets[0].icon.get_text()[0]
            ))
            step_widgets[0].generate_additional_input()
            self.view.step_pile.focus_position = 2

        except Exception as e:
            self.__handle_exception('E002', e)
            return

        app.ui.set_header(
            title="Additional Application Configuration",
            excerpt="Please finish the installation by configuring your "
            "application with these steps.")
        app.ui.set_body(self.view)
        app.ui.set_footer('')
        self.update()
Exemple #9
0
 def render_form(self, error):
     if juju.has_jaas_auth() and not error:
         self.register()
         return
     track_screen("Login to JaaS")
     app.ui.set_header(title="Login to JaaS",
                       excerpt='Enter your Ubuntu SSO credentials')
     app.ui.set_body(JaaSLoginView(app, error=error, cb=self.register))
Exemple #10
0
    def render(self):
        """ Render
        """
        track_screen("LXD Setup")
        view = LXDSetupView(app, cb=self.finish)

        app.ui.set_header(title="Configure LXD", )
        app.ui.set_body(view)
Exemple #11
0
    def render(self):
        """ Render
        """
        track_screen("LXD Setup")
        self.view = LXDSetupView(app, self.finish)

        app.ui.set_header(title="Setup LXD Bridge", )
        app.ui.set_body(self.view)
Exemple #12
0
 async def login(self, controller, model):
     await juju.login()
     self.authenticating.clear()
     track_screen("Destroy Confirm Model")
     view = DestroyConfirmView(app, controller, model, cb=self.finish)
     app.ui.set_header(
         title="Destroy Confirmation",
         excerpt="Are you sure you wish to destroy the deployment?")
     app.ui.set_body(view)
Exemple #13
0
 def render_interstitial(self):
     track_screen("Controller Login Wait")
     app.ui.set_header(title="Waiting")
     self.view = BootstrapWaitView(
         app=app, message="Logging in to model. Please wait.")
     app.ui.set_body(self.view)
     self.authenticating.set()
     app.loop.create_task(self._refresh())
     self._refresh()
Exemple #14
0
    def render(self):
        track_screen("Steps")
        if len(self.step_metas) == 0:
            self.finish(None, None, done=True)
            return

        step_widgets = deque()
        self.n_completed_steps = 0
        for step_meta_path in self.step_metas:
            step_ex_path, ext = path.splitext(step_meta_path)
            if not path.isfile(step_ex_path) or \
               not os.access(step_ex_path, os.X_OK):
                app.log.error(
                    'Unable to process step, missing {}'.format(step_ex_path))
                continue
            step_metadata = {}
            with open(step_meta_path) as fp:
                step_metadata = yaml.load(fp.read())

            try:
                # Store step model and its widget
                model = StepModel(step_metadata, step_meta_path)
                step_widget = StepWidget(app, model, self.finish)
                if not step_widget.model.viewable:
                    app.log.debug("Skipping step: {}".format(step_widget))
                    continue
                model.path = step_ex_path
                step_widgets.append(step_widget)
                app.log.debug("Queueing step: {}".format(step_widget))
            except Exception as e:
                self.__handle_exception('E002', e)
                return

        try:
            self.all_step_widgets = list(step_widgets)
            self.view = StepsView(app, step_widgets, self.finish)

            # Set initial step as active and viewable
            step_widgets[0].description.set_text(
                ('body', step_widgets[0].model.description))
            step_widgets[0].icon.set_text(
                ('pending_icon', step_widgets[0].icon.get_text()[0]))
            step_widgets[0].generate_additional_input()
            self.view.step_pile.focus_position = 2

        except Exception as e:
            self.__handle_exception('E002', e)
            return

        app.ui.set_header(
            title="Additional Application Configuration",
            excerpt="Please finish the installation by configuring your "
            "application with these steps.")
        app.ui.set_body(self.view)
        app.ui.set_footer('')
        self.update()
Exemple #15
0
    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("")
Exemple #16
0
    def render(self):
        """ Render
        """
        track_screen("LXD Setup")
        self.view = LXDSetupView(app,
                                 self.finish)

        app.ui.set_header(
            title="Setup LXD Bridge",
        )
        app.ui.set_body(self.view)
Exemple #17
0
    def render(self, results):
        track_screen("Summary")
        app.log.debug("Rendering summary results: {}".format(results))

        common.write_results(results, self.save_path)
        self.view = SummaryView(app, results, self.finish)
        app.ui.set_header(title="Deploy Summary",
                          excerpt="Deployment summary for {}".format(
                              app.config['spell']))
        app.ui.set_body(self.view)
        app.ui.set_footer("Your big software is deployed, press "
                          "(Q) key to return to shell.")
Exemple #18
0
    def render(self, results):
        track_screen("Summary")
        app.log.debug("Rendering summary results: {}".format(results))

        common.write_results(results, self.save_path)
        self.view = SummaryView(app, results, self.finish)
        app.ui.set_header(title="Deploy Summary",
                          excerpt="Deployment summary for {}".format(
                              app.config['spell']))
        app.ui.set_body(self.view)
        app.ui.set_footer("Your big software is deployed, press "
                          "(Q) key to return to shell.")
Exemple #19
0
    def render(self):
        "Pick or create a cloud to bootstrap a new controller on"
        track_screen("Cloud Select")
        clouds = list_clouds()
        excerpt = app.config.get(
            'description', "Please select from a list of available clouds")
        view = CloudView(app, clouds, cb=self.finish)

        app.ui.set_header(title="Choose a Cloud", excerpt=excerpt)
        app.ui.set_body(view)
        app.ui.set_footer('Please press [ENTER] on highlighted '
                          'Cloud to proceed.')
Exemple #20
0
    def render(self):
        track_screen("Bootstrap wait")
        app.log.debug("Rendering bootstrap wait")

        self.view = BootstrapWaitView(
            app=app,
            message="Juju Controller is initializing. Please wait.")
        app.ui.set_header(title="Waiting")
        app.ui.set_body(self.view)

        app.bootstrap.running.add_done_callback(self.finish)
        self.__refresh()
Exemple #21
0
    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("")
Exemple #22
0
    def render(self):
        models_map = {}
        existing_controllers = juju.get_controllers()['controllers']
        for cname, d in existing_controllers.items():
            models_map[cname] = juju.get_models(cname)

        track_screen("Destroy Controller")
        excerpt = ("Press [ENTER] on the highlighted item to destroy")
        view = DestroyView(app, models=models_map, cb=self.finish)

        app.ui.set_header(title="Choose a deployment to teardown",
                          excerpt=excerpt)
        app.ui.set_body(view)
Exemple #23
0
    def render(self):
        track_screen("Steps")
        if len(self.step_metas) == 0:
            self.finish(None, None, done=True)
            return

        step_widgets = deque()
        self.n_completed_steps = 0
        for step_meta_path in self.step_metas:
            try:
                # Store step model and its widget
                model = common.load_step(step_meta_path)
                if not model.viewable:
                    app.log.debug("Skipping step: {}".format(model.title))
                    continue
                step_widget = StepWidget(
                    app,
                    model,
                    self.finish)
                step_widgets.append(step_widget)
                app.log.debug("Queueing step: {}".format(step_widget))
            except Exception as e:
                app.log.exception(e)
                self.__handle_exception('E002', e)
                return

        try:
            self.all_step_widgets = list(step_widgets)
            self.view = StepsView(app, step_widgets, self.finish)

            # Set initial step as active and viewable
            step_widgets[0].description.set_text((
                'body', step_widgets[0].model.description))
            step_widgets[0].icon.set_text((
                'pending_icon', step_widgets[0].icon.get_text()[0]
            ))
            step_widgets[0].generate_additional_input()
            self.view.step_pile.focus_position = 2

        except Exception as e:
            self.__handle_exception('E002', e)
            return

        app.ui.set_header(
            title="Additional Application Configuration",
            excerpt="Please finish the installation by configuring your "
            "application with these steps.")
        app.ui.set_body(self.view)
        app.ui.set_footer('')
        self.update()
Exemple #24
0
    def render(self):
        """ Render deploy status view
        """
        track_screen("Deploy Status")
        self.view = DeployStatusView(app)

        try:
            name = app.config["metadata"]["friendly-name"]
        except KeyError:
            name = app.config["spell"]
        app.ui.set_header(title="Conjuring up {}".format(name))
        app.ui.set_body(self.view)
        self.__refresh()
        self.__wait_for_applications()
Exemple #25
0
    def render(self):
        # If bootstrap fails fast, we may be called after the error
        # screen was already shown. We should bail to avoid
        # overwriting the error screen.
        bf = app.bootstrap.running
        if bf and bf.done() and bf.exception():
            return

        track_screen("Deploy")
        try:
            future = async .submit(self._pre_deploy_exec,
                                   partial(self._handle_exception, 'E003'),
                                   queue_name=juju.JUJU_ASYNC_QUEUE)
            if future:
                future.add_done_callback(self._pre_deploy_done)
        except Exception as e:
            return self._handle_exception('E003', e)

        self.applications = sorted(app.metadata_controller.bundle.services,
                                   key=attrgetter('service_name'))
        self.undeployed_applications = self.applications[:]

        cloud_type = juju.get_cloud_types_by_name()[app.current_cloud]
        if cloud_type == 'maas':

            def try_setup_maas():
                """Try to init maas client.
                loops until we get an unexpected exception or we succeed.
                """
                n = 30
                while True:
                    try:
                        setup_maas()
                    except juju.ControllerNotFoundException as e:
                        async .sleep_until(1)
                        n -= 1
                        if n == 0:
                            raise e
                        continue
                    else:
                        break

            async .submit(try_setup_maas, partial(self._handle_exception,
                                                  'EM'))

        self.list_view = ApplicationListView(self.applications,
                                             app.metadata_controller, self)
        self.list_header = "Review and Configure Applications"
        app.ui.set_header(self.list_header)
        app.ui.set_body(self.list_view)
Exemple #26
0
    def render(self):
        """ Render deploy status view
        """
        track_screen("Deploy Status")
        view = DeployStatusView(app)

        try:
            name = app.config['metadata']['friendly-name']
        except KeyError:
            name = app.config['spell']
        app.ui.set_header(title="Conjuring up {}".format(name))
        app.ui.set_body(view)
        app.loop.create_task(self._refresh(view))
        app.loop.create_task(self._wait_for_applications())
Exemple #27
0
    def render(self, controller, model):
        app.current_controller = controller
        app.current_model = model['name']

        track_screen("Destroy Confirm Model")
        view = DestroyConfirmView(app,
                                  controller,
                                  model,
                                  cb=self.finish)
        app.ui.set_header(
            title="Destroy Confirmation",
            excerpt="Are you sure you wish to destroy the deployment?"
        )
        app.ui.set_body(view)
Exemple #28
0
    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("")
Exemple #29
0
    def render(self):
        track_screen("Configure Applications")
        self.applications = sorted(app.metadata_controller.bundle.services,
                                   key=attrgetter('service_name'))
        self.undeployed_applications = self.applications[:]

        cloud_type = juju.get_cloud_types_by_name()[app.provider.cloud]
        if cloud_type == cloud_types.MAAS:
            app.loop.create_task(self.connect_maas())

        self.list_view = ApplicationListView(self.applications,
                                             app.metadata_controller, self)
        self.list_header = "Review and Configure Applications"
        app.ui.set_header(self.list_header)
        app.ui.set_body(self.list_view)
Exemple #30
0
    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("")
Exemple #31
0
    def render(self, last_deploy_action_future):
        """ Render deploy status view
        """
        track_screen("Deploy Status")
        self.view = DeployStatusView(app)

        try:
            name = app.config['metadata']['friendly-name']
        except KeyError:
            name = app.config['spell']
        app.ui.set_header(title="Conjuring up {}".format(name))
        app.ui.set_body(self.view)
        self.__refresh()
        if last_deploy_action_future:
            last_deploy_action_future.add_done_callback(
                self.__wait_for_applications)
Exemple #32
0
    def render(self):
        "Pick or create a cloud to bootstrap a new controller on"
        track_screen("Cloud Select")
        clouds = list_clouds()
        excerpt = app.config.get(
            'description',
            "Please select from a list of available clouds")
        view = CloudView(app,
                         clouds,
                         cb=self.finish)

        app.ui.set_header(
            title="Choose a Cloud",
            excerpt=excerpt
        )
        app.ui.set_body(view)
        app.ui.set_footer('Please press [ENTER] on highlighted '
                          'Cloud to proceed.')
Exemple #33
0
    def render(self):
        track_screen("Bootstrap wait")
        app.log.debug("Rendering bootstrap wait")

        if app.is_jaas:
            bootstrap_stderr_path = None
        else:
            cache_dir = Path(app.config['spell-dir'])
            bootstrap_stderr_path = cache_dir / '{}-bootstrap.err'.format(
                app.current_controller)
        view = BootstrapWaitView(
            app=app,
            message="Juju Controller is initializing. Please wait.",
            watch_file=bootstrap_stderr_path)
        app.ui.set_header(title="Waiting")
        app.ui.set_body(view)

        app.loop.create_task(self.refresh(view))
        app.loop.create_task(self.finish())
Exemple #34
0
async def _start(*args, **kwargs):
    # NB: we have to set the exception handler here because we need to
    # override the one set by urwid, which happens in MainLoop.run()
    app.loop.set_exception_handler(events.handle_exception)

    track_screen("Application Start")
    track_event("OS", platform.platform(), "")

    if app.endpoint_type in [None, EndpointType.LOCAL_SEARCH]:
        controllers.use('spellpicker').render()
        return

    controllers.setup_metadata_controller()

    if app.headless:
        controllers.use('clouds').render()
    elif app.selected_addons:
        controllers.use('clouds').render()
    else:
        controllers.use('addons').render()
Exemple #35
0
    def render(self):
        "Pick or create a cloud to bootstrap a new controller on"
        track_screen("Cloud Select")

        compatible_clouds = juju.get_compatible_clouds()
        all_clouds = juju.get_clouds()
        clouds = []

        for k, v in all_clouds.items():
            if v['type'] in compatible_clouds:
                clouds.append(k)

        excerpt = app.config.get(
            'description', "Please select from a list of available clouds")
        view = CloudView(app, sorted(clouds), cb=self.finish)

        app.ui.set_header(title="Choose a Cloud", excerpt=excerpt)
        app.ui.set_body(view)
        app.ui.set_footer('Please press [ENTER] on highlighted '
                          'Cloud to proceed.')
Exemple #36
0
    def render(self):
        track_screen("Deploy")
        try:
            future = async.submit(self._pre_deploy_exec,
                                  partial(self._handle_exception, 'E003'),
                                  queue_name=juju.JUJU_ASYNC_QUEUE)
            future.add_done_callback(self._pre_deploy_done)
        except Exception as e:
            return self._handle_exception('E003', e)

        self.applications = sorted(app.metadata_controller.bundle.services,
                                   key=attrgetter('service_name'))
        self.undeployed_applications = self.applications[:]

        if app.current_cloud == 'maas':
            def try_setup_maas():
                """Try to init maas client.
                loops until we get an unexpected exception or we succeed.
                """
                n = 30
                while True:
                    try:
                        setup_maas()
                    except juju.ControllerNotFoundException as e:
                        async.sleep_until(1)
                        n -= 1
                        if n == 0:
                            raise e
                        continue
                    else:
                        break

            async.submit(try_setup_maas,
                         partial(self._handle_exception, 'EM'))

        self.list_view = ApplicationListView(self.applications,
                                             app.metadata_controller,
                                             self)
        self.list_header = "Review and Configure Applications"
        app.ui.set_header(self.list_header)
        app.ui.set_body(self.list_view)
Exemple #37
0
    def render(self):
        existing_controllers = juju.get_controllers()['controllers']
        self.check_jaas()

        filtered_controllers = {
            n: d
            for n, d in existing_controllers.items()
            if d['cloud'] == app.provider.cloud
        }

        if not app.jaas_ok and len(filtered_controllers) == 0:
            return self.finish(None)

        track_screen("Controller Picker")
        excerpt = app.config.get(
            'description', "Please select an existing controller,"
            " or choose to bootstrap a new one.")
        view = ControllerListView(app, filtered_controllers, self.finish)

        app.ui.set_header(title="Controller", excerpt=excerpt)
        app.ui.set_body(view)
Exemple #38
0
    def render(self):
        track_screen("Bootstrap")

        if app.is_jaas or self.is_existing_controller():
            bootstrap_stderr_path = None
            msg = 'Model'
        else:
            cache_dir = Path(app.config['spell-dir'])
            bootstrap_stderr_path = cache_dir / '{}-bootstrap.err'.format(
                app.current_controller)
            msg = 'Controller'

        view = BootstrapWaitView(
            app=app,
            message="Juju {} is initializing. Please wait.".format(msg),
            watch_file=bootstrap_stderr_path)
        app.ui.set_header(title="Waiting")
        app.ui.set_body(view)

        app.loop.create_task(self.run())
        app.loop.create_task(self.wait(view))
Exemple #39
0
    def render(self):
        existing_controllers = juju.get_controllers()['controllers']
        if len(existing_controllers) == 0:
            return controllers.use('clouds').render()

        metadata = app.config['metadata']
        whitelisted_clouds = [c for c in metadata.get('cloud-whitelist', [])]
        blacklisted_clouds = [c for c in metadata.get('cloud-blacklist', [])]
        if len(whitelisted_clouds) > 0:
            filtered_controllers = {n: d for n, d
                                    in existing_controllers.items()
                                    if d['cloud'] in whitelisted_clouds}
        elif len(blacklisted_clouds) > 0:
            filtered_controllers = {n: d for n, d
                                    in existing_controllers.items()
                                    if d['cloud'] not in blacklisted_clouds}
        else:
            filtered_controllers = existing_controllers

        if len(filtered_controllers) == 0:
            return controllers.use('clouds').render()

        track_screen("Controller Picker")
        excerpt = app.config.get(
            'description',
            "Please select an existing controller,"
            " or choose to bootstrap a new one.")
        view = ControllerListView(app,
                                  filtered_controllers,
                                  self.finish)

        app.ui.set_header(
            title="Choose a Controller or Create new",
            excerpt=excerpt
        )
        app.ui.set_body(view)