
    Vh=(                         d dl mZmZmZ eZdZdZ	 d dlm	Z	m
ZmZ d dlmZ dZ	 d d	lmZ  G d
 de      Z
y# e$ rZdZY dZ[dZ[ww xY w# e$ r Y 'w xY w)    )absolute_importdivisionprint_functiona  
    name: openshift
    author:
      - Chris Houseknecht (@chouseknecht)

    short_description: OpenShift inventory source

    description:
      - Fetch containers, services and routes for one or more clusters
      - Groups by cluster name, namespace, namespace_services, namespace_pods, namespace_routes, and labels
      - Uses openshift.(yml|yaml) YAML configuration file to set parameter values.

    deprecated:
      removed_in: 5.0.0
      why: |
        As discussed in U(https://github.com/ansible-collections/kubernetes.core/issues/31), we decided to
        remove the openshift inventory plugin in release 5.0.0.
      alternative: "Use M(kubernetes.core.k8s_info) and M(ansible.builtin.add_host) instead."

    options:
      plugin:
        description: token that ensures this is a source file for the 'openshift' plugin.
        required: True
        choices: ['openshift', 'community.okd.openshift']
      connections:
          description:
          - Optional list of cluster connection settings. If no connections are provided, the default
            I(~/.kube/config) and active context will be used, and objects will be returned for all namespaces
            the active user is authorized to access.
          suboptions:
              name:
                  description:
                  - Optional name to assign to the cluster. If not provided, a name is constructed from the server
                    and port.
              kubeconfig:
                  description:
                  - Path to an existing Kubernetes config file. If not provided, and no other connection
                    options are provided, the Kubernetes client will attempt to load the default
                    configuration file from I(~/.kube/config). Can also be specified via K8S_AUTH_KUBECONFIG
                    environment variable.
              context:
                  description:
                  - The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment
                    variable.
              host:
                  description:
                  - Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.
              api_key:
                  description:
                  - Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment
                    variable.
              username:
                  description:
                  - Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME
                    environment variable.
              password:
                  description:
                  - Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD
                    environment variable.
              client_cert:
                  description:
                  - Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE
                    environment variable.
                  aliases: [ cert_file ]
              client_key:
                  description:
                  - Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE
                    environment variable.
                  aliases: [ key_file ]
              ca_cert:
                  description:
                  - Path to a CA certificate used to authenticate with the API. Can also be specified via
                    K8S_AUTH_SSL_CA_CERT environment variable.
                  aliases: [ ssl_ca_cert ]
              validate_certs:
                  description:
                  - "Whether or not to verify the API server's SSL certificates. Can also be specified via
                    K8S_AUTH_VERIFY_SSL environment variable."
                  type: bool
                  aliases: [ verify_ssl ]
              namespaces:
                  description:
                  - List of namespaces. If not specified, will fetch all containers for all namespaces user is authorized
                    to access.

    requirements:
    - "python >= 3.6"
    - "kubernetes >= 12.0.0"
    - "PyYAML >= 3.11"
a  
# File must be named openshift.yaml or openshift.yml

- name: Authenticate with token, and return all pods and services for all namespaces
  plugin: community.okd.openshift
  connections:
    - host: https://192.168.64.4:8443
      api_key: xxxxxxxxxxxxxxxx
      verify_ssl: false

- name: Use default config (~/.kube/config) file and active context, and return objects for a specific namespace
  plugin: community.okd.openshift
  connections:
    - namespaces:
        - testing

- name: Use a custom config file, and a specific context.
  plugin: community.okd.openshift
  connections:
    - kubeconfig: /path/to/config
      context: 'awx/192-168-64-4:8443/developer'
)K8sInventoryExceptionInventoryModuleformat_dynamic_api_exc)get_api_clientTFN)DynamicApiErrorc                   6     e Zd ZdZdZdZd Z fdZd Z xZ	S )r   zcommunity.okd.openshiftzcommunity.okd.ococc                 &    t         st        d      y )Nz0The kubernetes.core collection must be installed)HAS_KUBERNETES_COLLECTIONr   )selfs    m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/okd/plugins/inventory/openshift.pycheck_kubernetes_collectionz+InventoryModule.check_kubernetes_collection   s    ('B  )    c                    | j                          t        t        |   |       | j                  j                  ddd       |rt        |t              st        d      |D ]  }t        di |}|j                  d| j                  |j                  j                              }|j                  d      r|d   }n| j                  |      }|D ]  }| j                  |||         y t               }| j                  |j                  j                        }| j                  |      }|D ]  }| j                  |||        y )	NzYThe 'openshift' inventory plugin has been deprecated and will be removed in release 5.0.0z5.0.0zcommunity.okd)versioncollection_namez#Expecting connections to be a list.name
namespaces )r   superr   fetch_objectsdisplay
deprecated
isinstancelistr   r	   getget_default_host_nameconfigurationhostget_available_namespacesget_routes_for_namespace)r   connections
connectionclientr   r   	namespace	__class__s          r   r   zInventoryModule.fetch_objects   sE   ((*ot2;?g+ 	  	
 k40+,QRR) 
K
'5*5!~~D66v7K7K7P7PQ >>,/!+L!9J!%!>!>v!FJ!+ KI11&$	JK
K $%F--f.B.B.G.GHD66v>J' G	--fdIFGr   c                 	   | j                          |j                  j                  dd      }	 |j                  |      }dj                  |      }dj                  |      }| j                  j                  |       | j                  j                  |       | j                  j                  ||       | j                  j                  |       | j                  j                  ||       |j                  D ]M  }	|	j                  j                  }
|	j                  j                  si nt!        |	j                  j                        }| j                  j#                  |
       |	j                  j$                  r|	j                  j$                  D ]N  \  }}dj                  ||      }| j                  j                  |       | j                  j                  ||
       P t!        |	j                  j$                        }ni }| j                  j                  ||
       | j                  j'                  |
