當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Quantity.Value方法代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/api/resource.Quantity.Value方法的典型用法代碼示例。如果您正苦於以下問題:Golang Quantity.Value方法的具體用法?Golang Quantity.Value怎麽用?Golang Quantity.Value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在k8s/io/kubernetes/pkg/api/resource.Quantity的用法示例。


在下文中一共展示了Quantity.Value方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: formatImageStreamQuota

func formatImageStreamQuota(out *tabwriter.Writer, c client.Interface, kc kclient.Interface, stream *imageapi.ImageStream) {
	quotas, err := kc.ResourceQuotas(stream.Namespace).List(api.ListOptions{})
	if err != nil {
		return
	}

	var limit *resource.Quantity
	for _, item := range quotas.Items {
		// search for smallest ImageStream quota
		if value, ok := item.Spec.Hard[imageapi.ResourceImageStreamSize]; ok {
			if limit == nil || limit.Cmp(value) > 0 {
				limit = &value
			}
		}
	}
	if limit != nil {
		quantity := imagequota.GetImageStreamSize(c, stream, make(map[string]*imageapi.Image))
		scale := mega
		if quantity.Value() >= (1<<giga.scale) || limit.Value() >= (1<<giga.scale) {
			scale = giga
		}
		formatString(out, "Quota Usage", fmt.Sprintf("%s / %s",
			formatQuantity(quantity, scale), formatQuantity(limit, scale)))
	}
}
開發者ID:poomsujarit,項目名稱:origin,代碼行數:25,代碼來源:helpers.go

示例2: limitRequestRatioConstraint

