Code Monkey home page Code Monkey logo

Comments (6)

mikebarkmin avatar mikebarkmin commented on May 26, 2024 1

For future readers: I ended up doing this

def exists_remote(host, path):
    """Test if a file exists at path on a host accessible with SSH."""
    status = subprocess.call(["ssh", host, "test -f {}".format(pipes.quote(path))])
    if status == 0:
        return True
    if status == 1:
        return False
    raise Exception("SSH failed")

while not exists_remote(f"root@{ip}", "/var/lib/cloud/instance/boot-finished"):
    print(".")
    time.sleep(5)

from hcloud-python.

Optiligence avatar Optiligence commented on May 26, 2024

i use this, although you probably rather want to test if you can actually already connect
or let the instance itself signal that it’s ready

for retries in range(10):
    if instance.status == instance.STATUS_RUNNING:
        break
    time.sleep(10)
    instance = instance.update()
assert instance.status == instance.STATUS_RUNNING

from hcloud-python.

LKaemmerling avatar LKaemmerling commented on May 26, 2024

There is no way how we can determine if the server is ready (boot finished), as we don't have access to the server itself. I would recommend looking for /var/lib/cloud/instance/boot-finished on the server.

from hcloud-python.

rvencu avatar rvencu commented on May 26, 2024

Hi @mikebarkmin can you provide an example of how do you get the ip of the server after creating it? It seems you already done that and I cannot find this info on the docs...

from hcloud-python.

mikebarkmin avatar mikebarkmin commented on May 26, 2024

Hi. You can get the IP when you create a new server (see the response sample here https://docs.hetzner.cloud/#servers-create-a-server). Here is how I used it.

def up(server_type="cx11"):
    client = Client(token=os.getenv("HCLOUD_API_TOKEN"))

    with open("cloud-config.yml", "r") as user_data:
        response: CreateServerResponse = client.servers.create(
            name="load-testing",
            server_type=ServerType(name=server_type),
            image=Image(name="ubuntu-20.04"),
            ssh_keys=client.ssh_keys.get_all(),
            user_data=user_data.read()
        )
        server: BoundServer = response.server
        return server.public_net.ipv4.ip

I describe it in a tutorial on how to use the hetzner sdk for setting up a load testing environment. https://dev.to/mikebarkmin/spin-up-real-infrastructure-for-load-testing-with-locust-on-hetznercloud-35oa

from hcloud-python.

rvencu avatar rvencu commented on May 26, 2024

Thanks a lot, did not find the tutorial before.

from hcloud-python.

Related Issues (20)

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.