How to maintain a local mirror of ONAP’s git repositories


For various reasons, I like to maintain a local mirror of git repositories I use a lot, in this case ONAP. This is mostly because of the generally poor network connectivity in Australia, but its also because it makes cloning a new repository super fast.

Tony Breeds and I baked up a script to do this for OpenStack repositories a while ago. I therefore present a version of that mirror script which does the right thing for ONAP projects.

One important thing to note here that differs from OpenStack — ONAP projects aren’t named in a way where they will consistently sit in a directory structure together. For example, there is an “oom” repository, as well as an “oom/registrator” repository. We therefore need to normalise repository names on clone to ensure they don’t clobber each other — I do that by replacing path separators with underscores.

So here’s the script:


from __future__ import print_function

import datetime
import json
import os
import subprocess
import random
import requests

ONAP_GIT_BASE = 'ssh://'

def get_onap_projects():
    data = subprocess.check_output(
               ['ssh', '', 'gerrit',
    for project in data:
        yield (ONAP_GIT_BASE, project,
               'onap/%s' % project.replace('/', '_'))

def _ensure_path(path):
    if not path:

    full = []
    for elem in path.split('/'):
        if not os.path.exists('/'.join(full)):

starting_dir = os.getcwd()
projects = list(get_onap_projects())

for base_url, project, subdir in projects:
    print('%s Considering %s %s'
          %(, base_url, project))

    if os.path.isdir(subdir):

        print('%s Updating %s'
              %(, project))
                ['git', 'remote', '-vvv', 'update'])
        except Exception as e:
            print('%s FAILED: %s'
                  %(, e))
        git_url = os.path.join(base_url, project)

        print('%s Cloning %s'
              %(, project))
            ['ionice', '-c', 'idle', 'git', 'clone',
             '-vvv', '--mirror', git_url, subdir])

Note that your ONAP gerrit username probably isn’t “mikal”, so you might want to change that.

This script will checkout all ONAP git repositories into a directory named “onap” in your current working directory. A second run will add any new repositories, as well as updating the existing ones. Note that these are clones intended to be served with a local git server, instead of being clones you’d edit directly. To clone one of the mirrored repositories for development, you would then do something like:

$ git clone onap/aai_babel development/aai_babel

Or similar.


One thought on “How to maintain a local mirror of ONAP’s git repositories”

Leave a Reply