Code Monkey home page Code Monkey logo

hcloud-php's Introduction

PHP library for the Hetzner Cloud API by Exploriment

License Latest Stable Version Total Downloads

Installation: Composer

You can install this library via Composer. Run the following command:

composer require exploriment/hcloud-php

Documentation and examples

Full technical documentation can be found in DOCUMENTATION.md. The more user-friendly documentation can be found in the wiki.

HetznerCloud

<?php
use Exploriment\HetznerCloud;

/**
 * set your API token like this and you are ready to
 * make API calls using this library!
 */
HetznerCloud\HetznerCloud::setToken('my_token_here');

// retrieve the pricing object
$pricing = HetznerCloud\HetznerCloud::getPricing();

/**
 * retrieve the rate limit status, returns the following:
 * 
 * object(stdClass)#1 (3) {
 *    ["limit"]=>
 *    int(0)
 *    ["remaining"]=>
 *    int(0)
 *    ["reset"]=>
 *    int(1517655111)
 *  }
 * 
 * values of these will be `null` if no requests to the API were made
 */
$rateLimit = HetznerCloud\HetznerCloud::getRateLimit();

Prerequisites and dependencies

License

MIT

hcloud-php's People

Contributors

dyhli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hcloud-php's Issues

404 Not Found on isos

hi
I use your library and don't work isos.
I recieve 404 not found when call isos part.

Servers::create issue

I have tested the script and I found I little problem with it.
When I use the $creation = HetznerCloud\Servers::create($config); it returns an object with null members like in the example bellow :

object(Exploriment\HetznerCloud\Objects\ServerCreation)#105 (3) {
  ["action"]=>
  NULL
  ["server"]=>
  NULL
  ["root_password"]=>
  NULL
}

I saw that the response is returned after the command is given, and the action is still in progress. It should be modified to wait until the action is finished and send the response only after that. Otherwise I have to use after the creation the command to get the server details, but it`s not the best way in my opinion.

Request Console not implemented

I saw another useful server action available on Hetzner API name Request Console (https://docs.hetzner.cloud/#resources-server-actions-post-17), that I didn't find implemented in your code.

I added it on the Servers class like this :

/**
     * Request console
     *
     * @param $id
     * @return \Exploriment\HetznerCloud\ApiResponse
     * @throws \Exploriment\HetznerCloud\Exceptions\MalformedResponse
     * @throws \ReflectionException
     */
    public static function requestConsole($id)
    {
        $response = self::request('POST', $id.'/actions/request_console');

        return $response->getBody();
    }

Maybe you can implement it or something like this. Thank you!

Add Volume

is possible to update the package to add volume actions ?

Servers::changeDnsPtr

I saw that the method changeDnsPtr from the Servers class is not implemented correctly, or the Hetzner API has changed from the time you implemented it. It should accept as body parameters ip and dns_ptr.
I have changed the method to :

/**
     * Changes the hostname that will appear when getting the hostname belonging to the primary IPs (ipv4 and ipv6)
     * of this server.
     * Floating IPs assigned to the server are not affected by this.
     * @see https://docs.hetzner.cloud/#resources-server-actions-post-15
     *
     * @param int $id
     * @param string $ipv4
     * @param null|string $dns_ptr
     * @return Action
     * @throws Exceptions\MalformedResponse
     * @throws \Exception
     * @throws \ReflectionException
     */
    public static function changeDnsPtr($id, $ipv4, $dns_ptr = null)
    {
        return self::action($id, 'change_dns_ptr', [
            'ip' => $ipv4,
            'dns_ptr' => $dns_ptr
        ]);
    }

and in that way it works.

Servers::rebuild not returning new password

I have tested the Servers::rebuild method and the response of it is an Action object that has no root password and don't allow getRootPassword() method.

The public static function rebuild($id, $image) method from the final class Servers uses the trait Actionable action() method that returns only new Action($response->action), but the new root password is in $response->root_password.

Thank you!

Invalid input: root must be an object

I tried to implement the reboot and shutdown method from HetznerCloud\Servers but I keep getting the error : exception 'Exploriment\HetznerCloud\Exceptions\ApiInvalidInput' with message 'invalid input: root must be an object' in /home/hvbeta/public_html/modules/addons/hv_hetzner/vendor/exploriment/hcloud-php/src/Http.php:123
I tried to check the input of the request method from Http class and it looks ok :

string(6) "597685" string(31) "servers/597685/actions/shutdown" 
array(0) { } 
array(0) { } 

I also tried the API from Hetzner directly with curl and it works, so the problem must be somewhere at the method that sends the request, but I cannot figure out where.

Problem with tightenco/collect

Hi there!

Thanks for making this awesome package!

I have a small problem with installing this package in my project.

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - exploriment/hcloud-php v1.1.0 requires tightenco/collect v5.4.33 -> satisfiable by tightenco/collect[v5.4.33].
    - exploriment/hcloud-php v1.1.1 requires tightenco/collect v5.4.33 -> satisfiable by tightenco/collect[v5.4.33].
    - exploriment/hcloud-php v1.1.2 requires tightenco/collect v5.4.33 -> satisfiable by tightenco/collect[v5.4.33].
    - Conclusion: don't install tightenco/collect v5.4.33
    - Installation request for exploriment/hcloud-php ^1.1 -> satisfiable by exploriment/hcloud-php[v1.1.0, v1.1.1, v1.1.2].


Installation failed, reverting ./composer.json to its original content.

Composer spews error's all over the place for me at this moment. Is it a idea to pin tightenco/collect on version 5.6.* in composer.json?

Or will this pose other issues?

Thanks in advance,
Ramon

Cannot reset password because guest agent is unavailable

I use automatting scripts to create and setup Debian 10 server unattended. After creating a server, the script connect with SSH and the user is requested to set a new password. But my script needs to execute shell commands directly after the login - so the password change request is disturbing.

A workaround is to reset the server password, because when doing this manually, the password change prompt won't appear when logging in with the generated password, and it's possible to access the shell directly. But this seems to work manually with the Cloud API web interface only:

When I want to execute the Servers::resetPassword method, I get an error for a new created up and running server:

Code: guest_agent_unavailable
Message: Cannot reset password because guest agent is unavailable

Now I don't know if this is a server image misconfiguration, or I need to wait until the guest agent is available, or how I can determine from a script (maybe using the Could API?) when/if the guest agent is available? Or is there a solution to change the initial password from a PHP script using ssh2 without the need to use Servers::resetPassword? Fact is, I never logged in to the server and I never uninstalled the guest agent.

I use the server image 5924233, server type 9 and data center 4.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.