Esempio n. 1
0
    def finish(self, single_service=None):
        """handles deployment

        Arguments:

        single_service: a dict for the service that was just
        configured. finish will schedule a deploy for it and
        call render() again to display the next one.

        if service is None, schedules deploys for all remaining services,
        schedules relations, then continues to next controller

        """
        if single_service:
            juju.deploy_service(single_service,
                                app.ui.set_footer,
                                partial(self._handle_exception, "ED"))
            self.svc_idx += 1
            return self.render()
        else:
            for service in self.services[self.svc_idx:]:
                juju.deploy_service(service,
                                    app.ui.set_footer,
                                    partial(self._handle_exception, "ED"))

            juju.set_relations(self.services,
                               app.ui.set_footer,
                               partial(self._handle_exception, "ED"))

            if app.bootstrap.running and not app.bootstrap.running.done():
                return controllers.use('bootstrapwait').render()
            else:
                return controllers.use('deploystatus').render()

        utils.pollinate(app.session_id, 'PC')
Esempio n. 2
0
    def finish(self, credentials=None, back=False):
        """ Load the Model controller passing along the selected cloud.

        Arguments:
        credentials: credentials to store for provider
        back: if true loads previous controller
        """
        if back:
            return controllers.use('clouds').render()

        if credentials is not None:
            common.save_creds(self.cloud, credentials)

        credentials_key = common.try_get_creds(self.cloud)

        if self.cloud == 'maas':
            self.cloud = '{}/{}'.format(self.cloud,
                                        credentials['@maas-server'].value)
        utils.pollinate(app.session_id, 'CA')

        self.__do_bootstrap(credential=credentials_key)

        if app.fetcher != "charmstore-search":
            return controllers.use('bundlereadme').render()
        else:
            return controllers.use('variants').render()
Esempio n. 3
0
    def render(self, cloud):
        """ Render

        Arguments:
        cloud: The cloud to create credentials for
        """

        self.cloud = cloud
        if app.current_controller is None:
            app.current_controller = petname.Name()

        # 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()
            if app.fetcher != 'charmstore-search':
                return controllers.use('bundlereadme').render()
            else:
                return controllers.use('variants').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))
            if app.fetcher != 'charmstore-search':
                return controllers.use('bundlereadme').render()
            else:
                return controllers.use('variants').render()

        # show credentials editor otherwise
        try:
            creds = Schema[self.cloud]
        except KeyError as e:
            utils.pollinate(app.session_id, 'EC')
            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)
Esempio n. 4
0
    def finish(self):
        """ handles deployment
        """
        for service in self.services:
            juju.deploy_service(service, utils.info,
                                partial(self.__handle_exception, "ED"))

        f = juju.set_relations(self.services,
                               utils.info,
                               partial(self.__handle_exception, "ED"))
        concurrent.futures.wait([f])

        utils.pollinate(app.session_id, 'PC')
        controllers.use('deploystatus').render()
Esempio n. 5
0
    def finish(self):
        """ handles deployment
        """
        for service in self.applications:
            juju.deploy_service(service,
                                app.metadata_controller.series,
                                utils.info,
                                partial(self.__handle_exception, "ED"))

        f = juju.set_relations(self.applications,
                               utils.info,
                               partial(self.__handle_exception, "ED"))
        concurrent.futures.wait([f])

        controllers.use('deploystatus').render()
Esempio n. 6
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)

        # 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)
Esempio n. 7
0
    def render(self, cloud):

        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'

        if self.cloud != 'localhost':
            if not common.try_get_creds(self.cloud):
                utils.warning("You attempted to do an install against a cloud "
                              "that requires credentials that could not be "
                              "found.  If you wish to supply those "
                              "credentials please run "
                              "`juju add-credential {}`.".format(self.cloud))
                sys.exit(1)

        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.")

        utils.info("Bootstrapping Juju controller")
        juju.bootstrap(controller=app.current_controller,
                       cloud=self.cloud,
                       credential=common.try_get_creds(self.cloud))
        self.do_post_bootstrap()
        self.finish()
Esempio n. 8
0
    def finish(self):
        """ Finalizes welcome controller

        Arguments:
        name: name of charm/bundle to use
        """
        utils.pollinate(app.session_id, 'B001')
        return controllers.use('deploy').render()
