def compare_usage_metrics_for_always_on()

in source/ecs/workspaces_helper.py [0:0]


    def compare_usage_metrics_for_always_on(self, workspace_id, billable_time, hourly_threshold,
                                            workspace_running_mode):
        """
        This method compares the usage metrics for Always ON mode
        :param workspace_id: workspace id
        :param billable_time: billable time
        :param hourly_threshold: hourly threshold
        :param workspace_running_mode: workspace running mode
        :return: Result code and new running mode
        """
        log.debug('workspaceRunningMode {} == ALWAYS_ON'.format(workspace_running_mode))

        # Only perform metrics gathering for ALWAYS_ON Workspaces at the end of the month.
        if self.settings.get('testEndOfMonth'):
            log.debug('testEndOfMonth {} == True'.format(self.settings.get('testEndOfMonth')))

            # If billable time is under the threshold for this bundle type
            if billable_time <= hourly_threshold:
                log.debug('billableTime {} < hourlyThreshold {}'.format(billable_time, hourly_threshold))

                # Change the workspace to AUTO_STOP
                result_code = self.modify_workspace_properties(workspace_id, AUTO_STOP)
                # if there was an exception in the modify workspace API call, new mode is same as old mode
                if result_code == '-E-':
                    new_mode = ALWAYS_ON
                else:
                    new_mode = AUTO_STOP

            # Otherwise, report no change for the Workspace
            else:  # billable_time > hourly_threshold:
                log.debug('billableTime {} >= hourlyThreshold {}'.format(billable_time, hourly_threshold))
                result_code = '-N-'
                new_mode = ALWAYS_ON
        else:
            log.debug('testEndOfMonth {} == False'.format(self.settings.get('testEndOfMonth')))
            result_code = '-N-'
            new_mode = ALWAYS_ON

        return result_code, new_mode