Exemple #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()
Exemple #2
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)
Exemple #3
0
    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()
Exemple #4
0
    def finish(self, schema=None, region=None, back=False):
        if region:
            app.current_region = region

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

        if schema is not None:
            # Attempt to setup LXD with our selected interface
            if self.cloud_type == 'localhost':
                try:
                    common.lxd_init(schema.network_interface.value)

                    # Store LXD setup completion so we dont reconfigure on
                    # subsequent runs
                    common.get_lxd_setup_path().touch()
                except Exception:
                    raise

            elif self.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, schema)

                try:
                    juju.get_cloud(app.current_cloud)
                except LookupError:
                    juju.add_cloud(app.current_cloud,
                                   schema.cloud_config())
            else:
                common.save_creds(app.current_cloud, schema)
        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()