Scalr\Service\OpenStack\Services\Network\V2\NetworkApi::addRouterInterface PHP Метод

addRouterInterface() публичный Метод

This operation attaches a subnet to an internal router interface. Either a subnet identifier or a port identifier must be passed in the request body. If both are specified, a 400 Bad Request error is returned. When the subnet_id attribute is specified in the request body, the subnet's gateway ip address is used to create the router interface; otherwise, if port_id is specified, the IP address associated with the port is used for creating the router interface. It is worth remarking that a 400 Bad Request error is returned if several IP addresses are associated with the specified port, or if no IP address is associated with the port; also a 409 Conflict is returned if the port is already used.
public addRouterInterface ( string $routerId, string $subnetId = null, string $portId = null ) : object
$routerId string The ID of the router
$subnetId string optional The identifier of the subnet
$portId string optional The identifier of the port
Результат object Returns both port and subnet identifiers as object's properties
    public function addRouterInterface($routerId, $subnetId = null, $portId = null)
    {
        $result = null;
        $options = array();
        if (!empty($subnetId)) {
            $options['subnet_id'] = $this->escape($subnetId);
        }
        if (!empty($portId)) {
            $options['port_id'] = $this->escape($portId);
        }
        if (empty($options) || isset($options['port_id']) && isset($options['subnet_id'])) {
            throw new \InvalidArgumentException(sprintf('Either a subnet identifier or a port identifier must be passed in the method.'));
        }
        $response = $this->getClient()->call($this->service, sprintf('/routers/%s/add_router_interface', $this->escape($routerId)), array('_putData' => json_encode($options)), 'PUT');
        if ($response->hasError() === false) {
            $result = json_decode($response->getContent());
        }
        return $result;
    }