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


Python client.V1ResourceRequirements方法代碼示例

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


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

示例1: _createKubePVC

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def _createKubePVC(parser_args,CoreV1Api):
    if parser_args.component=="search":
        # {tenantName}-{environment}-search-master-gluster-volume
        if parser_args.envtype == "auth":
            _pvc_name=parser_args.tenant+parser_args.env+"-search-master-"+"volume"
        elif parser_args.envtype == "live":
            _pvc_name=parser_args.tenant+parser_args.env+"-search-repeater-"+"volume"

        # Below config boby still need refine to accept more flexible extension
        metadata = {'name': _pvc_name, 'namespace': parser_args.namespace}
        requests = {'storage': parser_args.storage_size}
        _V1ResourceRequirements=client.V1ResourceRequirements(requests=requests)
        _V1PersistentVolumeClaimSpec=client.V1PersistentVolumeClaimSpec(resources=_V1ResourceRequirements,storage_class_name=parser_args.storage_class,access_modes=['ReadWriteMany'])
        body = client.V1PersistentVolumeClaim(api_version='v1',kind='PersistentVolumeClaim', metadata=metadata,spec=_V1PersistentVolumeClaimSpec,)  # V1PersistentVolumeClaim |

        try:
             api_response = CoreV1Api.create_namespaced_persistent_volume_claim(parser_args.namespace, body)
             print(api_response)
        except ApiException as e:
            print("Exception when calling CoreV1Api->create_namespaced_persistent_volume_claim: %s\n" % e)
    else:
        print("Compoennt %s not need to create persistent volume chain on Kubernetes" %(parser_args.component)) 
開發者ID:IBM,項目名稱:wc-devops-utilities,代碼行數:24,代碼來源:kube_pvc.py

示例2: simple_persistentvolumeclaim

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def simple_persistentvolumeclaim():
    """Return the Kubernetes config matching the simple-persistentvolumeclaim.yaml manifest."""
    return client.V1PersistentVolumeClaim(
        api_version='v1',
        kind='PersistentVolumeClaim',
        metadata=client.V1ObjectMeta(
            name='my-pvc'
        ),
        spec=client.V1PersistentVolumeClaimSpec(
            access_modes=[
                'ReadWriteMany'
            ],
            resources=client.V1ResourceRequirements(
                requests={
                    'storage': '16Mi'
                }
            )
        )
    ) 
開發者ID:vapor-ware,項目名稱:kubetest,代碼行數:21,代碼來源:conftest.py

示例3: pod3

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def pod3():
    return V1Pod(
        metadata=V1ObjectMeta(name='pod3', annotations=dict()),
        status=V1PodStatus(
            phase='Pending',
            conditions=[
                V1PodCondition(status='False', type='PodScheduled', reason='Unschedulable')
            ]
        ),
        spec=V1PodSpec(
            containers=[
                V1Container(
                    name='container2',
                    resources=V1ResourceRequirements(requests={'cpu': '1.5'})
                )
            ],
            node_selector={'clusterman.com/pool': 'bar'}
        )
    ) 
開發者ID:Yelp,項目名稱:clusterman,代碼行數:21,代碼來源:kubernetes_cluster_connector_test.py

示例4: pod5

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def pod5():
    return V1Pod(
        metadata=V1ObjectMeta(name='pod5', annotations=dict()),
        status=V1PodStatus(
            phase='Pending',
            conditions=None,
        ),
        spec=V1PodSpec(
            containers=[
                V1Container(
                    name='container2',
                    resources=V1ResourceRequirements(requests={'cpu': '1.5'})
                )
            ],
            node_selector={'clusterman.com/pool': 'bar'}
        )
    ) 
開發者ID:Yelp,項目名稱:clusterman,代碼行數:19,代碼來源:kubernetes_cluster_connector_test.py