d	|       | j                  j'                  |
d
|       | j                  j'                  |
d|	j                  j(                         | j                  j'                  |
dd       | j                  j'                  |
d|	j                  j*                         | j                  j'                  |
d|	j                  j,                         | j                  j'                  |
d|	j                  j.                         |	j0                  j2                  r1| j                  j'                  |
d|	j0                  j2                         |	j0                  j4                  r1| j                  j'                  |
d|	j0                  j4                         t7        |	j0                  j8                  d      s|	j0                  j8                  j:                  s| j                  j'                  |
dt!        |	j0                  j8                               P y # t        $ r7}| j                  j                  |       t        dt        |      z        d }~ww xY w)Nzroute.openshift.io/v1Route)api_versionkind)r(   zError fetching Routes list: %sznamespace_{0}z
{0}_routeszlabel_{0}_{1}labelsannotationscluster_nameobject_typeroute	self_linkresource_versionuidr"   path
targetPortport)r   	resourcesr   r
   r   debugr   r   format	inventory	add_group	add_childitemsmetadatar   r/   dictadd_hostr.   set_variableclusterNameselfLinkresourceVersionr5   specr"   r6   hasattrr8   r7   )r   r'   r   r(   v1_routeobjexcnamespace_groupnamespace_routes_groupr2   
route_nameroute_annotationskeyvalue
group_nameroute_labelss                   r   r$   z(InventoryModule.get_routes_for_namespace   si   ((*##''/g ( 
	,,,3C *00;!-!4!4_!E  &  1  7  !78  2HIYY ,	WE,,J ~~11 %..445  NN##J/~~$$"'.."7"7 EJC!0!7!7U!CJNN,,Z8NN,,ZDE  $ENN$9$9:!NN$$%;ZH NN''
HlKNN''
MCTUNN''NENN,F,F NN''
M7KNN''K)@)@ NN''.0N0N NN''
E5>>;M;MNzz++J

Pzz++J

Puzz5%**//:T:T++JUZZ__@UVY,	W  	LLs#'03I#3NN 	s   Q
 
	R
2RR
)
__name__
__module____qualname__NAMEconnection_plugin	transportr   r   r$   __classcell__)r)   s   @r   r   r      s&    $D*IG@AWr   r   )
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLES9ansible_collections.kubernetes.core.plugins.inventory.k8sr   r   K8sInventoryModuler   Cansible_collections.kubernetes.core.plugins.module_utils.k8s.clientr	   r   ImportErrorekubernetes.dynamic.exceptionsr
   r   r   r   <module>rf      s    A @Yv.& 
 !%
	=
mW( mW  & %&  		s%   7 A AAAAA