Skip to content
Permalink
Browse files

Updated documentation

  • Loading branch information...
mxschmitt committed Aug 27, 2018
1 parent 9c20764 commit 33cecde281e71edbcd8db9307d53b8cd69a9f997
Showing with 1 addition and 1 deletion.
  1. +1 −1 Dynamic Folder/Hetzner/Hetzner Cloud/Hetzner Cloud (Python).rdfe
@@ -1 +1 @@
{"Name":"Dynamic Folder Export","Objects":[{"Type":"DynamicFolder","Name":"Hetzner Cloud (Python)","Notes":"<h2 class=\"cs2654AE3A\">\r\n\t\t\t<span class=\"cs2F2A7C7\">Dynamic Folder support for Hetzner Cloud</span></h2>\r\n\t\t<p class=\"csAD7A2888\"><span class=\"cs4306042E\">Version</span><span class=\"csC8F6D76\">: 1.0<br/></span><span class=\"cs4306042E\">Author</span><span class=\"csC8F6D76\">: Max Schmitt</span></p><p class=\"csAD7A2888\"><span class=\"csC8F6D76\">This Dynamic Folder script will list all your servers for the given API Key of the Hetzner Cloud.</span></p><p class=\"csAD7A2888\"><span class=\"cs5DBD961F\">Prerequisites</span></p><ul style=\"margin-top:0;margin-bottom:0;\">\r\n\t\t\t<li class=\"cs15B7AE4B\"><span class=\"csC8F6D76\"><a class=\"cs26DADAAD\" href=\"https://github.com/hetznercloud/cli\"><span class=\"csCCA9035D\">Hetzner Cloud Command Line Interface</span></a></span><span class=\"csC8F6D76\"> (CLI) needs to be installed, so it&#39;s binary is available in the PATH environment variable.</span></li></ul>\r\n\t\t<h3 class=\"cs2654AE3A\">\r\n\t\t\t<span class=\"cs5DBD961F\">Setup</span></h3>\r\n\t\t<ul style=\"margin-top:0;margin-bottom:0;\">\r\n\t\t\t<li class=\"cs15B7AE4B\"><span class=\"csC8F6D76\">Enter your API Key, which you&#39;ve got from the Hetzner Cloud Console and place it under the Custom Fields =&gt; Protected section of the Dynamic Folder. There&#39;s a &quot;Custom Field 11&quot;, which is used to store the API Key.</span></li></ul>\r\n\t\t<h3 class=\"cs2654AE3A\">\r\n\t\t\t<span class=\"cs5DBD961F\">Notes</span></h3>\r\n\t\t<ul style=\"margin-top:0;margin-bottom:0;\">\r\n\t\t\t<li class=\"cs15B7AE4B\"><span class=\"csC8F6D76\">Per default the auto created servers are setup to inherit their credentials from the Dynamic Folder. So if you set their the credentials all underlying servers will use them.</span></li></ul>\r\n\t","CustomProperties":[{"Name":"API Key","Type":"Protected","Value":"TODO"}],"ScriptInterpreter":"python","DynamicCredentialScriptInterpreter":"json","Script":"import subprocess\r\nimport json\r\nimport os\r\nimport re\r\nimport sys\r\n\r\n# log_error will write the error to the stderr, so that Royal TS will display it.\r\n\r\n\r\ndef log_error(err):\r\n print(\"error: {}\".format(err.strip()), file=sys.stderr)\r\n exit(1)\r\n\r\n\r\ndef get_instances(api_key):\r\n os.environ[\"HCLOUD_TOKEN\"] = api_key\r\n cmd = \"hcloud\"\r\n store = {\r\n \"Objects\": []\r\n }\r\n # get servers\r\n server_list_process = subprocess.Popen(\r\n \"{} server list -o columns=id,name,ipv4 -o noheader\".format(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)\r\n (stdout, stderr) = server_list_process.communicate()\r\n exit_code = server_list_process.wait()\r\n # check if hcloud returned a successful status code != 0\r\n if exit_code != 0:\r\n log_error(\"could not get server list: {}\".format(stderr.decode()))\r\n # loop over the returned servers and build the royal ts JSON\r\n for line in stdout.decode().strip().splitlines():\r\n values = re.findall(r\"[^ ]+\", line)\r\n store[\"Objects\"].append({\r\n \"ID\": values[0],\r\n \"Name\": values[1],\r\n \"ComputerName\": values[2],\r\n \"Username\": \"root\",\r\n \"Type\": \"TerminalConnection\",\r\n \"TerminalConnectionType\": \"SSH\",\r\n \"CredentialsFromParent\": True\r\n })\r\n return json.dumps(store)\r\n\r\n\r\nprint(get_instances(\"$CustomProperty.APIKey$\"))\r\n"}]}
{"Name":"Dynamic Folder Export","Objects":[{"Type":"DynamicFolder","Name":"Hetzner Cloud (Python)","Notes":"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n\t<head>\r\n\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>\r\n\t\t</title>\r\n\t\t<style type=\"text/css\">\r\n\t\t\t.cs2654AE3A{text-align:left;text-indent:0pt;margin:0pt 0pt 0pt 0pt}\r\n\t\t\t.csE8BD414E{color:#000000;background-color:transparent;font-family:'Times New Roman';font-size:18pt;font-weight:bold;font-style:normal;}\r\n\t\t\t.csAD7A2888{text-align:left;text-indent:0pt;margin:12pt 0pt 12pt 0pt}\r\n\t\t\t.cs23FB0664{color:#000000;background-color:transparent;font-family:'Times New Roman';font-size:12pt;font-weight:normal;font-style:normal;}\r\n\t\t\t.cs17BF9202{color:#000000;background-color:transparent;font-family:'Times New Roman';font-size:13.5pt;font-weight:bold;font-style:normal;}\r\n\t\t\t.cs37063928{text-align:left;margin:0pt 0pt 0pt 0pt;list-style-type:disc;color:#000000;background-color:transparent;font-family:Arial;font-size:12pt;font-weight:normal;font-style:normal}\r\n\t\t\t.cs9033B17D{color:#000000;background-color:transparent;font-family:'Times New Roman';font-size:12pt;font-weight:normal;font-style:normal;text-decoration: none;}\r\n\t\t\t.cs1BEFE4A5{color:#0000FF;background-color:transparent;font-family:'Times New Roman';font-size:12pt;font-weight:normal;font-style:normal;text-decoration: underline;}\r\n\t\t</style>\r\n\t</head>\r\n\t<body>\r\n\t\t<h2 class=\"cs2654AE3A\">\r\n\t\t\t<span class=\"csE8BD414E\">Dynamic Folder support for Hetzner Cloud</span></h2>\r\n\t\t<p class=\"csAD7A2888\"><span class=\"cs23FB0664\">Version: 1.0<br/>Author: Max Schmitt</span></p><p class=\"csAD7A2888\"><span class=\"cs23FB0664\">This Dynamic Folder script will list all your servers for the given API Key of the Hetzner Cloud.</span></p><p class=\"csAD7A2888\"><span class=\"cs17BF9202\">Prerequisites</span></p><ul style=\"margin-top:0;margin-bottom:0;\">\r\n\t\t\t<li class=\"cs37063928\"><span class=\"cs23FB0664\"><a class=\"cs9033B17D\" href=\"https://github.com/hetznercloud/cli\"><span class=\"cs1BEFE4A5\">Hetzner Cloud Command Line Interface</span></a></span><span class=\"cs23FB0664\"> (CLI) needs to be installed, so it&#39;s binary is available in the PATH environment variable.</span></li></ul>\r\n\t\t<h3 class=\"cs2654AE3A\">\r\n\t\t\t<span class=\"cs17BF9202\">Setup</span></h3>\r\n\t\t<ul style=\"margin-top:0;margin-bottom:0;\">\r\n\t\t\t<li class=\"cs37063928\"><span class=\"cs23FB0664\">Enter your API Key, which you&#39;ve got from the Hetzner Cloud Console and place it under the Custom Properties section of the Dynamic Folder. There&#39;s a property&quot;API Key&quot;, which is used to store the API Key of your project.</span></li></ul>\r\n\t\t<h3 class=\"cs2654AE3A\">\r\n\t\t\t<span class=\"cs17BF9202\">Notes</span></h3>\r\n\t\t<ul style=\"margin-top:0;margin-bottom:0;\">\r\n\t\t\t<li class=\"cs37063928\"><span class=\"cs23FB0664\">Per default the auto created servers are setup to inherit their credentials from the Dynamic Folder. So if you set their the credentials all underlying servers will use them.</span></li></ul>\r\n\t</body>\r\n</html>\r\n","CustomProperties":[{"Name":"API Key","Type":"Protected","Value":"TODO"}],"ScriptInterpreter":"python","DynamicCredentialScriptInterpreter":"json","Script":"import subprocess\r\nimport json\r\nimport os\r\nimport re\r\nimport sys\r\n\r\n# log_error will write the error to the stderr, so that Royal TS will display it.\r\n\r\n\r\ndef log_error(err):\r\n print(\"error: {}\".format(err.strip()), file=sys.stderr)\r\n exit(1)\r\n\r\n\r\ndef get_instances(api_key):\r\n os.environ[\"HCLOUD_TOKEN\"] = api_key\r\n cmd = \"hcloud\"\r\n store = {\r\n \"Objects\": []\r\n }\r\n # get servers\r\n server_list_process = subprocess.Popen(\r\n \"{} server list -o columns=id,name,ipv4 -o noheader\".format(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)\r\n (stdout, stderr) = server_list_process.communicate()\r\n exit_code = server_list_process.wait()\r\n # check if hcloud returned a successful status code != 0\r\n if exit_code != 0:\r\n log_error(\"could not get server list: {}\".format(stderr.decode()))\r\n # loop over the returned servers and build the royal ts JSON\r\n for line in stdout.decode().strip().splitlines():\r\n values = re.findall(r\"[^ ]+\", line)\r\n store[\"Objects\"].append({\r\n \"ID\": values[0],\r\n \"Name\": values[1],\r\n \"ComputerName\": values[2],\r\n \"Username\": \"root\",\r\n \"Type\": \"TerminalConnection\",\r\n \"TerminalConnectionType\": \"SSH\",\r\n \"CredentialsFromParent\": True\r\n })\r\n return json.dumps(store)\r\n\r\n\r\nprint(get_instances(\"$CustomProperty.APIKey$\"))\r\n"}]}

0 comments on commit 33cecde

Please sign in to comment.
You can’t perform that action at this time.