%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyo

�
���^c@@sdZddlmZmZmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlmZddlmZddlmZddlmZddlZddlZddlZddlZddlZdd	lmZdd
lmZy�ddl Z ddl!Z ddl"m#Z#ddl$m%Z%y$dd
l!m&Z'ddl!m(Z)Wn1e*k
r�ddl!m'Z'ddl!m)Z)nXe+Z,Wne*k
r�e-Z,nXe
j.e/�Z0dZ1d�Z2ej3j4j5�sed��Z6dZ7nd�Z8d�Z9d�Z:d�Z;d�Z<d�Z=d�Z>d�Z?d�Z@d�ZAd�ZBd d!�ZCd d"�ZDd d#�ZEd d$�ZFd d%�ZGd d&�ZHd d'�ZId d(�ZJd)�ZKd e-d*�ZLd d+�ZMd d,�ZNd d-�ZOd d.�ZPd/�ZQd d0�ZRd d1�ZSd2�ZTd3�ZUd4�ZVd dddd5d6�ZXddd5d7�ZYd8�ZZd d9�Z[d d:�Z\ddd5d d;�Z]ddd5d d<�Z^d=�Z_d>�Z`d?�Zad@�ZbdA�ZcdB�ZddC�ZedS(Du5
Module for handling kubernetes calls.

:optdepends:    - kubernetes Python client
:configuration: The k8s API settings are provided either in a pillar, in
    the minion's config file, or in master's config file::

        kubernetes.kubeconfig: '/path/to/kubeconfig'
        kubernetes.kubeconfig-data: '<base64 encoded kubeconfig content'
        kubernetes.context: 'context'