示例5: create_deployment_object

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def create_deployment_object():
    # Configureate Pod template container
    container = client.V1Container(
        name="nginx",
        image="nginx:1.15.4",
        ports=[client.V1ContainerPort(container_port=80)],
        resources=client.V1ResourceRequirements(
            requests={"cpu": "100m", "memory": "200Mi"},
            limits={"cpu": "500m", "memory": "500Mi"}
        )
    )
    # Create and configurate a spec section
    template = client.V1PodTemplateSpec(
        metadata=client.V1ObjectMeta(labels={"app": "nginx"}),
        spec=client.V1PodSpec(containers=[container]))
    # Create the specification of deployment
    spec = client.V1DeploymentSpec(
        replicas=3,
        template=template,
        selector={'matchLabels': {'app': 'nginx'}})
    # Instantiate the deployment object
    deployment = client.V1Deployment(
        api_version="apps/v1",
        kind="Deployment",
        metadata=client.V1ObjectMeta(name=DEPLOYMENT_NAME),
        spec=spec)

    return deployment 
開發者ID:kubernetes-client,項目名稱:python,代碼行數:30,代碼來源:deployment_crud.py

示例6: get_resource_requirements

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def get_resource_requirements(self) -> V1ResourceRequirements:
        return V1ResourceRequirements(
            limits={
                "cpu": self.get_cpus() + self.get_cpu_burst_add(),
                "memory": f"{self.get_mem()}Mi",
                "ephemeral-storage": f"{self.get_disk()}Mi",
            },
            requests={
                "cpu": self.get_cpus(),
                "memory": f"{self.get_mem()}Mi",
                "ephemeral-storage": f"{self.get_disk()}Mi",
            },
        ) 
開發者ID:Yelp,項目名稱:paasta,代碼行數:15,代碼來源:kubernetes_tools.py

示例7: get_sidecar_resource_requirements

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def get_sidecar_resource_requirements(self) -> V1ResourceRequirements:
        return V1ResourceRequirements(
            limits={"cpu": 0.1, "memory": "1024Mi", "ephemeral-storage": "256Mi"},
            requests={"cpu": 0.1, "memory": "1024Mi", "ephemeral-storage": "256Mi"},
        ) 
開發者ID:Yelp,項目名稱:paasta,代碼行數:7,代碼來源:kubernetes_tools.py

示例8: get_volume_claim_templates

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def get_volume_claim_templates(self) -> Sequence[V1PersistentVolumeClaim]:
        return [
            V1PersistentVolumeClaim(
                metadata=V1ObjectMeta(name=self.get_persistent_volume_name(volume)),
                spec=V1PersistentVolumeClaimSpec(
                    # must be ReadWriteOnce for EBS
                    access_modes=["ReadWriteOnce"],
                    storage_class_name=self.get_storage_class_name(volume),
                    resources=V1ResourceRequirements(
                        requests={"storage": f"{volume['size']}Gi"}
                    ),
                ),
            )
            for volume in self.get_persistent_volumes()
        ] 
開發者ID:Yelp,項目名稱:paasta,代碼行數:17,代碼來源:kubernetes_tools.py

示例9: get_kubernetes_resource_request

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def get_kubernetes_resource_request(
    resources: V1ResourceRequirements,
) -> Mapping[str, float]:
    if not resources:
        requests: Mapping[str, str] = {}
    else:
        requests = resources.requests or {}

    parsed = kubernetes_tools.parse_container_resources(requests)
    return {
        "cpus": parsed.cpus,
        "mem": parsed.mem,
        "disk": parsed.disk,
    } 
開發者ID:Yelp,項目名稱:paasta,代碼行數:16,代碼來源:get_running_task_allocation.py

示例10: test_get_resource_requirements

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def test_get_resource_requirements(self):
        with mock.patch(
            "paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_cpus",
            autospec=True,
            return_value=0.3,
        ), mock.patch(
            "paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_cpu_burst_add",
            autospec=True,
            return_value=1,
        ), mock.patch(
            "paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_mem",
            autospec=True,
            return_value=2048,
        ), mock.patch(
            "paasta_tools.kubernetes_tools.KubernetesDeploymentConfig.get_disk",
            autospec=True,
            return_value=4096,
        ):
            assert self.deployment.get_resource_requirements() == V1ResourceRequirements(
                limits={"cpu": 1.3, "memory": "2048Mi", "ephemeral-storage": "4096Mi"},
                requests={
                    "cpu": 0.3,
                    "memory": "2048Mi",
                    "ephemeral-storage": "4096Mi",
                },
            ) 
