get total resources and available ones
431847
def resources(self):
        '''  '''
        used_resources = self._used_resources()
        ret = collections.defaultdict(dict)
        for resource, total in six.iteritems(self._resources):
            ret[resource]['total'] = total
            if resource in used_resources:
                ret[resource]['used'] = used_resources[resource]
            else:
                ret[resource]['used'] = 0
        return ret
35431
def _get_total_available_slots(self, context, template_id, capacity):
        
        query = context.session.query(hd_models.HostingDevice.id)
        query = query.outerjoin(
            hd_models.SlotAllocation,
            hd_models.HostingDevice.id == hd_models.SlotAllocation
            .hosting_device_id)
        query = query.filter(
            hd_models.HostingDevice.template_id == template_id,
            hd_models.HostingDevice.admin_state_up == expr.true(),
            hd_models.HostingDevice.tenant_bound == expr.null())
        query = query.group_by(hd_models.HostingDevice.id)
        query = query.having(
            func.sum(hd_models.SlotAllocation.num_allocated) == expr.null())
        num_hosting_devices = query.count()
        return num_hosting_devices * capacity
1038750
def get_all_resources(datasets):
        # type: (List['Dataset']) -> List[hdx.data.resource.Resource]
        
        resources = []
        for dataset in datasets:
            for resource in dataset.get_resources():
                resources.append(resource)
        return resources
904922
public List getResources() {

        if ((m_resources == null) || m_resources.isEmpty()) {
            m_resources = new ArrayList();
            m_resources.add("/");
        }
        return m_resources;
    }
534065
public function getAvailableResources()
    {
        $cache = Cache::getTransientCache();
        $cacheId = 'transifex_resources_' . $this->projectSlug;
        $resources = $cache->fetch($cacheId);

        if (empty($resources)) {
            $apiPath = 'project/' . $this->projectSlug . '/resources';
            $resources = $this->getApiResults($apiPath);
            $cache->save($cacheId, $resources);
        }

        return $resources;
    }
1217016
def resources_availability(self):
        """"""
        # Flatten the list.
        availabilities = list(
            chain(
                *[org.check_availability() for org in self.organizations]
            )
        )
        # Filter out the unknown
        availabilities = [a for a in availabilities if type(a) is bool]
        if availabilities:
            # Trick will work because it's a sum() of booleans.
            return round(100. * sum(availabilities) / len(availabilities), 2)
        # if nothing is unavailable, everything is considered OK
        return 100
1359193
def resource_info(self):
        
        return self.visalib.parse_resource_extended(self._resource_manager.session, self.resource_name)
833368
function resources(data) {
    var items = [],
        fid = schedule.functor(id),
        favailable = schedule.functor(available),
        freserve = schedule.functor(isNotReservable);

    for(var i = 0, len = data.length; i < len; i++) {
      var resource = data[i],
          rId = fid.call(this, resource, i),
          rAvailable = favailable.call(this, resource, i),
          rReserve = freserve.call(this, resource, i);

      items.push({id: rId, available: rAvailable, isNotReservable: rReserve});
    }

    return items;
  }
390429
protected function totalAmountResourceCallable()
    {
        return function () {
            $idKey = $this->getDataModel()->getKeyName();

            return $this->getDataModel()->query()->count([$idKey]);
        };
    }
1301892
def resource_list(self):
        
        self.prune()
        resources = [
            dict(
                name=resource,
                num_total=r_dict['total'],
                num_used=r_dict['used']
            ) for resource, r_dict in six.iteritems(self.resources())]
        if self._resources is not None:
            consumers = collections.defaultdict(dict)
            for task in self._state.get_active_tasks_by_status(RUNNING):
                if task.status == RUNNING and task.resources:
                    for resource, amount in six.iteritems(task.resources):
                        consumers[resource][task.id] = self._serialize_task(task.id, include_deps=False)
            for resource in resources:
                tasks = consumers[resource['name']]
                resource['num_consumer'] = len(tasks)
                resource['running'] = tasks
        return resources
274189
def get_resources(resources):  # pylint:disable=too-many-branches
    
    limits = {}
    requests = {}
    if resources is None:
        return None
    if resources.cpu:
        if resources.cpu.limits:
            limits['cpu'] = resources.cpu.limits
        if resources.cpu.requests:
            requests['cpu'] = resources.cpu.requests

    if resources.memory:
        if resources.memory.limits:
            limits['memory'] = '{}Mi'.format(resources.memory.limits)
        if resources.memory.requests:
            requests['memory'] = '{}Mi'.format(resources.memory.requests)

    if resources.gpu:
        if resources.gpu.limits:
            limits[conf.get('K8S_GPU_RESOURCE_KEY')] = resources.gpu.limits
        if resources.gpu.requests:
            requests[conf.get('K8S_GPU_RESOURCE_KEY')] = resources.gpu.requests

    if resources.tpu:
        if resources.tpu.limits:
            limits[conf.get('K8S_TPU_RESOURCE_KEY')] = resources.tpu.limits
        if resources.tpu.requests:
            requests[conf.get('K8S_TPU_RESOURCE_KEY')] = resources.tpu.requests
    return client.V1ResourceRequirements(limits=limits or None, requests=requests or None)
881961
def my_resource_list():
    """"""
    rl = ResourceList( resources=iter(my_resources), count=len(my_resources) )
    rl.max_sitemap_entries = max_sitemap_entries
    return(rl)
453136
def _resource(resource, pretty: bool = None, **data):
    """"""
    data = clean_data(data)

    ctx = click.get_current_context()
    if ctx.obj.get("env_prefix"):
        data["env_prefix"] = ctx.obj["env_prefix"]

    rsp = resource(**data)
    dump = partial(json.dumps, indent=4) if pretty else partial(json.dumps)
    click.echo(dump(rsp))
1118994
public Resource getTotalUsedResources() {
    return getInstances().stream()
        .map(PackingPlan.InstancePlan::getResource)
        .reduce(Resource.EMPTY_RESOURCE, Resource::plus)
        .plus(getPadding());
  }
26725
def get_resources(cls):
        """"""
        exts = []
        parent = dict(member_name=ciscohostingdevicemanager.DEVICE,
                      collection_name=ciscohostingdevicemanager.DEVICES)
        controller = resource.Resource(
            RouterHostingDeviceSchedulerController(), cb_faults.FAULT_MAP)
        exts.append(extensions.ResourceExtension(
            DEVICE_L3_ROUTERS, controller, parent, path_prefix="/dev_mgr"))
        parent = dict(member_name="router",
                      collection_name=l3_const.ROUTERS)
        controller = resource.Resource(
            HostingDevicesHostingRouterController(), cb_faults.FAULT_MAP)
        exts.append(extensions.ResourceExtension(L3_ROUTER_DEVICES, controller,
                                                 parent))
        return exts
861663
async def get_instances(self, **kwargs) -> List[ApiResource]:
        """"""
        raw_resources = await self.get_resources(**kwargs)
        _instances = [
            self._resource_factory(_raw)
            for _raw in self._loop_raw(raw_resources)
        ]
        return _instances
1326376
@Nullable
    public final Resources getResources() {
        Activity activity = getActivity();
        return activity != null ? activity.getResources() : null;
    }