These settings can be overridden by adding `context and `kubeconfig` or
`kubeconfig_data` parameters when calling a function.

The data format for `kubernetes.kubeconfig-data` value is the content of
`kubeconfig` base64 encoded in one line.

Only `kubeconfig` or `kubeconfig-data` should be provided. In case both are
provided `kubeconfig` entry is preferred.

.. code-block:: bash

    salt '*' kubernetes.nodes kubeconfig=/etc/salt/k8s/kubeconfig context=minikube

.. versionadded: 2017.7.0
.. versionchanged:: 2019.2.0

.. warning::

    Configuration options changed in 2019.2.0. The following configuration options have been removed:

    - kubernetes.user
    - kubernetes.password
    - kubernetes.api_url
    - kubernetes.certificate-authority-data/file
    - kubernetes.client-certificate-data/file
    - kubernetes.client-key-data/file

    Please use now:

    - kubernetes.kubeconfig or kubernetes.kubeconfig-data
    - kubernetes.context

i(tabsolute_importtunicode_literalstprint_functionN(tsleep(tcontextmanager(tCommandExecutionError(t	iteritems(tsix(tTimeoutError(trange(tApiException(t	HTTPError(tV1beta1Deployment(tV1beta1DeploymentSpec(tAppsV1beta1Deployment(tAppsV1beta1DeploymentSpecu
kubernetescC@str
tStdfS(u
    Check dependencies
    u#python kubernetes library not found(tHAS_LIBSt__virtualname__tFalse(((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt__virtual__\scc@sGd�}tjtj|�tj|�z	dVWdtjd�XdS(NcS@s
t�dS(N(R(tsignumtframe((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytsignal_handlerisi(tsignaltSIGALRMtalarm(tsecondsR((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt_time_limitgs	
	ic
K@s5tddd�}tdd�}tdd�}tdd�}tdd�}tdd�}tdd	�}tdd
�}tdd�}	d|kr�|jd�}nd
|kr�|jd
�}nd|kr�|jd�}nd|kr|jd�}nd|kr)|jd�}nd|krG|jd�}	ntjjj|ks�tjjj|ks�tjjj|kr�tjjj�n|tjj_|tjj_|tjj_	|r�|tjj_
na|r0tjdddt
��/}
|
jtj|��|
jtjj_
WdQXndtjj_
|rW|tjj_na|r�tjdddt
��/}|jtj|��|jtjj_WdQXndtjj_|	r�|	tjj_na|r"tjdddt
��/}|jtj|��|jtjj_WdQXndtjj_iS(u?
    Setup kubernetes API connection singleton the old way
    u
config.optionukubernetes.api_urluhttp://localhost:8080ukubernetes.userukubernetes.passwordu%kubernetes.certificate-authority-datau"kubernetes.client-certificate-dataukubernetes.client-key-datau%kubernetes.certificate-authority-fileu"kubernetes.client-certificate-fileukubernetes.client-key-fileuapi_urluapi_useruapi_passworduapi_certificate_authority_fileuapi_client_certificate_fileuapi_client_key_filetprefixu
salt-kube-tdeleteN(t__salt__tgett
kubernetestclientt
configurationthosttusertpasswordt__init__tpasswdtssl_ca_certttempfiletNamedTemporaryFileRtwritetbase64t	b64decodetnametNonet	cert_filetkey_file(
tkwargsR#tusernameR%tca_certtclient_certt
client_keytca_cert_filetclient_cert_filetclient_key_filetcatctk((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt_setup_conn_oldusf
	cK@sn|jd�ptdd�}|jd�p;tdd�}|jd�pZtdd�}|rj|s|r�|jd�r�tjdd	d
t��&}|jtj|��|j}WdQXn|o�|sC|jd�s�tdd
�r4t	j
jjdd�yt
|�SWq@tk
r0td��q@XqCtd��ntjjd|d|�i|d6|d6S(u3
    Setup kubernetes API connection singleton
    u
kubeconfigu
config.optionukubernetes.kubeconfigukubeconfig_dataukubernetes.kubeconfig-dataucontextukubernetes.contextRusalt-kubeconfig-RNuapi_urlukubernetes.api_urluSodiumu�Kubernetes configuration via url, certificate, username and password will be removed in Sodiom. Use 'kubeconfig' and 'context' instead.uROld style kubernetes configuration is only supported up to python-kubernetes 2.0.0uTInvalid kubernetes configuration. Parameter 'kubeconfig' and 'context' are required.tconfig_filetcontext(RRR)R*RR+R,R-R.tsalttutilstversionst
warn_untilR=t	ExceptionRR tconfigtload_kube_config(R2t
kubeconfigtkubeconfig_dataR?tkcfg((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt_setup_conn�s$"
cK@s$ytjjj}tjjj}tjjj}|rytjj|�rytjj	|�j
d�rytjj
j|�n|r�tjj|�r�tjj	|�j
d�r�tjj
j|�n|rtjj|�rtjj	|�j
d�rtjj
j|�nWntk
rnXdS(Nu
salt-kube-(R R!R"R(R0R1tostpathtexiststbasenamet
startswithR@RAtfilestsafe_rmRD(R2R:tcerttkey((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt_cleanup_old�s333
cK@s�|st|�Sd|kr�|jd�}|r�tjj|�jd�r�ytj|�Wq�ttfk
r�}|j	t	j
kr�tj|�q�q�Xq�ndS(Nu
kubeconfigusalt-kubeconfig-(
RTRRKRLRNROtunlinktIOErrortOSErrorterrnotENOENTtlogt	exception(R2RGterr((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt_cleanup�s
!cK@s2t}yt|�Wntk
r-t}nX|S(u�
    Checks connections with the kubernetes API server.
    Returns True if the connection can be established, False otherwise.

    CLI Example:
        salt '*' kubernetes.ping
    (tTruetnodesRR(R2tstatus((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytping�s

cK@s�t|�}z�yMtjj�}|j�}g|j�jd�D]}|dd^qCSWnTttfk
r�}t	|t�r�|j
dkr�dStj
d�t|��nXWdt|�XdS(u�
    Return the names of the nodes composing the kubernetes cluster

    CLI Examples::

        salt '*' kubernetes.nodes
        salt '*' kubernetes.nodes kubeconfig=/etc/salt/k8s/kubeconfig context=minikube
    uitemsumetadataunamei�u+Exception when calling CoreV1Api->list_nodeN(RJR R!t	CoreV1Apit	list_nodetto_dictRR
Rt
isinstanceR`R/RZR[RR](R2tcfgtapi_instancetapi_responsetk8s_nodetexc((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyR_s	2
cK@s�t|�}zzytjj�}|j�}WnTttfk
r�}t|t�rh|jdkrhdSt
jd�t|��nXWdt
|�Xx-|jD]"}|jj|kr�|j�Sq�WdS(u�
    Return the details of the node identified by the specified name

    CLI Examples::

        salt '*' kubernetes.node name='minikube'
    i�u+Exception when calling CoreV1Api->list_nodeN(RJR R!RbRcR
RReR`R/RZR[RR]titemstmetadataR.Rd(R.R2RfRgRhRjRi((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytnode%s
cK@s+t||�}|dk	r'|ddSiS(u�
    Return the labels of the node identified by the specified name

    CLI Examples::

        salt '*' kubernetes.node_labels name="minikube"
    umetadataulabelsN(RmR/(R.R2tmatch((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytnode_labelsAsc	K@s�t|�}z�yDtjj�}iii||6d6d6}|j||�}|SWnTttfk
r�}t|t�r�|jdkr�dSt
jd�t|��nXWdt
|�XdS(u.
    Set the value of the label identified by `label_name` to `label_value` on
    the node identified by the name `node_name`.
    Creates the lable if not present.

    CLI Examples::

        salt '*' kubernetes.node_add_label node_name="minikube"             label_name="foo" label_value="bar"
    ulabelsumetadatai�u,Exception when calling CoreV1Api->patch_nodeN(RJR R!Rbt
patch_nodeR
RReR`R/RZR[RR](	t	node_namet
label_nametlabel_valueR2RfRgtbodyRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytnode_add_labelQs"
cK@s�t|�}z�yDtjj�}iiid|6d6d6}|j||�}|SWnTttfk
r�}t|t�r�|j	dkr�dSt
jd�t|��nXWdt
|�XdS(u�
    Removes the label identified by `label_name` from
    the node identified by the name `node_name`.

    CLI Examples::

        salt '*' kubernetes.node_remove_label node_name="minikube"             label_name="foo"
    ulabelsumetadatai�u,Exception when calling CoreV1Api->patch_nodeN(RJR R!RbR/RpR
RReR`RZR[RR](RqRrR2RfRgRtRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytnode_remove_labelss"

cK@s�t|�}z�yMtjj�}|j�}g|j�jd�D]}|dd^qCSWnTttfk
r�}t	|t�r�|j
dkr�dStj
d�t|��nXWdt|�XdS(u�
    Return the names of the available namespaces

    CLI Examples::

        salt '*' kubernetes.namespaces
        salt '*' kubernetes.namespaces kubeconfig=/etc/salt/k8s/kubeconfig context=minikube
    uitemsumetadataunamei�u0Exception when calling CoreV1Api->list_namespaceN(RJR R!Rbtlist_namespaceRdRR
RReR`R/RZR[RR](R2RfRgRhtnmsRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt
namespaces�s	2
udefaultcK@s�t|�}z�yPtjj�}|j|�}g|j�jd�D]}|dd^qFSWnTttfk
r�}t	|t�r�|j
dkr�dStj
d�t|��nXWdt|�XdS(u�
    Return a list of kubernetes deployments defined in the namespace

    CLI Examples::

        salt '*' kubernetes.deployments
        salt '*' kubernetes.deployments namespace=default
    uitemsumetadataunamei�uGException when calling ExtensionsV1beta1Api->list_namespaced_deploymentN(RJR R!tExtensionsV1beta1Apitlist_namespaced_deploymentRdRR
RReR`R/RZR[RR](t	namespaceR2RfRgRhtdepRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytdeployments�s	2cK@s�t|�}z�yPtjj�}|j|�}g|j�jd�D]}|dd^qFSWnTttfk
r�}t	|t�r�|j
dkr�dStj
d�t|��nXWdt|�XdS(u�
    Return a list of kubernetes services defined in the namespace

    CLI Examples::

        salt '*' kubernetes.services
        salt '*' kubernetes.services namespace=default
    uitemsumetadataunamei�u9Exception when calling CoreV1Api->list_namespaced_serviceN(RJR R!Rbtlist_namespaced_serviceRdRR
RReR`R/RZR[RR](R|R2RfRgRhtsrvRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytservices�s	2cK@s�t|�}z�yPtjj�}|j|�}g|j�jd�D]}|dd^qFSWnTttfk
r�}t	|t�r�|j
dkr�dStj
d�t|��nXWdt|�XdS(u�
    Return a list of kubernetes pods defined in the namespace

    CLI Examples::

        salt '*' kubernetes.pods
        salt '*' kubernetes.pods namespace=default
    uitemsumetadataunamei�u5Exception when calling CoreV1Api->list_namespaced_podN(RJR R!Rbtlist_namespaced_podRdRR
RReR`R/RZR[RR](R|R2RfRgRhtpodRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytpods�s	2cK@s�t|�}z�yPtjj�}|j|�}g|j�jd�D]}|dd^qFSWnTttfk
r�}t	|t�r�|j
dkr�dStj
d�t|��nXWdt|�XdS(u�
    Return a list of kubernetes secrets defined in the namespace

    CLI Examples::

        salt '*' kubernetes.secrets
        salt '*' kubernetes.secrets namespace=default
    uitemsumetadataunamei�u8Exception when calling CoreV1Api->list_namespaced_secretN(RJR R!Rbtlist_namespaced_secretRdRR
RReR`R/RZR[RR](R|R2RfRgRhtsecretRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytsecretss	2cK@s�t|�}z�yPtjj�}|j|�}g|j�jd�D]}|dd^qFSWnTttfk
r�}t	|t�r�|j
dkr�dStj
d�t|��nXWdt|�XdS(u�
    Return a list of kubernetes configmaps defined in the namespace

    CLI Examples::

        salt '*' kubernetes.configmaps
        salt '*' kubernetes.configmaps namespace=default
    uitemsumetadataunamei�u<Exception when calling CoreV1Api->list_namespaced_config_mapN(RJR R!Rbtlist_namespaced_config_mapRdRR
RReR`R/RZR[RR](R|R2RfRgRhR�Rj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt
configmapss	2cK@s�t|�}z�y/tjj�}|j||�}|j�SWnTttfk
r�}t|t�rx|j	dkrxdStjd�t
|��nXWdt|�XdS(u�
    Return the kubernetes deployment defined by name and namespace

    CLI Examples::

        salt '*' kubernetes.show_deployment my-nginx default
        salt '*' kubernetes.show_deployment name=my-nginx namespace=default
    i�uGException when calling ExtensionsV1beta1Api->read_namespaced_deploymentN(RJR R!Rztread_namespaced_deploymentRdR
RReR`R/RZR[RR](R.R|R2RfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytshow_deployment9s	cK@s�t|�}z�y/tjj�}|j||�}|j�SWnTttfk
r�}t|t�rx|j	dkrxdStjd�t
|��nXWdt|�XdS(u�
    Return the kubernetes service defined by name and namespace

    CLI Examples::

        salt '*' kubernetes.show_service my-nginx default
        salt '*' kubernetes.show_service name=my-nginx namespace=default
    i�u9Exception when calling CoreV1Api->read_namespaced_serviceN(RJR R!Rbtread_namespaced_serviceRdR
RReR`R/RZR[RR](R.R|R2RfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytshow_serviceUs	cK@s�t|�}z�y/tjj�}|j||�}|j�SWnTttfk
r�}t|t�rx|j	dkrxdStjd�t
|��nXWdt|�XdS(u�
    Return POD information for a given pod name defined in the namespace

    CLI Examples::

        salt '*' kubernetes.show_pod guestbook-708336848-fqr2x
        salt '*' kubernetes.show_pod guestbook-708336848-fqr2x namespace=default
    i�u5Exception when calling CoreV1Api->read_namespaced_podN(RJR R!Rbtread_namespaced_podRdR
RReR`R/RZR[RR](R.R|R2RfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytshow_podqs	cK@s�t|�}z�y,tjj�}|j|�}|j�SWnTttfk
r�}t|t�ru|j	dkrudStjd�t
|��nXWdt|�XdS(u�
    Return information for a given namespace defined by the specified name

    CLI Examples::

        salt '*' kubernetes.show_namespace kube-system
    i�u0Exception when calling CoreV1Api->read_namespaceN(RJR R!Rbtread_namespaceRdR
RReR`R/RZR[RR](R.R2RfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytshow_namespace�sc
K@s�t|�}z�y�tjj�}|j||�}|jr�|sN|dkr�x7|jD])}|j|}tj|�|j|<qXWn|j�SWnTt	t
fk
r�}	t|	t	�r�|	jdkr�dStjd�t|	��nXWdt|�XdS(u�
    Return the kubernetes secret defined by name and namespace.
    The secrets can be decoded if specified by the user. Warning: this has
    security implications.

    CLI Examples::

        salt '*' kubernetes.show_secret confidential default
        salt '*' kubernetes.show_secret name=confidential namespace=default
        salt '*' kubernetes.show_secret name=confidential decode=True
    uTruei�u8Exception when calling CoreV1Api->read_namespaced_secretN(RJR R!Rbtread_namespaced_secrettdataR,R-RdR
RReR`R/RZR[RR](
R.R|tdecodeR2RfRgRhRStvalueRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytshow_secret�s"
cK@s�t|�}z�y/tjj�}|j||�}|j�SWnTttfk
r�}t|t�rx|j	dkrxdStjd�t
|��nXWdt|�XdS(u�
    Return the kubernetes configmap defined by name and namespace.

    CLI Examples::

        salt '*' kubernetes.show_configmap game-config default
        salt '*' kubernetes.show_configmap name=game-config namespace=default
    i�u<Exception when calling CoreV1Api->read_namespaced_config_mapN(RJR R!Rbtread_namespaced_config_mapRdR
RReR`R/RZR[RR](R.R|R2RfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytshow_configmap�s		c
K@s�t|�}tjjdt�}zpytjj�}|jd|d|d|�}|j�}tj	j
j�s�yGtt
��5x-t||�dk	r�td�q�Wd|d<WdQXWqtk
r�qXnDxAtd	�D]3}t||�dkrd|d<Pq�td�q�W|ddkr4tjd
�n|SWnTttfk
r�}	t|	t�rs|	jdkrsdStjd�t|	��nXWdt|�XdS(
u�
    Deletes the kubernetes deployment defined by name and namespace

    CLI Examples::

        salt '*' kubernetes.delete_deployment my-nginx
        salt '*' kubernetes.delete_deployment name=my-nginx namespace=default
    torphan_dependentsR.R|Rtii�ucodeNi<u|Reached polling time limit. Deployment is not yet deleted, but we are backing off. Sorry, but you'll have to check manually.i�uIException when calling ExtensionsV1beta1Api->delete_namespaced_deployment(RJR R!tV1DeleteOptionsR^Rztdelete_namespaced_deploymentRdR@RAtplatformt
is_windowsRtPOLLING_TIME_LIMITR�R/RRR	RZtwarningR
RReR`R[RR](
R.R|R2RfRtRgRhtmutable_api_responsetiRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytdelete_deployment�sB			


cK@s�t|�}z�y5tjj�}|jd|d|�}|j�SWnTttfk
r�}t|t�r~|j	dkr~dStjd�t
|��nXWdt|�XdS(u�
    Deletes the kubernetes service defined by name and namespace

    CLI Examples::

        salt '*' kubernetes.delete_service my-nginx default
        salt '*' kubernetes.delete_service name=my-nginx namespace=default
    R.R|i�u;Exception when calling CoreV1Api->delete_namespaced_serviceN(RJR R!Rbtdelete_namespaced_serviceRdR
RReR`R/RZR[RR](R.R|R2RfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytdelete_service!s			cK@s�t|�}tjjdt�}z�y;tjj�}|jd|d|d|�}|j�SWnTtt	fk
r�}t
|t�r�|jdkr�dSt
jd�t|��nXWdt|�XdS(u�
    Deletes the kubernetes pod defined by name and namespace

    CLI Examples::

        salt '*' kubernetes.delete_pod guestbook-708336848-5nl8c default
        salt '*' kubernetes.delete_pod name=guestbook-708336848-5nl8c namespace=default
    R�R.R|Rti�u7Exception when calling CoreV1Api->delete_namespaced_podN(RJR R!R�R^Rbtdelete_namespaced_podRdR
RReR`R/RZR[RR](R.R|R2RfRtRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt
delete_pod?s"			cK@s�t|�}tjjdt�}z�y5tjj�}|jd|d|�}|j�SWnTtt	fk
r�}t
|t�r�|jdkr�dSt
jd�t|��nXWdt|�XdS(u�
    Deletes the kubernetes namespace defined by name

    CLI Examples::

        salt '*' kubernetes.delete_namespace salt
        salt '*' kubernetes.delete_namespace name=salt
    R�R.Rti�u2Exception when calling CoreV1Api->delete_namespaceN(RJR R!R�R^Rbtdelete_namespaceRdR
RReR`R/RZR[RR](R.R2RfRtRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyR�`s	cK@s�t|�}tjjdt�}z�y;tjj�}|jd|d|d|�}|j�SWnTtt	fk
r�}t
|t�r�|jdkr�dSt
jd�t|��nXWdt|�XdS(u�
    Deletes the kubernetes secret defined by name and namespace

    CLI Examples::

        salt '*' kubernetes.delete_secret confidential default
        salt '*' kubernetes.delete_secret name=confidential namespace=default
    R�R.R|Rti�u:Exception when calling CoreV1Api->delete_namespaced_secretN(RJR R!R�R^Rbtdelete_namespaced_secretRdR
RReR`R/RZR[RR](R.R|R2RfRtRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt
delete_secret}s"			cK@s�t|�}tjjdt�}z�y;tjj�}|jd|d|d|�}|j�SWnTtt	fk
r�}t
|t�r�|jdkr�dSt
jd�t|��nXWdt|�XdS(u�
    Deletes the kubernetes configmap defined by name and namespace

    CLI Examples::

        salt '*' kubernetes.delete_configmap settings default
        salt '*' kubernetes.delete_configmap name=settings namespace=default
    R�R.R|Rti�u>Exception when calling CoreV1Api->delete_namespaced_config_mapN(RJR R!R�R^Rbtdelete_namespaced_config_mapRdR
RReR`R/RZR[RR](R.R|R2RfRtRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytdelete_configmap�s"			c
K@s�tdddtdtd|d|d|d|d	|d
|d|�
}t|�}	z�y/tjj�}
|
j||�}|j�SWnTt	t
fk
r�}t|t	�r�|jdkr�dStjd
�t|��nXWdt|	�XdS(uC
    Creates the kubernetes deployment as defined by the user.
    tkindu
Deploymentt	obj_classtspec_creatorR.R|Rltspectsourcettemplatetsaltenvi�uIException when calling ExtensionsV1beta1Api->create_namespaced_deploymentN(t__create_object_bodyRt__dict_to_deployment_specRJR R!Rztcreate_namespaced_deploymentRdR
RReR`R/RZR[RR](
R.R|RlR�R�R�R�R2RtRfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytcreate_deployment�s2	c
K@s�tdddtjjdtd|d|d|d|d	|d
|d|�
}t|�}	z�y/tjj�}
|
j||�}|j�SWnTt	t
fk
r�}t|t	�r�|jdkr�dStjd
�t|��nXWdt|	�XdS(uC
    Creates the kubernetes deployment as defined by the user.
    R�uPodR�R�R.R|RlR�R�R�R�i�u7Exception when calling CoreV1Api->create_namespaced_podN(R�R R!tV1Podt__dict_to_pod_specRJRbtcreate_namespaced_podRdR
RReR`R/RZR[RR](
R.R|RlR�R�R�R�R2RtRfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt
create_pod�s2	c
K@s�tdddtjjdtd|d|d|d|d	|d
|d|�
}t|�}	z�y/tjj�}
|
j||�}|j�SWnTt	t
fk
r�}t|t	�r�|jdkr�dStjd
�t|��nXWdt|	�XdS(u@
    Creates the kubernetes service as defined by the user.
    R�uServiceR�R�R.R|RlR�R�R�R�i�u;Exception when calling CoreV1Api->create_namespaced_serviceN(R�R R!t	V1Servicet__dict_to_service_specRJRbtcreate_namespaced_serviceRdR
RReR`R/RZR[RR](
R.R|RlR�R�R�R�R2RtRfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytcreate_services2	ubasec
K@s3|rt|||�}n|dkr0i}nt|�}x%|D]}tj||�||<qCWtjjdt||i�d|�}t	|�}	z�y/tjj
�}
|
j||�}|j�SWnTt
tfk
r}t|t
�r|jdkrdStjd�t|��nXWdt|	�XdS(u-
    Creates the kubernetes secret as defined by the user.

    CLI Examples::

        salt 'minion1' kubernetes.create_secret             passwords default '{"db": "letmein"}'

        salt 'minion2' kubernetes.create_secret             name=passwords namespace=default data='{"db": "letmein"}'
    RlR�i�u:Exception when calling CoreV1Api->create_namespaced_secretN(t__read_and_render_yaml_fileR/t__enforce_only_strings_dictR,t	b64encodeR R!tV1Secrett__dict_to_object_metaRJRbtcreate_namespaced_secretRdR
RReR`RZR[RR](
R.R|R�R�R�R�R2RSRtRfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt
create_secretEs0	
	cK@s|rt|||�}n|dkr0i}nt|�}tjjdt||i�d|�}t|�}z�y/tjj�}	|	j	||�}
