// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUStats
420190
func (c *Connect) GetCPUStats(cpuNum int, flags uint32) (*NodeCPUStats, error) {
	var cnparams C.int

	var err C.virError
	ret := C.virNodeGetCPUStatsWrapper(c.ptr, C.int(cpuNum), nil, &cnparams, C.uint(0), &err)
	if ret == -1 {
		return nil, makeError(&err)
	}

	params := make([]C.virNodeCPUStats, cnparams)
	ret = C.virNodeGetCPUStatsWrapper(c.ptr, C.int(cpuNum), (*C.virNodeCPUStats)(unsafe.Pointer(&params[0])), &cnparams, C.uint(flags), &err)
	if ret == -1 {
		return nil, makeError(&err)
	}

	stats := &NodeCPUStats{}
	for i := 0; i < int(cnparams); i++ {
		param := params[i]
		field := C.GoString((*C.char)(unsafe.Pointer(&param.field)))
		switch field {
		case C.VIR_NODE_CPU_STATS_KERNEL:
			stats.KernelSet = true
			stats.Kernel = uint64(param.value)
		case C.VIR_NODE_CPU_STATS_USER:
			stats.UserSet = true
			stats.User = uint64(param.value)
		case C.VIR_NODE_CPU_STATS_IDLE:
			stats.IdleSet = true
			stats.Idle = uint64(param.value)
		case C.VIR_NODE_CPU_STATS_IOWAIT:
			stats.IowaitSet = true
			stats.Iowait = uint64(param.value)
		case C.VIR_NODE_CPU_STATS_INTR:
			stats.IntrSet = true
			stats.Intr = uint64(param.value)
		case C.VIR_NODE_CPU_STATS_UTILIZATION:
			stats.UtilizationSet = true
			stats.Utilization = uint64(param.value)
		}
	}

	return stats, nil
}
593987
func (c *Connect) GetStoragePoolCapabilities(flags uint32) (string, error) {
	if C.LIBVIR_VERSION_NUMBER < 5002000 {
		return "", makeNotImplementedError("virConnectGetStoragePoolCapabilities")
	}

	var err C.virError
	ret := C.virConnectGetStoragePoolCapabilitiesWrapper(c.ptr, C.uint(flags), &err)
	if ret == nil {
		return "", makeError(&err)
	}

	defer C.free(unsafe.Pointer(ret))

	return C.GoString(ret), nil
}
621519
func GetPorts(lookupPids bool) map[string][]GOnetstat.Process {
	ports := make(map[string][]GOnetstat.Process)
	netstat, _ := GOnetstat.Tcp(lookupPids)
	var net string
	//netPorts := make(map[string]GOnetstat.Process)
	//ports["tcp"] = netPorts
	net = "tcp"
	for _, entry := range netstat {
		if entry.State == "LISTEN" {
			port := strconv.FormatInt(entry.Port, 10)
			ports[net+":"+port] = append(ports[net+":"+port], entry)
		}
	}
	netstat, _ = GOnetstat.Tcp6(lookupPids)
	//netPorts = make(map[string]GOnetstat.Process)
	//ports["tcp6"] = netPorts
	net = "tcp6"
	for _, entry := range netstat {
		if entry.State == "LISTEN" {
			port := strconv.FormatInt(entry.Port, 10)
			ports[net+":"+port] = append(ports[net+":"+port], entry)
		}
	}
	netstat, _ = GOnetstat.Udp(lookupPids)
	//netPorts = make(map[string]GOnetstat.Process)
	//ports["udp"] = netPorts
	net = "udp"
	for _, entry := range netstat {
		port := strconv.FormatInt(entry.Port, 10)
		ports[net+":"+port] = append(ports[net+":"+port], entry)
	}
	netstat, _ = GOnetstat.Udp6(lookupPids)
	//netPorts = make(map[string]GOnetstat.Process)
	//ports["udp6"] = netPorts
	net = "udp6"
	for _, entry := range netstat {
		port := strconv.FormatInt(entry.Port, 10)
		ports[net+":"+port] = append(ports[net+":"+port], entry)
	}
	return ports
}
941032
func (qri *QueryRespItem) getSortedTimestampStrs() []string {
	timestampStrs := make([]string, 0)
	for timestampStr := range qri.Dps {
		timestampStrs = append(timestampStrs, timestampStr)
	}
	sort.Strings(timestampStrs)
	return timestampStrs
}
834618
func GetDisks(ctx types.Context) (map[string]string, error) {
	disksJSON, err := getMetadata(ctx, diskURL)
	if err != nil {
		return nil, err
	}

	disks := make(map[string]string)
	diskList := make([]*Disk, 1, 1)

	// TODO: fix taking the bytes from original request being returned
	// as a string, only to be cast back to byte here
	err = json.Unmarshal([]byte(disksJSON), &diskList)
	if err != nil {
		return nil, err
	}

	for _, disk := range diskList {
		disks[disk.DeviceName] = disk.DeviceName
	}

	return disks, nil
}
315204
func getVIPs(svcs []vip) []string {
	result := []string{}
	for _, svc := range svcs {
		result = appendIfMissing(result, svc.IP)
	}

	return result
}
1096859
func (c *RedisCache) GetGobBytes(key string) ([]byte, bool) {
	item, ok := c.getGobItem(key)
	switch {
	case !ok:
		return nil, false
	case item.Value == nil:
		return nil, false
	}

	var buf bytes.Buffer
	enc := gob.NewEncoder(&buf)
	err := enc.Encode(item.Value)
	if err != nil {
		return nil, false
	}

	return buf.Bytes(), true
}
201647
func (client *Client) GetBuildpacks(filters ...Filter) ([]Buildpack, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetBuildpacksRequest,
		Query:       ConvertFilterParameters(filters),
	})

	if err != nil {
		return nil, nil, err
	}

	var buildpacks []Buildpack
	warnings, err := client.paginate(request, Buildpack{}, func(item interface{}) error {
		if buildpack, ok := item.(Buildpack); ok {
			buildpacks = append(buildpacks, buildpack)
		} else {
			return ccerror.UnknownObjectInListError{
				Expected:   Buildpack{},
				Unexpected: item,
			}
		}
		return nil
	})

	return buildpacks, warnings, err
}
1088815
func GetFreeTCPPorts(n int, offset ...int) (PortList, error) {
	list := make(PortList, 0, n)
	start := PortStartingNumber
	if len(offset) != 0 {
		start = offset[0]
	}
	for i := start; i < start+n; i++ {
		list = append(list, strconv.Itoa(i))
	}
	return list, nil
}
319880
func (r Hardware_SecurityModule750) GetVirtualLicenses() (resp []datatypes.Software_VirtualLicense, err error) {
	err = r.Session.DoRequest("SoftLayer_Hardware_SecurityModule750", "getVirtualLicenses", nil, &r.Options, &resp)
	return
}
1058640
func (api *RoutersAPI) GetSubnets(routerID string, options *SubnetGetOptions) (result *Subnets, err error) {
	uri := api.client.Endpoint + routerUrl + routerID + "/subnets"
	if options != nil {
		uri += getQueryString(options)
	}
	res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
	if err != nil {
		return
	}

	result = &Subnets{}
	err = json.Unmarshal(res, result)
	return
}
365526
func (u *FakeAPIUtil) GetAndResetDeletedPVs() map[string]*v1.PersistentVolume {
	deletedPVs := u.deletedPVs
	u.deletedPVs = map[string]*v1.PersistentVolume{}
	return deletedPVs
}
893278
func (c *Connect) GetCPUMap(flags uint32) (map[int]bool, uint, error) {
	var ccpumap *C.uchar
	var conline C.uint
	var err C.virError
	ret := C.virNodeGetCPUMapWrapper(c.ptr, &ccpumap, &conline, C.uint(flags), &err)
	if ret == -1 {
		return map[int]bool{}, 0, makeError(&err)
	}
	defer C.free(unsafe.Pointer(ccpumap))

	cpumapbytes := C.GoBytes(unsafe.Pointer(ccpumap), C.int(ret/8))

	cpumap := make(map[int]bool, 0)
	for i := 0; i < int(ret); i++ {
		idx := int(i / 8)
		val := byte(cpumapbytes[idx])
		shift := i % 8
		cpumap[i] = (val & (1 << uint(shift))) == 1
	}

	return cpumap, uint(conline), nil
}
192225
func (c Client) GetPartitions(appName, serviceName string) (*PartitionItemsPage, error) {
	var aggregatePartitionItemsPages PartitionItemsPage
	var continueToken string
	for {
		basePath := "Applications/" + appName + "/$/GetServices/" + serviceName + "/$/GetPartitions/"
		res, err := c.getHTTP(basePath, withContinue(continueToken))
		if err != nil {
			return nil, err
		}

		var partitionsItemsPage PartitionItemsPage
		err = json.Unmarshal(res, &partitionsItemsPage)
		if err != nil {
			return nil, fmt.Errorf("could not deserialise JSON response: %+v", err)
		}

		aggregatePartitionItemsPages.Items = append(aggregatePartitionItemsPages.Items, partitionsItemsPage.Items...)

		continueToken = getString(partitionsItemsPage.ContinuationToken)
		if continueToken == "" {
			break
		}
	}
	return &aggregatePartitionItemsPages, nil
}
748367
func (document *Document) GetPartPageRectangles() []image.Rectangle {
	var rectangles []image.Rectangle
	rawRectangles := C.GoString(C.get_part_page_rectangles(document.handle))
	pageRectangles := strings.Split(rawRectangles, ";")
	for _, points := range pageRectangles {
		var intPoints []int
		strPoints := strings.Split(points, ",")
		for _, point := range strPoints {
			point = strings.Trim(point, " ")
			i, _ := strconv.Atoi(point)
			intPoints = append(intPoints, i)
		}
		x0, y0 := intPoints[0], intPoints[1]
		x1, y1 := x0+intPoints[2], y0+intPoints[3]
		rectangles = append(rectangles, image.Rect(x0, y0, x1, y1))
	}
	return rectangles
}
1157794
func (c *Connect) GetFreePages(pageSizes []uint64, startCell int, maxCells uint, flags uint32) ([]uint64, error) {
	if C.LIBVIR_VERSION_NUMBER < 1002006 {
		return []uint64{}, makeNotImplementedError("virNodeGetFreePages")
	}
	cpageSizes := make([]C.uint, len(pageSizes))
	ccounts := make([]C.ulonglong, len(pageSizes)*int(maxCells))

	for i := 0; i < len(pageSizes); i++ {
		cpageSizes[i] = C.uint(pageSizes[i])
	}

	var err C.virError
	ret := C.virNodeGetFreePagesWrapper(c.ptr, C.uint(len(pageSizes)), (*C.uint)(unsafe.Pointer(&cpageSizes)), C.int(startCell),
		C.uint(maxCells), (*C.ulonglong)(unsafe.Pointer(&ccounts)), C.uint(flags), &err)
	if ret == -1 {
		return []uint64{}, makeError(&err)
	}

	counts := make([]uint64, ret)
	for i := 0; i < int(ret); i++ {
		counts[i] = uint64(ccounts[i])
	}

	return counts, nil
}
751221
func (r *runtimeOCI) libcontainerStats(ctr *Container) (*libcontainer.Stats, error) {
	factory, err := loadFactory(r.root)
	if err != nil {
		return nil, err
	}
	container, err := factory.Load(ctr.ID())
	if err != nil {
		return nil, err
	}
	return container.Stats()
}