示例#1
0
def init_whoville_service():
    init_start_ts = _dt.utcnow()
    log.info("------------- Initialising Whoville Deployment Service at [%s]",
             init_start_ts)
    log.info("------------- Validating Profile")
    utils.validate_profile()
    log.info("------------- Loading Default Resources")
    default_resources = []
    for d in os.listdir(
            os.path.abspath(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             'resources'))):
        if d[0] == 'v':
            default_resources.append(d)
    for d in default_resources:
        horton.resources.update(
            utils.load_resources_from_files(
                os.path.abspath(
                    os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                 'resources', d))))
    log.info("------------- Fetching Resources from Profile Definitions")
    if 'resources' in config.profile and config.profile['resources']:
        for res_def in config.profile['resources']:
            if res_def['loc'] == 'local':
                log.info("Loading resources from Local path [%s]",
                         res_def['uri'])
                horton.resources.update(
                    utils.load_resources_from_files(res_def['uri']))
            elif res_def['loc'] == 'github':
                log.info("Loading resources from Github Repo [%s]",
                         res_def['repo'])
                horton.resources.update(
                    utils.load_resources_from_github(
                        repo_name=res_def['repo'],
                        username=config.profile['githubuser'],
                        token=config.profile['githubtoken'],
                        tgt_dir=res_def['subdir']))
            else:
                raise ValueError("Resource Location [%s] Unsupported",
                                 res_def['loc'])
    else:
        log.info("Unable to find additional Demo resources")
    key_test = _re.compile(r'[a-z0-9-.]')
    for def_key, res_list in horton.resources.items():
        log.debug('def_key [%s] res_list [%s]', def_key, res_list)
        if not def_key[0] == '.':
            # Skipping any dot files or directories as unsafe
            for res_filename, res_content in res_list.items():
                if not bool(key_test.match(res_filename)):
                    raise ValueError(
                        "Resource Name must only contain 0-9 a-z - .")
            horton.defs[def_key] = res_list[def_key + '.yaml']
    init_finish_ts = _dt.utcnow()
    diff_ts = init_finish_ts - init_start_ts
    log.info("Completed Service Init at [%s] after [%d] seconds",
             init_finish_ts, diff_ts.seconds)
示例#2
0
def step_1_init_service():
    init_start_ts = _dt.utcnow()
    log.info("------------- Initialising Whoville Deployment Service at [%s]",
             init_start_ts)
    log.info("------------- Validating Profile")
    whoville.utils.validate_profile()
    log.info("------------- Loading Default Resources")
    default_resources = os.path.abspath(os.path.join(
        os.path.dirname(os.path.abspath(__file__)), 'resources', 'v2'
    ))
    horton.resources.update(
        utils.load_resources_from_files(default_resources)
    )
    log.info("------------- Fetching Resources from Profile Definitions")
    if config.profile['resources']:
        for res_def in config.profile['resources']:
            if res_def['loc'] == 'local':
                log.info("Loading resources from Local path [%s]",
                         res_def['uri'])
                horton.resources.update(utils.load_resources_from_files(
                    res_def['uri']
                ))
            elif res_def['loc'] == 'github':
                log.info("Loading resources from Github Repo [%s]",
                         res_def['repo'])
                horton.resources.update(utils.load_resources_from_github(
                    repo_name=res_def['repo'],
                    username=config.profile['githubuser'],
                    token=config.profile['githubtoken'],
                    tgt_dir=res_def['subdir']
                ))
            else:
                raise ValueError("Resource Location [%s] Unsupported",
                                 res_def['loc'])
    else:
        log.warning("Found no additional Resources to load!")
    key_test = _re.compile(r'[a-z0-9-.]')
    for def_key, res_list in horton.resources.items():
        for res_filename, res_content in res_list.items():
            if not bool(key_test.match(res_filename)):
                raise ValueError("Resource Name must only contain 0-9 a-z - .")
        horton.defs[def_key] = res_list[def_key + '.yaml']
    init_finish_ts = _dt.utcnow()
    diff_ts = init_finish_ts - init_start_ts
    log.info("Completed Service Init at [%s] after [%d] seconds",
             init_finish_ts, diff_ts.seconds)