// limitRequestRatioConstraint enforces the limit to request ratio over the specified resource
func limitRequestRatioConstraint(limitType api.LimitType, resourceName api.ResourceName, enforced resource.Quantity, request api.ResourceList, limit api.ResourceList) error {
	req, reqExists := request[resourceName]
	lim, limExists := limit[resourceName]
	observedReqValue, observedLimValue, _ := requestLimitEnforcedValues(req, lim, enforced)

	if !reqExists || (observedReqValue == int64(0)) {
		return fmt.Errorf("%s max limit to request ratio per %s is %s, but no request is specified or request is 0.", resourceName, limitType, enforced.String())
	}
	if !limExists || (observedLimValue == int64(0)) {
		return fmt.Errorf("%s max limit to request ratio per %s is %s, but no limit is specified or limit is 0.", resourceName, limitType, enforced.String())
	}

	observedRatio := float64(observedLimValue) / float64(observedReqValue)
	displayObservedRatio := observedRatio
	maxLimitRequestRatio := float64(enforced.Value())
	if enforced.Value() <= resource.MaxMilliValue {
		observedRatio = observedRatio * 1000
		maxLimitRequestRatio = float64(enforced.MilliValue())
	}

	if observedRatio > maxLimitRequestRatio {
		return fmt.Errorf("%s max limit to request ratio per %s is %s, but provided ratio is %f.", resourceName, limitType, enforced.String(), displayObservedRatio)
	}

	return nil
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:27,代碼來源:admission.go

示例3: calculatePodScore

// Calculates score for all pods and returns podInfo structure.
// Score is defined as cpu_sum/node_capacity + mem_sum/node_capacity.
// Pods that have bigger requirements should be processed first, thus have higher scores.
func calculatePodScore(pods []*apiv1.Pod, nodeTemplate *schedulercache.NodeInfo) []*podInfo {
	podInfos := make([]*podInfo, 0, len(pods))

	for _, pod := range pods {
		cpuSum := resource.Quantity{}
		memorySum := resource.Quantity{}

		for _, container := range pod.Spec.Containers {
			if request, ok := container.Resources.Requests[apiv1.ResourceCPU]; ok {
				cpuSum.Add(request)
			}
			if request, ok := container.Resources.Requests[apiv1.ResourceMemory]; ok {
				memorySum.Add(request)
			}
		}
		score := float64(0)
		if cpuAllocatable, ok := nodeTemplate.Node().Status.Allocatable[apiv1.ResourceCPU]; ok && cpuAllocatable.MilliValue() > 0 {
			score += float64(cpuSum.MilliValue()) / float64(cpuAllocatable.MilliValue())
		}
		if memAllocatable, ok := nodeTemplate.Node().Status.Allocatable[apiv1.ResourceMemory]; ok && memAllocatable.Value() > 0 {
			score += float64(memorySum.Value()) / float64(memAllocatable.Value())
		}

		podInfos = append(podInfos, &podInfo{
			score: score,
			pod:   pod,
		})
	}
	return podInfos
}
開發者ID:kubernetes,項目名稱:contrib,代碼行數:33,代碼來源:binpacking_estimator.go

示例4: addCpuLimit

func addCpuLimit(opts []*unit.UnitOption, limit *resource.Quantity) ([]*unit.UnitOption, error) {
	if limit.Value() > resource.MaxMilliValue {
		return nil, fmt.Errorf("cpu limit exceeds the maximum millivalue: %v", limit.String())
	}
	quota := strconv.Itoa(int(limit.MilliValue()/10)) + "%"
	opts = append(opts, unit.NewUnitOption("Service", "CPUQuota", quota))
	return opts, nil
}
開發者ID:sinfomicien,項目名稱:rkt,代碼行數:8,代碼來源:cgroup.go

示例5: validateBandwidthIsReasonable

func validateBandwidthIsReasonable(rsrc *resource.Quantity) error {
	if rsrc.Value() < minRsrc.Value() {
		return fmt.Errorf("resource is unreasonably small (< 1kbit)")
	}
	if rsrc.Value() > maxRsrc.Value() {
		return fmt.Errorf("resoruce is unreasonably large (> 1Pbit)")
	}
	return nil
}
開發者ID:CodeJuan,項目名稱:kubernetes,代碼行數:9,代碼來源:utils.go

示例6: printSingleResourceUsage

func printSingleResourceUsage(out io.Writer, resourceType api.ResourceName, quantity resource.Quantity) {
	switch resourceType {
	case api.ResourceCPU:
		fmt.Fprintf(out, "%vm", quantity.MilliValue())
	case api.ResourceMemory:
		fmt.Fprintf(out, "%vMi", quantity.Value()/(1024*1024))
	default:
		fmt.Fprintf(out, "%v", quantity.Value())
	}
}
開發者ID:alex-mohr,項目名稱:kubernetes,代碼行數:10,代碼來源:metrics_printer.go

示例7: formatQuantity

// formatQuantity prints quantity according to passed scale. Manual scaling was
// done here to make sure we print correct binary values for quantity.
func formatQuantity(quantity *resource.Quantity, scale scale) string {
	integer := quantity.Value() >> scale.scale
	// fraction is the reminder of a division shifted by one order of magnitude
	fraction := (quantity.Value() % (1 << scale.scale)) >> (scale.scale - 10)
	// additionally we present only 2 digits after dot, so divide by 10
	fraction = fraction / 10
	if fraction > 0 {
		return fmt.Sprintf("%d.%02d%s", integer, fraction, scale.unit)
	}
	return fmt.Sprintf("%d%s", integer, scale.unit)
}
開發者ID:poomsujarit,項目名稱:origin,代碼行數:13,代碼來源:helpers.go

示例8: printSingleResourceUsage

func printSingleResourceUsage(out io.Writer, resourceType v1.ResourceName, quantity resource.Quantity) {
	switch resourceType {
	case v1.ResourceCPU:
		fmt.Fprintf(out, "%vm", quantity.MilliValue())
	case v1.ResourceMemory:
		fmt.Fprintf(out, "%vMi", quantity.Value()/(1024*1024))
	case v1.ResourceStorage:
		// TODO: Change it after storage metrics collection is finished.
		fmt.Fprint(out, "-")
	default:
		fmt.Fprintf(out, "%v", quantity.Value())
	}
}
開發者ID:AdoHe,項目名稱:kubernetes,代碼行數:13,代碼來源:metrics_printer.go

示例9: RunApplyQuotaCommand

func (cr *realQuotaCommandRunner) RunApplyQuotaCommand(fsDevice string, quota resource.Quantity, fsGroup int64) (string, string, error) {
	args := []string{"-x", "-c",
		fmt.Sprintf("limit -g bsoft=%d bhard=%d %d", quota.Value(), quota.Value(), fsGroup),
		fsDevice,
	}

	cmd := exec.Command("xfs_quota", args...)
	var stderr bytes.Buffer
	cmd.Stderr = &stderr

	err := cmd.Run()
	glog.V(5).Infof("Ran: xfs_quota %s", args)
	return "", stderr.String(), err
}
開發者ID:carriercomm,項目名稱:origin,代碼行數:14,代碼來源:quota.go

示例10: applyQuota

func (xqa *xfsQuotaApplicator) applyQuota(volDevice string, quota resource.Quantity, fsGroupID int64) error {
	_, stderr, err := xqa.cmdRunner.RunApplyQuotaCommand(volDevice, quota, fsGroupID)
	if err != nil {
		return err
	}
	// xfs_quota is very happy to fail but return a success code, likely due to its
	// interactive shell approach. Grab stderr, if we see anything written to it we'll
	// consider this an error.
	if len(stderr) > 0 {
		return fmt.Errorf("xfs_quota wrote to stderr: %s", stderr)
	}

	glog.V(4).Infof("XFS quota applied: device=%s, quota=%d, fsGroup=%d", volDevice, quota.Value(), fsGroupID)
	return nil
}
開發者ID:carriercomm,項目名稱:origin,代碼行數:15,代碼來源:quota.go

示例11: newPodMemoryStats

func newPodMemoryStats(pod *api.Pod, workingSet resource.Quantity) statsapi.PodStats {
	result := statsapi.PodStats{
		PodRef: statsapi.PodReference{
			Name: pod.Name, Namespace: pod.Namespace, UID: string(pod.UID),
		},
	}
	for range pod.Spec.Containers {
		workingSetBytes := uint64(workingSet.Value())
		result.Containers = append(result.Containers, statsapi.ContainerStats{
			Memory: &statsapi.MemoryStats{
				WorkingSetBytes: &workingSetBytes,
			},
		})
	}
	return result
}
開發者ID:odacremolbap,項目名稱:kubernetes,代碼行數:16,代碼來源:helpers_test.go

示例12: applyQuota

func (xqa *xfsQuotaApplicator) applyQuota(volDevice string, quota resource.Quantity, fsGroupID int64) error {
	_, stderr, err := xqa.cmdRunner.RunApplyQuotaCommand(volDevice, quota, fsGroupID)

	// xfs_quota is very happy to fail but return a success code, likely due to its
	// interactive shell approach. Grab stderr, if we see anything written to it we'll
	// consider this an error.
	//
	// If we exit non-zero *and* write to stderr, stderr is likely to have the details on what
	// actually went wrong, so we'll use this as the error message instead.
	if len(stderr) > 0 {
		return fmt.Errorf("error applying quota: %s", stderr)
	}

	if err != nil {
		return fmt.Errorf("error applying quota: %v", err)
	}

	glog.V(4).Infof("XFS quota applied: device=%s, quota=%d, fsGroup=%d", volDevice, quota.Value(), fsGroupID)
	return nil
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:20,代碼來源:quota.go

示例13: newPodDiskStats

// newPodDiskStats returns stats with specified usage amounts.
func newPodDiskStats(pod *api.Pod, rootFsUsed, logsUsed, perLocalVolumeUsed resource.Quantity) statsapi.PodStats {
	result := statsapi.PodStats{
		PodRef: statsapi.PodReference{
			Name: pod.Name, Namespace: pod.Namespace, UID: string(pod.UID),
		},
	}

	rootFsUsedBytes := uint64(rootFsUsed.Value())
	logsUsedBytes := uint64(logsUsed.Value())
	for range pod.Spec.Containers {
		result.Containers = append(result.Containers, statsapi.ContainerStats{
			Rootfs: &statsapi.FsStats{
				UsedBytes: &rootFsUsedBytes,
			},
			Logs: &statsapi.FsStats{
				UsedBytes: &logsUsedBytes,
			},
		})
	}

	perLocalVolumeUsedBytes := uint64(perLocalVolumeUsed.Value())
	for _, volumeName := range localVolumeNames(pod) {
		result.VolumeStats = append(result.VolumeStats, statsapi.VolumeStats{
			Name: volumeName,
			FsStats: statsapi.FsStats{
				UsedBytes: &perLocalVolumeUsedBytes,
			},
		})
	}

	return result
}
開發者ID:AdoHe,項目名稱:kubernetes,代碼行數:33,代碼來源:helpers_test.go

示例14: requestLimitEnforcedValues

// requestLimitEnforcedValues returns the specified values at a common precision to support comparability
func requestLimitEnforcedValues(requestQuantity, limitQuantity, enforcedQuantity resource.Quantity) (request, limit, enforced int64) {
	request = requestQuantity.Value()
	limit = limitQuantity.Value()
	enforced = enforcedQuantity.Value()
	// do a more precise comparison if possible (if the value won't overflow)
	if request <= resource.MaxMilliValue && limit <= resource.MaxMilliValue && enforced <= resource.MaxMilliValue {
		request = requestQuantity.MilliValue()
		limit = limitQuantity.MilliValue()
		enforced = enforcedQuantity.MilliValue()
	}
	return
}
開發者ID:jpartner,項目名稱:kubernetes,代碼行數:13,代碼來源:admission.go

示例15: makeKBitString

func makeKBitString(rsrc *resource.Quantity) string {
	return fmt.Sprintf("%dkbit", (rsrc.Value() / 1000))
}
開發者ID:CodeJuan,項目名稱:kubernetes,代碼行數:3,代碼來源:linux.go


注:本文中的k8s/io/kubernetes/pkg/api/resource.Quantity.Value方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。