当前位置: 首页>>代码示例>>Python>>正文


Python client.V1DeleteOptions方法代码示例

本文整理汇总了Python中kubernetes.client.V1DeleteOptions方法的典型用法代码示例。如果您正苦于以下问题:Python client.V1DeleteOptions方法的具体用法?Python client.V1DeleteOptions怎么用?Python client.V1DeleteOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kubernetes.client的用法示例。


在下文中一共展示了client.V1DeleteOptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete_replica_set

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def delete_replica_set(name: str, ns: str = "default",
                       label_selector: str = "name in ({name})",
                       secrets: Secrets = None):
    """
    Delete a replica set by `name` in the namespace `ns`.

    The replica set is deleted without a graceful period to trigger an abrupt
    termination.

    The selected resources are matched by the given `label_selector`.
    """
    label_selector = label_selector.format(name=name)
    api = create_k8s_api_client(secrets)
    v1 = client.ExtensionsV1beta1Api(api)
    if label_selector:
        ret = v1.list_namespaced_replica_set(ns, label_selector=label_selector)
    else:
        ret = v1.list_namespaced_replica_set(ns)

    logger.debug("Found {d} replica sets named '{n}'".format(
        d=len(ret.items), n=name))

    body = client.V1DeleteOptions()
    for r in ret.items:
        v1.delete_namespaced_replica_set(r.metadata.name, ns, body=body) 
开发者ID:chaostoolkit,项目名称:chaostoolkit-kubernetes,代码行数:27,代码来源:actions.py

示例2: delete_pods

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def delete_pods(name: str, ns: str = "default",
                label_selector: str = "name in ({name})",
                secrets: Secrets = None):
    """
    Delete pods by `name` in the namespace `ns`.

    The pods are deleted without a graceful period to trigger an abrupt
    termination.

    The selected resources are matched by the given `label_selector`.
    """
    label_selector = label_selector.format(name=name)
    api = create_k8s_api_client(secrets)
    v1 = client.CoreV1Api(api)
    if label_selector:
        ret = v1.list_namespaced_pod(ns, label_selector=label_selector)
    else:
        ret = v1.list_namespaced_pod(ns)

    logger.debug("Found {d} pods named '{n}'".format(
        d=len(ret.items), n=name))

    body = client.V1DeleteOptions()
    for p in ret.items:
        v1.delete_namespaced_pod(p.metadata.name, ns, body=body) 
开发者ID:chaostoolkit,项目名称:chaostoolkit-kubernetes,代码行数:27,代码来源:actions.py

示例3: delete

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def delete(self):
        self._validate()

        try:
            if self.namespace:
                return self.api.delete_namespaced_custom_object(
                    self.group, self.version, self.namespace, self.plural, self.name,
                    client.V1DeleteOptions(propagation_policy='Foreground')
                )

            return self.api.delete_cluster_custom_object(
                self.group, self.version, self.plural, self.name,
                client.V1DeleteOptions(propagation_policy='Foreground')
            )

        except ApiException as e:
            if e.reason == 'Not Found':
                return None

            log.error(
                '{}'.format(add_indent(e.body)))
            raise ProvisioningError(e) 
开发者ID:2gis,项目名称:k8s-handle,代码行数:24,代码来源:adapters.py

示例4: delete_pod_disruption_budget

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def delete_pod_disruption_budget(self, kube_client: KubeClient) -> None:
        try:
            kube_client.policy.delete_namespaced_pod_disruption_budget(
                name=self.item.metadata.name,
                namespace=self.item.metadata.namespace,
                body=V1DeleteOptions(),
            )
        except ApiException as e:
            if e.status == 404:
                # Deployment does not exist, nothing to delete but
                # we can consider this a success.
                self.logging.debug(
                    "not deleting nonexistent pod disruption budget/{} from namespace/{}".format(
                        self.item.metadata.name, self.item.metadata.namespace
                    )
                )
            else:
                raise
        else:
            self.logging.info(
                "deleted pod disruption budget/{} from namespace/{}".format(
                    self.item.metadata.name, self.item.metadata.namespace
                )
            ) 
