Exemplo n.º 1
0
    def finish(self, credentials=None, region=None, back=False):
        if region:
            app.current_region = region

        if back:
            return controllers.use('clouds').render()

        if credentials is not None:
            cloud_type = juju.get_cloud_types_by_name()[app.current_cloud]
            if cloud_type == 'maas':
                # Now that we are passed the selection of a cloud we create a
                # new cloud name for the remainder of the deployment and make
                # sure this cloud is saved for future use.
                app.current_cloud = utils.gen_cloud()

                # Save credentials for new cloud
                common.save_creds(app.current_cloud, credentials)

                try:
                    juju.get_cloud(app.current_cloud)
                except LookupError:
                    juju.add_cloud(app.current_cloud,
                                   credentials.cloud_config())
            else:
                common.save_creds(app.current_cloud, credentials)
        credentials_key = common.try_get_creds(app.current_cloud)
        app.loop.create_task(
            common.do_bootstrap(credentials_key,
                                msg_cb=app.ui.set_footer,
                                fail_msg_cb=lambda e: None))
        controllers.use('deploy').render()
Exemplo 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()
Exemplo n.º 3
0
    def finish(self, controller):
        if controller is None:
            return controllers.use('clouds').render()

        if controller == 'jaas':
            if not app.jaas_controller or not juju.has_jaas_auth():
                # jaas is either not registered or not logged in
                return controllers.use('jaaslogin').render()
            # jaas already registered, but we they still need to pick a cloud
            app.current_controller = app.jaas_controller
            app.is_jaas = True
            events.Bootstrapped.set()
            return controllers.use('clouds').render()

        app.current_controller = controller
        app.current_model = utils.gen_model()

        c_info = juju.get_controller_info(app.current_controller)
        app.current_cloud = c_info['details']['cloud']

        events.Bootstrapped.set()

        app.loop.create_task(
            juju.add_model(app.current_model, app.current_controller,
                           app.current_cloud))
        return controllers.use('deploy').render()
Exemplo n.º 4
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')
Exemplo n.º 5
0
 async def do_destroy(self, model, controller):
     track_event("Destroying model", "Destroy", "")
     app.ui.set_footer("Destroying model {} in controller {}".format(
         model, controller))
     await juju.destroy_model(controller, model)
     app.ui.set_footer("")
     controllers.use('destroy').render()
Exemplo n.º 6
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)
        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:
            return controllers.use('newcloud').render(app.argv.cloud)

        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()
Exemplo n.º 7
0
    def finish(self):
        if app.argv.model:
            app.current_model = app.argv.model
        else:
            app.current_model = utils.gen_model()

        if not app.argv.controller:
            app.current_controller = "conjure-up-{}-{}".format(
                app.current_cloud, utils.gen_hash())

            return controllers.use('newcloud').render()

        app.current_controller = app.argv.controller
        if not self.__controller_exists(app.current_controller):
            return controllers.use('newcloud').render()
        else:
            utils.info("Using controller '{}'".format(app.current_controller))
            utils.info("Creating new model named '{}', "
                       "please wait.".format(app.current_model))
            app.loop.create_task(
                juju.add_model(app.current_model,
                               app.current_controller,
                               app.current_cloud,
                               allow_exists=True))
            return controllers.use('deploy').render()

        utils.error("Something happened with the controller or model, "
                    "please check the logs.")
        events.Shutdown.set(1)
Exemplo n.º 8
0
    def finish(self):
        app.current_cloud = app.argv.cloud

        if app.argv.model:
            app.current_model = app.argv.model
        else:
            app.current_model = "conjure-up-{}-{}".format(
                app.env['CONJURE_UP_SPELL'], utils.gen_hash())

        if not app.argv.controller:
            app.current_controller = "conjure-up-{}-{}".format(
                app.current_cloud, utils.gen_hash())

            return controllers.use('newcloud').render()

        app.current_controller = app.argv.controller
        if self.__get_existing_controller(app.current_controller) is None:
            return controllers.use('newcloud').render()
        else:
            utils.info("Using controller '{}'".format(app.current_controller))
            utils.info("Creating new deployment named '{}', "
                       "please wait.".format(app.current_model))
            juju.add_model(app.current_model, app.current_controller)
            return controllers.use('deploy').render()

        utils.error("Something happened with the controller or model, "
                    "please check the logs.")
        sys.exit(1)
