Beispiel #1
0
    async def do_bootstrap(self):
        await self.pre_bootstrap()
        self.emit('Bootstrapping Juju controller.')
        track_event("Juju Bootstrap", "Started", "")
        cloud_with_region = app.provider.cloud
        if app.provider.region:
            cloud_with_region = '/'.join([app.provider.cloud,
                                          app.provider.region])
        success = await juju.bootstrap(app.provider.controller,
                                       cloud_with_region,
                                       app.provider.model,
                                       credential=app.provider.credential)
        if not success:
            log_file = '{}-bootstrap.err'.format(app.provider.controller)
            log_file = Path(app.config['spell-dir']) / log_file
            err_log = log_file.read_text('utf8').splitlines()
            app.log.error("Error bootstrapping controller: "
                          "{}".format(err_log))
            app.sentry.context.merge({'extra': {'err_log': err_log[-400:]}})
            raise Exception('Unable to bootstrap (cloud type: {})'.format(
                app.provider.cloud_type))

        self.emit('Bootstrap complete.')
        track_event("Juju Bootstrap", "Done", "")

        await juju.login()  # login to the newly created (default) model

        step = StepModel({},
                         filename='00_post-bootstrap',
                         name='post-bootstrap')
        await step.run(self.msg_cb, 'Juju Post-Bootstrap')
        events.Bootstrapped.set()
Beispiel #2
0
 async def pre_bootstrap(self):
     """ runs pre bootstrap script if exists
     """
     step = StepModel({},
                      filename='00_pre-bootstrap',
                      name='pre-bootstrap')
     await step.run(self.msg_cb)
Beispiel #3
0
async def pre_deploy(msg_cb):
    """ runs pre deploy script if exists
    """
    await events.ModelConnected.wait()
    step = StepModel({}, filename='00_pre-deploy', name='pre-deploy')
    await step.run(msg_cb)
    events.PreDeployComplete.set()
Beispiel #4
0
async def wait_for_applications(msg_cb):
    await events.DeploymentComplete.wait()
    msg = 'Waiting for deployment to settle.'
    app.log.info(msg)
    msg_cb(msg)

    # retry done check a few times to work around
    # https://bugs.launchpad.net/juju-wait/+bug/1680963
    for i in range(3):
        try:
            step = StepModel({},
                             filename='00_deploy-done',
                             name='Deployment Watcher')
            await utils.run_step(step, msg_cb)
            break
        except Exception as e:
            if i < 2 and 'Applications did not start successfully' in str(e):
                await asyncio.sleep(5)
                app.log.debug('Retrying 00_deploy-done: {}'.format(i))
                continue
            raise

    events.ModelSettled.set()
    msg = 'Model settled.'
    app.log.info(msg)
    msg_cb(msg)
Beispiel #5
0
    def render(self):

        if len(self.step_metas) == 0:
            self.finish(None, None, done=True)
            return

        step_widgets = deque()

        for step_meta_path in self.step_metas:
            step_ex_path, ext = path.splitext(step_meta_path)
            if not path.isfile(step_ex_path) or \
               not os.access(step_ex_path, os.X_OK):
                app.log.error(
                    'Unable to process step, missing {}'.format(step_ex_path))
                continue
            step_metadata = {}
            with open(step_meta_path) as fp:
                step_metadata = yaml.load(fp.read())

            try:
                # Store step model and its widget
                model = StepModel(step_metadata, step_meta_path)
                step_widget = StepWidget(app, model, self.finish)
                if not step_widget.model.viewable:
                    app.log.debug("Skipping step: {}".format(step_widget))
                    continue
                model.path = step_ex_path
                step_widgets.append(step_widget)
                app.log.debug("Queueing step: {}".format(step_widget))
            except Exception as e:
                self.__handle_exception('E002', e)
                return

        try:
            self.all_step_widgets = list(step_widgets)
            self.view = StepsView(app, step_widgets, self.finish)

            # Set initial step as active and viewable
            step_widgets[0].description.set_text(
                ('body', step_widgets[0].model.description))
            step_widgets[0].icon.set_text(
                ('pending_icon', step_widgets[0].icon.get_text()[0]))
            step_widgets[0].generate_additional_input()
            self.view.step_pile.focus_position = 2

        except Exception as e:
            self.__handle_exception('E002', e)
            return

        app.ui.set_header(
            title="Additional Application Configuration",
            excerpt="Please finish the installation by configuring your "
            "application with these steps.")
        app.ui.set_body(self.view)
        app.ui.set_footer('')
        self.update()
Beispiel #6
0
 def build_widget(self):
     app.steps_data['name'] = {
         'USERNAME': '******',
         'PASSWORD': '',
         'EMAIL': '',
     }
     super().build_widget()
     self.add_step(
         StepForm(
             app,
             StepModel(
                 {
                     'description': 'Download Deis CLI',
                     'viewable': True,
                 }, '', '')))
     self.add_step(
         StepForm(
             app,
             StepModel(
                 {
                     'description':
                     'Create Admin User',
                     'viewable':
                     True,
                     'additional-input': [
                         {
                             'label': 'Username',
                             'key': 'USERNAME',
                             'type': 'text'
                         },
                         {
                             'label': 'Password',
                             'key': 'PASSWORD',
                             'type': 'password'
                         },
                         {
                             'label': 'Email',
                             'key': 'EMAIL',
                             'type': 'text'
                         },
                     ],
                 }, 'filename', 'name')))
     return self.step_pile