Esempio n. 9
0
    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:
            utils.pollinate(app.session_id, 'E001')
            return self.__handle_exception(Exception(
                'There was an error during the post '
                'bootstrap processing phase: {}.'.format(result)))
        utils.pollinate(app.session_id, 'J002')
        app.ui.set_footer('')
        app.log.debug("Switching to controller: {}".format(
            app.current_controller))
        juju.switch_controller(app.current_controller)
        controllers.use('bundlereadme').render()
Esempio n. 10
0
    def finish(self):
        if app.argv.cloud == "localhost":
            if not utils.check_bridge_exists():
                back = "{} to localhost".format(app.argv.config['spell'])
                os.execl("/usr/share/conjure-up/run-lxd-config",
                         "/usr/share/conjure-up/run-lxd-config",
                         back)

        existing_controller = juju.get_controller_in_cloud(app.argv.cloud)
        if existing_controller is None:
            return controllers.use('newcloud').render(app.argv.cloud)

        app.current_controller = existing_controller
        app.current_model = petname.Name()
        utils.info("Creating new juju model named '{}', "
                   "please wait.".format(app.current_model))
        juju.add_model(app.current_model, app.current_controller)

        return controllers.use('deploy').render()
Esempio n. 11
0
 def finish(self, spellname):
     utils.set_chosen_spell(spellname,
                            os.path.join(app.argv.cache_dir,
                                         spellname))
     download_local(os.path.join(app.config['spells-dir'],
                                 spellname),
                    app.config['spell-dir'])
     utils.set_spell_metadata()
     utils.setup_metadata_controller()
     return controllers.use('controllerpicker').render()
Esempio n. 12
0
    def finish(self, cloud):
        """ Load the Model controller passing along the selected cloud.

        Arguments:
        cloud: Cloud to create the controller/model on.
        """
        utils.pollinate(app.session_id, 'CS')
        existing_controller = get_controller_in_cloud(cloud)

        if existing_controller is None:
            return controllers.use('newcloud').render(cloud)

        app.current_controller = existing_controller
        app.current_model = petname.Name()
        async.submit(self.__add_model,
                     self.__handle_exception,
                     queue_name=juju.JUJU_ASYNC_QUEUE)

        return controllers.use('bundlereadme').render()
Esempio n. 13
0
    def finish(self, cloud):
        """Show the 'newcloud' screen to enter credentials for a new
        controller on 'cloud'.  There will not be an existing
        controller.

        Arguments:
        cloud: Cloud to create the controller/model on.

        """
        app.current_cloud = cloud
        return controllers.use('newcloud').render()
Esempio n. 14
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 = 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)
Esempio n. 15
0
    def finish(self, spellname):

        utils.pollinate(app.session_id, 'CS')

        utils.set_chosen_spell(spellname,
                               os.path.join(app.argv.cache_dir,
                                            spellname))
        download_local(os.path.join(app.config['spells-dir'],
                                    spellname),
                       app.config['spell-dir'])
        utils.set_spell_metadata()
        return controllers.use('clouds').render()
Esempio n. 16
0
    def finish(self, cloud):
        """ Load the Model controller passing along the selected cloud.

        Arguments:
        cloud: Cloud to create the controller/model on.
        """
        utils.pollinate(app.session_id, 'CS')
        existing_controller = get_controller_in_cloud(cloud)

        if existing_controller is None:
            return controllers.use('newcloud').render(cloud)

        app.current_controller = existing_controller
        app.current_model = petname.Name()
        async.submit(self.__add_model,
                     self.__handle_exception,
                     queue_name=juju.JUJU_ASYNC_QUEUE)

        # Go through the rest of the gui since we already provide a direct
        # spell path
        if app.fetcher != 'charmstore-search':
            return controllers.use('bundlereadme').render()
        return controllers.use('variants').render()
