rackspace/gophercloud — pull request #139 by benbp (2014-02-27 10:48:22+00:00)
Title: Fix null pointer error and FloatingIp struct tag.

CreateFloatingIp() can cause a null pointer exception if Nova returns an error, which can happen if there are no more floating ips, or if the floating ip pool specified does not exist. In this case, the response data looks like this:

{"itemNotFound": {"message": "NoMoreFloatingIps: Zero floating ips available.", "code": 404}}

As a result, the fip pointer gets dereferenced without having been initialized, because none of the struct tags match the JSON. This PR fixes that with a call to new(FloatingIp), and returns a zero-initialized struct plus an error when Nova returns an error.

This also fixes another struct tag: id is an int, not a string. Example response:

{"floating_ip": {"instance_id": null, "ip": "172.24.4.2", "fixed_ip": null, "id": 2, "pool": "public"}}