示例#1
0
def _init_dockyards():
    try:
        with open(consul_config.ORIGINAL_RUNTIME_SETTINGS_PATH) as runtime_settings_json:
            runtime_settings = json.load(runtime_settings_json)
    except:
        runtime_settings = {}

    # Initialize dockyard list with fallback dockyard.
    if not alias.get_alias(alias.DOCKYARD_FALLBACK_ALIAS):
        alias.set_alias(alias.DOCKYARD_FALLBACK_ALIAS, alias.DOCKYARD_FALLBACK_ADDRESS)

    dockyards = runtime_settings.get('dockyards', {})
    default_alias = None
    for info in dockyards:
        dockyard_alias = info.get('name')
        if dockyard_alias and not alias.get_alias(dockyard_alias):
            alias.set_alias(dockyard_alias, info.get('address'), info.get('user'), info.get('password'))
            if info.get('is_default'):
                default_alias = dockyard_alias
    if default_alias:
        alias.set_default(default_alias)
示例#2
0
def get_dockyard_dict(alias_name=None):
    try:
        if not alias_name:
            alias_name = get_default_alias()
        dockyard = alias.get_alias(alias_name)
        if not dockyard:
            raise CriticalDockyardException('Dockyard alias: {alias_name} does not exist.'.format(**locals()))
        return dockyard
    except DockyardException as e:
        dockyard_address = alias.DOCKYARD_FALLBACK_ADDRESS
        print('WARNING: Could not get dockyard_address ({e}), falling back to: {dockyard_address}'.format(**locals()))
        return {'address': dockyard_address}
示例#3
0
def _init_dockyards():
    try:
        with open(consul_config.ORIGINAL_RUNTIME_SETTINGS_PATH) as runtime_settings_json:
            runtime_settings = json.load(runtime_settings_json)
    except:
        runtime_settings = {}

    # Initialize dockyard list with fallback dockyard.
    if not alias.get_alias(alias.DOCKYARD_FALLBACK_ALIAS):
        alias.set_alias(alias.DOCKYARD_FALLBACK_ALIAS, alias.DOCKYARD_FALLBACK_ADDRESS)

    dockyards = runtime_settings.get('dockyards', {})
    default_alias = None
    for info in dockyards:
        dockyard_alias = info.get('name')
        if dockyard_alias and not alias.get_alias(dockyard_alias):
            alias.set_alias(dockyard_alias, info.get('address'), info.get('user'), info.get('password'))
            if info.get('is_default'):
                default_alias = dockyard_alias
    if default_alias:
        alias.set_default(default_alias)
示例#4
0
def get_dockyard_dict(alias_name=None):
    try:
        if not alias_name:
            alias_name = get_default_alias()
        dockyard = alias.get_alias(alias_name)
        if not dockyard:
            raise CriticalDockyardException("Dockyard alias: {alias_name} does not exist.".format(**locals()))
        return dockyard
    except DockyardException as e:
        dockyard_address = alias.DOCKYARD_FALLBACK_ADDRESS
        print("WARNING: Could not get dockyard_address ({e}), falling back to: {dockyard_address}".format(**locals()))
        return {"address": dockyard_address}
示例#5
0
def get_default_alias():
    default_alias = alias.get_default()
    if default_alias:
        dockyard = alias.get_alias(default_alias)
        if not dockyard:
            raise DockyardException('Default dockyard does not exist.')
        return default_alias
    alias_list = alias.get_list()
    if not alias_list:
        raise DockyardException('There are no running dockyards.')
    if len(alias_list) > 1:
        raise CriticalDockyardException('There are multiple running dockyards and no default set.'
                                        'Please specify dockyard by -d/--dockyard or set the default.')
    return alias_list[0]['name']
示例#6
0
文件: dockyard.py 项目: labuzm/armada
def get_default_alias():
    default_alias = alias.get_default()
    if default_alias:
        dockyard = alias.get_alias(default_alias)
        if not dockyard:
            raise DockyardException('Default dockyard does not exist.')
        return default_alias
    alias_list = alias.get_list()
    if not alias_list:
        raise DockyardException('There are no running dockyards.')
    if len(alias_list) > 1:
        raise CriticalDockyardException('There are multiple running dockyards and no default set.'
                                        'Please specify dockyard by -d/--dockyard or set the default.')
    return alias_list[0]['name']