Code Monkey home page Code Monkey logo

cli's Introduction

hcloud: Command-line interface for Hetzner Cloud

Build status

hcloud is a command-line interface for interacting with Hetzner Cloud.

asciicast

Installation

You can download pre-built binaries for Linux, FreeBSD, macOS, and Windows on the releases page.

On macOS, you can install hcloud via Homebrew:

brew install hcloud

Third-party packages

There are unofficial packages maintained by third-party users. Please note that these packages aren’t supported nor maintained by Hetzner Cloud and may not always be up-to-date. Downloading the binary or building from source is still the recommended install method.

Operating System Command
Debian (>= bullseye) apt install hcloud-cli
Ubuntu (>= 19.04) apt install hcloud-cli
Arch Linux pacman -Syu hcloud
Void Linux xbps-install -Syu hcloud
Gentoo Linux emerge hcloud

Build manually

If you have Go installed, you can build and install the hcloud program with:

go get -u github.com/hetznercloud/cli/cmd/hcloud

Getting Started

  1. Visit the Hetzner Cloud Console at console.hetzner.cloud, select your project, and create a new API token.

  2. Configure the hcloud program to use your token:

    hcloud context create my-project
    
  3. You’re ready to use the program. For example, to get a list of available server types, run:

    hcloud server-type list
    

See hcloud help for a list of commands.

Shell Completion

To enable shell completion, run one of the following commands (or better, add it to your .bashrc or .zshrc):

$ source <(hcloud completion bash)   # bash
$ source <(hcloud completion zsh)    # zsh

If you are using antigen with zsh and completion doesn't work with the above try adding

function _hcloud_completion {
  source <(hcloud completion zsh)    # zsh  
}
compctl -K _hcloud_completion hcloud

instead.

Output configuration

You can control output via the -o option:

  • For list commands, you can specify -o noheader to omit the table header.

  • For list commands, you can specify -o columns=id,name to only show certain columns in the table.

  • For describe commands, you can specify -o json to get a JSON representation of the resource. The schema is identical to those in the Hetzner Cloud API which are documented at docs.hetzner.cloud.

  • For describe commands, you can specify -o format={{.ID}} to format output according to the given Go template. The template’s input is the resource’s corresponding struct in the hcloud-go library.

Configure hcloud using environment variables

You can use the following environment variables to configure hcloud:

  • HCLOUD_TOKEN
  • HCLOUD_CONTEXT
  • HCLOUD_CONFIG

When using hcloud in scripts, for example, it may be cumbersome to work with contexts. Instead of creating a context, you can set the token via the HCLOUD_TOKEN environment variable. When combined with tools like direnv, you can configure a per-directory context by setting HCLOUD_CONTEXT=my-context via .envrc.

Examples

List all servers

$ hcloud server list            
ID       NAME                    STATUS    IPV4
210216   test1                   running   78.46.122.12
210729   ubuntu-8gb-nbg1-dc3-1   running   94.130.177.158

Create a server

$ hcloud server create --name test --image debian-9 --type cx11 --ssh-key demo
   7s [====================================================================] 100%
Server 325211 created

License

MIT license

cli's People

Contributors

arete avatar artheus avatar climann avatar eike-fokken avatar fhofherr avatar jawher avatar joto avatar lkaemmerling avatar lnjx avatar minus7 avatar nikolak avatar patrickschaffrath avatar phil-davis avatar philippgille avatar renovate[bot] avatar thcyron avatar thetechnick avatar uskudnik avatar

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.