开发者ID:Yelp,项目名称:paasta,代码行数:26,代码来源:controller_wrappers.py

示例5: delete_horizontal_pod_autoscaler

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def delete_horizontal_pod_autoscaler(self, kube_client: KubeClient) -> None:
        try:
            kube_client.autoscaling.delete_namespaced_horizontal_pod_autoscaler(
                name=self.item.metadata.name,
                namespace=self.item.metadata.namespace,
                body=V1DeleteOptions(),
            )
        except ApiException as e:
            if e.status == 404:
                # Deployment does not exist, nothing to delete but
                # we can consider this a success.
                self.logging.debug(
                    f"not deleting nonexistent HPA/{self.item.metadata.name} from namespace/{self.item.metadata.namespace}"
                )
            else:
                raise
        else:
            self.logging.info(
                "deleted HPA/{} from namespace/{}".format(
                    self.item.metadata.name, self.item.metadata.namespace
                )
            ) 
开发者ID:Yelp,项目名称:paasta,代码行数:24,代码来源:controller_wrappers.py

示例6: remove_pods

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def remove_pods(
    client: KubeClient, services: Mapping[str, Sequence[EvictedPod]], dry_run: bool,
) -> None:
    delete_options = V1DeleteOptions()
    for service in services:
        # Do not remove more than 2 pods per run
        for pod in services[service][0:2]:
            if dry_run:
                log.info(f"Would have removed pod {pod.podname}")
            else:
                client.core.delete_namespaced_pod(
                    pod.podname,
                    pod.namespace,
                    body=delete_options,
                    grace_period_seconds=0,
                    propagation_policy="Background",
                )
                log.info(f"Removing pod {pod.podname}") 
开发者ID:Yelp,项目名称:paasta,代码行数:20,代码来源:kubernetes_remove_evicted_pods.py

示例7: delete_custom_resource

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def delete_custom_resource(
    kube_client: KubeClient,
    name: str,
    namespace: str,
    group: str,
    version: str,
    plural: str,
) -> None:
    return kube_client.custom.delete_namespaced_custom_object(
        name=name,
        namespace=namespace,
        group=group,
        version=version,
        plural=plural,
        body=V1DeleteOptions(),
    ) 
开发者ID:Yelp,项目名称:paasta,代码行数:18,代码来源:kubernetes_tools.py

示例8: delete_namespace

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def delete_namespace(name, id_token):
    body = k8s_client.V1DeleteOptions()
    response = 'Namespace {} does not exist'.format(name)
    api_instance = get_k8s_api_client(id_token)
    existed = True
    try:
        response = api_instance.delete_namespace(name, body)
    except ApiException as apiException:
        if apiException.status != RESOURCE_DOES_NOT_EXIST and \
                apiException.status != NAMESPACE_BEING_DELETED:
            raise KubernetesDeleteException('namespace', apiException)
        existed = False
    if existed:
        logger.info('Namespace {} deleted'.format(name))
    else:
        logger.info('Namespace {} does not exist'.format(name))

    return response 
开发者ID:IntelAI,项目名称:inference-model-manager,代码行数:20,代码来源:tenants_utils.py

示例9: _delete_crd_server

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def _delete_crd_server(self, object_to_delete):
        delete_body = client.V1DeleteOptions()
        try:
            response = self.k8s_client_custom.delete_namespaced_custom_object(
                CRD_GROUP, CRD_VERSION, object_to_delete['namespace'], CRD_PLURAL,
                object_to_delete['name'], delete_body, grace_period_seconds=0)
        except Exception as e:
            logging.error(e)
            raise

        deletion_status = self._wait_server_deletion(object_to_delete)
        if deletion_status == OperationStatus.SUCCESS:
            logging.info('CRD {} deleted successfully.'.format(object_to_delete['name']))
        elif deletion_status == OperationStatus.TERMINATED:
            logging.info('CRD {} status unknown.'.format(object_to_delete['name']))
        else:
            logging.info('CRD {} deletion timeout.'.format(object_to_delete['name']))
        return response 
