本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource.NewQuantity函数的典型用法代码示例。如果您正苦于以下问题:Golang NewQuantity函数的具体用法?Golang NewQuantity怎么用?Golang NewQuantity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewQuantity函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: parseMesosState
func parseMesosState(blob []byte) (*mesosState, error) {
type State struct {
ClusterName string `json:"cluster"`
Slaves []*struct {
Id string `json:"id"` // ex: 20150106-162714-3815890698-5050-2453-S2
Pid string `json:"pid"` // ex: slave(1)@10.22.211.18:5051
Hostname string `json:"hostname"` // ex: 10.22.211.18, or slave-123.nowhere.com
Resources map[string]interface{} `json:"resources"` // ex: {"mem": 123, "ports": "[31000-3200]"}
} `json:"slaves"`
}
state := &State{ClusterName: defaultClusterName}
if err := json.Unmarshal(blob, state); err != nil {
return nil, err
}
nodes := []*slaveNode{}
for _, slave := range state.Slaves {
if slave.Hostname == "" {
continue
}
node := &slaveNode{hostname: slave.Hostname}
cap := api.ResourceList{}
if slave.Resources != nil && len(slave.Resources) > 0 {
// attempt to translate CPU (cores) and memory (MB) resources
if cpu, found := slave.Resources["cpus"]; found {
if cpuNum, ok := cpu.(float64); ok {
cap[api.ResourceCPU] = *resource.NewQuantity(int64(cpuNum), resource.DecimalSI)
} else {
log.Warningf("unexpected slave cpu resource type %T: %v", cpu, cpu)
}
} else {
log.Warningf("slave failed to report cpu resource")
}
if mem, found := slave.Resources["mem"]; found {
if memNum, ok := mem.(float64); ok {
cap[api.ResourceMemory] = *resource.NewQuantity(int64(memNum), resource.BinarySI)
} else {
log.Warningf("unexpected slave mem resource type %T: %v", mem, mem)
}
} else {
log.Warningf("slave failed to report mem resource")
}
}
if len(cap) > 0 {
node.resources = &api.NodeResources{
Capacity: cap,
}
log.V(4).Infof("node %q reporting capacity %v", node.hostname, cap)
}
nodes = append(nodes, node)
}
result := &mesosState{
clusterName: state.ClusterName,
nodes: nodes,
}
return result, nil
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:58,代码来源:client.go
示例2: makeResources
func makeResources(milliCPU int64, memory int64, pods int64) api.NodeResources {
return api.NodeResources{
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(milliCPU, resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(memory, resource.BinarySI),
api.ResourcePods: *resource.NewQuantity(pods, resource.DecimalSI),
},
}
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:9,代码来源:predicates_test.go
示例3: TestGetResources
func TestGetResources(t *testing.T) {
instances := make([]ec2.Instance, 3)
instances[0].PrivateDNSName = "m3.medium"
instances[0].InstanceType = "m3.medium"
instances[0].State.Name = "running"
instances[1].PrivateDNSName = "r3.8xlarge"
instances[1].InstanceType = "r3.8xlarge"
instances[1].State.Name = "running"
instances[2].PrivateDNSName = "unknown.type"
instances[2].InstanceType = "unknown.type"
instances[2].State.Name = "running"
aws1 := mockInstancesResp(instances)
res1, err1 := aws1.GetNodeResources("m3.medium")
if err1 != nil {
t.Errorf("Should not error when instance type found: %v", err1)
}
e1 := &api.NodeResources{
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(int64(3.0*1000), resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(int64(3.75*1024*1024*1024), resource.BinarySI),
},
}
if !reflect.DeepEqual(e1, res1) {
t.Errorf("Expected %v, got %v", e1, res1)
}
res2, err2 := aws1.GetNodeResources("r3.8xlarge")
if err2 != nil {
t.Errorf("Should not error when instance type found: %v", err2)
}
e2 := &api.NodeResources{
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(int64(104.0*1000), resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(int64(244.0*1024*1024*1024), resource.BinarySI),
},
}
if !reflect.DeepEqual(e2, res2) {
t.Errorf("Expected %v, got %v", e2, res2)
}
res3, err3 := aws1.GetNodeResources("unknown.type")
if err3 != nil {
t.Errorf("Should not error when unknown instance type")
}
if res3 != nil {
t.Errorf("Should return nil resources when unknown instance type")
}
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:50,代码来源:aws_test.go
示例4: ExampleFormat
func ExampleFormat() {
memorySize := resource.NewQuantity(5*1024*1024*1024, resource.BinarySI)
fmt.Printf("memorySize = %v\n", memorySize)
diskSize := resource.NewQuantity(5*1000*1000*1000, resource.DecimalSI)
fmt.Printf("diskSize = %v\n", diskSize)
cores := resource.NewMilliQuantity(5300, resource.DecimalSI)
fmt.Printf("cores = %v\n", cores)
// Output:
// memorySize = 5Gi
// diskSize = 5G
// cores = 5300m
}
开发者ID:eghobo,项目名称:kubedash,代码行数:15,代码来源:quantity_example_test.go
示例5: Instances
// Instances returns an implementation of Instances for OpenStack.
func (os *OpenStack) Instances() (cloudprovider.Instances, bool) {
glog.V(4).Info("openstack.Instances() called")
if err := openstack.Authenticate(os.provider, os.authOpts); err != nil {
glog.Warningf("Failed to reauthenticate: %v", err)
return nil, false
}
compute, err := openstack.NewComputeV2(os.provider, gophercloud.EndpointOpts{
Region: os.region,
})
if err != nil {
glog.Warningf("Failed to find compute endpoint: %v", err)
return nil, false
}
pager := flavors.ListDetail(compute, nil)
flavor_to_resource := make(map[string]*api.NodeResources)
err = pager.EachPage(func(page pagination.Page) (bool, error) {
flavorList, err := flavors.ExtractFlavors(page)
if err != nil {
return false, err
}
for _, flavor := range flavorList {
rsrc := api.NodeResources{
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewQuantity(int64(flavor.VCPUs), resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(int64(flavor.RAM)*MiB, resource.BinarySI),
"openstack.org/disk": *resource.NewQuantity(int64(flavor.Disk)*GB, resource.DecimalSI),
"openstack.org/rxTxFactor": *resource.NewMilliQuantity(int64(flavor.RxTxFactor)*1000, resource.DecimalSI),
"openstack.org/swap": *resource.NewQuantity(int64(flavor.Swap)*MiB, resource.BinarySI),
},
}
flavor_to_resource[flavor.ID] = &rsrc
}
return true, nil
})
if err != nil {
glog.Warningf("Failed to find compute flavors: %v", err)
return nil, false
}
glog.V(3).Infof("Found %v compute flavors", len(flavor_to_resource))
glog.V(1).Info("Claiming to support Instances")
return &Instances{compute, flavor_to_resource}, true
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:49,代码来源:openstack.go
示例6: TestCreateGetCloudNodesWithSpec
func TestCreateGetCloudNodesWithSpec(t *testing.T) {
resourceList := api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(1000, resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(3000, resource.DecimalSI),
}
table := []struct {
fakeCloud *fake_cloud.FakeCloud
machines []string
expectedNodes *api.NodeList
}{
{
fakeCloud: &fake_cloud.FakeCloud{},
expectedNodes: &api.NodeList{},
},
{
fakeCloud: &fake_cloud.FakeCloud{
Machines: []string{"node0"},
NodeResources: &api.NodeResources{Capacity: resourceList},
},
expectedNodes: &api.NodeList{
Items: []api.Node{
{
ObjectMeta: api.ObjectMeta{Name: "node0"},
Spec: api.NodeSpec{Capacity: resourceList},
},
},
},
},
{
fakeCloud: &fake_cloud.FakeCloud{
Machines: []string{"node0", "node1"},
NodeResources: &api.NodeResources{Capacity: resourceList},
},
expectedNodes: &api.NodeList{
Items: []api.Node{
{
ObjectMeta: api.ObjectMeta{Name: "node0"},
Spec: api.NodeSpec{Capacity: resourceList},
},
{
ObjectMeta: api.ObjectMeta{Name: "node1"},
Spec: api.NodeSpec{Capacity: resourceList},
},
},
},
},
}
for _, item := range table {
nodeController := NewNodeController(item.fakeCloud, ".*", nil, &api.NodeResources{}, nil, nil, 10, time.Minute)
nodes, err := nodeController.GetCloudNodesWithSpec()
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !reflect.DeepEqual(item.expectedNodes, nodes) {
t.Errorf("expected node list %+v, got %+v", item.expectedNodes, nodes)
}
}
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:60,代码来源:nodecontroller_test.go
示例7: PodMemory
// PodMemory computes the memory usage of a pod
func PodMemory(pod *api.Pod) *resource.Quantity {
val := int64(0)
for j := range pod.Spec.Containers {
val = val + pod.Spec.Containers[j].Resources.Limits.Memory().Value()
}
return resource.NewQuantity(int64(val), resource.DecimalSI)
}
开发者ID:Ima8,项目名称:kubernetes,代码行数:8,代码来源:resource_quota_controller.go
示例8: TestResourceQuotaStatusConversion
func TestResourceQuotaStatusConversion(t *testing.T) {
// should serialize as "0"
expected := resource.NewQuantity(int64(0), resource.DecimalSI)
if "0" != expected.String() {
t.Errorf("Expected: 0, Actual: %v, do not require units", expected.String())
}
parsed := resource.MustParse("0")
if "0" != parsed.String() {
t.Errorf("Expected: 0, Actual: %v, do not require units", parsed.String())
}
quota := &api.ResourceQuota{}
quota.Status = api.ResourceQuotaStatus{}
quota.Status.Hard = api.ResourceList{}
quota.Status.Used = api.ResourceList{}
quota.Status.Hard[api.ResourcePods] = *expected
// round-trip the object
data, _ := versioned.Codec.Encode(quota)
object, _ := versioned.Codec.Decode(data)
after := object.(*api.ResourceQuota)
actualQuantity := after.Status.Hard[api.ResourcePods]
actual := &actualQuantity
// should be "0", but was "0m"
if expected.String() != actual.String() {
t.Errorf("Expected %v, Actual %v", expected.String(), actual.String())
}
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:30,代码来源:conversion_test.go
示例9: makeNodeResources
// Builds an api.NodeResources
// cpu is in ecus, memory is in GiB
// We pass the family in so that we could provide more info (e.g. GPU or not)
func makeNodeResources(family string, cpu float64, memory float64) (*api.NodeResources, error) {
return &api.NodeResources{
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(int64(cpu*1000), resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(int64(memory*1024*1024*1024), resource.BinarySI),
},
}, nil
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:11,代码来源:aws.go
示例10: makeResources
func makeResources(milliCPU int64, memory int64) api.NodeResources {
return api.NodeResources{
Capacity: api.ResourceList{
"cpu": *resource.NewMilliQuantity(milliCPU, resource.DecimalSI),
"memory": *resource.NewQuantity(memory, resource.BinarySI),
},
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:8,代码来源:predicates_test.go
示例11: makeResources
// cpu is in cores, memory is in GiB
func makeResources(cpu float64, memory float64) *api.NodeResources {
return &api.NodeResources{
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(int64(cpu*1000), resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(int64(memory*1024*1024*1024), resource.BinarySI),
},
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:9,代码来源:gce.go
示例12: TestLimitedResources
func TestLimitedResources(t *testing.T) {
assert := assert.New(t)
task, _ := fakePodTask("limited")
pod := &task.Pod
pod.Spec = api.PodSpec{
Containers: []api.Container{{
Name: "a",
Resources: api.ResourceRequirements{
Limits: api.ResourceList{
api.ResourceCPU: *resource.NewQuantity(1, resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(256*1024*1024, resource.BinarySI),
},
},
}, {
Name: "b",
Resources: api.ResourceRequirements{
Limits: api.ResourceList{
api.ResourceCPU: *resource.NewQuantity(2, resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(512*1024*1024, resource.BinarySI),
},
},
}},
}
beforeLimitingCPU := mresource.CPUForPod(pod, mresource.DefaultDefaultContainerCPULimit)
beforeLimitingMem := mresource.MemForPod(pod, mresource.DefaultDefaultContainerMemLimit)
unboundedCPU := mresource.LimitPodCPU(pod, mresource.DefaultDefaultContainerCPULimit)
unboundedMem := mresource.LimitPodMem(pod, mresource.DefaultDefaultContainerMemLimit)
cpu := mresource.PodCPULimit(pod)
mem := mresource.PodMemLimit(pod)
assert.False(unboundedCPU, "CPU resources are defined as limited")
assert.False(unboundedMem, "mem resources are defined as limited")
assert.Equal(3.0, float64(cpu))
assert.Equal(768.0, float64(mem))
assert.Equal(cpu, beforeLimitingCPU)
assert.Equal(mem, beforeLimitingMem)
}
开发者ID:Ima8,项目名称:kubernetes,代码行数:43,代码来源:pod_task_test.go
示例13: makeMinion
func makeMinion(node string, milliCPU, memory int64) api.Node {
return api.Node{
ObjectMeta: api.ObjectMeta{Name: node},
Status: api.NodeStatus{
Capacity: api.ResourceList{
"cpu": *resource.NewMilliQuantity(milliCPU, resource.DecimalSI),
"memory": *resource.NewQuantity(memory, resource.BinarySI),
},
},
}
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:11,代码来源:priorities_test.go
示例14: CapacityFromMachineInfo
func CapacityFromMachineInfo(info *cadvisorApi.MachineInfo) api.ResourceList {
c := api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(
int64(info.NumCores*1000),
resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(
info.MemoryCapacity,
resource.BinarySI),
}
return c
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:11,代码来源:util.go
示例15: makeMinion
func makeMinion(node string, milliCPU, memory int64) api.Node {
return api.Node{
ObjectMeta: api.ObjectMeta{Name: node},
Spec: api.NodeSpec{
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(milliCPU, resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(memory, resource.BinarySI),
},
},
}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:11,代码来源:priorities_test.go
示例16: newResourcePod
func newResourcePod(usage ...resourceRequest) api.Pod {
containers := []api.Container{}
for _, req := range usage {
containers = append(containers, api.Container{
Memory: *resource.NewQuantity(req.memory, resource.BinarySI),
CPU: *resource.NewMilliQuantity(req.milliCPU, resource.DecimalSI),
})
}
return api.Pod{
Spec: api.PodSpec{
Containers: containers,
},
}
}
开发者ID:nhr,项目名称:kubernetes,代码行数:14,代码来源:predicates_test.go
示例17: RunControllerManager
// RunControllerManager starts a controller
func RunControllerManager(machineList []string, cl *client.Client, nodeMilliCPU, nodeMemory int64) {
nodeResources := &api.NodeResources{
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(nodeMilliCPU, resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(nodeMemory, resource.BinarySI),
},
}
nodeController := nodeControllerPkg.NewNodeController(nil, "", machineList, nodeResources, cl)
nodeController.Run(10 * time.Second)
endpoints := service.NewEndpointController(cl)
go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)
controllerManager := controller.NewReplicationManager(cl)
controllerManager.Run(10 * time.Second)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:17,代码来源:standalone.go
示例18: newResourcePod
func newResourcePod(usage ...resourceRequest) *api.Pod {
containers := []api.Container{}
for _, req := range usage {
containers = append(containers, api.Container{
Resources: api.ResourceRequirements{
Limits: api.ResourceList{
"cpu": *resource.NewMilliQuantity(req.milliCPU, resource.DecimalSI),
"memory": *resource.NewQuantity(req.memory, resource.BinarySI),
},
},
})
}
return &api.Pod{
Spec: api.PodSpec{
Containers: containers,
},
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:18,代码来源:predicates_test.go
示例19: runControllerManager
// RunControllerManager starts a controller
func runControllerManager(machineList []string, cl *client.Client, nodeMilliCPU, nodeMemory int64) {
nodeResources := &api.NodeResources{
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(nodeMilliCPU, resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(nodeMemory, resource.BinarySI),
},
}
kubeClient := &client.HTTPKubeletClient{Client: http.DefaultClient, Port: ports.KubeletPort}
nodeController := nodeControllerPkg.NewNodeController(nil, "", machineList, nodeResources, cl, kubeClient, 10, 5*time.Minute)
nodeController.Run(10*time.Second, true, true)
endpoints := service.NewEndpointController(cl)
go util.Forever(func() { endpoints.SyncServiceEndpoints() }, time.Second*10)
controllerManager := controller.NewReplicationManager(cl)
controllerManager.Run(controller.DefaultSyncPeriod)
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:19,代码来源:kubernetes.go
示例20: runControllerManager
// RunControllerManager starts a controller
func runControllerManager(machineList []string, cl *client.Client, nodeMilliCPU, nodeMemory int64) {
nodeResources := &api.NodeResources{
Capacity: api.ResourceList{
api.ResourceCPU: *resource.NewMilliQuantity(nodeMilliCPU, resource.DecimalSI),
api.ResourceMemory: *resource.NewQuantity(nodeMemory, resource.BinarySI),
},
}
nodeController := nodecontroller.NewNodeController(
nil, "", machineList, nodeResources, cl, 10, 5*time.Minute, util.NewTokenBucketRateLimiter(*deletingPodsQps, *deletingPodsBurst), 40*time.Second, 60*time.Second, 5*time.Second, "")
nodeController.Run(10*time.Second, true)
serviceController := servicecontroller.New(nil, cl, "kubernetes")
if err := serviceController.Run(); err != nil {
glog.Warningf("Running without a service controller: %v", err)
}
endpoints := service.NewEndpointController(cl)
go endpoints.Run(5, util.NeverStop)
controllerManager := controller.NewReplicationManager(cl)
controllerManager.Run(controller.DefaultSyncPeriod)
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:24,代码来源:kubernetes.go
注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource.NewQuantity函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论