diff options
author | Scott Moser <smoser@ubuntu.com> | 2018-03-19 14:50:54 -0400 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2018-03-19 14:50:54 -0400 |
commit | e88e35483e373b39b4485f30f7a867f50571027c (patch) | |
tree | 9acb68fc91dc94e2f6fd66d741ff6f75f4abe830 /cloudinit/sources/helpers/hetzner.py | |
parent | de34dc7c467b318b2d04d065f8d752c7a530e155 (diff) | |
download | vyos-cloud-init-e88e35483e373b39b4485f30f7a867f50571027c.tar.gz vyos-cloud-init-e88e35483e373b39b4485f30f7a867f50571027c.zip |
Add Hetzner Cloud DataSource
The Hetzner Cloud metadata service is an AWS-style service available
over HTTP via the link local address 169.254.169.254.
https://hetzner.com/cloud
https://docs.hetzner.cloud/
Diffstat (limited to 'cloudinit/sources/helpers/hetzner.py')
-rw-r--r-- | cloudinit/sources/helpers/hetzner.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cloudinit/sources/helpers/hetzner.py b/cloudinit/sources/helpers/hetzner.py new file mode 100644 index 00000000..2554530d --- /dev/null +++ b/cloudinit/sources/helpers/hetzner.py @@ -0,0 +1,26 @@ +# Author: Jonas Keidel <jonas.keidel@hetzner.com> +# Author: Markus Schade <markus.schade@hetzner.com> +# +# This file is part of cloud-init. See LICENSE file for license information. + +from cloudinit import log as logging +from cloudinit import url_helper +from cloudinit import util + +LOG = logging.getLogger(__name__) + + +def read_metadata(url, timeout=2, sec_between=2, retries=30): + response = url_helper.readurl(url, timeout=timeout, + sec_between=sec_between, retries=retries) + if not response.ok(): + raise RuntimeError("unable to read metadata at %s" % url) + return util.load_yaml(response.contents.decode()) + + +def read_userdata(url, timeout=2, sec_between=2, retries=30): + response = url_helper.readurl(url, timeout=timeout, + sec_between=sec_between, retries=retries) + if not response.ok(): + raise RuntimeError("unable to read userdata at %s" % url) + return response.contents |