<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
[root@lidabai ~]# vim harbor_clearimage.py # -*- coding:utf-8 -*- import requests from requests.auth import HTTPBasicAuth from requests.adapters import HTTPAdapter from requests.packages.urllib3.util.retry import Retry import os import time import logging from logging.handlers import RotatingFileHandler class Harbor(object): def __init__(self, api_url, api_user, api_passwd, tag_num, proj_exclude): self.api_url = api_url self.api_user = api_user self.api_passwd = api_passwd self.api_auth = HTTPBasicAuth(self.api_user, self.api_passwd) self.tag_num = int(tag_num) self.proj_exclude = proj_exclude self.proj_url = self.api_url + "/projects" self.repos_url = self.api_url + "/repositories" self.header_dict = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded' } self.deldata = [] self.session = requests.Session() self.session.auth = self.api_auth retry = Retry(connect=3, backoff_factor=1) adapter = HTTPAdapter(max_retries=retry) self.session.mount('http://', adapter) self.session.keep_alive = False def soft_del_repos(self): try: projresp = self.session.get(self.proj_url, headers=self.header_dict) if projresp.status_code == 200: projdata = projresp.json() for proj in projdata: if proj['name'] not in self.proj_exclude # and proj['name'] == "gxjxhwebtest-28003" : try: reporesp = self.session.get(self.repos_url, params={"project_id": proj['project_id']} , headers=self.header_dict) if reporesp.status_code == 200: repodata = reporesp.json() for repo in repodata: if repo["tags_count"] > self.tag_num: tag_url = self.repos_url + "/" + repo['name'] + "/tags" tags = self.session.get(tag_url).json() tagdata = sorted(tags, key=lambda a: a["created"]) del_tags = tagdata[0:len(tagdata) - self.tag_num] for tag in del_tags: del_repo_tag_url = tag_url + "/" + tag['name'] cmd = 'curl -v -X DELETE -u "' + self.api_user + ":" + self.api_passwd + '" -H "accept: application/json" ' + del_repo_tag_url try: #del_resp = self.session.delete(del_repo_tag_url,headers=self.header_dict) ok = os.system(cmd) if ok == 0 : logging.info("httpdel:" + del_repo_tag_url ) _deldata = {"project_id":proj['project_id'],"project_name":proj['name'],"repo_name":repo['name'],"tag_name":tag['name']} self.deldata.append(_deldata) logging.info("httpdel project_id=" + str(proj['project_id']) + ",project_name=" + proj['name'] + ",repo_name=" + repo['name'] + ",tag_name=" + tag['name']) else: logging.error("exec_cmd fail:" + cmd ) except: logging.error("exec_cmd fail:" + cmd ) except: logging.error("httpget fail:" + self.repos_url) else: logging.error("httpget fail:" + self.proj_url ) except: logging.error("apilogin fail:" + self.api_url ) return self.deldata def hard_del_repo(self): pwd_cmd = "cd /dcos/app/harbor/ " #進入到Harbor安裝目錄 stop_cmd = "docker-compose stop" #停止Harbor服務 del_cmd = "docker run -it --name gc --rm --volumes-from registry goharbor/registry-photon:v2.7.1-patch-2819-v1.8.6 garbage-collect /etc/registryctl/config.yml" start_cmd = "docker-compose start" #啟動Harbor服務 os.system(pwd_cmd) ok1 = os.system(stop_cmd) if ok1 == 0 : time.sleep(10) ok2 = os.system(del_cmd) ok3 = os.system(start_cmd) if ok3 == 0 : logging.info("hard_del_repo ok:") else: logging.error("hard_del_repo fail:") if __name__ == "__main__": Rthandler = RotatingFileHandler('harbor_repo_clear.log', maxBytes=10*1024*1024,backupCount=5) logging.basicConfig(level=logging.INFO) formatter = logging.Formatter('%(levelname)s %(asctime)s %(process)d %(thread)d %(pathname)s %(filename)s %(funcName)s[line:%(lineno)d] %(message)s') Rthandler.setFormatter(formatter) logging.getLogger('').addHandler(Rthandler) api_url = "http://192.168,2,66:443/api" #Harbor服務的API URL api_user = "admin" #超級管理員 api_passwd = "Harbor12345" #超級管理員的使用者密碼 tag_num = 20 #保留的tag數量 proj_exclude = ["library"] harborClient = Harbor(api_url,api_user,api_passwd,tag_num,proj_exclude) data = harborClient.soft_del_repos() if len(data) > 0 : #harborClient.hard_del_repos() logging.info("hard_del_repo:")
[root@lidabai ~]# python harbor_clearimage.py
到此這篇關於Python實現Harbor私有映象倉庫垃圾自動化清理詳情的文章就介紹到這了,更多相關 Harbor垃圾清理內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45