Ask Your Question

Revision history [back]

Code itself :- [root@SeverMitaka01 test(keystone_admin)]# cat upload.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

def get_nova_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['api_key'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['project_id'] = 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('/root/trusty-server-cloudimg-amd64-disk1.img') as fimage:
    glance.images.create(name="Ubuntu1404-image1", is_public=True, disk_format="qcow2",
                         container_format="bare", data=fimage)

Run :-

$python upload.py
$ [root@SeverMitaka01 ~(keystone_admin)]# . keystonerc_glance
[root@SeverMitaka01 ~(keystone_glance)]# glance image-list
+--------------------------------------+----------------------+
| ID                                   | Name                 |
+--------------------------------------+----------------------+
| 75e68a5e-5669-4c3f-8ed7-9ec6718cbc26 | CirrOS34-image       |
| bddfe258-9a6c-45f2-9e8e-dfe509a05b48 | ubuntu-trusty-x86_64 |
| c3f5bb3c-681b-41e9-aaa9-8ced70a8280a | Ubuntu1404-image1    |
| 291f6a39-b10b-4495-9e99-1233927ae8c5 | Ubuntu1510-image     |
| 91e11e67-9e76-4b2a-ac4b-27c5ce83fb83 | VF23Cloud-image      |
+--------------------------------------+----------------------+

System has swift set up as glance back end :-

[root@SeverMitaka01 ~(keystone_glance)]# glance image-list
+--------------------------------------+----------------------+
| ID                                   | Name                 |
+--------------------------------------+----------------------+
| 75e68a5e-5669-4c3f-8ed7-9ec6718cbc26 | CirrOS34-image       |
| bddfe258-9a6c-45f2-9e8e-dfe509a05b48 | ubuntu-trusty-x86_64 |
| c3f5bb3c-681b-41e9-aaa9-8ced70a8280a | Ubuntu1404-image1    |
| 291f6a39-b10b-4495-9e99-1233927ae8c5 | Ubuntu1510-image     |
| 91e11e67-9e76-4b2a-ac4b-27c5ce83fb83 | VF23Cloud-image      |
+--------------------------------------+----------------------+
[root@SeverMitaka01 ~(keystone_glance)]# swift list glance | grep c3f5bb3c-681b-41e9-aaa9-8ced70a8280a
c3f5bb3c-681b-41e9-aaa9-8ced70a8280a

Code itself :- :-
[root@SeverMitaka01 test(keystone_admin)]# cat upload.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

def get_nova_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['api_key'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['project_id'] = 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('/root/trusty-server-cloudimg-amd64-disk1.img') as fimage:
    glance.images.create(name="Ubuntu1404-image1", is_public=True, disk_format="qcow2",
                         container_format="bare", data=fimage)

Run :-

$python upload.py
$ [root@SeverMitaka01 ~(keystone_admin)]# . keystonerc_glance
[root@SeverMitaka01 ~(keystone_glance)]# glance image-list
+--------------------------------------+----------------------+
| ID                                   | Name                 |
+--------------------------------------+----------------------+
| 75e68a5e-5669-4c3f-8ed7-9ec6718cbc26 | CirrOS34-image       |
| bddfe258-9a6c-45f2-9e8e-dfe509a05b48 | ubuntu-trusty-x86_64 |
| c3f5bb3c-681b-41e9-aaa9-8ced70a8280a | Ubuntu1404-image1    |
| 291f6a39-b10b-4495-9e99-1233927ae8c5 | Ubuntu1510-image     |
| 91e11e67-9e76-4b2a-ac4b-27c5ce83fb83 | VF23Cloud-image      |
+--------------------------------------+----------------------+

System has swift set up as glance back end :-

[root@SeverMitaka01 ~(keystone_glance)]# glance image-list
+--------------------------------------+----------------------+
| ID                                   | Name                 |
+--------------------------------------+----------------------+
| 75e68a5e-5669-4c3f-8ed7-9ec6718cbc26 | CirrOS34-image       |
| bddfe258-9a6c-45f2-9e8e-dfe509a05b48 | ubuntu-trusty-x86_64 |
| c3f5bb3c-681b-41e9-aaa9-8ced70a8280a | Ubuntu1404-image1    |
| 291f6a39-b10b-4495-9e99-1233927ae8c5 | Ubuntu1510-image     |
| 91e11e67-9e76-4b2a-ac4b-27c5ce83fb83 | VF23Cloud-image      |
+--------------------------------------+----------------------+
[root@SeverMitaka01 ~(keystone_glance)]# swift list glance | grep c3f5bb3c-681b-41e9-aaa9-8ced70a8280a
c3f5bb3c-681b-41e9-aaa9-8ced70a8280a
<br>

image description

Code itself :-
[root@SeverMitaka01 test(keystone_admin)]# cat upload.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

def get_nova_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['api_key'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['project_id'] = 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('/root/trusty-server-cloudimg-amd64-disk1.img') as fimage:
    glance.images.create(name="Ubuntu1404-image1", is_public=True, disk_format="qcow2",
                         container_format="bare", data=fimage)

Run :-

$python upload.py
$ [root@SeverMitaka01 ~(keystone_admin)]# . keystonerc_glance
[root@SeverMitaka01 ~(keystone_glance)]# glance image-list
+--------------------------------------+----------------------+
| ID                                   | Name                 |
+--------------------------------------+----------------------+
| 75e68a5e-5669-4c3f-8ed7-9ec6718cbc26 | CirrOS34-image       |
| bddfe258-9a6c-45f2-9e8e-dfe509a05b48 | ubuntu-trusty-x86_64 |
| c3f5bb3c-681b-41e9-aaa9-8ced70a8280a | Ubuntu1404-image1    |
| 291f6a39-b10b-4495-9e99-1233927ae8c5 | Ubuntu1510-image     |
| 91e11e67-9e76-4b2a-ac4b-27c5ce83fb83 | VF23Cloud-image      |
+--------------------------------------+----------------------+

System has swift set up as glance back end :-

[root@SeverMitaka01 ~(keystone_glance)]# glance image-list
+--------------------------------------+----------------------+
| ID                                   | Name                 |
+--------------------------------------+----------------------+
| 75e68a5e-5669-4c3f-8ed7-9ec6718cbc26 | CirrOS34-image       |
| bddfe258-9a6c-45f2-9e8e-dfe509a05b48 | ubuntu-trusty-x86_64 |
| c3f5bb3c-681b-41e9-aaa9-8ced70a8280a | Ubuntu1404-image1    |
| 291f6a39-b10b-4495-9e99-1233927ae8c5 | Ubuntu1510-image     |
| 91e11e67-9e76-4b2a-ac4b-27c5ce83fb83 | VF23Cloud-image      |
+--------------------------------------+----------------------+
[root@SeverMitaka01 ~(keystone_glance)]# swift list glance | grep c3f5bb3c-681b-41e9-aaa9-8ced70a8280a
c3f5bb3c-681b-41e9-aaa9-8ced70a8280a
<br>

image description