简体   繁体   中英

serverList() only returns 100 results

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));

分页的默认限制为100.可以使用更高的限制覆盖此限制,如下所示:

$list = $service->serverList(null, array('limit' => 700));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM