php-opencloud / openstack

PHP SDK for OpenStack clouds
Apache License 2.0
222 stars 152 forks source link

[Question, potentially a bug] How to debug requests when creating a server #403

Closed BelleNottelling closed 4 months ago

BelleNottelling commented 4 months ago

Hi there, I'd appreciate some assistance on the following error that's produced by the SDK:

[09-Feb-2024 07:13:20 UTC] HTTP Error
~~~~~~~~~~
The remote server returned a "400 Bad Request" error for the following transaction:

Request
~~~~~~~
POST /compute/v2.1/servers HTTP/1.1
User-Agent: GuzzleHttp/7
Content-Type: application/json
Host: something

Response
~~~~~~~~
HTTP/1.1 400 Bad Request
Date: Fri, 09 Feb 2024 07:13:20 GMT
Server: Apache/2.4.52 (Ubuntu)
OpenStack-API-Version: compute 2.1
X-OpenStack-Nova-API-Version: 2.1
Vary: OpenStack-API-Version,X-OpenStack-Nova-API-Version
Content-Type: application/json; charset=UTF-8
Content-Length: 137
x-openstack-request-id: something
x-compute-request-id: something else
Connection: close

Further information
~~~~~~~~~~~~~~~~~~~
Please ensure that your input values are valid and well-formed. Visit http://docs.php-opencloud.com/en/latest/http-codes for more information about debugging HTTP status codes, or file a support issue on https://github.com/php-opencloud/openstack/issues.

This error is produced with code as follows:

// Creates a new user on the OpenStack server and then establishes a new OpenStack connection instance using the new user's credentials.
$OpenStack = $this->authenticateAsClient();

// Now create a new network for the server to be attached to
$network = $OpenStack->networkingV2()->createNetwork([
    'name'         => "Some name",
    'adminStateUp' => true,
]);

// Finally create the server
$server = $OpenStack->computeV2()->createServer([
    'name'     => "Some name",
    'imageId'  => "The image ID",
    'flavorId' => "The flavor ID",
    'networks'  => [
        ['uuid' => $network->id]
    ],
]);

I am fairly new to OpenStack and I am working on a project with it, so I apologize if there's something I am blaitantly doing wrong here, but the logged message isn't particularly clear on what the problem is & searching "debug" on the docs returns no results.

Thanks!

k0ka commented 4 months ago

Hello,

1) you can get full request/response by passing additional options to the Openstack object. Like we do for debugging integration tests:

$options = [
    'debugLog'         => true,
    'logger'           => new \OpenStack\Sample\DefaultLogger(),
    'messageFormatter' => new \GuzzleHttp\MessageFormatter(\GuzzleHttp\MessageFormatter::DEBUG),
    // .. auth options ...
];
$openstack = new OpenStack($options);

2) You can find official API documentation for this endpoint at https://docs.openstack.org/api-ref/compute/#create-server

k0ka commented 4 months ago

What php memory limit do you have? It should output the full request/response body in the error by default: https://github.com/php-opencloud/openstack/blob/d823be3079c4772b2ddf16ff2d013f285113eb59/src/Common/Error/Builder.php#L99

k0ka commented 4 months ago

released in https://github.com/php-opencloud/openstack/releases/tag/v3.9.0