// Return a list of redings associated with the device and value descriptor
// Limit exceeded exception 413 if the limit exceeds the max limit
// api/v1/reading/name/{name}/device/{device}/{limit}
776528
func readingByValueDescriptorAndDeviceHandler(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()

	vars := mux.Vars(r)
	ctx := r.Context()

	// Get the variables from the URL
	name, err := url.QueryUnescape(vars["name"])
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		LoggingClient.Error("Error unescaping the value descriptor name: " + err.Error())
		return
	}

	device, err := url.QueryUnescape(vars["device"])
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		LoggingClient.Error("Error unescaping the device: " + err.Error())
		return
	}

	limit, err := strconv.Atoi(vars["limit"])
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		LoggingClient.Error("Error converting limit to an integer: " + err.Error())
		return
	}

	err = checkMaxLimit(limit)
	if err != nil {
		http.Error(w, maxExceededString, http.StatusRequestEntityTooLarge)
		return
	}

	// Check device
	if err := checkDevice(device, ctx); err != nil {
		LoggingClient.Error(fmt.Sprintf("error checking device %s %v", device, err))
		switch err := err.(type) {
		case *types.ErrServiceClient:
			http.Error(w, err.Error(), err.StatusCode)
			return
		default: //return an error on everything else.
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	}

	// Check for value descriptor
	if Configuration.Writable.ValidateCheck {
		_, err = getValueDescriptorByName(name)
		if err != nil {
			switch err.(type) {
			case *errors.ErrDbNotFound:
				http.Error(w, "Value descriptor not found for reading", http.StatusConflict)
				return
			default:
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
		}
	}

	readings, err := getReadingsByDeviceAndValueDescriptor(device, name, limit)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	encode(readings, w)
}
924179
func limitReader(r io.Reader, n int64) io.Reader {
	return &limitedReader{r: r, n: n}
}
227442
func (s *NuageVSPService) ListNuageVspDevices(p *ListNuageVspDevicesParams) (*ListNuageVspDevicesResponse, error) {
	resp, err := s.cs.newRequest("listNuageVspDevices", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r ListNuageVspDevicesResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
597139
func (c *Connect) ListDevices(cap string, flags uint32) ([]string, error) {
	ccap := C.CString(cap)
	defer C.free(unsafe.Pointer(ccap))
	const maxNodeDevices = 1024
	var uuids [maxNodeDevices](*C.char)
	uuidsPtr := unsafe.Pointer(&uuids)
	var err C.virError
	numNodeDevices := C.virNodeListDevicesWrapper(
		c.ptr, ccap,
		(**C.char)(uuidsPtr),
		maxNodeDevices, C.uint(flags), &err)
	if numNodeDevices == -1 {
		return nil, makeError(&err)
	}
	goUuids := make([]string, numNodeDevices)
	for k := 0; k < int(numNodeDevices); k++ {
		goUuids[k] = C.GoString(uuids[k])
		C.free(unsafe.Pointer(uuids[k]))
	}
	return goUuids, nil
}
1052926
func getDeviceResources(deviceGroupStats []*api.DeviceGroupStats) []string {
	statsSummaryMap := buildDeviceStatsSummaryMap(deviceGroupStats)

	result := make([]string, 0, len(statsSummaryMap))
	for id, stats := range statsSummaryMap {
		result = append(result, id+"|"+stats.String())
	}

	sort.Strings(result)

	return result
}
193646
func (s *RedisMapStore) GetAll(keys []string, options *ListOptions) ([]interface{}, error) {
	if len(keys) == 0 {
		return []interface{}{}, nil
	}

	for i, key := range keys {
		if !strings.HasPrefix(key, s.prefix) {
			keys[i] = s.prefix + key
		}
	}

	sort.Strings(keys)

	selectedKeys := selectKeys(keys, options)
	if len(selectedKeys) == 0 {
		return []interface{}{}, nil
	}

	pipe := s.client.Pipeline()
	defer pipe.Close()

	// Add all commands to pipeline
	cmds := make(map[string]*redis.StringStringMapCmd)
	for _, key := range selectedKeys {
		cmds[key] = pipe.HGetAll(key)
	}

	// Execute pipeline
	_, err := pipe.Exec()
	if err != nil {
		return nil, err
	}

	// Get all results from pipeline
	results := make([]interface{}, len(selectedKeys))
	for i, key := range selectedKeys {
		if result, err := cmds[key].Result(); err == nil {
			result, _ = s.migrate(key, result)
			if result, err := s.decoder(result); err == nil {
				results[i] = result
			}
		}
	}

	return results, nil
}
349320
func (r User_Customer_OpenIdConnect) GetMobileDevices() (resp []datatypes.User_Customer_MobileDevice, err error) {
	err = r.Session.DoRequest("SoftLayer_User_Customer_OpenIdConnect", "getMobileDevices", nil, &r.Options, &resp)
	return
}
657472
func discardInput(r io.Reader, n uint32) {
	maxSize := uint32(10 * 1024) // 10k at a time
	numReads := n / maxSize
	bytesRemaining := n % maxSize
	if n > 0 {
		buf := make([]byte, maxSize)
		for i := uint32(0); i < numReads; i++ {
			io.ReadFull(r, buf)
		}
	}
	if bytesRemaining > 0 {
		buf := make([]byte, bytesRemaining)
		io.ReadFull(r, buf)
	}
}
73006
func (d *DeviceMapperDriver) List() (result []string) {
	md := d.MetadataDir()
	if files, err := ioutil.ReadDir(md); err != nil {
		glog.Errorf("Error trying to read from metadata directory: %s", md)
		return
	} else {
		for _, fi := range files {
			if fi.IsDir() {
				result = append(result, fi.Name())
			}
		}
	}
	return
}
487973
func NewDeviceAllocator(lastIndex int) DeviceAllocator {
	possibleDevices := []mountDevice{}
	for _, firstChar := range []rune{'b', 'c'} {
		for i := 'a'; i <= 'z'; i++ {
			dev := mountDevice([]rune{firstChar, i})
			possibleDevices = append(possibleDevices, dev)
		}
	}
	return &deviceAllocator{
		possibleDevices: possibleDevices,
		lastIndex:       lastIndex,
	}
}
127371
func (d *DeviceMapperDriver) readDeviceInfo(deviceHash string, devInfo *devInfo) error {
	fh, err := os.Open(d.deviceInfoPath(deviceHash))
	if err != nil {
		glog.Errorf("Could not read device info for %s: %s", deviceHash, err)
		return err
	}
	defer fh.Close()
	if err := json.NewDecoder(fh).Decode(devInfo); err != nil {
		glog.Errorf("Could not decode device info for %s: %s", deviceHash, err)
		return err
	}
	return nil
}
1281468
func getSystemIdValues(key string, instanceIds []instance.Id) url.Values {
	values := url.Values{}
	for _, instanceId := range instanceIds {
		values.Add(key, extractSystemId(instanceId))
	}
	return values
}
863403
func (a *Application) DeviceConstraints() (map[string]DeviceConstraints, error) {
	cons, err := readDeviceConstraints(a.st, a.deviceConstraintsKey())
	if errors.IsNotFound(err) {
		return nil, nil
	} else if err != nil {
		return nil, errors.Trace(err)
	}
	return cons, nil
}
666164
func (lim *limiter) processDevicesConfigurationLocked(from, to config.Configuration) {
	seen := make(map[protocol.DeviceID]struct{})

	// Mark devices which should not be removed, create new limiters if needed and assign new limiter rate
	for _, dev := range to.Devices {
		if dev.DeviceID == to.MyID {
			// This limiter was created for local device. Should skip this device
			continue
		}
		seen[dev.DeviceID] = struct{}{}

		if lim.setLimitsLocked(dev) {
			readLimitStr := "is unlimited"
			if dev.MaxRecvKbps > 0 {
				readLimitStr = fmt.Sprintf("limit is %d KiB/s", dev.MaxRecvKbps)
			}
			writeLimitStr := "is unlimited"
			if dev.MaxSendKbps > 0 {
				writeLimitStr = fmt.Sprintf("limit is %d KiB/s", dev.MaxSendKbps)
			}

			l.Infof("Device %s send rate %s, receive rate %s", dev.DeviceID, writeLimitStr, readLimitStr)
		}
	}

	// Delete remote devices which were removed in new configuration
	for _, dev := range from.Devices {
		if _, ok := seen[dev.DeviceID]; !ok {
			l.Debugf("deviceID: %s should be removed", dev.DeviceID)

			delete(lim.deviceWriteLimiters, dev.DeviceID)
			delete(lim.deviceReadLimiters, dev.DeviceID)
		}
	}
}
774958
func (_m *DBClient) GetAllDeviceProfiles() ([]models.DeviceProfile, error) {
	ret := _m.Called()

	var r0 []models.DeviceProfile
	if rf, ok := ret.Get(0).(func() []models.DeviceProfile); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]models.DeviceProfile)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func() error); ok {
		r1 = rf()
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
1127688
func (_m *DBClient) GetDevicesByServiceId(sid string) ([]models.Device, error) {
	ret := _m.Called(sid)

	var r0 []models.Device
	if rf, ok := ret.Get(0).(func(string) []models.Device); ok {
		r0 = rf(sid)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]models.Device)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string) error); ok {
		r1 = rf(sid)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
330998
func (_m *DBClient) ReadingsByDeviceAndValueDescriptor(deviceId string, valueDescriptor string, limit int) ([]models.Reading, error) {
	ret := _m.Called(deviceId, valueDescriptor, limit)

	var r0 []models.Reading
	if rf, ok := ret.Get(0).(func(string, string, int) []models.Reading); ok {
		r0 = rf(deviceId, valueDescriptor, limit)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]models.Reading)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string, string, int) error); ok {
		r1 = rf(deviceId, valueDescriptor, limit)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}