開發者ID:Yelp,項目名稱:paasta,代碼行數:28,代碼來源:test_kubernetes_tools.py

示例11: init_resource_requirements

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def init_resource_requirements(self, container):
        limits = dict()
        requests = dict()
        if container.num_cpus:
            limits.update({'cpu': container.num_cpus})
            requests.update({'cpu': container.num_cpus})
        if container.mem_size:
            limits.update({'memory': container.mem_size})
            requests.update({'memory': container.mem_size})
        return client.V1ResourceRequirements(limits=limits,
                                             requests=requests) 
開發者ID:openstack,項目名稱:tacker,代碼行數:13,代碼來源:translate_outputs.py

示例12: pod1

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def pod1():
    return V1Pod(
        metadata=V1ObjectMeta(name='pod1'),
        status=V1PodStatus(phase='Running'),
        spec=V1PodSpec(containers=[
               V1Container(
                    name='container1',
                    resources=V1ResourceRequirements(requests={'cpu': '1.5'})
                )
            ]
        )
    ) 
開發者ID:Yelp,項目名稱:clusterman,代碼行數:14,代碼來源:kubernetes_cluster_connector_test.py

示例13: pod2

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def pod2():
    return V1Pod(
        metadata=V1ObjectMeta(name='pod2', annotations={'clusterman.com/safe_to_evict': 'false'}),
        status=V1PodStatus(phase='Running'),
        spec=V1PodSpec(containers=[
               V1Container(
                    name='container1',
                    resources=V1ResourceRequirements(requests={'cpu': '1.5'})
                )
            ]
        )
    ) 
開發者ID:Yelp,項目名稱:clusterman,代碼行數:14,代碼來源:kubernetes_cluster_connector_test.py

示例14: pod6

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def pod6():
    return V1Pod(
        spec=V1PodSpec(
            containers=[
                V1Container(
                    name='container',
                    resources=V1ResourceRequirements(requests={'cpu': '1.5'})
                )
            ],
            affinity=V1Affinity(
                node_affinity=V1NodeAffinity(
                    required_during_scheduling_ignored_during_execution=V1NodeSelector(
                        node_selector_terms=[
                            V1NodeSelectorTerm(
                                match_expressions=[
                                    V1NodeSelectorRequirement(
                                        key='clusterman.com/pool',
                                        operator='In',
                                        values=['bar']
                                    )
                                ]
                            )
                        ]
                    )
                )
            )
        )
    ) 
開發者ID:Yelp,項目名稱:clusterman,代碼行數:30,代碼來源:kubernetes_cluster_connector_test.py

示例15: test_calculate_resource_utilization_for_kube_nodes

# 需要導入模塊: from kubernetes import client [as 別名]
# 或者: from kubernetes.client import V1ResourceRequirements [as 別名]
def test_calculate_resource_utilization_for_kube_nodes():
    fake_nodes = [
        V1Node(
            metadata=V1ObjectMeta(name="fake_node1"),
            status=V1NodeStatus(
                allocatable={
                    "cpu": "500",
                    "ephemeral-storage": "200Mi",
                    "memory": "750Mi",
                },
            ),
        )
    ]
    fake_pods_by_node = {
        "fake_node1": [
            V1Pod(
                metadata=V1ObjectMeta(name="pod1"),
                status=V1PodStatus(phase="Running"),
                spec=V1PodSpec(
                    containers=[
                        V1Container(
                            name="container1",
                            resources=V1ResourceRequirements(
                                requests={
                                    "cpu": "20",
                                    "ephemeral-storage": "20Mi",
                                    "memory": "20Mi",
                                }
                            ),
                        )
                    ]
                ),
            )
        ]
    }
    free = metastatus_lib.calculate_resource_utilization_for_kube_nodes(
        nodes=fake_nodes, pods_by_node=fake_pods_by_node
    )["free"]

    assert free.cpus == 480
    assert free.mem == 730
    assert free.disk == 180 
開發者ID:Yelp,項目名稱:paasta,代碼行數:44,代碼來源:test_metastatus_lib.py


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