]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Optimizing vminfo
authorMladen Uzunov <mladen.uzunov@digitaspixelpark.com>
Thu, 2 Jun 2022 12:29:42 +0000 (15:29 +0300)
committerMladen Uzunov <mladen.uzunov@digitaspixelpark.com>
Thu, 2 Jun 2022 12:29:42 +0000 (15:29 +0300)
bin/vminfo.py [deleted file]
setup.py

diff --git a/bin/vminfo.py b/bin/vminfo.py
deleted file mode 100755 (executable)
index 4730e00..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/usr/bin/env python3
-import sys
-import requests
-from tabulate import tabulate
-import re
-from os import _exit
-
-
-class FactGetter:
-    def __init__(self, baseUrl, tableFormat):
-        self.baseUrl = baseUrl
-        self.tableFormat = tableFormat
-
-    def complexTabulate(self, data, excludeValue=None, exludeHeader=None, addtionalSpot=None):
-        finalData = []
-        for items in data["value"].items():
-            if excludeValue is not None:
-                values = [x for x in items[1].values() if x !=
-                          excludeValue and not re.match(excludeValue, str(x))]
-            else:
-                values = [x for x in items[1].values()]
-
-            if exludeHeader is not None:
-                headers = [x for x in items[1].keys() if x !=
-                           exludeHeader and not re.match(exludeHeader, str(x))]
-            else:
-                headers = [x for x in items[1].keys()]
-            if addtionalSpot is not None:
-                if len(values) < addtionalSpot["size"]:
-                    values.insert(addtionalSpot["location"], "-x-")
-            finalData.append(values)
-        print(tabulate(finalData, headers=headers, tablefmt=self.tableFormat))
-
-    def generalInfo(self):
-        result = []
-        URL = f"{self.baseUrl}/customer"
-        data = requests.get(URL).json()[0]
-        for k, v in data.items():
-            result.append([k, v])
-        print("\n", " GENERAL INFO ".center(60, "#"))
-        print(tabulate(result, tablefmt=self.tableFormat))
-
-    def cpuInfo(self):
-        URL = f"{self.baseUrl}/processorcount"
-        data = requests.get(URL).json()[0]
-        print("\n", " CPU ".center(60, "#"))
-        print(tabulate([["CPU cores", str(data['value'])]],
-              tablefmt=self.tableFormat))
-
-    def memInfo(self):
-        URL = f"{self.baseUrl}/memory"
-        data = requests.get(URL).json()[0]
-        print("\n", " MEMORY (RAM) ".center(60, "#"))
-        self.complexTabulate(data)
-
-    def diskInfo(self):
-        serialNum = re.compile(r'^[\d]{20}$')
-        URL = f"{self.baseUrl}/disks"
-        data = requests.get(URL).json()[0]
-        print("\n", " DISKS ".center(60, "#"))
-        self.complexTabulate(data, excludeValue=serialNum,
-                             exludeHeader="serial")
-
-    def partitionInfo(self):
-        partuuid = re.compile(r"^[\d\w]{8}\-[\d\w]{2}$")
-        URL = f"{self.baseUrl}/partitions"
-        data = requests.get(URL).json()[0]
-        print("\n", " PARTITIONS ".center(60, "#"))
-        self.complexTabulate(data, addtionalSpot={
-                             "size": 5, "location": 2}, exludeHeader="partuuid", excludeValue=partuuid)
-
-    def networkInfo(self):
-        data = []
-        URL = f"{self.baseUrl}/interfaces"
-        interfaces = requests.get(URL).json()[0]["value"].split(',')
-        print("\n", " NETWORK ".center(60, "#"))
-        for interface in interfaces:
-            URL = f"{self.baseUrl}/ipaddress_{interface}"
-            data.append([interface, requests.get(URL).json()[0]["value"]])
-        data.insert(0, ["default", requests.get(
-            f"{self.baseUrl}/ipaddress").json()[0]["value"]])
-        print(tabulate(data, headers=["Interface",
-              "IPaddr"], tablefmt=self.tableFormat))
-
-
-_usage = f"""
-    usage: {sys.argv[0]} [hostname]
-
-    Description: 
-    The script will display the following information about the host:
-    - General information
-    - CPU information
-    - Memory information
-    - Disk information
-    - Partition information
-    - Network information
-    """
-
-
-try:
-    hostname = sys.argv[1]
-except:
-    print(_usage)
-    _exit(1)
-
-factGetter = FactGetter(
-    f"https://puppetdb01.pixelpark.com/pdb/query/v4/nodes/{hostname}/facts", tableFormat="psql")
-factGetter.generalInfo()
-factGetter.cpuInfo()
-factGetter.memInfo()
-factGetter.diskInfo()
-factGetter.partitionInfo()
-factGetter.networkInfo()
-
-
-__author__ = 'Mladen Uzunov <mladen.uzunov@pixelpark.com>'
-__copyright__ = '(C) 2022 by Mladen Uzunov, Pixelpark GmbH, Berlin'
index 6a208fd7e0a3f2e8867c9e3f1d1fd929807a60bd..1cf7587ff5d056dda686331d352aeb87abb3d56a 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -136,7 +136,7 @@ read_requirements()
 __scripts__ = [
     'bin/create-terraform',
     'bin/pre-terraform',
-    'bin/vminfo.py'
+    'bin/vminfo'
 ]
 
 # -----------------------------------