php-opencloud / openstack

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

$compute->getServer return null values #386

Closed mshannaq closed 5 months ago

mshannaq commented 5 months ago

If I want to know specific data about the server for example status or addresses I got null values.

I use the code:

use OpenStack\OpenStack;

//.....
/.....

$authUrl = 'https://URL:5000/v3';
$projectId = 'validprojectidhere';
$username = 'validusername';
$password = 'validpassword';
$region = 'validregion';

$openstack = new OpenStack([
    'authUrl' => $authUrl,
    'domain' => ['id' => "default"],
    "identity" => [
        "methods" => "password",
    ],
    'region' => $region,
    'user' => [
        'name' => $username,
        'password' => $password,
        'domain' => ['id' => "default"],
    ],
    'scope' => [
        'project' => ['id' => $projectId],
    ],
]);

//get server info
 $compute = $openstack->computeV2();
 $server = $compute->getServer(['id' => 'valid-server-id-here']);
 dd($server);

the returned values as null as of:

 #resourceKey: "server"
..... text here
.... text here
+id: "d1baf6a6-1d5b-477e-846f-3dad86c9d2d7"
  +ipv4: null 
  +ipv6: null
  +addresses: null
  +created: null
  +updated: null
  +flavor: null
  +hostId: null
  +hypervisorHostname: null
  +image: null
  +links: null
  +metadata: null
  +name: null
  +progress: null
  +status: null
  +tenantId: null
  +userId: null
  +adminPass: null
  +taskState: null
  +powerState: null
  +vmState: null
  +fault: null
  +keyName: null

image

any body know why they return null even status: null while the server is running okay

when I run the OpenStack CLI openstack server show d1baf6a6-server-id-here

it run okay and give me valid values like

| addresses                           | MN-Network=10.10.10.162, XX.XX.XX.XX                                                                                                                                                                                      |
| ramdisk_id                          | None                                                                                                                                                                                             |
| reservation_id                      | None                                                                                                                                                                                             |
| root_device_name                    | None                                                                                                                                                                                             |
| scheduler_hints                     | None                                                                                                                                                                                             |
| security_groups                     | name='Cpanel-Shared-Server'                                                                                                                                                                      |
| server_groups                       | []                                                                                                                                                                                               |
| status                              | ACTIVE      
| is_locked                           | False 

if I run $servers = $compute->listServers(); i get a list of server okay but the servers data still null as above

Thanks alot.

k0ka commented 5 months ago

See https://php-openstack-sdk.readthedocs.io/en/latest/services/compute/v2/servers.html#retrieve-a-server

getServer just creates a resource, without retrieving it in case you want to manage it somehow - like delete. you should call $server->retrieve(); to fetch information about the server from API.

mshannaq commented 5 months ago

See https://php-openstack-sdk.readthedocs.io/en/latest/services/compute/v2/servers.html#retrieve-a-server

getServer just creates a resource, without retrieving it in case you want to manage it somehow - like delete. you should call $server->retrieve(); to fetch information about the server from API.

@k0ka now $server->retrieve(); return null

 $compute = $openstack->computeV2();
$server = $compute->getServer(['id' => 'd1baf6a6-1d5b-477e-846f-3dad86c9d2d7'])->retrieve();
dd($server);
k0ka commented 5 months ago
$compute = $openstack->computeV2();
$server = $compute->getServer(['id' => 'd1baf6a6-1d5b-477e-846f-3dad86c9d2d7']);
$server->retrieve();
dd($server);