
    Vh3                     R    d Z dZdZddlmZ  G d de      Zd Zedk(  r e        y	y	)
a  
---
module: keypair
short_description: Add/Delete a keypair from OpenStack
author: OpenStack Ansible SIG
description:
  - Add or Remove key pair from OpenStack
options:
  name:
    description:
      - Name that has to be given to the key pair
    required: true
    type: str
  public_key:
    description:
      - The public key that would be uploaded to nova and injected into VMs
        upon creation.
    type: str
  public_key_file:
    description:
      - Path to local file containing ssh public key. Mutually exclusive
        with public_key.
    type: str
  state:
    description:
      - Should the resource be present or absent. If state is replace and
        the key exists but has different content, delete it and recreate it
        with the new content.
    choices: [present, absent, replace]
    default: present
    type: str
extends_documentation_fragment:
- openstack.cloud.openstack
ah  
# Creates a key pair with the running users public key
- openstack.cloud.keypair:
      cloud: mordred
      state: present
      name: ansible_key
      public_key_file: /home/me/.ssh/id_rsa.pub

# Creates a new key pair and the private key returned after the run.
- openstack.cloud.keypair:
      cloud: rax-dfw
      state: present
      name: ansible_key
a  
keypair:
    description: Dictionary describing the keypair.
    returned: On success when I(state) is 'present'
    type: dict
    contains:
        created_at:
            description: Date the keypair was created
            returned: success
            type: str
        fingerprint:
            description: The short fingerprint associated with the public_key
                         for this keypair.
            returned: success
            type: str
        id:
            description: Unique UUID.
            returned: success
            type: str
        is_deleted:
            description: Whether the keypair is deleted or not
            returned: success
            type: bool
        name:
            description: Name given to the keypair.
            returned: success
            type: str
        private_key:
            description: The private key value for the keypair.
            returned: Only when a keypair is generated for the user (e.g., when
                      creating one and a public key is not specified).
            type: str
        public_key:
            description: The public key value for the keypair.
            returned: success
            type: str
        type:
            description: The type of keypair
            returned: success
            type: str
        user_id:
            description: The user id for a keypair
            returned: success
            type: str
    )OpenStackModulec            
       ~    e Zd Z e ed       e        e        edg d            Z eddgg	      Zd
 Zd Zy)KeyPairModuleT)requiredpresent)absentr   replace)defaultchoices)name
public_keypublic_key_filestater   r   )mutually_exclusivec                 B    | j                   d   }|dk(  r|sy|dk(  r|ryy)Nr   r   Tr   F)params)selfkeypairr   s      k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/keypair.py_system_state_changez"KeyPairModule._system_state_changez   s-    G$IgH    c                    | j                   d   }| j                   d   }| j                   d   }| j                   d   r1t        | j                   d         5 }|j                         }d d d        | j                  j                  j                  |      }| j                  j                  r!| j                  | j                  |             d}|dv r|rq|d   |k(  ri|r||d   k7  r}|dk(  r| j                  d	|z  
       nb| j                  j                  j                  |       | j                  j                  ||      }d}n| j                  j                  ||      }d}| j                  ||j                  d             y |dk(  rL|r7| j                  j                  j                  |       | j                  d       | j                  d       y y # 1 sw Y   sxY w)Nr   r   r   r   )changedF)r   r	   r   zKKey name %s present but key hash not the same as offered. Delete key first.)msgT)computed)r   r   r   )r   openreadconncomputefind_keypairansible
check_mode	exit_jsonr   	fail_jsondelete_keypaircreate_keypairto_dict)r   r   r   r   public_key_fhr   r   s          r   runzKeyPairModule.run   s   G${{6"[[.
;;()dkk"345 2*//1
2 ))##006<<""NN4#<#<W#ENF**76?d2:1F#F	)!ACG!H ' 
 		))88A"&))":":4"L"&))224DNN%)H  J h		!!009t,NN5N)	 92 2s   GG!N)__name__
__module____qualname__dictargument_specmodule_kwargsr   r)    r   r   r   r   m   sN    4 69;=	M )+<=>@M'*r   r   c                  &    t               }  |         y )N)r   )modules    r   mainr3      s    _F
Hr   __main__N)DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   r3   r*   r0   r   r   <module>r9      sG   !F,
\<*O <*~
 zF r   