import requests
import json


def get_port_stats(auth):
    """
    Function to get list of port statistics from Aruba OS switch
    :param auth:  AOSSAuth class object returned by pyarubaoss.auth
    :return list of ports statistics
    :rtype list
    """
    url_portstats = "http://" + auth.ipaddr + "/rest/"+auth.version+"/port-statistics"
    try:
        r = requests.get(url_portstats, headers=auth.cookie)
        portstats = json.loads(r.text)['port_statistics_element']
        return portstats
    except requests.exceptions.RequestException as error:
        return "Error:\n" + str(error) + " get_port_stats: An Error has occured"