from ..utils import minimum_version


class SystemApiMixin:
    def system_status_get(self, **kwargs):
        """
        This method allows you to query NETLAB+ system information.

        :return: Returns a system status object with the following properties:
        :rtype: dict

        **Properties**

        cpu_n
            Number of CPUs detected by the virtual appliance.
        uptime_sec
            System uptime in seconds.
        hostname
            NETLAB+ domain name
        sys_lic_exp_date
            License expiration date
        sys_lic_op_state
            License operation stsate
        sys_logins_enabled
            User logins status
        sys_maint_ends
            Mainenance end date
        sys_mode
            System mode
        sys_name
            System name
        sys_product_id
            Product identifier
        sys_sdn_release_date
            Software distribution date
        sys_sdn_release_type
            Software distribution release type
        sys_sdn_version
            Software distribution version
        sys_serial
            System serial number
        """
        method = "system.status.get"
        return self.call(method, **kwargs)

    @minimum_version('17.1.3')
    def system_usage_cpu(self, **kwargs):
        """
        This method allows you to query NETLAB+ CPU usage.

        :return: Returns an object with N+1 properties, where N is the number of CPUs. The CPUs are listed from 0 to
                 N-1 and also includes **all** . They each contain an object with the following properties:
        :rtype: dict

        **Properties**

        gnice_pct
            The percentage of time spent by the CPU or CPUs to run a niced guest.
        guest_pct
            The percentage of time spent by the CPU or CPUs to run a virtual processor.
        idle_pct
            The percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O
            request.
        iowait_pct
            The percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O
            request.
        irq_pct
            The percentage of time spent by the CPU or CPUs to service hardware interrupts.
        nice_pct
            The percentage of CPU utilization that occurred while executing at the user level with nice priority.
        soft_pct
            The percentage of time spent by the CPU or CPUs to service software interrupts.
        steal_pct
            The percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was
            servicing another virtual processor.
        sys_pct
            The percentage of CPU utilization that occurred while executing at the system level (kernel). Note that
            this does not include time spent servicing hardware and software interrupts.
        usr_pct
            The percentage of CPU utilization that occurred while executing at the user level (application).
        """
        method = "system.usage.cpu"
        return self.call(method, **kwargs)

    @minimum_version('17.1.3')
    def system_usage_disk(self, **kwargs):
        """
        This method allows you to query NETLAB+ disk usage.

        :return: Returns an object with two properties, **data** and **programs** . They each contain an object with the
                 following properties:
        :rtype: dict

        **Properties**

        avail_b
            Available disk space in bytes.
        total_b
            Total disk space in bytes.
        used_b
            Used disk space in bytes.
        used_pct
            Disk space used as a percentage of the whole.
        """
        method = "system.usage.disk"
        return self.call(method, **kwargs)

    @minimum_version('17.1.3')
    def system_usage_memory(self, **kwargs):
        """
        This method allows you to query NETLAB+ memory usage.

        :return: Returns an object with a single property, **ram**. It contains an object with the following properties:
        :rtype: dict

        **Properties**

        free_b
            Free memory in bytes.
        total_b
            Total memory in bytes.
        used_b
            Used memory in bytes.
        """
        method = "system.usage.memory"
        return self.call(method, **kwargs)

    @minimum_version('17.1.4')
    def system_time_timezone_get(self, *, tz_id, **kwargs):
        """
        Match a netlab timezone id to the timezone iana.

        :return: Returns an object that represents a timezone.
        :rtype: dict

        **Properties**

        tz_id
            The id of timezone (specific to netlab).
        tz_iana
            The iana identifier of the timezone.
        tz_name
            The name of the timezone.
        tz_sort
            The sort order of the timezone.
        """
        method = 'system.time.timezone.get'
        return self.call(method, tz_id=tz_id, **kwargs)

    @minimum_version('17.1.4')
    def system_time_timezone_list(self, **kwargs):
        """
        Match a netlab timezone id to the timezone iana.

        :return: Returns an object that represents a timezone.
        :rtype: dict

        **Properties**

        tz_id
            The id of timezone (specific to netlab).
        tz_iana
            The iana identifier of the timezone.
        tz_name
            The name of the timezone.
        tz_sort
            The sort order of the timezone.
        """

        method = 'system.time.timezone.list'
        return self.call(method, **kwargs)