Beispiel #7
0
def load_step(step_meta_path):
    step_meta_path = Path(step_meta_path)
    step_name = step_meta_path.stem
    step_ex_path = step_meta_path.parent / step_name
    if not step_ex_path.is_file():
        raise ValidationError(
            'Step {} has no implementation'.format(step_name))
    elif not os.access(str(step_ex_path), os.X_OK):
        raise ValidationError('Step {} is not executable'.format(step_name))
    step_metadata = yaml.load(step_meta_path.read_text())
    model = StepModel(step_metadata, str(step_ex_path), step_name)
    return model
Beispiel #8
0
def load_step(step_meta_path):
    step_ex_path, ext = path.splitext(step_meta_path)
    short_path = '/'.join(step_ex_path.split('/')[-3:])
    if not path.isfile(step_ex_path):
        raise ValidationError(
            'Step {} has no implementation'.format(short_path))
    elif not os.access(step_ex_path, os.X_OK):
        raise ValidationError('Step {} is not executable, make sure it has '
                              'the executable bit set'.format(short_path))
    with open(step_meta_path) as fp:
        step_metadata = yaml.load(fp.read())
        model = StepModel(step_metadata, step_ex_path)
        return model
Beispiel #9
0
    async def pre_bootstrap(self):
        """ runs pre bootstrap script if exists
        """

        # Set provider type for post-bootstrap
        app.env['JUJU_PROVIDERTYPE'] = juju.get_cloud_types_by_name()[
            app.current_cloud]
        app.env['JUJU_CONTROLLER'] = app.current_controller
        app.env['JUJU_MODEL'] = app.current_model
        app.env['CONJURE_UP_SPELLSDIR'] = app.argv.spells_dir

        step = StepModel({}, filename='00_pre-bootstrap', name='pre-bootstrap')
        await utils.run_step(step, self.msg_cb)
Beispiel #10
0
async def wait_for_applications(msg_cb):
    await events.DeploymentComplete.wait()
    msg = 'Waiting for deployment to settle.'
    app.log.info(msg)
    msg_cb(msg)

    step = StepModel({'title': 'Deployment Watcher'},
                     filename='00_deploy-done',
                     name='00_deploy-done')
    await step.run(msg_cb)

    events.ModelSettled.set()
    msg = 'Model settled.'
    app.log.info(msg)
    msg_cb(msg)
Beispiel #11
0
async def pre_deploy(msg_cb):
    """ runs pre deploy script if exists
    """
    await events.ModelConnected.wait()

    # Set provider type for post-bootstrap
    app.env['JUJU_PROVIDERTYPE'] = app.juju.client.info.provider_type
    # Set current credential name (localhost doesn't have one)
    app.env['JUJU_CREDENTIAL'] = app.current_credential or ''
    app.env['JUJU_CONTROLLER'] = app.current_controller
    app.env['JUJU_MODEL'] = app.current_model
    app.env['CONJURE_UP_SPELLSDIR'] = app.argv.spells_dir

    step = StepModel({}, filename='00_pre-deploy', name='pre-deploy')
    await utils.run_step(step, msg_cb)
    events.PreDeployComplete.set()
Beispiel #12
0
 def render(self):
     for step_meta_path in self.step_metas:
         step_ex_path, ext = path.splitext(step_meta_path)
         if not path.isfile(step_ex_path) or \
            not os.access(step_ex_path, os.X_OK):
             app.log.error(
                 'Unable to process step, missing {}'.format(step_ex_path))
             continue
         step_metadata = {}
         with open(step_meta_path) as fp:
             step_metadata = yaml.load(fp.read())
         model = StepModel(step_metadata, step_meta_path)
         model.path = step_ex_path
         app.log.debug("Running step: {}".format(model))
         try:
             step_model, _ = common.do_step(model, None, utils.info)
             self.results[step_model.title] = step_model.result
         except Exception as e:
             utils.error("Failed to run {}: {}".format(model.path, e))
             sys.exit(1)
     self.finish()
Beispiel #13
0
    async def do_bootstrap(self, creds):
        if app.is_jaas:
            return

        await self.pre_bootstrap()
        self.emit('Bootstrapping Juju controller.')
        track_event("Juju Bootstrap", "Started", "")
        cloud_with_region = app.current_cloud
        if app.current_region:
            cloud_with_region = '/'.join(
                [app.current_cloud, app.current_region])
        success = await juju.bootstrap(app.current_controller,
                                       cloud_with_region,
                                       app.current_model,
                                       credential=creds)
        if not success:
            log_file = '{}-bootstrap.err'.format(app.current_controller)
            log_file = Path(app.config['spell-dir']) / log_file
            err_log = log_file.read_text('utf8').splitlines()
            app.log.error("Error bootstrapping controller: "
                          "{}".format(err_log))
            app.sentry.context.merge({'extra': {'err_log': err_log}})
            raise Exception('Unable to bootstrap (cloud type: {})'.format(
                app.current_cloud_type))

        self.emit('Bootstrap complete.')
        track_event("Juju Bootstrap", "Done", "")

        await juju.login()  # login to the newly created (default) model

        # Set provider type for post-bootstrap
        app.env['JUJU_PROVIDERTYPE'] = app.juju.client.info.provider_type
        app.env['JUJU_CONTROLLER'] = app.current_controller
        app.env['JUJU_MODEL'] = app.current_model

        step = StepModel({},
                         filename='00_post-bootstrap',
                         name='post-bootstrap')
        await utils.run_step(step, self.msg_cb, 'Juju Post-Bootstrap')
        events.Bootstrapped.set()