Esempio n. 17
0
    def finish(self):
        if app.argv.controller:
            existing_controller = app.argv.controller
            if juju.get_controller(existing_controller) is None:
                utils.error("Specified controller '{}' "
                            "could not be found in cloud '{}'.".format(
                                existing_controller, app.argv.cloud))
                sys.exit(1)
        else:
            existing_controller = juju.get_controller_in_cloud(app.argv.cloud)

        if existing_controller is None:
            app.current_cloud = app.argv.cloud
            return controllers.use('newcloud').render()

        utils.info("Using controller '{}'".format(existing_controller))

        app.current_controller = existing_controller
        app.current_model = petname.Name()
        utils.info("Creating new juju model named '{}', "
                   "please wait.".format(app.current_model))
        juju.add_model(app.current_model, app.current_controller)

        return controllers.use('deploy').render()
Esempio n. 18
0
def _start(*args, **kwargs):
    if app.endpoint_type in [None, EndpointType.LOCAL_SEARCH]:
        controllers.use('spellpicker').render()
        return

    utils.setup_metadata_controller()

    if app.argv.status_only:
        controllers.use('deploystatus').render()
    else:
        controllers.use('clouds').render()
Esempio n. 19
0
    def finish(self, spell):
        """ Finalizes and downloads chosen variant

        Arguments:
        spell: dictionary of charm/bundle to use
        """
        app.current_bundle = spell['Meta']['bundle-metadata']

        spell_name = spell['Meta']['id']['Name']

        # Check cache dir for spells
        spell_dir = path.join(app.config['spell-dir'],
                              spell_name)

        app.log.debug("Chosen spell: {}".format(spell_name))
        utils.pollinate(app.session_id, 'B001')

        metadata_path = path.join(spell_dir,
                                  'conjure/metadata.json')

        remote = get_remote_url(spell['Id'])
        purge_top_level = True
        if remote is not None:
            if app.fetcher == "charmstore-search" or \
               app.fetcher == "charmstore-direct":
                purge_top_level = False
            download(remote, spell_dir, purge_top_level)
        else:
            utils.warning("Could not find spell: {}".format(spell))
            sys.exit(1)

        with open(metadata_path) as fp:
            metadata = json.load(fp)

        app.config = {'metadata': metadata,
                      'spell-dir': spell_dir,
                      'spell': spell_name}

        utils.setup_metadata_controller()

        return controllers.use('bundlereadme').render()
Esempio n. 20
0
    def render(self):

        if app.current_controller is None:
            app.current_controller = petname.Name()

        if app.current_model is None:
            app.current_model = 'conjure-up'

        if app.current_cloud != 'localhost':
            if not common.try_get_creds(app.current_cloud):
                utils.warning("You attempted to do an install against a cloud "
                              "that requires credentials that could not be "
                              "found.  If you wish to supply those "
                              "credentials please run "
                              "`juju add-credential "
                              "{}`.".format(app.current_cloud))
                sys.exit(1)

        if app.current_cloud == 'localhost':
            if not utils.check_bridge_exists():
                return controllers.use('lxdsetup').render()

            app.log.debug("Found an IPv4 address, "
                          "assuming LXD is configured.")

        utils.info("Bootstrapping Juju controller")
        p = juju.bootstrap(controller=app.current_controller,
                           cloud=app.current_cloud,
                           credential=common.try_get_creds(app.current_cloud))
        if p.returncode != 0:
            pathbase = os.path.join(
                app.config['spell-dir'],
                '{}-bootstrap').format(app.current_controller)
            with open(pathbase + ".err") as errf:
                utils.error("Error bootstrapping controller: "
                            "{}".format("".join(errf.readlines())))
            sys.exit(1)

        self.do_post_bootstrap()
        self.finish()
Esempio n. 21
0
 def finish(self):
     return controllers.use('deploy').render()
Esempio n. 22
0
 def finish(self):
     return controllers.use('variants').render()
Esempio n. 23
0
 def finish(self):
     controllers.use('deploystatus').render()
Esempio n. 24
0
 def finish(self, future):
     if not future.exception():
         return controllers.use('steps').render()
     EventLoop.remove_alarms()
Esempio n. 25
0
 def finish(self):
     return controllers.use('summary').render(self.results)
Esempio n. 26
0
 def finish(self, future):
     if not future.exception():
         return controllers.use('steps').render()
Esempio n. 27
0
 def finish(self, *args):
     if self.alarm_handle:
         EventLoop.remove_alarm(self.alarm_handle)
     return controllers.use('deploystatus').render()