示例#1
0
文件: tui.py 项目: mnama/conjure-up
    def do_post_bootstrap(self):
        """ runs post bootstrap script if exists
        """
        # Set provider type for post-bootstrap
        app.env['JUJU_PROVIDERTYPE'] = model_info('default')['provider-type']

        post_bootstrap_sh = os.path.join(app.config['spell-dir'],
                                         'steps/00_post-bootstrap')
        if os.path.isfile(post_bootstrap_sh) \
           and os.access(post_bootstrap_sh, os.X_OK):
            utils.pollinate(app.session_id, 'J001')
            utils.info("Running post-bootstrap tasks.")
            try:
                sh = utils.run(post_bootstrap_sh,
                               shell=True,
                               stdout=PIPE,
                               stderr=PIPE,
                               env=app.env)
                result = json.loads(sh.stdout.decode('utf8'))
                utils.info("Finished post bootstrap task: {}".format(
                    result['message']))
            except Exception as e:
                utils.warning(
                    "Failed to run post bootstrap task: {}".format(e))
                sys.exit(1)
示例#2
0
    def do_pre_deploy(self):
        """ runs pre deploy script if exists
        """
        # Set provider type for post-bootstrap
        app.env['JUJU_PROVIDERTYPE'] = model_info('default')['provider-type']

        pre_deploy_sh = os.path.join(app.config['spell-dir'],
                                     'conjure/steps/00_pre-deploy')
        if os.path.isfile(pre_deploy_sh) \
           and os.access(pre_deploy_sh, os.X_OK):
            utils.pollinate(app.session_id, 'J001')
            utils.info("Running pre deployment tasks.")
            try:
                sh = run(pre_deploy_sh, shell=True,
                         stdout=PIPE,
                         stderr=PIPE,
                         env=app.env)
                result = json.loads(sh.stdout.decode('utf8'))
                if result['returnCode'] > 0:
                    utils.error("Failed to run pre-deploy task: "
                                "{}".format(result['message']))
                    sys.exit(1)

                utils.info("Finished pre deploy task: {}".format(
                    result['message']))
            except Exception as e:
                utils.error(
                    "Failed to run pre deploy task: {}".format(e))
                sys.exit(1)
示例#3
0
    def __post_bootstrap_exec(self):
        """ Executes post-bootstrap.sh if exists
        """
        info = model_info(juju.get_current_model())
        # Set our provider type environment var so that it is
        # exposed in future processing tasks
        app.env['JUJU_PROVIDERTYPE'] = info['provider-type']

        _post_bootstrap_sh = path.join(app.config['spell-dir'],
                                       'conjure/steps/00_post-bootstrap')
        app.log.debug(
            'Checking for post bootstrap task: {}'.format(_post_bootstrap_sh))
        if path.isfile(_post_bootstrap_sh) \
           and os.access(_post_bootstrap_sh, os.X_OK):
            app.ui.set_footer('Running post-bootstrap tasks...')
            utils.pollinate(app.session_id, 'J001')
            app.log.debug("post_bootstrap running: {}".format(
                _post_bootstrap_sh
            ))
            try:
                future = async.submit(partial(check_output,
                                              _post_bootstrap_sh,
                                              shell=True,
                                              env=app.env),
                                      self.__handle_exception)
                future.add_done_callback(self.__post_bootstrap_done)
            except Exception as e:
                return self.__handle_exception(e)
示例#4
0
    def do_pre_deploy(self):
        """ runs pre deploy script if exists
        """
        # Set provider type for post-bootstrap
        app.env['JUJU_PROVIDERTYPE'] = model_info('default')['provider-type']

        pre_deploy_sh = os.path.join(app.config['spell-dir'],
                                     'conjure/steps/00_pre-deploy')
        if os.path.isfile(pre_deploy_sh) \
           and os.access(pre_deploy_sh, os.X_OK):
            utils.pollinate(app.session_id, 'J001')
            utils.info("Running pre deployment tasks.")
            try:
                sh = run(pre_deploy_sh, shell=True,
                         stdout=PIPE,
                         stderr=PIPE,
                         env=app.env)
                result = json.loads(sh.stdout.decode('utf8'))
                if result['returnCode'] > 0:
                    utils.error("Failed to run pre-deploy task: "
                                "{}".format(result['message']))
                    sys.exit(1)

                utils.info("Finished pre deploy task: {}".format(
                    result['message']))
            except Exception as e:
                utils.error(
                    "Failed to run pre deploy task: {}".format(e))
                sys.exit(1)