Exemplo n.º 9
0
    def finish(self, controller):
        if controller is None:
            app.current_controller = "conjure-up-{}-{}".format(
                app.current_cloud, utils.gen_hash())
            return controllers.use('bootstrap').render()

        if controller == 'jaas':
            if not app.jaas_controller or not juju.has_jaas_auth():
                # jaas is either not registered or not logged in
                return controllers.use('jaaslogin').render()
            # jaas already registered
            app.current_controller = app.jaas_controller
            app.is_jaas = True
        else:
            app.current_controller = controller

        if app.current_controller not in juju.get_controllers()['controllers']:
            return controllers.use('bootstrap').render()

        events.Bootstrapped.set()

        app.loop.create_task(
            juju.add_model(app.current_model, app.current_controller,
                           app.current_cloud))
        return controllers.use('deploy').render()
Exemplo n.º 10
0
 def finish(self):
     app.selected_addons = self.view.selected
     if app.selected_addons:
         for addon in app.selected_addons:
             track_event("Addon Selected", addon, "")
         # reload the bundle data w/ addons merged
         setup_metadata_controller()
     controllers.use('clouds').render()
Exemplo n.º 11
0
 async def _try_token_auth(self, error):
     app.log.info('Attempting to register JAAS with saved token')
     try:
         await juju.register_controller(app.jaas_controller, JAAS_DOMAIN,
                                        '', '', '')
         controllers.use('showsteps').render()
     except CalledProcessError:
         self.show_login_screen(error)
Exemplo n.º 12
0
 async def wait(self, view):
     while not events.Bootstrapped.is_set():
         if events.Error.is_set():
             # bootstrap or add_model task failed, so stop refreshing
             # (the error screen will be shown instead)
             return
         view.redraw_kitt()
         await asyncio.sleep(1)
     controllers.use('deploy').render()
Exemplo n.º 13
0
    def finish(self):
        juju.set_relations(self.applications, 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')
Exemplo n.º 14
0
    def finish(self):
        app.loop.create_task(self.watch_for_deploy_complete())

        self.sync_assignment_opts()
        common.write_bundle(self.assignments)

        if not events.Bootstrapped.is_set():
            return controllers.use('bootstrapwait').render()
        else:
            return controllers.use('deploystatus').render()
Exemplo n.º 15
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)
Exemplo n.º 16
0
 async def _try_token_auth(self):
     app.log.info('Attempting to register JAAS with saved token')
     try:
         await juju.register_controller(app.jaas_controller,
                                        JAAS_DOMAIN,
                                        '', '', '')
         controllers.use('showsteps').render()
     except CalledProcessError:
         # empty-but-not-None message to skip retrying token auth
         self.login_error = ''
         self.render_login()
Exemplo n.º 17
0
 def render(self):
     if not app.jaas_ok:
         utils.error('JaaS not compatible with specified cloud')
         return events.Shutdown.set(1)
     if not app.jaas_controller:
         utils.error('No JaaS controller registered')
         return events.Shutdown.set(1)
     if not juju.has_jaas_auth():
         utils.error('JaaS controller not authenticated')
         return events.Shutdown.set(1)
     app.is_jaas = True
     controllers.use('showsteps').render()
Exemplo n.º 18
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()
Exemplo n.º 19
0
    def finish(self):
        """ handles deployment
        """
        for service in self.applications:
            juju.deploy_service(service, utils.info,
                                partial(self.__handle_exception, "ED"))

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

        utils.pollinate(app.session_id, 'PC')
        controllers.use('deploystatus').render()
Exemplo n.º 20
0
 async def _register(self, email, password, twofa):
     if not await juju.register_controller(app.jaas_controller,
                                           JAAS_DOMAIN,
                                           email,
                                           password,
                                           twofa,
                                           fail_cb=self.fail,
                                           timeout_cb=self.timeout):
         return
     app.current_controller = app.jaas_controller
     app.is_jaas = True
     self.authenticating.clear()
     app.log.info('JAAS is registered')
     controllers.use('showsteps').render()
