#!/usr/bin/env python
-
+# Version checking copied from `create-terraform` script
+# written by Frank B.
+#
from __future__ import print_function
import sys
*sys.version_info), file=sys.stderr)
sys.exit(1)
+# Actual `pre-terraform` code begins here
+#
import math
from os import _exit
from urllib.request import urlopen,Request
import json
import yaml
-
+# This is for debugging purposes, it helps track the HTTP requests'
+# input and ouput and detect errors along the way. Better leave it here
+# for debuggin purposes. The script will later be fixed so that debug mode
+# can be enabled on demand.
+#
# http_handler = urllib.request.HTTPHandler(debuglevel=1)
-
# try:
# import ssl
# https_handler = urllib.request.HTTPSHandler(debuglevel=1)
# urllib.request.install_opener(opener)
url = "https://puppetdb01.pixelpark.com/pdb/query/v4/facts"
+
try:
data = '["=", "certname", "%s"]' % (sys.argv[1]) # argv[1] is the hostname we ask information for from the PuppetDB
except:
"customer": "__",
"purpose": "__",
"datastore_cluster": "ds-cluster-hdd-vmcc-l105-01 <<< Check this",
- "datastore_type": "sata",
+ "datastore_type": "sata <<< Check this",
"root_disk": { "size": 0 },
"data_disks": [],
"puppet": {
sample_pre_tf["defaults"]["dns_options"] = f"timeout: {timeout} attempts: {attempts}"
# Disks root
- sample_pre_tf["defaults"]["root_disk"]["size"] = int(data["disks"]["value"]["sda"]["size_bytes"]/int(1<<30))
+ # Note: This is required because on Solaris setup is different than RedHat based distros
+ # and disks are numbered sd0, sd1, etc., also for some servers sd0 reports 0 size
+ try:
+ sample_pre_tf["defaults"]["root_disk"]["size"] = int(data["disks"]["value"]["sda"]["size_bytes"]/int(1<<30))
+ except:
+ sample_pre_tf["defaults"]["root_disk"]["size"] = "<<<<<<<<<<<<<<<<< Check this"
# Disks additional
+ # Note: Same as above
for disk in data["disks"]["value"]:
if disk.startswith("sd") and disk != "sda":
- sample_pre_tf["defaults"]["data_disks"].append(
- {
- "size": int(data["disks"]["value"][disk]["size"].split(".")[0])
- }
- )
+ try:
+ sample_pre_tf["defaults"]["data_disks"].append(
+ {
+ "size": int(data["disks"]["value"][disk]["size"].split(".")[0])
+ }
+ )
+ except:
+ sample_pre_tf["defaults"]["data_disks"].append(
+ {
+ "size": "<<<<<<<<<<<<<<<<< Check this"
+ }
+ )
# Interface IPs
# Environment
sample_pre_tf["defaults"]["puppet"]["tier"] = data["tier"]["value"]
sample_pre_tf["defaults"]["puppet"]["environment"] = data["tier"]["value"]
-except:
+except Exception as e:
print("ERROR: Failed parsing required fields from output. Please check if hostname is in PuppetDB")
+ # print(f"ERROR: {e}")
_exit(1)
# Print the YAML configuration file
# These are the facts - All
# print(facts)
-# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
\ No newline at end of file
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4