示例#5
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')
示例#6
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()
示例#7
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()
示例#8
0
 def render(self):
     self.view = VariantView(self.finish)
     app.log.debug("Rendering GUI controller for Variant")
     utils.pollinate(app.session_id, 'W001')
     app.ui.set_header(
         title='Please choose a spell to conjure'
     )
     app.ui.set_body(self.view)
示例#9
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')
示例#10
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)
示例#11
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()
        utils.setup_metadata_controller()
        return controllers.use('controllerpicker').render()
示例#12
0
    def render(self):
        """ Render
        """
        utils.pollinate(app.session_id, 'L001')
        self.view = LXDSetupView(app,
                                 self.finish)

        app.ui.set_header(
            title="Setup LXD Bridge",
        )
        app.ui.set_body(self.view)
示例#13
0
    def render(self):
        """ Render
        """
        utils.pollinate(app.session_id, 'L001')
        self.view = LXDSetupView(app,
                                 self.finish)

        app.ui.set_header(
            title="Setup LXD Bridge",
        )
        app.ui.set_body(self.view)
示例#14
0
文件: gui.py 项目: tych0/conjure-up
    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()
示例#15
0
文件: tui.py 项目: mnama/conjure-up
    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()
示例#16
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()
示例#17
0
    def __handle_bootstrap_done(self, future):
        app.log.debug("handle bootstrap")
        result = future.result()
        if result.returncode < 0:
            # bootstrap killed via user signal, we're quitting
            return
        if result.returncode > 0:
            err = result.stderr.read().decode()
            app.log.error(err)
            return self.__handle_exception(Exception("error "))

        utils.pollinate(app.session_id, 'J004')
        EventLoop.remove_alarms()
        app.ui.set_footer('Bootstrap complete...')
        juju.switch_controller(app.current_controller)
        self.__post_bootstrap_exec()
示例#18
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()
示例#19
0
文件: gui.py 项目: tych0/conjure-up
    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()
示例#20
0
    def _pre_deploy_done(self, future):
        try:
            result = json.loads(future.result().stdout.decode())
        except AttributeError:
            result = json.loads(future.result())
        except:
            return self._handle_exception(
                'E003',
                Exception("Problem with pre-deploy: \n{}, ".format(
                    future.result())))

        app.log.debug("pre_deploy_done: {}".format(result))
        if result['returnCode'] > 0:
            utils.pollinate(app.session_id, 'E003')
            return self._handle_exception(
                'E003',
                Exception('There was an error during the pre '
                          'deploy processing phase: {}.'.format(result)))
        else:
            app.ui.set_footer("Pre-deploy processing done.")
示例#21
0
    def _pre_deploy_done(self, future):
        try:
            result = json.loads(future.result().stdout.decode())
        except AttributeError:
            result = json.loads(future.result())
        except:
            return self._handle_exception(
                'E003',
                Exception(
                    "Problem with pre-deploy: \n{}, ".format(
                        future.result())))

        app.log.debug("pre_deploy_done: {}".format(result))
        if result['returnCode'] > 0:
            utils.pollinate(app.session_id, 'E003')
            return self._handle_exception('E003', Exception(
                'There was an error during the pre '
                'deploy processing phase: {}.'.format(result)))
        else:
            app.ui.set_footer("Pre-deploy processing done.")