Exemplo n.º 21
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()
Exemplo n.º 22
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)

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

    utils.setup_metadata_controller()

    if os.getenv('CONJUREUP_STATUS_ONLY'):
        # Developer tool only
        # format is: CONJUREUP_STATUS_ONLY=1/<controller>/<model>
        try:
            _, controller, model = os.getenv(
                'CONJUREUP_STATUS_ONLY').split('/')
            app.current_controller = controller
            app.current_model = model
            app.env['JUJU_CONTROLLER'] = app.current_controller
            app.env['JUJU_MODEL'] = app.current_model
        except ValueError:
            utils.error("Unable to parse the controller and model to access")
            sys.exit(1)
        controllers.use('deploystatus').render()
        return

    if app.argv.cloud:
        controllers.use('clouds').render()
        return

    controllers.use('controllerpicker').render()
Exemplo n.º 23
0
    def finish(self, controller):
        if controller is None:
            app.current_controller = "conjure-up-{}-{}".format(
                app.current_cloud, utils.gen_hash())
        else:
            app.current_controller = controller

        if controller == 'jaas':
            if not app.jaas_controller or not juju.has_jaas_auth():
                # jaas is either not registered or not logged in
                return controllers.use('jaaslogin').render()
            # jaas already registered
            app.current_controller = app.jaas_controller
            app.is_jaas = True
        return controllers.use('showsteps').render()
Exemplo n.º 24
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()
Exemplo n.º 25
0
    def finish(self):
        if app.conjurefile['model']:
            app.provider.model = app.conjurefile['model']
        else:
            app.provider.model = utils.gen_model()

        return controllers.use('credentials').render()
Exemplo n.º 26
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()
Exemplo n.º 27
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)
Exemplo n.º 28
0
 def finish(self, data):
     app.provider.model_defaults = {
         'primary-network': data['primary-network'],
         'external-network': data['external-network'],
         'datastore': data['datastore']
     }
     return controllers.use('controllerpicker').render()
Exemplo n.º 29
0
 def render(self):
     if not app.jaas_ok:
         utils.error('JaaS not compatible with specified cloud')
         return events.Shutdown.set(1)
     if not app.jaas_controller:
         utils.error('No JaaS controller registered')
         return events.Shutdown.set(1)
     if not juju.has_jaas_auth():
         utils.error('JaaS controller not authenticated')
         return events.Shutdown.set(1)
     app.is_jaas = True
     events.Bootstrapped.set()
     app.loop.create_task(
         juju.add_model(app.current_model, app.current_controller,
                        app.current_cloud))
     controllers.use('deploy').render()
Exemplo n.º 30
0
 def back(self):
     if self.was_picker:
         # if they were on the picker and chose New, BACK should
         # take them back to the picker, not to the cloud selection
         self.was_picker = False
         return self.render_picker()
     return controllers.use('clouds').render()
Exemplo n.º 31
0
    def finish(self):
        if app.argv.model:
            app.provider.model = app.argv.model
        else:
            app.provider.model = utils.gen_model()

        return controllers.use('credentials').render()
Exemplo n.º 32
0
    def finish(self):
        if app.argv.model:
            app.current_model = app.argv.model
        else:
            app.current_model = utils.gen_model()

        return controllers.use('regions').render()
Exemplo n.º 33
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)
Exemplo n.º 34
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 = 'default'

        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()
Exemplo n.º 35
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()
Exemplo n.º 36
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()
Exemplo n.º 37
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()
Exemplo n.º 38
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()
Exemplo n.º 39
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()
Exemplo n.º 40
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()
Exemplo n.º 41
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)
Exemplo n.º 42
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()
Exemplo n.º 43
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()
Exemplo n.º 44
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()
Exemplo n.º 45
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()
Exemplo n.º 46
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()
Exemplo n.º 47
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()
Exemplo n.º 48
0
 def finish(self):
     controllers.use('deploystatus').render()
Exemplo n.º 49
0
 def finish(self):
     return controllers.use('deploy').render()
Exemplo n.º 50
0
 def finish(self, future):
     if not future.exception():
         return controllers.use('steps').render()
     EventLoop.remove_alarms()
Exemplo n.º 51
0
 def finish(self, *args):
     if self.alarm_handle:
         EventLoop.remove_alarm(self.alarm_handle)
     return controllers.use('deploystatus').render()
Exemplo n.º 52
0
 def finish(self, future):
     if not future.exception():
         return controllers.use('steps').render()
Exemplo n.º 53
0
 def finish(self):
     return controllers.use('summary').render(self.results)
Exemplo n.º 54
0
 def finish(self):
     return controllers.use('variants').render()