-
Notifications
You must be signed in to change notification settings - Fork 0
/
debdistlist.py
executable file
·108 lines (98 loc) · 3.43 KB
/
debdistlist.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/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,arches):
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
if len(arches)>2:
mycmd=mycmd+" --architectures="+arches
if len(releases)>2:
mycmd=mycmd+" --releases="+releases
print mycmd
myresult=subprocess.check_output(mycmd.replace(" "," ").split(" "))
mycmd="pulp-admin "+repotype+" repo sync run --bg --repo-id="+str(id)
myresult=myresult+subprocess.check_output(mycmd.split(" "))
print mycmd
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:
myid=repo["repo_id"]
myrelurl=repo["config"]["relative_url"]
repotype="unknown"
if "yum" in repo["distributor_type_id"]:
continue
elif "deb" in repo["distributor_type_id"]:
mypulpurl=debrel+myrelurl
repotype="deb"
myurl2="https://"+myparent+"/pulp/api/v2/repositories/"+myid+"/?details=true"
myjunk=json.loads(getPulp(myurl2))
try:
print myid
myreleases=" "
myarches=" "
try:
myarches=myjunk["importers"][0]["config"]["architectures"]
except:
pass
try:
myreleases=myjunk["importers"][0]["config"]["releases"]
except:
pass
try:
if len(myarches)<2:
if "metadesc-arches" in myjunk["description"]:
myarches=myjunk["description"].split(":metadesc-arches:")[1]
except:
pass
try:
if len(myreleases)<2:
if "metadesc-releases" in myjunk["description"]:
myreleases=myjunk["description"].split(":metadesc-releases:")[1]
except:
pass
print createDebReleases(myid,myrelurl,mypulpurl,repotype,myownrepos,myreleases,myarches)
except Exception as e:
print e
pass
else:
continue