Scalr\Modules\Platforms\Ec2\Helpers\EipHelper::associateIpAddress PHP Method

associateIpAddress() private static method

Associates IP Address to the server
private static associateIpAddress ( DBServer $dbServer, string $ipAddress, $allocationId = null )
$dbServer DBServer DBServer object
$ipAddress string Public IP address to associate with server.
    private static function associateIpAddress(DBServer $dbServer, $ipAddress, $allocationId = null)
    {
        $aws = $dbServer->GetEnvironmentObject()->aws($dbServer);
        $assign_retries = 1;
        $retval = false;
        while (true) {
            try {
                // Associate elastic ip address with instance
                $request = new AssociateAddressRequestData($dbServer->GetProperty(\EC2_SERVER_PROPERTIES::INSTANCE_ID), $ipAddress);
                if ($allocationId) {
                    $request->allocationId = $allocationId;
                    $request->publicIp = null;
                    $request->allowReassociation = true;
                }
                $aws->ec2->address->associate($request);
                $retval = true;
                break;
            } catch (Exception $e) {
                if (!stristr($e->getMessage(), "does not belong to you") || $assign_retries == 3) {
                    throw new Exception($e->getMessage());
                } else {
                    // Waiting...
                    \Scalr::getContainer()->logger(__CLASS__)->debug(_("Waiting 2 seconds..."));
                    sleep(2);
                    $assign_retries++;
                    continue;
                }
            }
            break;
        }
        return $retval;
    }