开发者ID:IntelAI,项目名称:inference-model-manager,代码行数:20,代码来源:context.py

示例10: delete_ds

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def delete_ds(config, version, ds_name, ns_name="default",
              body=V1DeleteOptions()):
    k8s_api_core = client_from_config(config)

    if version >= util.parse_version("v1.9.0"):
        k8s_api_apps = apps_api_client_from_config(config)
        k8s_api_apps.delete_namespaced_daemon_set(ds_name,
                                                  ns_name,
                                                  grace_period_seconds=0,
                                                  orphan_dependents=False)
    else:
        k8s_api_ext = extensions_client_from_config(config)
        k8s_api_ext.delete_namespaced_daemon_set(ds_name,
                                                 ns_name,
                                                 grace_period_seconds=0,
                                                 orphan_dependents=False)

    # Pod in ds has fixed label so we use label selector
    data = k8s_api_core.list_namespaced_pod(
        ns_name, label_selector="app={}".format(ds_name)).to_dict()
    # There should be only one pod
    for pod in data["items"]:
        logging.debug("Removing pod \"{}\"".format(pod["metadata"]["name"]))
        delete_pod(None, pod["metadata"]["name"], ns_name)
    return 
开发者ID:intel,项目名称:CPU-Manager-for-Kubernetes,代码行数:27,代码来源:k8s.py

示例11: delete

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def delete(self, name, snapshots=False):
        crds = self.crds
        core = self.core
        namespace = self.namespace
        try:
            vm = crds.get_namespaced_custom_object(DOMAIN, VERSION, namespace, 'virtualmachines', name)
            crds.delete_namespaced_custom_object(DOMAIN, VERSION, namespace, 'virtualmachines', name,
                                                 client.V1DeleteOptions())
        except:
            return {'result': 'failure', 'reason': "VM %s not found" % name}
        pvcvolumes = [v['persistentVolumeClaim']['claimName'] for v in vm['spec']['template']['spec']['volumes'] if
                      'persistentVolumeClaim' in v]
        pvcs = [pvc for pvc in core.list_namespaced_persistent_volume_claim(namespace).items
                if pvc.metadata.name in pvcvolumes]
        for p in sorted(pvcs):
            pvcname = p.metadata.name
            common.pprint("Deleting pvc %s" % pvcname, color='blue')
            core.delete_namespaced_persistent_volume_claim(pvcname, namespace, client.V1DeleteOptions())
        try:
            core.delete_namespaced_service('%s-ssh' % name, namespace)
        except:
            pass
        return {'result': 'success'} 
开发者ID:karmab,项目名称:kcli,代码行数:25,代码来源:__init__.py

示例12: delete_image

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def delete_image(self, image):
        common.pprint("Deleting image %s" % image)
        core = self.core
        if self.cdi:
            cdinamespace = self.cdinamespace
            pvc = core.list_namespaced_persistent_volume_claim(cdinamespace)
            images = [p.metadata.name for p in pvc.items if p.metadata.annotations is not None and
                      'cdi.kubevirt.io/storage.import.endpoint' in p.metadata.annotations and
                      self.get_image_name(p.metadata.annotations['cdi.kubevirt.io/storage.import.endpoint']) ==
                      image]
            if images:
                core.delete_namespaced_persistent_volume_claim(images[0], cdinamespace, client.V1DeleteOptions())
                return {'result': 'success'}
        else:
            pvc = core.list_namespaced_persistent_volume_claim(self.namespace)
            images = [p.metadata.name for p in pvc.items
                      if p.metadata.annotations is not None and 'kcli/image' in p.metadata.annotations and
                      p.metadata.annotations['kcli/image'] == image]
            if images:
                core.delete_namespaced_persistent_volume_claim(images[0], self.namespace, client.V1DeleteOptions())
                return {'result': 'success'}
        return {'result': 'failure', 'reason': 'image %s not found' % image} 
