Ask Your Question
2

Deleting Network with Python httplib2 doesn't work?

asked 2014-07-17 03:53:29 -0500

Huaming gravatar image

updated 2014-07-17 16:07:58 -0500

smaffulli gravatar image

I am trying to delete a network with python scripts which uses httplib2:

import httplib2
h=httplib2.Http()
resp = h.request('https://x.x.x.x/v2.0/networks/xxxxxxxx','DELETE',{},{'Content-Type':'application/json','X-Auth-Token':'xxxxxxx'})

While I got response like : ({'date': 'Thu, 17 Jul 2014 06:47:42 GMT', 'status': '500', 'content-length': '88', 'content-type': 'application/json; charset=UTF-8'}, '{"NeutronError": "Request Failed: internal server error while processing your request."}')

When I use java with the same Neutron API and token, it works fine. Anybody can help me to explain this issue?

Many thanks in advance.

edit retag flag offensive close merge delete

Comments

Any idea, folks?

Huaming gravatar imageHuaming ( 2014-07-20 22:50:24 -0500 )edit
1

I don't know whether ,{}, is the right way to send the body empty? Did you try {''} perhaps?

annegentle gravatar imageannegentle ( 2014-10-10 13:28:09 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-10-10 21:05:45 -0500

larsks gravatar image

updated 2014-10-10 21:42:15 -0500

I took a brief look at this. I started by creating a network:

neutron net-create testnet
Created a new network:
+----------------+--------------------------------------+
| Field          | Value                                |
+----------------+--------------------------------------+
| admin_state_up | True                                 |
| id             | 1c49fd1b-042e-40cb-8c94-e09c0fac941a |
| name           | testnet                              |
| shared         | False                                |
| status         | ACTIVE                               |
| subnets        |                                      |
| tenant_id      | 95d9bbd9b446438a89a353d8adb60704     |
+----------------+--------------------------------------+

The documentation for httplib2 says that the Http.request method looks like this:

request(self, uri, method='GET', body=None, headers=None,
        redirections=5, connection_type=None)

Which means I can get information about that network like this:

>>> import httplib2
>>> h = httplib2.Http()
>>> response = h.request('http://localhost:9696/v2.0/networks/1c49fd1b-042e-40cb-8c94-e09c0fac941a',
... headers={'x-auth-token': os.environ['TOKEN']})
>>> import pprint
>>> pprint.pprint(response)
({'content-length': '229',
  'content-location': 'http://localhost:9696/v2.0/networks/1c49fd1b-042e-40cb-8c94-e09c0fac941a',
  'content-type': 'application/json; charset=UTF-8',
  'date': 'Sat, 11 Oct 2014 02:03:21 GMT',
  'status': '200',
  'x-openstack-request-id': 'req-7f52669b-9efb-4587-83ff-20b9312ea757'},
 '{"network": {"status": "ACTIVE", "subnets": [], "name": "testnet", "router:external": false, "tenant_id": "95d9bbd9b446438a89a353d8adb60704", "admin_state_up": true, "shared": false, "id": "1c49fd1b-042e-40cb-8c94-e09c0fac941a"}}')

And I can delete the network like this:

>>> response = h.request('http://localhost:9696/v2.0/networks/1c49fd1b-042e-40cb-8c94-e09c0fac941a',
... headers={'x-auth-token': os.environ['TOKEN']}, method='DELETE')
>>> pprint.pprint(response)
({'content-length': '0',
  'date': 'Sat, 11 Oct 2014 02:04:41 GMT',
  'status': '204',
  'x-openstack-request-id': 'req-86a3d684-ba40-4519-9cf9-adc93849e507'},
 '')

So that request was successful. I can verify that from the command line that testnet no longer exists:

$ neutron net-list
+--------------------------------------+----------+--------------------------------------------------+
| id                                   | name     | subnets                                          |
+--------------------------------------+----------+--------------------------------------------------+
| 028d70dd-67b8-4901-8bdd-0c62b06cce2d | ext-nat  | 0918b173-9280-4f63-91e0-1df626830f4b             |
| 18fc1b31-9b2c-4b6e-8dea-7e04bfd1eb43 | net0     | 55c6da11-cfbe-4443-bb5f-19c4d0ea041a 10.0.0.0/24 |
+--------------------------------------+----------+--------------------------------------------------+
edit flag offensive delete link more
0

answered 2014-10-27 01:10:20 -0500

Huaming gravatar image

Many thanks folks, I followed your ideas and made it go away. The problem is about body {} which isn't treated as None in httplib2.

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

[hide preview]

Get to know Ask OpenStack

Resources for moderators

Question Tools

Stats

Asked: 2014-07-17 03:53:29 -0500

Seen: 236 times

Last updated: Oct 27 '14