예제 #1
0
def get_deposit_usage(allocation, package):
    if allocation.batch_service == 'MOAB':
        return allocation.deposit_usage
    else:
        quotas = Quotas(allocation.cpu_usage, allocation.gpu_usage,
                        allocation.ram_usage)
        return get_price(quotas, package)
예제 #2
0
 def set_resource_limits(self, allocation: models.Allocation):
     # TODO: add default limits configuration (https://opennode.atlassian.net/browse/WAL-3037)
     limits = Quotas(
         cpu=allocation.cpu_limit,
         gpu=allocation.gpu_limit,
         ram=allocation.ram_limit,
     )
     self.client.set_resource_limits(allocation.backend_id, limits)
예제 #3
0
 def get_allocation_limits(self, account):
     lines = self.client.get_resource_limits(account)
     correct_lines = [
         association for association in lines if association.resource_limits
     ]
     if len(correct_lines) > 0:
         line = correct_lines[0]
         limits = Quotas(cpu=line.cpu, gpu=line.gpu, ram=line.ram)
         return limits
예제 #4
0
 def pull_allocation(self, allocation):
     account = allocation.backend_id
     report = self.get_usage_report([account])
     usage = report.get(account)
     if not usage:
         usage = {'TOTAL_ACCOUNT_USAGE': Quotas()}
     self._update_quotas(allocation, usage)
     limits = self.get_allocation_limits(account)
     self._update_limits(allocation, limits)
예제 #5
0
    def set_resource_limits(self, allocation):
        quotas = Quotas(
            cpu=allocation.cpu_limit,
            gpu=allocation.gpu_limit,
            ram=allocation.ram_limit,
            deposit=allocation.deposit_limit,
        )

        self.client.set_resource_limits(self.get_allocation_name(allocation),
                                        quotas)
예제 #6
0
    def set_resource_limits(self, allocation):
        # TODO: add default limits configuration (https://opennode.atlassian.net/browse/WAL-3037)
        default_limits = django_settings.WALDUR_SLURM['DEFAULT_LIMITS']
        quotas = Quotas(
            cpu=default_limits['CPU'],
            gpu=default_limits['GPU'],
            ram=default_limits['RAM'],
            deposit=default_limits['DEPOSIT'],
        )

        self.client.set_resource_limits(allocation.backend_id, quotas)
예제 #7
0
    def get_usage_report(self, accounts):
        report = {}
        lines = self.client.get_usage_report(accounts)

        for line in lines:
            report.setdefault(line.account, {}).setdefault(line.user, Quotas())
            report[line.account][line.user] += line.quotas

        for usage in report.values():
            quotas = usage.values()
            total = reduce(operator.add, quotas)
            usage['TOTAL_ACCOUNT_USAGE'] = total

        return report
예제 #8
0
    def pull_allocation(self, allocation):
        account = allocation.backend_id

        if not account.strip():
            raise ServiceBackendError('Empty backend_id for allocation: %s' %
                                      allocation)

        report = self.get_usage_report([account])
        usage = report.get(account)
        if not usage:
            usage = {'TOTAL_ACCOUNT_USAGE': Quotas()}
        self._update_quotas(allocation, usage)
        limits = self.get_allocation_limits(account)
        self._update_limits(allocation, limits)
예제 #9
0
def get_deposit_limit(allocation, package):
    quotas = Quotas(allocation.cpu_limit, allocation.gpu_limit,
                    allocation.ram_limit)
    return get_price(quotas, package)