Skip to content

Instantly share code, notes, and snippets.

@sysadmind
Created March 16, 2016 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sysadmind/c9ceba7399a6695f8ca6 to your computer and use it in GitHub Desktop.
Save sysadmind/c9ceba7399a6695f8ca6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import subprocess
from urlparse import urlparse
repos = [
# Centos
{'name': 'centos-6-x86_64-base', 'feed': 'http://mirror.centos.org/centos/6/os/x86_64/'},
{'name': 'centos-6-x86_64-updates', 'feed': 'http://mirror.centos.org/centos/6/updates/x86_64/'},
{'name': 'centos-6-x86_64-extras', 'feed': 'http://mirror.centos.org/centos/6/extras/x86_64/'},
{'name': 'centos-7-x86_64-base', 'feed': 'http://mirror.centos.org/centos/7/os/x86_64/'},
{'name': 'centos-7-x86_64-updates', 'feed': 'http://mirror.centos.org/centos/7/updates/x86_64/'},
{'name': 'centos-7-x86_64-extras', 'feed': 'http://mirror.centos.org/centos/7/extras/x86_64/'},
# Epel
{'name': 'epel-6-x86_64', 'feed': 'http://mirror.cs.pitt.edu/epel/6/x86_64/'},
{'name': 'epel-7-x86_64', 'feed': 'http://mirror.cs.pitt.edu/epel/7/x86_64/'},
# Remi
{'name': 'remi-6-x86_64-safe', 'feed': 'http://rpms.remirepo.net/enterprise/6/safe/x86_64/'},
{'name': 'remi-6-x86_64', 'feed': 'http://rpms.remirepo.net/enterprise/6/remi/x86_64/'},
{'name': 'remi-6-x86_64-php55', 'feed': 'http://rpms.remirepo.net/enterprise/6/php55/x86_64/'},
{'name': 'remi-6-x86_64-php56', 'feed': 'http://rpms.remirepo.net/enterprise/6/php56/x86_64/'},
{'name': 'remi-6-x86_64-php70', 'feed': 'http://rpms.remirepo.net/enterprise/6/php70/x86_64/'},
{'name': 'remi-6-x86_64-test', 'feed': 'http://rpms.remirepo.net/enterprise/6/test/x86_64/'},
{'name': 'remi-7-x86_64-safe', 'feed': 'http://rpms.remirepo.net/enterprise/7/safe/x86_64/'},
{'name': 'remi-7-x86_64', 'feed': 'http://rpms.remirepo.net/enterprise/7/remi/x86_64/'},
{'name': 'remi-7-x86_64-php55', 'feed': 'http://rpms.remirepo.net/enterprise/7/php55/x86_64/'},
{'name': 'remi-7-x86_64-php56', 'feed': 'http://rpms.remirepo.net/enterprise/7/php56/x86_64/'},
{'name': 'remi-7-x86_64-php70', 'feed': 'http://rpms.remirepo.net/enterprise/7/php70/x86_64/'},
{'name': 'remi-7-x86_64-test', 'feed': 'http://rpms.remirepo.net/enterprise/7/test/x86_64/'},
# Atomic
{'name': 'atomic-6-x86_64', 'feed': 'http://mir01.syntis.net/atomic/atomic/centos/6/x86_64/'},
{'name': 'atomic-7-x86_64', 'feed': 'http://mir01.syntis.net/atomic/atomic/centos/7/x86_64/'},
# Maria DB
{'name': 'mariadb-7-x86_64-55', 'feed': 'http://yum.mariadb.org/5.5/centos7-amd64/', 'relative-url': '/mariadb/7/x86_64/5.5/'},
# Elasticsearch
{'name': 'elasticsearch-6-x86_64-10', 'feed': 'http://packages.elastic.co/elasticsearch/1.0/centos', 'relative-url': '/elasticsearch/6/x86_64/1.0/'},
{'name': 'elasticsearch-7-x86_64-17', 'feed': 'http://packages.elastic.co/elasticsearch/1.7/centos', 'relative-url': '/elasticsearch/7/x86_64/1.7/'},
{'name': 'elasticsearch-7-x86_64-2x', 'feed': 'http://packages.elastic.co/elasticsearch/2.x/centos', 'relative-url': '/elasticsearch/7/x86_64/2.x/'},
# Logstash
{'name': 'logstash-7-x86_64-2.2', 'feed': 'http://packages.elastic.co/logstash/2.2/centos/', 'relative-url': '/logstash/7/x86_64/2.2/'},
# Graylog
{'name': 'graylog2-7-x86_64-13', 'feed': 'https://packages.graylog2.org/repo/el/7/1.3/x86_64/', 'relative-url': '/graylog2/7/x86_64/1.3/'},
# Nginx
{'name': 'nginx-6-x86_64', 'feed': 'http://nginx.org/packages/centos/6/x86_64/', 'relative-url': '/nginx/6/x86_64/'},
{'name': 'nginx-7-x86_64', 'feed': 'http://nginx.org/packages/centos/7/x86_64/', 'relative-url': '/nginx/7/x86_64/'}
]
def getCreateCommands(repo):
return [
"pulp-admin rpm repo create --repo-id={0}_public --feed={1} --relative-url='public{2}'".format(
repo['name'],
repo['feed'],
repo['relative-url']
),
"pulp-admin rpm repo create --repo-id={0}_development --relative-url='development{1}'".format(
repo['name'],
repo['relative-url']
),
"pulp-admin rpm repo create --repo-id={0}_testing --relative-url='testing{1}'".format(repo['name'], repo['relative-url']),
"pulp-admin rpm repo create --repo-id={0}_production --relative-url='production{1}'".format(repo['name'], repo['relative-url'])
]
def getSyncCommands(repo):
return [
"pulp-admin rpm repo sync run --repo-id={0}_public".format(repo['name'])
]
def getCopyCommands(repo):
return [
"pulp-admin rpm repo copy all --from-repo-id='{0}_public' --to-repo-id='{0}_development'".format(repo['name']),
"pulp-admin rpm repo copy all --from-repo-id='{0}_public' --to-repo-id='{0}_testing'".format(repo['name']),
"pulp-admin rpm repo copy all --from-repo-id='{0}_public' --to-repo-id='{0}_production'".format(repo['name'])
]
def getPublishCommands(repo):
return [
"pulp-admin rpm repo publish run --repo-id='{0}_public'".format(repo['name']),
"pulp-admin rpm repo publish run --repo-id='{0}_development'".format(repo['name']),
"pulp-admin rpm repo publish run --repo-id='{0}_testing'".format(repo['name']),
"pulp-admin rpm repo publish run --repo-id='{0}_production'".format(repo['name'])
]
def runCommands(command_array):
for command in command_array:
print "Running: {0}".format(command)
print subprocess.Popen(
command,
shell=True,
stdout=subprocess.PIPE
).stdout.read()
for repo in repos:
if 'relative-url' not in repo.keys():
repo['relative-url'] = urlparse(repo['feed']).path
print repo['relative-url']
create_commands = getCreateCommands(repo)
sync_commands = getSyncCommands(repo)
copy_commands = getCopyCommands(repo)
publish_commands = getPublishCommands(repo)
runCommands(create_commands)
runCommands(sync_commands)
runCommands(copy_commands)
runCommands(publish_commands)
print subprocess.Popen("echo Hello World", shell=True, stdout=subprocess.PIPE).stdout.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment