Ask Your Question

Revision history [back]

This code works for me <br&lt; [root@ip-192-169-142-127="" ~(keystone_admin)]#="" cat="" uploadglance.py<="" p="">

#!/usr/bin/env  python
import keystoneclient.v2_0.client as ksclient
import glanceclient
import os

def get_keystone_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['password'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['tenant_name'] = os.environ['OS_TENANT_NAME']
    return d

creds = get_keystone_creds()
keystone = ksclient.Client(**creds)
glance_endpoint = keystone.service_catalog.url_for(service_type='image',
                                                   endpoint_type='publicURL')
glance = glanceclient.Client('1',glance_endpoint, token=keystone.auth_token)
with open('./ubuntu-15.10-server-cloudimg-amd64-disk1.img') as fimage:
    glance.images.create(name="Ubuntu15.10Cloud-via-python", is_public=True, disk_format="qcow2",
                         container_format="bare", data=fimage)

[root@ip-192-169-142-127 ~(keystone_admin)]# glance image-list

+--------------------------------------+-----------------------+
| ID                                   | Name                  |
+--------------------------------------+-----------------------+
| b5d502f1-274b-489b-bcf1-a4975c072706 | cirros                |
| 8d71b324-09a4-4797-bbba-66d7e09aa213 | Ubuntu1404Cloud       |
| 60d9f250-74b3-48ea-982e-46611a231b63 | Ubuntu1510Cloud-image |
| c8f4dcf2-e4cd-4541-aadb-84604e7bf3da | VF23Cloud             |
+--------------------------------------+-----------------------+

[root@ip-192-169-142-127 ~(keystone_admin)]# python uploadGlance.pyc

[root@ip-192-169-142-127 ~(keystone_admin)]# glance image-list
+--------------------------------------+-----------------------------+
| ID                                   | Name                        |
+--------------------------------------+-----------------------------+
| b5d502f1-274b-489b-bcf1-a4975c072706 | cirros                      |
| 8d71b324-09a4-4797-bbba-66d7e09aa213 | Ubuntu1404Cloud             |
| 7a214e14-579d-463c-9441-b334b7d90480 | Ubuntu15.10Cloud-via-python |
| 60d9f250-74b3-48ea-982e-46611a231b63 | Ubuntu1510Cloud-image       |
| c8f4dcf2-e4cd-4541-aadb-84604e7bf3da | VF23Cloud                   |
+--------------------------------------+-----------------------------+

This code works for me <br&lt; [root@ip-192-169-142-127="" ~(keystone_admin)]#="" cat="" uploadglance.py<="" <br&lt;< p="">

[root@ip-192-169-142-127 ~(keystone_admin)]# cat  uploadGlance.py

#!/usr/bin/env  python
import keystoneclient.v2_0.client as ksclient
import glanceclient
import os

def get_keystone_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['password'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['tenant_name'] = os.environ['OS_TENANT_NAME']
    return d

creds = get_keystone_creds()
keystone = ksclient.Client(**creds)
glance_endpoint = keystone.service_catalog.url_for(service_type='image',
                                                   endpoint_type='publicURL')
glance = glanceclient.Client('1',glance_endpoint, token=keystone.auth_token)
with open('./ubuntu-15.10-server-cloudimg-amd64-disk1.img') as fimage:
    glance.images.create(name="Ubuntu15.10Cloud-via-python", is_public=True, disk_format="qcow2",
                         container_format="bare", data=fimage)

[root@ip-192-169-142-127 ~(keystone_admin)]# glance image-list

+--------------------------------------+-----------------------+
| ID                                   | Name                  |
+--------------------------------------+-----------------------+
| b5d502f1-274b-489b-bcf1-a4975c072706 | cirros                |
| 8d71b324-09a4-4797-bbba-66d7e09aa213 | Ubuntu1404Cloud       |
| 60d9f250-74b3-48ea-982e-46611a231b63 | Ubuntu1510Cloud-image |
| c8f4dcf2-e4cd-4541-aadb-84604e7bf3da | VF23Cloud             |
+--------------------------------------+-----------------------+

[root@ip-192-169-142-127 ~(keystone_admin)]# python uploadGlance.pyc

[root@ip-192-169-142-127 ~(keystone_admin)]# glance image-list
+--------------------------------------+-----------------------------+
| ID                                   | Name                        |
+--------------------------------------+-----------------------------+
| b5d502f1-274b-489b-bcf1-a4975c072706 | cirros                      |
| 8d71b324-09a4-4797-bbba-66d7e09aa213 | Ubuntu1404Cloud             |
| 7a214e14-579d-463c-9441-b334b7d90480 | Ubuntu15.10Cloud-via-python |
| 60d9f250-74b3-48ea-982e-46611a231b63 | Ubuntu1510Cloud-image       |
| c8f4dcf2-e4cd-4541-aadb-84604e7bf3da | VF23Cloud                   |
+--------------------------------------+-----------------------------+

This code works for me <br&lt;< p="">


[root@ip-192-169-142-127 ~(keystone_admin)]# cat uploadGlance.py uploadGlance.py

#!/usr/bin/env  python
import keystoneclient.v2_0.client as ksclient
import glanceclient
import os

def get_keystone_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['password'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['tenant_name'] = os.environ['OS_TENANT_NAME']
    return d

creds = get_keystone_creds()
keystone = ksclient.Client(**creds)
glance_endpoint = keystone.service_catalog.url_for(service_type='image',
                                                   endpoint_type='publicURL')
glance = glanceclient.Client('1',glance_endpoint, token=keystone.auth_token)
with open('./ubuntu-15.10-server-cloudimg-amd64-disk1.img') as fimage:
    glance.images.create(name="Ubuntu15.10Cloud-via-python", is_public=True, disk_format="qcow2",
                         container_format="bare", data=fimage)

[root@ip-192-169-142-127 ~(keystone_admin)]# glance image-list

+--------------------------------------+-----------------------+
| ID                                   | Name                  |
+--------------------------------------+-----------------------+
| b5d502f1-274b-489b-bcf1-a4975c072706 | cirros                |
| 8d71b324-09a4-4797-bbba-66d7e09aa213 | Ubuntu1404Cloud       |
| 60d9f250-74b3-48ea-982e-46611a231b63 | Ubuntu1510Cloud-image |
| c8f4dcf2-e4cd-4541-aadb-84604e7bf3da | VF23Cloud             |
+--------------------------------------+-----------------------+

[root@ip-192-169-142-127 ~(keystone_admin)]# python uploadGlance.pyc

[root@ip-192-169-142-127 ~(keystone_admin)]# glance image-list
+--------------------------------------+-----------------------------+
| ID                                   | Name                        |
+--------------------------------------+-----------------------------+
| b5d502f1-274b-489b-bcf1-a4975c072706 | cirros                      |
| 8d71b324-09a4-4797-bbba-66d7e09aa213 | Ubuntu1404Cloud             |
| 7a214e14-579d-463c-9441-b334b7d90480 | Ubuntu15.10Cloud-via-python |
| 60d9f250-74b3-48ea-982e-46611a231b63 | Ubuntu1510Cloud-image       |
| c8f4dcf2-e4cd-4541-aadb-84604e7bf3da | VF23Cloud                   |
+--------------------------------------+-----------------------------+