开发者ID:karmab,项目名称:kcli,代码行数:24,代码来源:__init__.py

示例13: prepare_pvc

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def prepare_pvc(self, name, size=1):
        core = self.core
        namespace = self.namespace
        now = datetime.datetime.now().strftime("%Y%M%d%H%M")
        podname = '%s-%s-prepare' % (now, name)
        size = 1024 * int(size) - 48
        pod = {'kind': 'Pod', 'spec': {'restartPolicy': 'OnFailure',
                                       'containers': [{'image': 'alpine', 'volumeMounts': [{'mountPath': '/storage1',
                                                                                            'name': 'storage1'}],
                                                       'name': 'prepare', 'command': ['fallocate'],
                                                       'args': ['-l', '%sM' % size, '/storage1/disk.img']}],
                                       'volumes': [{'name': 'storage1', 'persistentVolumeClaim': {'claimName': name}}]},
               'apiVersion': 'v1', 'metadata': {'name': podname}}
        core.create_namespaced_pod(namespace, pod)
        completed = self.pod_completed(podname, namespace)
        if not completed:
            common.pprint("Using with pod %s. Leaving it for debugging purposes" % podname, color='red')
            return {'result': 'failure', 'reason': 'timeout waiting for preparation of disk to finish'}
        else:
            core.delete_namespaced_pod(podname, namespace, client.V1DeleteOptions())
        return {'result': 'success'} 
开发者ID:karmab,项目名称:kcli,代码行数:23,代码来源:__init__.py

示例14: delete_deployment

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def delete_deployment(params):
    from kubernetes.client import V1DeleteOptions

    spec = get_seldon_spec(params)
    name = get_deployment_name(params)  # spec["metadata"]["name"]
    namespace = "default"               # TODO: the namespace should be configured or be figured out dynamically
    plural = spec["kind"].lower()+"s"   # TODO: verify the "rule" for constructing plural
    group, version = spec["apiVersion"].split("/")

    del_opts = V1DeleteOptions()
    api_client = get_custom_objects_api_client()
    api_response = api_client.list_namespaced_custom_object(group, version, namespace, plural)

    if name in [deployment["metadata"]["name"] for deployment in api_response["items"]]:
        api_response = api_client.delete_namespaced_custom_object(group, version, namespace, plural, name, del_opts)
    else:
        LOG.error("Could not find the Seldon deployment '%s'" % name)
        return {
            "status": "Error",
            "details": "Could not find a Seldon deployment with name '%s'" % name
        }

    # api_response_filtered = {key: api_response[key] for key in ["apiVersion", "kind"]}
    LOG.info("%s ..." % str(api_response)[:160])
    return api_response 
开发者ID:kubeflow,项目名称:pipelines,代码行数:27,代码来源:app.py

示例15: deleteConfigMap

# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1DeleteOptions [as 别名]
def deleteConfigMap(parser_args,CorV1Client):
        print("delete config map")
        if listConfigMap(parser_args,CorV1Client):
            # create an instance of the API class
            name = parser_args.name  # str | name of the ConfigMap
            namespace = parser_args.namespace  # str | object name and auth scope, such as for teams and projects
            body = client.V1DeleteOptions()  # V1DeleteOptions |
            pretty = 'pretty_example'  # str | If 'true', then the output is pretty printed. (optional)

            try:
                api_response = CorV1Client.delete_namespaced_config_map(name, namespace, body, pretty=pretty)
                print(api_response)
            except ApiException as e:
                print("Exception when calling CoreV1Api->delete_namespaced_config_map: %s\n" % e)
        else:
            print("Not Found target cofigMap ojbect %s exist" % parser_args.name)

#Delete configMap 
开发者ID:IBM,项目名称:wc-devops-utilities,代码行数:20,代码来源:kube_configmap.py


注:本文中的kubernetes.client.V1DeleteOptions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。