<commit_before># ------------------------------------------------------------------------------
# This module contains all the features of the category Hardware and Operating
# System footprint.This module contains the actual logic built with the help of
# Cloudera Manager API, Generic API and commands.
# -------------------------------------------------------------------------------

# Importing required libraries
import os
from imports import *


class HardwareOSAPI:
    """This Class has functions related to Hardware and OS Footprint category.

    Has functions which fetch different hardware and os metrics from Hadoop 
    cluster like list of host and their details, list of services, core and 
    memory usage pattern over time, etc.

    Args:
        inputs (dict): Contains user input attributes
    """

    def __init__(self, inputs):
        """Initialize inputs"""

        self.inputs = inputs
        self.version = inputs["version"]
        self.cloudera_manager_host_ip = inputs["cloudera_manager_host_ip"]
        self.cloudera_manager_port = inputs["cloudera_manager_port"]
        self.cloudera_manager_username = inputs["cloudera_manager_username"]
        self.cloudera_manager_password = inputs["cloudera_manager_password"]
        self.cluster_name = inputs["cluster_name"]
        self.logger = inputs["logger"]
        self.config_path = inputs["config_path"]
        self.ssl = inputs["ssl"]
        if self.ssl:
            self.http = "https"
        else:
            self.http = "http"
        self.start_date = inputs["start_date"]
        self.end_date = inputs["end_date"]

    def os_version(self):
        """Get OS version using system CLI command.
        
        Returns:
            os_version (str): OS version and distribution of host
        """

        try:
            os_version = subprocess.Popen(
                "cat /etc/*-release",
                shell=True,
                stdout=subprocess.PIPE,
                encoding="utf-8",
            )
            os_version.wait()
            os_version, err = os_version.communicate()
            os_version = os_version.replace("\n", ",")
            os_version = os_version.split(",")
            os_version_series = pd.Series(data=os_version).T
            os_version = os_version_series.iloc[18]
            self.logger.info("os_version successful")
            return os_version
        except Exception as e:
            self.logger.error("os_version failed", exc_info=True)
            return None

    def cluster_items(self):
        """Get list of all clusters present in Cloudera Manager.

        Returns:
            cluster_items (dict): Metrics of all clusters
        """

        try:
            r = None
            if self.version == 7:
                r = requests.get(
                    "{}://{}:{}/api/v41/clusters".format(
                        self.http,
                        self.cloudera_manager_host_ip,
                        self.cloudera_manager_port,
                    ),
                    auth=HTTPBasicAuth(<commit_msg>os part updated in hardware os file<commit_after># ------------------------------------------------------------------------------
# This module contains all the features of the category Hardware and Operating
# System footprint.This module contains the actual logic built with the help of
# Cloudera Manager API, Generic API and commands.
# -------------------------------------------------------------------------------

# Importing required libraries
import os
from imports import *


class HardwareOSAPI:
    """This Class has functions related to Hardware and OS Footprint category.

    Has functions which fetch different hardware and os metrics from Hadoop 
    cluster like list of host and their details, list of services, core and 
    memory usage pattern over time, etc.

    Args:
        inputs (dict): Contains user input attributes
    """

    def __init__(self, inputs):
        """Initialize inputs"""

        self.inputs = inputs
        self.version = inputs["version"]
        self.cloudera_manager_host_ip = inputs["cloudera_manager_host_ip"]
        self.cloudera_manager_port = inputs["cloudera_manager_port"]
        self.cloudera_manager_username = inputs["cloudera_manager_username"]
        self.cloudera_manager_password = inputs["cloudera_manager_password"]
        self.cluster_name = inputs["cluster_name"]
        self.logger = inputs["logger"]
        self.config_path = inputs["config_path"]
        self.ssl = inputs["ssl"]
        if self.ssl:
            self.http = "https"
        else:
            self.http = "http"
        self.start_date = inputs["start_date"]
        self.end_date = inputs["end_date"]

    def os_version(self):
        """Get OS version using system CLI command.
        
        Returns:
            os_version (str): OS version and distribution of host
        """

        try:
            os_version=subprocess.Popen('grep PRETTY_NAME /etc/os-release',shell=True,stdout=subprocess.PIPE,encoding="utf-8")
            os_version, err = os_version.communicate()    
            os_version = os_version.split("=")
            os_version = os_version[1]
            self.logger.info("os_version successful")
            return os_version
        except Exception as e:
            self.logger.error("os_version failed", exc_info=True)
            return None

    def cluster_items(self):
        """Get list of all clusters present in Cloudera Manager.

        Returns:
            cluster_items (dict): Metrics of all clusters
        """

        try:
            r = None
            if self.version == 7:
                r = requests.get(
                    "{}://{}:{}/api/v41/clusters".format(
                        self.http,
                        self.cloudera_manager_host_ip,
                        self.cloudera_manager_port,
                    ),
                    auth=HTTPBasicAuth(
{'fraction_non_alphanumeric': 0.13468975954262655, 'fraction_numerical': 0.0018496721035816377, 'mean_word_length': 1.760092807424594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2091149', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1481, 'n_words': 412}