示例#1
0
文件: mock.go 项目: elleFlorio/gru
func setResources(totCpu int64, totMem string, usedCpu int64, usedMem string) {
	totMemB, _ := utils.RAMInBytes(totMem)
	usedMemB, _ := utils.RAMInBytes(usedMem)
	resources.Memory.Total = totMemB
	resources.Memory.Used = usedMemB
	resources.CPU.Total = totCpu
	resources.CPU.Used = usedCpu
}
示例#2
0
func createMemory(memory string) int64 {
	memInBytes, err := utils.RAMInBytes(memory)
	if err != nil {
		log.Debugln("Creating Host config: Memory limit not specified")
		return 0
	}

	return memInBytes
}
示例#3
0
func AvailableResourcesService(name string) float64 {
	var err error

	nodeCpu := resources.CPU.Total
	nodeUsedCpu := resources.CPU.Used
	nodeMem := resources.Memory.Total
	nodeUsedMem := resources.Memory.Used

	srv, _ := service.GetServiceByName(name)
	srvCpu := srv.Docker.CPUnumber
	log.WithFields(log.Fields{
		"service": name,
		"cpus":    srvCpu,
	}).Debugln("Service cpu resources")

	var srvMem int64
	if srv.Docker.Memory != "" {
		srvMem, err = utils.RAMInBytes(srv.Docker.Memory)
		if err != nil {
			log.WithField("err", err).Warnln("Cannot convert service RAM in Bytes.")
			return 0.0
		}
	} else {
		srvMem = 0
	}

	if nodeCpu < int64(srvCpu) || nodeMem < int64(srvMem) {
		return 0.0
	}

	if (nodeCpu-nodeUsedCpu) < int64(srvCpu) || (nodeMem-nodeUsedMem) < int64(srvMem) {
		return 0.0
	}

	return 1.0
}