Ask Your Question
0

unable to upload image using python-glanceclient

asked 2017-10-03 17:44:35 -0500

linuxuser26 gravatar image

updated 2017-10-03 17:46:26 -0500

I'm using Python API v2 and I'm unable to upload images to Glance.Here's the code snippet I'm using to upload images to Glance.

I'd appreciate any pointers.

from keystoneauth1 import loading
from keystoneauth1 import session
from glanceclient import Client

loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(
    auth_url="http://xx.yy.zz.aa:5000/v2.0/",
    username='admin',
    password='password',
    tenant_name='admin')
glance_session = session.Session(auth=auth)
glance = Client('2', session=glance_session)

for image in glance.images.list():  # This works
    print image

image = glance.images.create(name="my_image")
glance.images.upload(image.id, open('/tmp/image.qcow2', 'rb'))

It got stuck here:

-> image = glance.images.create(name="my_image")
(Pdb) p image.id
u'4944dc0f-35d2-4c81-8bf5-df0792abf9d5'
(Pdb) n
> /virtualenv/cfme_tests/scripts/glane_api.py(38)<module>()
-> glance.images.upload(image.id, open('/tmp/image.qcow2', 'rb'))
(Pdb) n
> /virtualenv/lib/python2.7/site-packages/glanceclient/v2/images.py(233)upload()
-> resp, body = self.http_client.put(url, headers=hdrs, data=body)
(Pdb) p url
u'/v2/images/4944dc0f-35d2-4c81-8bf5-df0792abf9d5/file'

When I interrupted from the keyboard, this was the backtrace:

 Pdb) n
Traceback (most recent call last):
  File "./scripts/glane_api.py", line 39, in <module>
    glance.images.upload(image.id, open('/tmp/image.qcow2', 'rb'))
  File "/virtualenv/lib/python2.7/site-packages/glanceclient/common/utils.py", line 545, in inner
    return RequestIdProxy(wrapped(*args, **kwargs))
  File "/virtualenv/lib/python2.7/site-packages/glanceclient/v2/images.py", line 231, in upload
    resp, body = self.http_client.put(url, headers=hdrs, data=body)
  File "/virtualenv/lib/python2.7/site-packages/keystoneauth1/adapter.py", line 232, in put
    return self.request(url, 'PUT', **kwargs)
  File "/virtualenv/lib/python2.7/site-packages/glanceclient/common/http.py", line 338, in request
    **kwargs)
  File "/virtualenv/lib/python2.7/site-packages/keystoneauth1/adapter.py", line 148, in request
    return self.session.request(url, method, **kwargs)
  File "/virtualenv/lib/python2.7/site-packages/positional/__init__.py", line 101, in inner
    return wrapped(*args, **kwargs)
  File "/virtualenv/lib/python2.7/site-packages/keystoneauth1/session.py", line 616, in request
    resp = send(**kwargs)
  File "/virtualenv/lib/python2.7/site-packages/keystoneauth1/session.py", line 674, in _send_request
    resp = self.session.request(method, url, **kwargs)
  File "/virtualenv/lib/python2.7/site-packages/requests/sessions.py", line 513, in request
    resp = self.send(prep, **send_kwargs)
  File "/virtualenv/lib/python2.7/site-packages/requests/sessions.py", line 623, in send
    r = adapter.send(request, **kwargs)
  File "/virtualenv/lib/python2.7/site-packages/requests/adapters.py", line 463, in send
    low_conn.send(i)
  File "/usr/lib64/python2.7/httplib.py", line 826, in send
    self.sock.sendall(data)
  File "/usr/lib64/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
KeyboardInterrupt
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-10-04 19:45:42 -0500

ericwong gravatar image

Hi,

I also hit the same and got 502 error (seen below). looks like this the example in https://docs.openstack.org/python-glanceclient/latest/reference/apiv2.html (https://docs.openstack.org/python-gla...) need update and adding extra fields works for me...

image = glance.images.create(name=IMAGE_NAME,container_format='bare',disk_format='qcow2')

Traceback (most recent call last): File "test-glance.py", line 40, in <module> glance.images.upload(image.id, open(IMAGE_FILE, 'rb')) File "/usr/local/lib/python2.7/dist-packages/glanceclient/common/utils.py", line 545, in inner return RequestIdProxy(wrapped(args, *kwargs)) File "/usr/local/lib/python2.7/dist-packages/glanceclient/v2/images.py", line 232, in upload resp, body = self.http_client.put(url, headers=hdrs, data=body) File "/usr/local/lib/python2.7/dist-packages/keystoneauth1/adapter.py", line 313, in put return self.request(url, 'PUT', **kwargs) File "/usr/local/lib/python2.7/dist-packages/glanceclient/common/http.py", line 349, in request return self._handle_response(resp) File "/usr/local/lib/python2.7/dist-packages/glanceclient/common/http.py", line 98, in _handle_response raise exc.from_response(resp, resp.content) glanceclient.exc.HTTPBadGateway: 502 Bad Gateway: Bad Gateway: The proxy server received an invalid: response from an upstream server.: Apache/2.4.18 (Ubuntu) Server at 10.99.162.38 Port 80 (HTTP 502)

edit flag offensive delete link more

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

Stats

Asked: 2017-10-03 17:44:35 -0500

Seen: 301 times

Last updated: Oct 03 '17