[关闭]
@cyysu 2017-09-26T07:50:09.000000Z 字数 904 阅读 666

python获取私有仓库镜像

  • 时间:2017年9月26日
  • 作者:Kali
  • 邮箱:cyysu.github.io@gmail.com
  • 版本:4.0
  • 描述:Python脚本

脚本编写


脚本内容

  1. #-*- coding:utf-8 -*-
  2. #!/usr/bin/env python
  3. '''
  4. Created on 2016.10.8
  5. @author: an_time
  6. @desc: get images name from registry
  7. '''
  8. import requests
  9. import json
  10. import traceback
  11. repo_ip = '10.0.0.78'
  12. repo_port = 5000
  13. def getImagesNames(repo_ip,repo_port):
  14. docker_images = []
  15. try:
  16. url = "http://" + repo_ip + ":" +str(repo_port) + "/v2/_catalog"
  17. res =requests.get(url).content.strip()
  18. res_dic = json.loads(res)
  19. images_type = res_dic['repositories']
  20. for i in images_type:
  21. url2 = "http://" + repo_ip + ":" +str(repo_port) +"/v2/" + str(i) + "/tags/list"
  22. res2 =requests.get(url2).content.strip()
  23. res_dic2 = json.loads(res2)
  24. name = res_dic2['name']
  25. tags = res_dic2['tags']
  26. for tag in tags:
  27. docker_name = str(repo_ip) + ":" + str(repo_port) + "/" + name + ":" + tag
  28. docker_images.append(docker_name)
  29. print docker_name
  30. except:
  31. traceback.print_exc()
  32. return docker_images
  33. a=getImagesNames(repo_ip, repo_port)
  34. print a

打赏

                    支付宝                                                         微信

微信与支付宝支付

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注