示例#22
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)
示例#23
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()
示例#24
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()
示例#25
0
    def finish(self, needs_lxd_setup=False, lxdnetwork=None, back=False):
        """ Processes the new LXD setup and loads the controller to
        finish bootstrapping the model.

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

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

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

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

        out = self.__format_conf(formatted_network)

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

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

        utils.pollinate(app.session_id, 'L002')
        controllers.use('newcloud').render(
            cloud='localhost', bootstrap=True)
示例#26
0
    def _pre_deploy_exec(self):
        """ runs pre deploy script if exists
        """
        app.env['JUJU_PROVIDERTYPE'] = model_info(
            juju.get_current_model())['provider-type']

        pre_deploy_sh = os.path.join(app.config['spell-dir'],
                                     'conjure/steps/00_pre-deploy')
        if os.path.isfile(pre_deploy_sh) \
           and os.access(pre_deploy_sh, os.X_OK):
            utils.pollinate(app.session_id, 'J001')
            msg = "Running pre-deployment tasks."
            app.log.debug(msg)
            app.ui.set_footer(msg)
            return run(pre_deploy_sh,
                       shell=True,
                       stdout=PIPE,
                       stderr=PIPE,
                       env=app.env)
        return json.dumps({'message': 'No pre deploy necessary',
                           'returnCode': 0,
                           'isComplete': True})
示例#27
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()
示例#28
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()
示例#29
0
    def do_post_bootstrap(self):
        """ runs post bootstrap script if exists
        """
        # Set provider type for post-bootstrap
        app.env['JUJU_PROVIDERTYPE'] = model_info('default')['provider-type']

        post_bootstrap_sh = os.path.join(app.config['spell-dir'],
                                         'steps/00_post-bootstrap')
        if os.path.isfile(post_bootstrap_sh) \
           and os.access(post_bootstrap_sh, os.X_OK):
            utils.pollinate(app.session_id, 'J001')
            utils.info("Running post-bootstrap tasks.")
            try:
                sh = utils.run(post_bootstrap_sh, shell=True,
                               stdout=PIPE,
                               stderr=PIPE,
                               env=app.env)
                result = json.loads(sh.stdout.decode('utf8'))
                utils.info("Finished post bootstrap task: {}".format(
                    result['message']))
            except Exception as e:
                utils.warning(
                    "Failed to run post bootstrap task: {}".format(e))
                sys.exit(1)
示例#30
0
 def __handle_exception(self, exc):
     utils.pollinate(app.session_id, "E004")
     app.ui.show_exception_message(exc)
示例#31
0
 def __handle_exception(self, tag, exc):
     utils.pollinate(app.session_id, tag)
     EventLoop.remove_alarms()
     app.ui.show_exception_message(exc)
示例#32
0
 def cancel(self, button):
     pollinate(app.session_id, 'UC')
     EventLoop.exit(0)
示例#33
0
 def _handle_exception(self, tag, exc):
     utils.pollinate(app.session_id, tag)
     app.ui.show_exception_message(exc)
     self.showing_error = True
     EventLoop.remove_alarms()
示例#34
0
 def __handle_exception(self, tag, exc):
     utils.pollinate(app.session_id, tag)
     utils.error(exc)
     sys.exit(1)
示例#35
0
 def _handle_exception(self, tag, exc):
     utils.pollinate(app.session_id, tag)
     app.ui.show_exception_message(exc)
     self.showing_error = True
     EventLoop.remove_alarms()
示例#36
0
 def cancel(self, button):
     pollinate(app.session_id, 'UC')
     EventLoop.exit(0)
示例#37
0
 def __handle_exception(self, tag, exc):
     utils.pollinate(app.session_id, tag)
     utils.error(exc)
     sys.exit(1)
示例#38
0
 def __handle_exception(self, tag, exc):
     utils.pollinate(app.session_id, tag)
     EventLoop.remove_alarms()
     app.ui.show_exception_message(exc)
示例#39
0
文件: gui.py 项目: tych0/conjure-up
 def __handle_exception(self, exc):
     utils.pollinate(app.session_id, "E004")
     app.ui.show_exception_message(exc)
示例#40
0
 def render(self):
     self.view = VariantView(self.finish)
     app.log.debug("Rendering GUI controller for Variant")
     utils.pollinate(app.session_id, 'W001')
     app.ui.set_header(title='Please choose a spell to conjure')
     app.ui.set_body(self.view)
示例#41
0
 def __handle_exception(self, exc):
     utils.pollinate(app.session_id, 'EB')
     return app.ui.show_exception_message(exc)