# Path: credentials.py
# NUTANIX_USER = 'youraccount'
# 
# Path: credentials.py
# NUTANIX_PASSWORD = 'yourpassword'


import json
import time
import operator
import requests
import logging.config
from credentials import NUTANIX_USER  # Login info now stored in credentials.py
from credentials import NUTANIX_PASSWORD  # Login info now stored in credentials.py
    def update_relative_weight(self):
        """The relative weight is used to determine how much we want to see the data of this VM."""
        self.relative_weight = 1

        # Add up all of the historical counter datapoints (higher counter = more weight)
        for i in self.ready:
            self.relative_weight += i


class NutanixVMRequestException(Exception):
    pass


def generate_json(monitor):
    """
    This function will connect to the Nutanix cluster and retrieve performance data, which
    will be stored in json format in the json property.

    Note that the /vms/ API returns all of the VMs with all of the data.  As of now, it doesn't have
    a way to select which properties to return, so we just get all of them.  I decided that although this was
    not efficient, it is still better than requesting /vms/{vmid}/stat separately for each VM.
    """
    logger = logging.getLogger("nutanix_vm_cpu_ready")

    # Check if there is a working session and create a new one if it is not working
    if monitor.session is None:
        logger.debug("No existing REST API session, creating a new one.")
        # Create Session object that will allow us to issue commands without having to login each time
        monitor.session = requests.Session()
        monitor.session.headers.update({'content-type': 'application/json'})

# Path: credentials.py
# NUTANIX_USER = 'youraccount'
# 
# Path: credentials.py
# NUTANIX_PASSWORD = 'yourpassword'


# Path: nutanix_vdi_vm_cpu_ready.py
import json
import time
import operator
import requests
import logging.config
from credentials import NUTANIX_USER  # Login info now stored in credentials.py
from credentials import NUTANIX_PASSWORD  # Login info now stored in credentials.py

    def update_relative_weight(self):
        """The relative weight is used to determine how much we want to see the data of this VM."""
        self.relative_weight = 1

        # Add up all of the historical counter datapoints (higher counter = more weight)
        for i in self.ready:
            self.relative_weight += i


class NutanixVMRequestException(Exception):
    pass


def generate_json(monitor):
    """
    This function will connect to the Nutanix cluster and retrieve performance data, which
    will be stored in json format in the json property.

    Note that the /vms/ API returns all of the VMs with all of the data.  As of now, it doesn't have
    a way to select which properties to return, so we just get all of them.  I decided that although this was
    not efficient, it is still better than requesting /vms/{vmid}/stat separately for each VM.
    """
    logger = logging.getLogger("nutanix_vm_cpu_ready")

    # Check if there is a working session and create a new one if it is not working
    if monitor.session is None:
        logger.debug("No existing REST API session, creating a new one.")
        # Create Session object that will allow us to issue commands without having to login each time
        monitor.session = requests.Session()
        monitor.session.headers.update({'content-type': 'application/json'})

        monitor.session.auth = (NUTANIX_USER, NUTANIX_PASSWORD)