コード例 #1
0
ファイル: tui.py プロジェクト: johnsca/conjure-up
    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)
コード例 #2
0
ファイル: common.py プロジェクト: darthsuogles/conjure-up
    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()
コード例 #3
0
    def save_credential(self, credential):
        cred_path = path.join(utils.juju_path(), 'credentials.yaml')
        cred_name = "conjure-{}-{}".format(app.current_cloud, utils.gen_hash())

        try:
            existing_creds = yaml.safe_load(open(cred_path))
        except:
            existing_creds = {'credentials': {}}

        if app.current_cloud in existing_creds['credentials'].keys():
            c = existing_creds['credentials'][app.current_cloud]
            c[cred_name] = self._format_creds(credential)
        else:
            # Handle the case where path exists but an entry for the cloud
            # has yet to be added.
            existing_creds['credentials'][app.current_cloud] = {
                cred_name: self._format_creds(credential)
            }

        with open(cred_path, 'w') as cred_f:
            cred_f.write(
                yaml.safe_dump(existing_creds, default_flow_style=False))

        # if it's a new MAAS cloud, save it now that we have a credential
        if app.current_cloud_type == 'maas':
            try:
                juju.get_cloud(app.current_cloud)
            except LookupError:
                juju.add_cloud(app.current_cloud, credential.cloud_config())

        # This should return the credential name so juju bootstrap knows
        # which credential to bootstrap with
        self.finish(cred_name)
コード例 #4
0
ファイル: tui.py プロジェクト: ops-sandy/conjure-up
    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)
コード例 #5
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("")
コード例 #6
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()
コード例 #7
0
ファイル: gui.py プロジェクト: yangmian7721/conjure-up
    async def _save_credential(self):
        cred_path = path.join(utils.juju_path(), 'credentials.yaml')
        app.provider.credential = "conjure-{}-{}".format(
            app.provider.cloud, utils.gen_hash())

        try:
            existing_creds = yaml.safe_load(open(cred_path))
        except:
            existing_creds = {'credentials': {}}

        if app.provider.cloud in existing_creds['credentials'].keys():
            c = existing_creds['credentials'][app.provider.cloud]
            c[app.provider.credential] = self._format_creds()
        else:
            # Handle the case where path exists but an entry for the cloud
            # has yet to be added.
            existing_creds['credentials'][app.provider.cloud] = {
                app.provider.credential: self._format_creds()
            }

        with open(cred_path, 'w') as cred_f:
            cred_f.write(
                yaml.safe_dump(existing_creds, default_flow_style=False))

        # Persist input fields in current provider, this is so we
        # can login to the provider for things like querying VSphere
        # for datacenters before that custom cloud is known to juju.
        await app.provider.save_form()

        # if it's a new MAAS or VSphere cloud, save it now that
        # we have a credential
        if app.provider.cloud_type in CUSTOM_PROVIDERS:
            try:
                juju.get_cloud(app.provider.cloud)
            except LookupError:
                juju.add_cloud(app.provider.cloud, await
                               app.provider.cloud_config())

        # This should return the credential name so juju bootstrap knows
        # which credential to bootstrap with
        self.finish()
コード例 #8
0
ファイル: gui.py プロジェクト: ops-sandy/conjure-up
    def render(self):
        track_screen("Cloud Creation")
        self.cloud_type = juju.get_cloud_types_by_name()[app.current_cloud]

        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.
        if self.cloud_type == 'localhost':
            lxd_setup_path = common.get_lxd_setup_path()
            app.log.debug("Determining if embedded LXD is setup and ready.")
            if lxd_setup_path.exists():
                return self.finish()
            else:
                self.render_newcloud()

        # TODO: Prompt user to select credentials and set a region
        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 self.cloud_type != 'maas'):
            return self.finish()

        # No existing credentials found, start credential editor
        self.render_newcloud()