Skip to content

FloatingIps::create

Danny Li edited this page Feb 4, 2018 · 1 revision

Parameters

Parameter Type Description
$config Configs\FloatingIp Floating IP configuration

Returns

FloatingIp object

Example

<?php
use Exploriment\HetznerCloud;

$ip = HetznerCloud\FloatingIps::create($config);

echo $ip->getIp();

FloatingIp configuration object

Creating a new floating IP requires the Configs\FloatingIp config object, an example below:

<?php
use Exploriment\HetznerCloud;

/**
 * new floating IP configuration
 *
 * You may also set the type immediately like so:
 * $config = new HetznerCloud\Configs\FloatingIp('ipv4');
 */
$config = new HetznerCloud\Configs\FloatingIp();

// set the type of the floating IP. ipv4/ipv6 (required)
$config->setType('ipv4');

/**
 * set the home location of the floating IP (semi-required)
 * either server or home_location must be provided
 *
 * $location can be either the location ID, location name or the Location object
 * @see https://github.com/Exploriment/hcloud-php/wiki/resources:-locations#location-object
 */
$config->setHomeLocation($location);

/**
 * assign the floating IP to a server (semi-required)
 * either server or home_location must be provided
 *
 * $server can be either the server ID or the Server object
 * @see https://github.com/Exploriment/hcloud-php/wiki/resources:-servers#server-object
 */
$config->setServer($server);

// give the floating IP a description (optional)
$config->setDescription('My amazing floating IP');

/**
 * Your configuration for the floating IP is now ready.
 */
Clone this wiki locally