def _get_local_running_containers():
    result = []
    for container_id in get_local_containers_ids():
        container_parameters = get_container_parameters(container_id)
        if container_parameters:
            result.append(container_parameters)
    return result
def _get_local_running_containers():
    result = []
    for container_id in get_local_containers_ids():
        container_parameters = get_container_parameters(container_id)
        if container_parameters:
            result.append(container_parameters)
    return result
def main():
    args = _parse_args()
    if not args.force and not _is_recovery_completed():
        print('Recovery is not completed. Aborting saving running containers.')
        return
    saved_containers_path = args.saved_containers_path
    try:
        wait_for_consul_ready()
        containers_ids = get_local_containers_ids()
        containers_parameters_list = []
        errors_count = 0
        for container_id in containers_ids:
            try:
                container_parameters = get_container_parameters(container_id)
                if container_parameters:
                    containers_parameters_list.append(container_parameters)
            except:
                errors_count += 1
                print_err('ERROR on getting container parameters for {container_id}:'.format(**locals()))
                traceback.print_exc()
        # Don't overwrite saved containers' list if it would become empty because of errors.
        if containers_parameters_list or not errors_count:
            _save_containers_parameters_list_in_file(containers_parameters_list, saved_containers_path)
            print('Containers have been saved to {saved_containers_path}.'.format(**locals()))
            try:
                _save_containers_parameters_list_in_kv_store(containers_parameters_list)
                print('Containers have been saved to kv store.')
            except:
                traceback.print_exc()
        else:
            print('Aborted saving container because of errors.')
    except:
        traceback.print_exc()
        sys.exit(1)
Example #4
0
def main():
    args = _parse_args()
    if not args.force and not _is_recovery_completed():
        get_logger().warning('Recovery is not completed. Aborting saving running containers.')
        return
    saved_containers_path = args.saved_containers_path
    try:
        wait_for_consul_ready()
        containers_ids = get_local_containers_ids()
        containers_parameters_list = []
        errors_count = 0
        for container_id in containers_ids:
            try:
                container_parameters = get_container_parameters(container_id)
                if container_parameters:
                    containers_parameters_list.append(container_parameters)
            except:
                errors_count += 1
                get_logger().error('ERROR on getting container parameters for {}:'.format(container_id))
                traceback.print_exc()
        containers_parameters_list.sort()
        # Don't overwrite saved containers' list if it would become empty because of errors.
        if containers_parameters_list or not errors_count:
            _save_containers_parameters_list_in_file(containers_parameters_list, saved_containers_path)
            get_logger().info('Containers have been saved to {}.'.format(saved_containers_path))
            try:
                _save_containers_parameters_list_in_kv_store(containers_parameters_list)
                get_logger().info('Containers have been saved to kv store.')
            except:
                traceback.print_exc()
        else:
            get_logger().info('Aborted saving container because of errors.')
    except:
        traceback.print_exc()
        sys.exit(1)
Example #5
0
def deregister_not_running_services():
    services_ids = get_local_services_ids()
    containers_ids = get_running_container_ids()
    for service_id in services_ids:
        if service_id != 'consul':
            container_id = service_id.split(':')[0]
            if container_id not in containers_ids:
                name = consul_query('agent/services')[service_id]['Service']
                params = get_container_parameters(container_id)
                kv_index = 0
                if kv.kv_list('service/{}/'.format(name)):
                    kv_index = int(
                        kv.kv_list(
                            'service/{}/'.format(name))[-1].split('/')[2]) + 1
                kv.save_service(name, kv_index, 'crashed', params,
                                container_id)
                deregister_services(container_id)
def _get_local_running_containers():
    return [get_container_parameters(container_id) for container_id in get_local_containers_ids()]
Example #7
0
def _mark_service_as_crashed(container_id, service_name):
    params = get_container_parameters(container_id)
    kv_index = 0
    if kv.kv_list('service/{}/'.format(service_name)):
        kv_index = int(kv.kv_list('service/{}/'.format(service_name))[-1].split('/')[2]) + 1
    kv.save_service(service_name, kv_index, 'crashed', params, container_id)
Example #8
0
def _get_local_running_containers():
    return [
        get_container_parameters(container_id)
        for container_id in get_local_containers_ids()
    ]