-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistlist.py
More file actions
executable file
·70 lines (61 loc) · 2.38 KB
/
Copy pathdistlist.py
File metadata and controls
executable file
·70 lines (61 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/env python
import base64
import urllib2
import ssl
import json
import subprocess
from loaddictfromfile import *
relationship=file2dict("relationship.dict")
creds=file2dict("credentials.dict")
myparent=relationship["parent"]
mychild=relationship["child"]
debrel="http://"+myparent+"/pulp/deb/"
rpmrel="http://"+myparent+"/pulp/repos/"
def getPulp(myurl):
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
hostsan=myurl.split("//")[-1].split("/")[0].split('?')[0]
username=creds[hostsan]["username"]
password=creds[hostsan]["password"]
request = urllib2.Request(myurl)
base64string = base64.b64encode('%s:%s' % (username, password))
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request, context=ctx)
return result.read()
def createRepo(id,relurl, feed,repotype,localrepos):
if id in localrepos:
return id+" already exists. Skipping"
mycmd="pulp-admin "+repotype+" repo create --repo-id="+str(id)+" --serve-http=true --relative-url="+relurl+" --feed="+feed
myresult=subprocess.check_output(mycmd.split(" "))
mycmd="pulp-admin "+repotype+" repo sync run --bg --repo-id="+str(id)
myresult=myresult+subprocess.check_output(mycmd.split(" "))
return myresult
def createDebReleases(id,relurl, feed,repotype,localrepos,releases):
if id in localrepos:
return id+" already exists. Skipping"
mycmd="pulp-admin "+repotype+" repo create --repo-id="+str(id)+" --serve-http=true --relative-url="+relurl+" --feed="+feed+" --releases="+releases
myresult=subprocess.check_output(mycmd.split(" "))
mycmd="pulp-admin "+repotype+" repo sync run --bg --repo-id="+str(id)
myresult=myresult+subprocess.check_output(mycmd.split(" "))
return myresult
# API queries require HTTPS
# get parent repos
myurl="https://"+myparent+"/pulp/api/v2/distributors/search/"
myrepos=json.loads(getPulp(myurl))
# get local repos
mylocalurl="https://"+mychild+"/pulp/api/v2/distributors/search/"
mylocalrepos=json.loads(getPulp(mylocalurl))
myownrepos=[]
for myrepo in mylocalrepos:
myownrepos.append(str(myrepo["repo_id"]))
for repo in myrepos:
skip=False
myid=repo["repo_id"]
myrelurl=repo["config"]["relative_url"]
repotype="unknown"
if "yum" in repo["distributor_type_id"]:
mypulpurl=rpmrel+myrelurl
repotype="rpm"
if not skip:
print createRepo(myid,myrelurl,mypulpurl,repotype,myownrepos)