def press_static_assets(target, instruction):
    """Uses a mercury_id indexed asset store which is supplied, in it's entirety, within the instruction
    :param target: A target containing a mercury_id
    :param instruction: A dictionary containing two fields, template and assets
        template is a string containing a yaml formatted press configuration mustache template
        assets is a dictionary indexed by mercury_id. Each value contains render information
        relevant to the template. If the asset data does not contain data for the target mercury_id
        a MercuryUserException exception is raised

        Note, this is throw away code. The mercury_assets backend will take over the functionality provided
        herein.
    :return: exec_press capability contract
    """

    template = '\n'.join(instruction.get('template'))
    asset_db = instruction.get('assets')

    if not template and asset_db:
        raise MercuryUserError('Contract is incomplete')

    render_data = asset_db.get(target['mercury_id'])

    __asset_list_hax(render_data)

    if not render_data:
        raise MercuryUserError('Assets supplied do not cover target')

    rendered = pystache.render(template, **render_data)

    configuration = yaml.load(rendered)

    return {'method': 'press', 'kwargs': {'configuration': configuration}}
Ejemplo n.º 2
0
def get_hp_raid_driver():
    hp_raid_driver = driver_class_cache.get('hpssa')
    if not hp_raid_driver:
        # Once dependent capabilities are added, this will no longer be necessary
        log.error('Attempt to use platform specific procedure without supporting driver')
        raise MercuryUserError('Required driver, hpssa, is not loaded. Check platform')
    return hp_raid_driver
Ejemplo n.º 3
0
    def create_task(self, target):
        # TODO: select ipv4 or ipv6
        # TODO: add yaml option: prefer_ipv6 (bool)
        try:
            mercury_id = target['mercury_id']
            host = target['active']['rpc_address']
            port = target['active']['rpc_port']
            backend = format_zurl(target['origin']['address'],
                                  target['origin']['port'])
        except KeyError:
            raise MercuryCritical('Encountered malformed target, the database '
                                  'is corrupted')

        # Preprocessor entry

        method = self.instruction.get('method')
        if method:
            self.primitive = True
            call_data = {
                'method': self.instruction['method'],
                'args': self.instruction.get('args', []),
                'kwargs': self.instruction.get('kwargs', {})
            }

        else:
            self.preprocessor = self.instruction.get('preprocessor')
            if not self.preprocessor:
                raise MercuryUserError('Contract invalid')

            preprocessor = instruction_preprocessors.get(self.preprocessor)
            if not preprocessor:
                raise MercuryUserError('Specified preprocessor does not exist')

            log.info('Calling %s preprocessor' % preprocessor['name'])
            call_data = preprocessor['entry'](target, self.instruction)

        task = Task(job_id=self.job_id,
                    mercury_id=mercury_id,
                    host=host,
                    port=port,
                    backend=backend,
                    **call_data)

        log.debug('Created task: %s' % task)
        return task
Ejemplo n.º 4
0
 def __check_method(self, method):
     for target in self.targets:
         try:
             capabilities = target['capabilities']
         except KeyError:
             raise MercuryCritical(
                 'Encountered malformed target, the database is corrupted')
         if method not in capabilities:
             raise MercuryUserError(
                 'One of more targets does not support method: %s' % method)