Openstack api调用images

调用image

import requests
import json
headers={}
headers['Content-Type']='application/json'
headers['Content-Type']='application/octet-stream'
headers['X-Auth-Token']=''

body={
    'name':'cirror',
    'container_format':'bare',
    'disk_format':'qcow2'
}

request=requests.post('http://172.25.253.17:9292/v2/images',headers=headers,json=body).json()
print(requests.put(f"http://172.25.253.17:9292{request['file']}",headers=headers,data=open("cirros-0.3.4-x86_64-disk.img","rb")).status_code)
a=requests.get('http://172.25.253.17:9292/v2/images',headers=headers,data=json.dumps(body))
print(a.text)
print('镜像创建成功')

# python3 create_glance.py 
204
{"images": [{"status": "active", "name": "cirror", "tags": [], "container_format": "bare", "created_at": "2021-12-14T04:18:34Z", "size": 13287936, "disk_format": "qcow2", "updated_at": "2021-12-14T04:18:35Z", "visibility": "shared", "self": "/v2/images/e4644668-de0c-41e4-b60c-071b7a142f0a", "min_disk": 0, "protected": false, "id": "e4644668-de0c-41e4-b60c-071b7a142f0a", "file": "/v2/images/e4644668-de0c-41e4-b60c-071b7a142f0a/file", "checksum": "ee1eca47dc88f4879d8a229cc70a07c6", "owner": "55b50cbb4dd4459b873cb15a8b03db43", "virtual_size": null, "min_ram": 0, "schema": "/v2/schemas/image"}], "schema": "/v2/schemas/images", "first": "/v2/images"}
镜像创建成功

# glance image-show e4644668-de0c-41e4-b60c-071b7a142f0a
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6     |
| container_format | bare                                 |
| created_at       | 2021-12-14T04:18:34Z                 |
| disk_format      | qcow2                                |
| id               | e4644668-de0c-41e4-b60c-071b7a142f0a |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | cirror                               |
| owner            | 55b50cbb4dd4459b873cb15a8b03db43     |
| protected        | False                                |
| size             | 13287936                             |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2021-12-14T04:18:35Z                 |
| virtual_size     | None                                 |
| visibility       | shared                               |
+------------------+--------------------------------------+

 

posted @ 2021-12-14 15:03  衡衡酱  阅读(5)  评论(0)    收藏  举报
Live2D