|
j
�SWnTttfk
r�}t
|t�r�|jdkr�dStjd�t|��nXWdt|�XdS(uV
    Creates the kubernetes configmap as defined by the user.

    CLI Examples::

        salt 'minion1' kubernetes.create_configmap             settings default '{"example.conf": "# example file"}'

        salt 'minion2' kubernetes.create_configmap             name=settings namespace=default data='{"example.conf": "# example file"}'
    RlR�i�u>Exception when calling CoreV1Api->create_namespaced_config_mapN(R�R/R�R R!tV1ConfigMapR�RJRbtcreate_namespaced_config_mapRdR
RReR`RZR[RR](R.R|R�R�R�R�R2RtRfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytcreate_configmap|s,		cK@s�tjjd|�}tjjd|�}||j_t|�}z�y,tjj�}|j|�}|j	�SWnTt
tfk
r�}t|t
�r�|j
dkr�dStjd�t|��nXWdt|�XdS(u�
    Creates a namespace with the specified name.

    CLI Example:
        salt '*' kubernetes.create_namespace salt
        salt '*' kubernetes.create_namespace name=salt
    R.Rli�u2Exception when calling CoreV1Api->create_namespaceN(R R!tV1ObjectMetatV1NamespaceRlR.RJRbtcreate_namespaceRdR
RReR`R/RZR[RR](R.R2tmeta_objRtRfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyR��s c
K@s�tdddtdtd|d|d|d|d	|d
|d|�
}t|�}	z�y2tjj�}
|
j|||�}|j�SWnTt	t
fk
r�}t|t	�r�|jdkr�dStjd
�t|��nXWdt|	�XdS(u�
    Replaces an existing deployment with a new one defined by name and
    namespace, having the specificed metadata and spec.
    R�u
DeploymentR�R�R.R|RlR�R�R�R�i�uJException when calling ExtensionsV1beta1Api->replace_namespaced_deploymentN(R�RR�RJR R!Rztreplace_namespaced_deploymentRdR
RReR`R/RZR[RR](
R.RlR�R�R�R�R|R2RtRfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytreplace_deployment�s2	cK@stdddtjjdtd|d|d|d|d	|d
|d|�
}	|dd
|	j_|dd|	j_t	|�}
z�y2tjj
�}|j|||	�}|j�SWnTt
tfk
r
}
t|
t
�r�|
jdkr�dStjd�t|
��nXWdt|
�XdS(u�
    Replaces an existing service with a new one defined by name and namespace,
    having the specificed metadata and spec.
    R�uServiceR�R�R.R|RlR�R�R�R�uspecu
cluster_ipumetadatauresource_versioni�u<Exception when calling CoreV1Api->replace_namespaced_serviceN(R�R R!R�R�R�t
cluster_ipRltresource_versionRJRbtreplace_namespaced_serviceRdR
RReR`R/RZR[RR](R.RlR�R�R�told_serviceR�R|R2RtRfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytreplace_service�s6
	c
K@s6|rt|||�}n|dkr0i}nt|�}x%|D]}tj||�||<qCWtjjdt||i�d|�}t	|�}	z�y2tjj
�}
|
j|||�}|j�SWnTt
tfk
r"}t|t
�r|jdkrdStjd�t|��nXWdt|	�XdS(uh
    Replaces an existing secret with a new one defined by name and namespace,
    having the specificed data.

    CLI Examples::

        salt 'minion1' kubernetes.replace_secret             name=passwords data='{"db": "letmein"}'

        salt 'minion2' kubernetes.replace_secret             name=passwords namespace=saltstack data='{"db": "passw0rd"}'
    RlR�i�u;Exception when calling CoreV1Api->replace_namespaced_secretN(R�R/R�R,R�R R!R�R�RJRbtreplace_namespaced_secretRdR
RReR`RZR[RR](
R.R�R�R�R�R|R2RSRtRfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytreplace_secret2s0	
	cK@s�|rt|||�}nt|�}tjjdt||i�d|�}t|�}z�y2tjj�}	|	j|||�}
|
j	�SWnTt
tfk
r�}t|t
�r�|j
dkr�dStjd�t|��nXWdt|�XdS(u�
    Replaces an existing configmap with a new one defined by name and
    namespace with the specified data.

    CLI Examples::

        salt 'minion1' kubernetes.replace_configmap             settings default '{"example.conf": "# example file"}'

        salt 'minion2' kubernetes.replace_configmap             name=settings namespace=default data='{"example.conf": "# example file"}'
    RlR�i�u>Exception when calling CoreV1Api->replace_namespaced_configmapN(R�R�R R!R�R�RJRbtreplace_namespaced_config_mapRdR
RReR`R/RZR[RR](R.R�R�R�R�R|R2RtRfRgRhRj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pytreplace_configmapis(	c
C@s�|r�t|||	�}
t|
t�sDd|
ksD|
d|kr\tdj|���nd|
kru|
d}nd|
kr�|
d}q�n|dt|||�d||��S(u3
    Create a Kubernetes Object body instance.
    ukindu/The source file should define only a {0} objectumetadatauspecRlR�(R�RetdictRtformatR�(R�R�R�R.R|RlR�R�R�R�tsrc_obj((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyR��s

cC@s'td||�}|s1tdj|���ntjjj|d���}|j�}|r
|tjjj	kr�tjjj	||dt
dt
d|dtdtd	td
t
�}|ds�tdj|d
���n|d
jd�}q
tdj|���ntjjj|�SWdQXdS(u�
    Read a yaml file and, if needed, renders that using the specifieds
    templating. Returns the python objects defined inside of the file.
    u
cp.cache_fileuSource file '{0}' not foundurtfrom_strtto_strR�tgrainstpillarR@toptsuresultu*Failed to render file path with error: {0}udatauutf-8uUnknown template specified: {0}N(RRR�R@RARPtfopentreadt	templatestTEMPLATE_REGISTRYR^t
__grains__t
__pillar__t__opts__tencodetyamlt	safe_load(R�R�R�tsfntsrctcontentsR�((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyR��s4	
cC@s�tjj�}||_d|kr1i|d<nd|dkr^djtj�|dd<nx<t|�D].\}}t||�rkt	|||�qkqkW|j
|kr�tjd�||_
n|S(uF
    Converts a dictionary into kubernetes ObjectMetaV1 instance.
    uannotationsukubernetes.io/change-causeu u[The object already has a name attribute, overwriting it with the one defined inside of salt(
R R!R�R|tjointsystargvRthasattrtsetattrR.RZR�(R.R|RlR�RSR�((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyR��s	
cC@s^td|jdd��}x<t|�D].\}}t||�r(t|||�q(q(W|S(uS
    Converts a dictionary into kubernetes AppsV1beta1DeploymentSpec instance.
    R�utemplateu(RRRR�R�(R�tspec_objRSR�((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyR�s
cC@sRtjj�}x<t|�D].\}}t||�rt|||�qqW|S(uC
    Converts a dictionary into kubernetes V1PodSpec instance.
    (R R!t	V1PodSpecRR�R�(R�R�RSR�((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyR�s
cC@s�tjj�}x�t|�D]�\}}|dkr�g|_x�|D]}tjj�}t|t�r�xHt|�D].\}}t||�rut	|||�ququWn	||_
|jj|�qDWqt||�rt	|||�qqW|S(uG
    Converts a dictionary into kubernetes V1ServiceSpec instance.
    uports(R R!t
V1ServiceSpecRtportst
V1ServicePortReR�R�R�tporttappend(R�R�RSR�R�t	kube_porttport_keyt
port_value((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyR�s	
	cC@sCi}x6t|�D](\}}tj|�|tj|�<qW|S(u?
    Returns a dictionary that has string keys and values.
    (RRt	text_type(t
dictionarytretRSR�((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyR�2s (ft__doc__t
__future__RRRR�tos.pathRKR,RXtloggingR)RttimeRt
contextlibRtsalt.exceptionsRtsalt.ext.sixRtsalt.extRtsalt.utils.filesR@tsalt.utils.platformtsalt.utils.templatestsalt.utils.versionstsalt.utils.yamlRtsalt.ext.six.movesR	R tkubernetes.clienttkubernetes.client.restR
turllib3.exceptionsRRRR
RtImportErrorR^RRt	getLoggert__name__RZRRRAR�R�RR�R=RJRTR]RaR_RmRoRuRvRyR~R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R/R�R�R�R�R�R�R�R�R�R�R�R�R�R�(((s>/usr/lib/python2.7/site-packages/salt/modules/kubernetesmod.pyt<module>-s�



	
		K								"	!		$7!	 !	-	-	/5-	)..4,	!	.				

Zerion Mini Shell 1.0