Corrections to Server createJson() for using keypairs with Rackspace #272
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In lib/OpenCloud/Compute/Resource/Server.php the keypair['publicKey'] check (line 641) was incorrectly failing. Keys returned by compute->listKeypairs() do not have a "publicKey" element, but rather "public_key". Correction on line 644 is just to make the print function output match reality as well.
Lines 647-650 incorrectly cause createJson() to add a "keypair" array to the "server" json payload that is sent to nova API to create a server. At least in Rackspace's deployment, this leads to a server being created but no key being placed on the new instance. Example (incorrect at least at Rackspace) json payload made by function as-is:
{"server":{"name":"jamesl1","imageRef":"857d7d36-34f3-409f-8435-693e8797be8b","flavorRef":"2","metadata":{"sdk":"OpenCloud/1.7.0 cURL/7.34.0 PHP/5.5.7-pl0-gentoo"},"networks":[{"uuid":"00000000-0000-0000-0000-000000000000"},{"uuid":"11111111-1111-1111-1111-111111111111"}],"keypair":{"key_name":"jamesl"}}}
The updated line 647 correctly adds "key_name" as a direct element of "server", causing createJson() to make a json payload that is both accepted by Rackspace's nova API and results in the key being placed on the instance. Example (correct at least at Rackspace) json payload made by modified line:
{"server":{"name":"jamesl1","imageRef":"857d7d36-34f3-409f-8435-693e8797be8b","flavorRef":"2","metadata":{"sdk":"OpenCloud/1.7.0 cURL/7.34.0 PHP/5.5.7-pl0-gentoo"},"networks":[{"uuid":"00000000-0000-0000-0000-000000000000"},{"uuid":"11111111-1111-1111-1111-111111111111"}],"key_name":"jamesl"}}
When performing the unit tests, I found that tests/OpenCloud/Tests/Compute/Resource/ServerTest.php also needed to be updated. It also had "publicKey" rather than "public_key" as the keypair key's attribute name. Corrected that and unit tests pass.
Changes to lib/OpenCloud/Common/Collection/PaginatedIterator.php that are included by github in this pull request were not from me.