Scalr\Service\OpenStack\Services\Network\V2\NetworkApi::listRouters PHP Method

listRouters() public method

This operation returns a list of routers to which the tenant has access. Default policy settings return only those routers that are owned by the tenant who submits the request, unless the request is submitted by an user with administrative rights. Users can control which attributes should be returned by using the fields query parameter. Additionally, results can be filtered by using query string parameters.
public listRouters ( string $routerId = null, Scalr\Service\OpenStack\Services\Network\Type\ListRoutersFilter $filter = null, array $fields = null ) : Scalr\Service\OpenStack\Type\DefaultPaginationList | object
$routerId string optional The ID of the router to show detailed info
$filter Scalr\Service\OpenStack\Services\Network\Type\ListRoutersFilter optional The filter options. Filter doesn't apply to detailed info
$fields array optional The list of the fields to show
return Scalr\Service\OpenStack\Type\DefaultPaginationList | object Returns the list of the router or the information about one router
    public function listRouters($routerId = null, ListRoutersFilter $filter = null, array $fields = null)
    {
        $result = null;
        $detailed = $routerId !== null ? sprintf("/%s", $this->escape($routerId)) : '';
        if (!empty($fields)) {
            $acceptedFields = array('status', 'name', 'admin_state_up', 'id', 'tenant_id', 'external_gateway_info', 'admin_state_up');
            $fields = join('&fields=', array_map("rawurlencode", array_intersect(array_values($fields), $acceptedFields)));
        }
        $querystr = ($filter !== null && $detailed == '' ? $filter->getQueryString() : '') . ($fields ? '&fields=' . $fields : '');
        $querystr = !empty($querystr) ? '?' . ltrim($querystr, '&') : '';
        $response = $this->getClient()->call($this->service, '/routers' . $detailed . $querystr);
        if ($response->hasError() === false) {
            $result = json_decode($response->getContent());
            if (empty($detailed)) {
                $result = new DefaultPaginationList($this->service, 'routers', $result->routers, isset($result->routers_links) ? $result->routers_links : null);
            } else {
                $result = $result->router;
            }
        }
        return $result;
    }