最近在研究kubernetes,docker仓库用到的比较多,每次查询都得curl好麻烦,所以才写了这个。
#!/usr/bin/env python # -*- coding: utf-8 -*- """ author = ‘Perling‘ time = ‘2016/11/10‘ """ import urllib2 import json registry="172.31.14.229:5000" registry_url = "http://%s"%registry def http_get(url): req = urllib2.Request(url) req.add_header("Content-Type","application/json-rpc") resp = urllib2.urlopen(req) resp_json = json.loads(resp.read()) return resp_json def get_repository_list(): data = http_get(registry_url+"/v2/_catalog") repository_list = data[‘repositories‘] return repository_list def get_repository_tags(repository): data = http_get("%s/v2/%s/tags/list"%(registry_url,repository)) tags = data[‘tags‘] return tags def get_all_repository_tags(): data = {} for repositoary in get_repository_list(): data[repositoary]=get_repository_tags(repositoary) return data if __name__ == ‘__main__‘: data = get_all_repository_tags() print "/" print "|" for key in data: print "|--- %s"%key for tag in data[key]: print "| |--- %-15s %s/%s:%s"%(tag,registry,key,tag)
时间: 2024-10-13 08:28:19