Ask Your Question
0

glanceclient.exc.HTTPNotFound: The resource could not be found. (HTTP 404)

asked 2016-03-22 01:13:18 -0500

genie gravatar image

when add the smallest image for user demo , got error

[root@localhost martin(keystone_demo)]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from glanceclient import client
>>> token = '5fd4ad2d0a7b4699'
>>> endpoint = 'http://192.168.157.131:5000/v2.0'
>>> glance = client.Client(token=token, endpoint=endpoint)
>>> image = glance.images.create(name="demo1quick")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/glanceclient/v2/images.py", line 228, in create
    image = self.model()
  File "/usr/lib/python2.7/site-packages/glanceclient/common/utils.py", line 447, in _memoized_property
    setattr(self, attr_name, fn(self))
  File "/usr/lib/python2.7/site-packages/glanceclient/v2/images.py", line 41, in model
    schema = self.schema_client.get('image')
  File "/usr/lib/python2.7/site-packages/glanceclient/v2/schemas.py", line 125, in get
    _, raw_schema = self.http_client.get(uri)
  File "/usr/lib/python2.7/site-packages/glanceclient/common/http.py", line 280, in get
    return self._request('GET', url, **kwargs)
  File "/usr/lib/python2.7/site-packages/glanceclient/common/http.py", line 272, in _request
    resp, body_iter = self._handle_response(resp)
  File "/usr/lib/python2.7/site-packages/glanceclient/common/http.py", line 93, in _handle_response
    raise exc.from_response(resp, resp.content)
glanceclient.exc.HTTPNotFound: The resource could not be found. (HTTP 404)
>>> print image.status
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'image' is not defined


from glanceclient import client
token = '5fd4ad2d0a7b4699'
endpoint = 'http://192.168.157.131:5000/v2.0'
glance = client.Client(token=token, endpoint=endpoint)
image = glance.images.create(name="demo1quick")
print image.status
image.update(data=open('http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img', 'rb'))
print image.status
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2016-03-22 02:36:27 -0500

dbaxps gravatar image

updated 2016-03-22 02:52:47 -0500

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

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

edit flag offensive delete link more

Comments

IOError: [Errno 2] No such file or directory: 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img' after change to glance = glanceclient.Client('1',glance_endpoint, token=keystone.auth_token) with open('http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img') as fimage

genie gravatar imagegenie ( 2016-03-22 03:24:10 -0500 )edit

Read python code one more time. I believe you need improve your focus. Either you don't understand that local path and URL are different things.

dbaxps gravatar imagedbaxps ( 2016-03-22 03:41:08 -0500 )edit

i am new to python, how to open http link?

genie gravatar imagegenie ( 2016-03-22 03:50:48 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

2 followers

Stats

Asked: 2016-03-22 01:13:18 -0500

Seen: 763 times

Last updated: Mar 22 '16