3

I'm trying to write a bit of code to inventory our OpenStack deployment, and I've run into an issue where serverList() only ever returns 100 results instead of the 600+ I'm expecting. I've reviewed the documentation and a bit of the source, and as far as I can tell there's no reason that this should be happening as the PaginatedIterator should be doing its pagination transparently.

There are no errors or warning either generated in my code, or logged on my controller [that I can find]. I am using php-opencloud v1.12 via composer.

use OpenCloud\OpenStack;
$client = new OpenStack('http://1.2.3.4:5000/v2.0/', array(
    'username'  => 'admin',
    'password'  => 'hunter2',
    'tenantName'=> 'admin',
));
$service = $client->computeService('nova', 'RegionOne');

$stmt = $dbh->prepare('INSERT INTO servers VALUES (?,?)');
/* foreach($service->serverList() as $server) {
    $stmt->execute([$server->id, $server->name]);
} // neither method works */
$list = $service->serverList();
while( $list->valid() ) {
    $server = $list->current();
    $stmt->execute([$server->id, $server->name]);
    $list->next();
}
echo "\n";
var_dump($dbh->query('SELECT * FROM servers')->fetchAll(PDO::FETCH_ASSOC));
4

1 回答 1

1

The default limit for pagination is 100. It is possible to override this with a higher limit like so:

$list = $service->serverList(null, array('limit' => 700));
于 2015-02-24T23:23:30.990 回答