// ParseDeviceTopic parses an MQTT device topic string to a DeviceTopic struct
331633
func ParseDeviceTopic(topic string) (*DeviceTopic, error) {
	pattern := regexp.MustCompile("^([0-9a-z](?:[_-]?[0-9a-z]){1,35}|\\+)/(devices)/([0-9a-z](?:[_-]?[0-9a-z]){1,35}|\\+)/(events|up|down)([0-9a-z/]+)?$")
	matches := pattern.FindStringSubmatch(topic)
	if len(matches) < 5 {
		return nil, fmt.Errorf("Invalid topic format")
	}
	var appID string
	if matches[1] != simpleWildcard {
		appID = matches[1]
	}
	var devID string
	if matches[3] != simpleWildcard {
		devID = matches[3]
	}
	topicType := DeviceTopicType(matches[4])
	deviceTopic := &DeviceTopic{appID, devID, topicType, ""}
	if (topicType == DeviceUplink || topicType == DeviceEvents) && len(matches) > 5 {
		deviceTopic.Field = strings.Trim(matches[5], "/")
	}
	return deviceTopic, nil
}
368183
func (ebs *awsElasticBlockStore) GetPodDeviceMapPath() (string, string) {
	name := awsElasticBlockStorePluginName
	return ebs.plugin.host.GetPodVolumeDeviceDir(ebs.podUID, utilstrings.EscapeQualifiedName(name)), ebs.volName
}
397905
func BootstrapActiveDeviceWithMetaContextAndAssertUID(m MetaContext, uid keybase1.UID) (ok bool, err error) {
	_, err = bootstrapActiveDeviceFromConfigReturnRawError(m, true, uid)
	switch err.(type) {
	case nil:
		return true, nil
	case LoginRequiredError:
		return false, nil
	case UIDMismatchError:
		return false, nil
	case NoUIDError:
		return false, nil
	default:
		if err == ErrUnlockNotPossible {
			return false, nil
		}
		return false, err
	}
}
455617
func (d *DeviceMapperDriver) resizeDevice(deviceHash string, size uint64) error {
	var devInfo devInfo
	if err := d.readDeviceInfo(deviceHash, &devInfo); err != nil {
		glog.Errorf("Could not read info for device %s: %s", deviceHash, err)
		return err
	}
	devInfo.Size = size
	if err := d.writeDeviceInfo(deviceHash, devInfo); err != nil {
		glog.Errorf("Could not write info for device %s: %s", deviceHash, err)
		return err
	}
	return nil
}
1252050
func (c *Client) ReleaseDedicatedPod(p *ReleaseDedicatedPodParameter) (*Result, error) {
	obj, err := c.Request("releaseDedicatedPod", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Result), err
}
787344
func ExtractSortFacetValuesBy(opts ...interface{}) *opt.SortFacetValuesByOption {
	for _, o := range opts {
		if v, ok := o.(*opt.SortFacetValuesByOption); ok {
			return v
		}
	}
	return nil
}
299398
func RemoveDevice(deviceName string, opts ...RemoveDeviceOpt) error {
	args := []string{
		"remove",
	}

	for _, opt := range opts {
		args = append(args, string(opt))
	}

	args = append(args, GetFullDevicePath(deviceName))

	_, err := dmsetup(args...)
	return err
}
131248
func (devices *DeviceSet) removeDevice(devname string) error {
	var err error

	logrus.WithField("storage-driver", "devicemapper").Debugf("removeDevice START(%s)", devname)
	defer logrus.WithField("storage-driver", "devicemapper").Debugf("removeDevice END(%s)", devname)

	for i := 0; i < 200; i++ {
		err = devicemapper.RemoveDevice(devname)
		if err == nil {
			break
		}
		if err != devicemapper.ErrBusy {
			return err
		}

		// If we see EBUSY it may be a transient error,
		// sleep a bit a retry a few times.
		devices.Unlock()
		time.Sleep(100 * time.Millisecond)
		devices.Lock()
	}

	return err
}
523650
func getBridgedDeviceKV(keyname, propname string) ([]ifKeyValue, error) {
	kvs := []ifKeyValue{}
	if keyname == "" || propname == "" {
		return kvs, nil
	}

	stdout, _, err := runner.Run("list", "bridgedifs")
	if err != nil {
		return kvs, err
	}
	matches := networkRegexp.FindAllString(stdout, -1)
	if len(matches) < 1 {
		return kvs, nil
	}

	keyid := strings.TrimSuffix(keyname, ":") + ":"
	propid := strings.TrimSuffix(propname, ":") + ":"
	// Each match is a device
	for _, device := range matches {
		var kv ifKeyValue
		// Find the record that contains keyname and retrieve propname value.
		for _, line := range strings.Split(device, "\n") {
			if strings.Contains(line, keyid) {
				kv.k = strings.TrimSpace(strings.TrimPrefix(line, keyid))
			} else if strings.Contains(line, propid) {
				kv.v = strings.TrimSpace(strings.TrimPrefix(line, propid))
			}
			if kv.k != "" && kv.v != "" {
				kvs = append(kvs, kv)
				break
			}
		}
	}
	return kvs, nil
}
1155969
func GetBridgedDeviceNameIPMap() (map[string]string, error) {
	m := map[string]string{}
	kvs, err := getBridgedDeviceKV("Name", "IPAddress")
	if err != nil {
		return m, err
	}
	for _, kv := range kvs {
		if kv.k != "" {
			m[kv.k] = kv.v
		}
	}
	return m, nil
}
109382
func (cd *cinderVolume) GetPodDeviceMapPath() (string, string) {
	name := cinderVolumePluginName
	return cd.plugin.host.GetPodVolumeDeviceDir(cd.podUID, utilstrings.EscapeQualifiedName(name)), cd.volName
}
343303
func (c *ClusterInfo) GetNSQDTopics(nsqdHTTPAddrs []string) ([]string, error) {
	var topics []string
	var lock sync.Mutex
	var wg sync.WaitGroup
	var errs []error

	type respType struct {
		Topics []struct {
			Name string `json:"topic_name"`
		} `json:"topics"`
	}

	for _, addr := range nsqdHTTPAddrs {
		wg.Add(1)
		go func(addr string) {
			defer wg.Done()

			endpoint := fmt.Sprintf("http://%s/stats?format=json", addr)
			c.logf("CI: querying nsqd %s", endpoint)

			var resp respType
			err := c.client.GETV1(endpoint, &resp)
			if err != nil {
				lock.Lock()
				errs = append(errs, err)
				lock.Unlock()
				return
			}

			lock.Lock()
			defer lock.Unlock()
			for _, topic := range resp.Topics {
				topics = stringy.Add(topics, topic.Name)
			}
		}(addr)
	}
	wg.Wait()

	if len(errs) == len(nsqdHTTPAddrs) {
		return nil, fmt.Errorf("Failed to query any nsqd: %s", ErrList(errs))
	}

	sort.Strings(topics)

	if len(errs) > 0 {
		return topics, ErrList(errs)
	}
	return topics, nil
}
552001
func NewDeviceApprovalsChangeDesktopPolicyType(Description string) *DeviceApprovalsChangeDesktopPolicyType {
	s := new(DeviceApprovalsChangeDesktopPolicyType)
	s.Description = Description
	return s
}
128596
func parseDefaultIfNameFromIPCmdAndroid(routeOut string) (string, error) {
	parsedLines := parseIfNameFromIPCmd(routeOut)
	if (len(parsedLines) > 0) {
		ifName := strings.TrimSpace(parsedLines[0][4])
		return ifName, nil
	}

	return "", errors.New("No default interface found")
}
661903
func deviceStatsToDatapoints(stats []IODeviceStats, prefix string, baseTags map[string]string, ts string) []producers.Datapoint {
	var datapoints []producers.Datapoint

	for _, stat := range stats {
		dev := devTotal
		if stat.Device.Major > 0 {
			dev = fmt.Sprintf("%d:%d", stat.Device.Major, stat.Device.Minor)
		}
		// Create a new tags map for these datapoints
		tags := map[string]string{blkioDevice: dev}
		for k, v := range baseTags {
			tags[k] = v
		}
		datapoints = append(datapoints, statValuesToDatapoints(stat.Serviced, prefix+"."+serviced, tags, ts)...)
		datapoints = append(datapoints, statValuesToDatapoints(stat.ServiceBytes, prefix+"."+serviceBytes, tags, ts)...)
		datapoints = append(datapoints, statValuesToDatapoints(stat.ServiceTime, prefix+"."+serviceTime, tags, ts)...)
		datapoints = append(datapoints, statValuesToDatapoints(stat.Merged, prefix+"."+merged, tags, ts)...)
		datapoints = append(datapoints, statValuesToDatapoints(stat.Queued, prefix+"."+queued, tags, ts)...)
		datapoints = append(datapoints, statValuesToDatapoints(stat.WaitTime, prefix+"."+waitTime, tags, ts)...)
	}

	return datapoints
}
1014818
func (mc MongoClient) ReadingsByDeviceAndValueDescriptor(deviceId, valueDescriptor string, limit int) ([]contract.Reading, error) {
	return mapReadings(mc.getReadingsLimit(bson.M{"device": deviceId, "name": valueDescriptor}, limit))
}
346215
func NewSPIDevice(bus int, chipSelect int) *SPIDevice {
	spi := new(SPIDevice)
	spi.Bus = bus
	spi.Chip = chipSelect

	return spi
}