From 22657b8bd22ee433fb7fccaf67d53cd472947e12 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 20 Jun 2024 20:03:52 +0800 Subject: [PATCH] update --- glance/__pycache__/glance_main.cpython-36.pyc | Bin 0 -> 1715 bytes glance/__pycache__/image.cpython-36.pyc | Bin 0 -> 3100 bytes glance/glance_main.py | 53 +++++++++- glance/image.py | 96 ++++++++++++++++++ .../__pycache__/keystone_main.cpython-36.pyc | Bin 4201 -> 4158 bytes keystone/keystone_main.py | 6 +- main.py | 19 +++- 7 files changed, 168 insertions(+), 6 deletions(-) create mode 100644 glance/__pycache__/glance_main.cpython-36.pyc create mode 100644 glance/__pycache__/image.cpython-36.pyc diff --git a/glance/__pycache__/glance_main.cpython-36.pyc b/glance/__pycache__/glance_main.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..758f8a7713bfb24ea21bf321f26b34d06231d2e5 GIT binary patch literal 1715 zcmaJ>&1>976xZl$wI6nD$8MVRYY#ni3lUjw;(%#Opp@Qn>7@w6B6h~MysHnS5ye4< zfYKywN!JkS5|V=hEp2*8eJG97xX%BfYgcRUzmQX(M)F#lib~A9kNLgdd-Fz`*3?v` zeV(rFl{xMoF8A=DUxVSj4-@7v>TxF05K45u$D4vCfG%M17N?0=`hsi7BS3Nu6iJ4u zuMtqnYlOC`-6d8hSxTNNj1r7bVR#}Wp+Fr1El56-C$^B;;)EYzDMVWwmbVb)H~0YI z5?0_Xhtd`waJbUtw|O_uTb+pKa4oZ^GC7^eGnt&pdJvvV@}?QwR}|s1U<)AU zL5d(3KuRFr04Y;pLkv*B2SOkQQXq%&R*7;!iE&CHhZ3f9P%Cmj1gxB3Lmv7t)(h}& zGW?h0+`>jF%@GO(=<^JHJBL>O2YrE|565VP--3N8P)|AAhZ2efS>A@Yq~E9gcn9Lj zV808p0`ZkBz8qBGj9%*k=HSzL@A{4Tj|(3EEPN)To8Jt-dotL+IoSVgc>mtu??=mi z4g8}2gYWq8e*E>%Krwp!y#7J+Vym%SzcJOk zx~R4;sf$Z$^J+5^F){5((y?h+k$j0g5o)p|6NFik`0m5_#b4m?xUhQ=AM_#O!fDG=s;AH62fq%p2h5xVl9 ztjEuOj}LDx*CVv#pBvMR%O4k2uy#^cqZ&z$YgiPn5XKZ%ywy7JI#%>wr*DBt+{Z)$5YMAuMNrX1*J3U*+Z9_NLNPE@j5v}GscuWbY<<7co zbV$S-P9(8gORF&2wxydyn@x30ypC%))UYkBiVd&ZUbS6Qr`k-%wkXs?+{_cnF7f;x zJz;Tlx~@%IBr7mwT{yLK%uhHsIqg^1K3iVt*qE$1n{?f_R&0k@9@RVDi@IaHW~D7z z$#q6`Hr?ctO}gm0FmXtkcttdaDifZ`_0*aNgbcVEys4(3=>knbGh=TOIR}H~zuu4{ rIjxHwW~6k8cz@{ws{zehenV0j`;Ne%x3U&aqt literal 0 HcmV?d00001 diff --git a/glance/__pycache__/image.cpython-36.pyc b/glance/__pycache__/image.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..40ea15fba8f2bd7e7368c6fdee8aa2405b3559ce GIT binary patch literal 3100 zcmcguO>f*p7#@$mW;f1eTiPapA_NFj3(^%us?-Sap_Use0;;x(f>y3)lJ#bH?T%*) zS$VmHLshA2FCY++=%Gk(Kmw_U9{2$q_yxX_ROG@B;KcimHydZwRw9bbP`kXwXP{=>_=NcN9rz--7&=(NRfRvc&%-~x00lQPGD|p}B||4O zxXGfxZcC|TvC$aJ zES@`a?o8vxnMTwNRz*6f2T9V2!azlFuhCB9o=*qf)rI%^sihJ-nVnB7j#8F#YGy*D8cvPCQ8?uE3xbbDzAs|UJ&(!9Q7#EjTa0F?zy~_#i|X;e`vs6>5@S zhenBHIwslFqyo|0zDn4v|dX(AfB91bth2P)RrlMAos;5FWu6 z!d4W|Kr64nI|TyxAjP*w2+*1#PrzM>(BOr0jQ4#RZc6($$NRSQzCqr4-yraz^ZBXF z#@%ywo?IZG&cOk2Ih!XLU8C|Wv@7#)Jg%R;LNW*BUOjw-ayY=6=2Rk!AVod`O&*8) z0yI_vt%kk(k;|F>LNnsIty_~&dSfVI%(L);6d~P1(=v`49{l8U&^tyIbv;HE4N8%W zWJX3e%%KVDA!|&Y|UKpicF4sB($skRgs)aGPP+ZVyj;qC38zuDgWanDui6Ry(uueP$QL`!c@%dv#4JBjQ(EM@}UNi?fz zEB>rd=BqF|MKSPWlkB?aKBlU`mwXwXhNyMC&}nep+C}d|qr?`t z0M#0>IiFm=dodhau$rtfcFG1l~Cl2IpK!$NGIX;}Z zA(lpw8YBFZgUFG7(uo7!jDqf}XyW$YfmzZyD0YwRF*v$M^|7rRS`4qjvk*fmUML1^ zYcYHQjglB_$djIAf+z&cs|pizF{|RPCLQe%Gb$t>Gb%Qwz5>*@FsmC;?>&b4>4Q;! zaK14rNer}Q?&T}kJLdk;cMl$Y{Y#1aqGKQTh4Y@m_YhM#g~d~Nul2;pWQ%0%_}+av zAsb6#Pnhy?*@V|mKq;e?>O+`&p9ZvTLt=#~mDa#%7~xlnHS6VKo~4tH!miNXwQERJ mi^SojFrhOUoy4%Wx-su}#M=gp(2)Y81e;-ud2EW+Sp8p#hVEbh literal 0 HcmV?d00001 diff --git a/glance/glance_main.py b/glance/glance_main.py index 7b15982..9d2fccd 100644 --- a/glance/glance_main.py +++ b/glance/glance_main.py @@ -1,5 +1,6 @@ from glance import image -def keystone_main(): +from keystone import get_token +def glance_main(): print("====================") print("选择一个操作:") print("====================") @@ -8,4 +9,52 @@ def keystone_main(): print("====================") choice = input("输入选项 (1-3): ") ip = "172.30.26.171" - token = get_token.get_token(ip,'demo','admin','admin','000000') \ No newline at end of file + token = get_token.get_token(ip,'demo','admin','admin','000000') + if choice == '1': + print("====================") + print("镜像管理") + print("====================") + print("1. 创建镜像") + print("2. 列出镜像") + print("3. 获取镜像") + print("4. 删除镜像") + print("5. 上传镜像文件") + print("6. 更新镜像") + print("====================") + choice = input("输入选项 (1-6): ") + if choice == '1': + image_name = input("输入镜像名称: ") + image_description = input("输入镜像描述: ") + disk_format = input("输入镜像格式: ") + container_format = input("输入镜像容器格式: ") + result=image.create_image(ip, token, image_name, image_description,disk_format, container_format) + print(result) + glance_main() + if choice == '2': + image.get_image(ip, token) + result=image.get_image(ip, token) + print(result) + glance_main() + if choice == '3': + image_name = input("输入镜像名称: ") + result=image.show_image(ip, token, image_name) + print(result) + glance_main() + if choice == '4': + image_name = input("输入镜像名称: ") + result=image.delete_image(ip, token, image_name) + print(result) + glance_main() + if choice == '5': + image_name = input("输入镜像名称: ") + image_path = input("输入镜像路径: ") + result=image.upload_iamge_file(ip,token,image_name,image_path) + print(result) + glance_main() + if choice == '6': + image_name = input("输入镜像名称: ") + new_image_name = input("输入新镜像名称: ") + new_image_description = input("输入新镜像描述: ") + result=image.update_image(ip, token, image_name, new_image_name, new_image_description) + print(result) + glance_main() \ No newline at end of file diff --git a/glance/image.py b/glance/image.py index e69de29..8052687 100644 --- a/glance/image.py +++ b/glance/image.py @@ -0,0 +1,96 @@ +import requests +import json +def create_image(ip, token, image_name, image_description,disk_format, container_format): + url = "http://" + ip + ":9292/v2/images" + headers = { + "X-Auth-Token": token, + "Content-Type": "application/json" + } + data = { + "name": image_name, + "description": image_description, + "disk_format": disk_format, + "container_format": container_format, + "visibility": "public" + } + response = requests.post(url, headers=headers, data=json.dumps(data)) + return response.json() +def get_image(ip, token): + url = "http://" + ip + ":9292/v2/images" + headers = { + "X-Auth-Token": token, + "Content-Type": "application/json" + } + response = requests.get(url, headers=headers) + return response.json() +def get_image_id(ip, token, image_name): + url = "http://" + ip + ":9292/v2/images" + headers = { + "X-Auth-Token": token, + "Content-Type": "application/json" + } + response = requests.get(url, headers=headers) + image_id = "" + for image in response.json()["images"]: + if image["name"] == image_name: + image_id = image["id"] + return image_id +def show_image(ip, token, image_name): + image_id=get_image_id(ip, token, image_name) + if image_id is None: + return {"error":"镜像不存在"} + url = "http://" + ip + ":9292/v2/images/" + image_id + headers = { + "X-Auth-Token": token, + "Content-Type": "application/json" + } + response = requests.get(url, headers=headers) + return response.json() +def delete_image(ip, token, image_name): + image_id=get_image_id(ip, token, image_name) + if image_id is None: + return {"error":"镜像不存在"} + url = "http://" + ip + ":9292/v2/images/" + image_id + headers = { + "X-Auth-Token": token, + "Content-Type": "application/json" + } + response = requests.delete(url, headers=headers) + if response.status_code == 204: + return {"message":"删除成功"} + else: + return {"error":"删除失败"+str(response.status_code)} +def upload_iamge_file(ip,token,image_name,image_path): + image_id=get_image_id(ip, token, image_name) + if image_id is None: + return {"error":"镜像不存在"} + url = "http://" + ip + ":9292/v2/images/" + image_id + "/file" + with open(image_path, "rb") as e: + image_data = e.read() + headers = { + "X-Auth-Token": token, + "Content-Type": "application/octet-stream" + } + response = requests.patch(url, headers=headers, data=image_data) + if response.status_code == 200: + return {"message":"上传成功"} + else: + return {"error":"上传失败"+str(response.status_code)} +def update_image(ip, token, image_name, new_image_name, new_image_description): + image_id=get_image_id(ip, token, image_name,) + if image_id is None: + return {"error":"镜像不存在"} + url = "http://" + ip + ":9292/v2/images/" + image_id + headers = { + "X-Auth-Token": token, + "Content-Type": "application/octet-stream" + } + data = { + "name": new_image_name, + "description": new_image_description, + } + response = requests.patch(url, headers=headers, data=json.dumps(data)) + if response.status_code == 200: + return {"message":"更新成功"} + else: + return {"error":"更新失败"+str(response.status_code)} \ No newline at end of file diff --git a/keystone/__pycache__/keystone_main.cpython-36.pyc b/keystone/__pycache__/keystone_main.cpython-36.pyc index d827a04b8999b804fc3dc14b4ec9f17366c1b9e4..6722a27c8e5f92716140753c73ff45673f9c62fa 100644 GIT binary patch literal 4158 zcmcgvTWl0n7@jk?&R*Ls%SAz55tT)$mQo)G8sjA~(Ga3b(V_GC8fK~B<2jhbeKACyc?zVmN!3X1$|2gNM*-N*S#OQ8zzjOZo zKmYxo%TO#9?%z>5P)bSC?^4T0hV_f^EANLtOR`8o8Yd|rNsa*MQ(x&cy~xD*9D!XG(r2s<@ph5Sj7e}Kz>(jp&PRsKzoe~`;J0(oL>hIkCv zZvhN}cVUdnsD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