hnhdigital-os/php-linode-api

View on GitHub
src/endpoints/Nodebalancers/Config.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace HnhDigital\LinodeApi\Nodebalancers;

/*
 * This file is part of the PHP Linode API.
 *
 * (c) H&H|Digital <hello@hnh.digital>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use HnhDigital\LinodeApi\Foundation\Base;

/**
 * This is the Config class.
 *
 * This file is automatically generated.
 *
 * @link https://developers.linode.com/api/v4#tag/Nodebalancers-Configs
 *
 * @author Rocco Howard <rocco@hnh.digital>
 */
class Config extends Base
{
    /**
     * Endpoint.
     *
     * @var string
     */
    protected $endpoint = 'nodebalancers/%s/configs/%s';

    /**
     * Node Balancer Id.
     *
     * @var int
     */
    protected $node_balancer_id;

    /**
     * This model is fillable.
     *
     * @var bool
     */
    protected $fillable = true;

    /**
     * This model's method that provides the data to fill it.
     *
     * @var string
     */
    protected $fill_method = 'get';

    /**
     * Constructor.
     *
     * @return void
     */
    public function __construct($node_balancer_id, $fill = [])
    {
        $this->node_balancer_id = $node_balancer_id;
        parent::__construct($node_balancer_id, $fill);
    }

    /**
     * Returns configuration information for a single port of this NodeBalancer.
     *
     * @link https://developers.linode.com/api/v4#operation/getNodeBalancerConfig
     *
     * @return array
     */
    public function get($config_id)
    {
        return $this->apiCall('get', '', [], ['auto-fill' => true]);
    }

    /**
     * Returns a paginated list of NodeBalancer nodes associated with this Config. These are the backends that will be sent
     * traffic for this port.
     *
     * @link https://developers.linode.com/api/v4#operation/getNodeBalancerConfigNodes
     *
     * @return array
     */
    public function getNodeBalancerConfigNodes($config_id)
    {
        return $this->apiSearch($this->endpoint.'/nodes', ['class' => 'Node\Balancer\Config\Node', 'parameters' => ['id']]);
    }

    /**
     * Updates the configuration for a single port on a NodeBalancer.
     *
     * @param int $node_balancer_id The ID of the NodeBalancer to access.
     * @param int $config_id        The ID of the config to access.
     *
     * @link https://developers.linode.com/api/v4#operation/updateNodeBalancerConfig
     *
     * @return void
     */
    public function update($config_id, $optional = [])
    {
        return $this->apiCall('put', '', ['json' => $this->getDirty($optional)]);
    }

    /**
     * Creates a NodeBalancer Node, a backend that can accept traffic for this NodeBalancer Config. Nodes are routed requests
     * on the configured port based on their status.
     *
     * @param int   $node_balancer_id The ID of the NodeBalancer to access.
     * @param array $optional
     *                                - [config_id=null] (integer) The NodeBalancer Config ID that this Node
     *                                belongs to.
     *                                - [id=null] (integer) This node's unique ID.
     *                                - [address=null] (string) The private IP Address where this backend can be
     *                                reached. This _must_ be a private IP address.
     *                                - [label=null] (string) The label for this node. This is for display
     *                                purposes only.
     *                                - [status=null] (string) The current status of this node, based on the
     *                                configured checks of its NodeBalancer Config.
     *                                - [weight=null] (integer) Used when picking a backend to serve a request
     *                                and is not pinned to a single backend yet. Nodes
     *                                with a higher weight will receive more traffic.
     *                                - [mode=null] (string) The mode this NodeBalancer should use when
     *                                sending traffic to this backend.
     *                                If set to `accept` this backend is accepting
     *                                traffic.
     *                                If set to `reject` this backend will not
     *                                receive traffic.
     *                                If set to `drain` this backend will not receive
     *                                _new_ traffic, but connections already pinned to
     *                                it will continue to be routed to it.
     *                                - [nodebalancer_id=null] (integer) The NodeBalancer ID that this Node belongs to.
     *
     * @link https://developers.linode.com/api/v4#operation/createNodeBalancerNode
     *
     * @return mixed
     */
    public function createNodeBalancerNode($optional = [])
    {
        return $this->apiCall('post', '/nodes', ['json' => array_merge([
            'node_balancer_id' => $node_balancer_id,
        ], $optional)]);
    }

    /**
     * Deletes the Config for a port of this NodeBalancer.
     *
     * This cannot be undone.
     *
     * Once completed, this NodeBalancer will no longer respond to requests on the given port. This also deletes all associated
     * NodeBalancerNodes, but the Linodes they were routing traffic to will be unchanged and will not be removed.
     *
     * @param int $node_balancer_id The ID of the NodeBalancer to access.
     * @param int $config_id        The ID of the config to access.
     *
     * @link https://developers.linode.com/api/v4#operation/deleteNodeBalancerConfig
     *
     * @return void
     */
    public function delete()
    {
        return $this->apiCall('delete', '');
    }
}