
    VhEH                     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: image
short_description: Manage images of OpenStack image (Glance) service.
author: OpenStack Ansible SIG
description:
  - Create or delete images in OpenStack image (Glance) service.
options:
  checksum:
    description:
      - The checksum of the image.
    type: str
  container_format:
    description:
      - The format of the container.
      - This image attribute cannot be changed.
      - Examples are C(ami), C(aki), C(ari), C(bare), C(ovf), C(ova) or
        C(docker).
    default: bare
    type: str
  disk_format:
    description:
      - The format of the disk that is getting uploaded.
      - This image attribute cannot be changed.
      - Examples are C(ami), C(ari), C(aki), C(vhd), C(vmdk), C(raw),
        C(qcow2), C(vdi), c(iso), C(vhdx) or C(ploop).
    default: qcow2
    type: str
  filename:
    description:
      - The path to the file which has to be uploaded.
      - This image attribute cannot be changed.
    type: str
  id:
    description:
      - The ID of the image when uploading an image.
      - This image attribute cannot be changed.
    type: str
  is_protected:
    description:
      - Prevent image from being deleted.
    aliases: ['protected']
    type: bool
  is_public:
    description:
      - Whether the image can be accessed publicly.
      - Setting I(is_public) to C(true) requires admin role by default.
      - I(is_public) has been deprecated. Use I(visibility) instead of
        I(is_public).
    type: bool
    default: false
  kernel:
    description:
      - The name of an existing kernel image that will be associated with this
        image.
    type: str
  min_disk:
    description:
      - The minimum disk space (in GB) required to boot this image.
    type: int
  min_ram:
    description:
      - The minimum ram (in MB) required to boot this image.
    type: int
  name:
    description:
      - The name of the image when uploading - or the name/ID of the image if
        deleting.
      - If provided with the id, it can be used to change the name of existing
        image.
    required: true
    type: str
  owner:
    description:
      - The name or ID of the project owning the image.
    type: str
    aliases: ['project']
  owner_domain:
    description:
      - The name or id of the domain the project owning the image belongs to.
      - May be used to identify a unique project when providing a name to the
        project argument and multiple projects with such name exist.
    type: str
    aliases: ['project_domain']
  properties:
    description:
      - Additional properties to be associated with this image.
    default: {}
    type: dict
  ramdisk:
    description:
      - The name of an existing ramdisk image that will be associated with this
        image.
    type: str
  state:
    description:
      - Should the resource be present, absent or inactive.
    choices: [present, absent, inactive]
    default: present
    type: str
  tags:
    description:
      - List of tags to be applied to the image.
    default: []
    type: list
    elements: str
  visibility:
    description:
      - The image visibility.
    type: str
    choices: [public, private, shared, community]
  volume:
    description:
      - ID of a volume to create an image from.
      - The volume must be in AVAILABLE state.
      - I(volume) has been deprecated. Use module M(openstack.cloud.volume)
        instead.
    type: str
  use_import:
    description:
      - Use the 'glance-direct' method of the interoperable image import mechanism.
      - Should only be used when needed, such as when the user needs the cloud to
        transform image format.
    type: bool
extends_documentation_fragment:
  - openstack.cloud.openstack
a  
- name: Upload an image from a local file named cirros-0.3.0-x86_64-disk.img
  openstack.cloud.image:
    cloud: devstack-admin
    name: cirros
    container_format: bare
    disk_format: qcow2
    state: present
    filename: cirros-0.3.0-x86_64-disk.img
    kernel: cirros-vmlinuz
    ramdisk: cirros-initrd
    tags:
      - custom
    properties:
      cpu_arch: x86_64
      distro: ubuntu
a  
image:
  description: Dictionary describing the Glance image.
  returned: On success when I(state) is C(present) or C(inactive).
  type: dict
  contains:
    id:
      description: Unique UUID.
      type: str
    name:
      description: Name given to the image.
      type: str
    status:
      description: Image status.
      type: str
    architecture:
      description: The CPU architecture that must be supported by
                   the hypervisor.
      type: str
    created_at:
      description: Image created at timestamp.
      type: str
    container_format:
      description: Container format of the image.
      type: str
    direct_url:
      description: URL to access the image file kept in external store.
      type: str
    min_ram:
      description: Min amount of RAM required for this image.
      type: int
    disk_format:
      description: Disk format of the image.
      type: str
    file:
      description: The URL for the virtual machine image file.
      type: str
    has_auto_disk_config:
      description: If root partition on disk is automatically resized
                   before the instance boots.
      type: bool
    hash_algo:
      description: The algorithm used to compute a secure hash of the
                   image data.
      type: str
    hash_value:
      description: The hexdigest of the secure hash of the image data
                   computed using the algorithm whose name is the value of the
                   os_hash_algo property.
      type: str
    hw_cpu_cores:
      description: Used to pin the virtual CPUs (vCPUs) of instances to
                   the host's physical CPU cores (pCPUs).
      type: str
    hw_cpu_policy:
      description: The hexdigest of the secure hash of the image data.
      type: str
    hw_cpu_sockets:
      description: Preferred number of sockets to expose to the guest.
      type: str
    hw_cpu_thread_policy:
      description: Defines how hardware CPU threads in a simultaneous
                   multithreading-based (SMT) architecture be used.
      type: str
    hw_cpu_threads:
      description: The preferred number of threads to expose to the guest.
      type: str
    hw_disk_bus:
      description: Specifies the type of disk controller to attach disk
                   devices to.
      type: str
    hw_machine_type:
      description: Enables booting an ARM system using the
                   specified machine type.
      type: str
    hw_qemu_guest_agent:
      description: "A string boolean, which if 'true', QEMU guest agent
                    will be exposed to the instance."
      type: str
    hw_rng_model:
      description: "Adds a random-number generator device to the image's
                   instances."
      type: str
    hw_scsi_model:
      description: Enables the use of VirtIO SCSI (virtio-scsi) to
                   provide block device access for compute instances.
      type: str
    hw_video_model:
      description: The video image driver used.
      type: str
    hw_video_ram:
      description: Maximum RAM for the video image.
      type: str
    hw_vif_model:
      description: Specifies the model of virtual network interface device to
                   use.
      type: str
    hw_watchdog_action:
      description: Enables a virtual hardware watchdog device that
                   carries out the specified action if the server hangs.
      type: str
    hypervisor_type:
      description: The hypervisor type.
      type: str
    instance_type_rxtx_factor:
      description: Optional property allows created servers to have a
                   different bandwidth cap than that defined in the network
                   they are attached to.
      type: str
    instance_uuid:
      description: For snapshot images, this is the UUID of the server
                   used to create this image.
      type: str
    is_hidden:
      description: Controls whether an image is displayed in the default
                   image-list response
      type: bool
    is_hw_boot_menu_enabled:
      description: Enables the BIOS bootmenu.
      type: bool
    is_hw_vif_multiqueue_enabled:
      description: Enables the virtio-net multiqueue feature.
      type: bool
    kernel_id:
      description: The ID of an image stored in the Image service that
                   should be used as the kernel when booting an AMI-style
                   image.
      type: str
    locations:
      description: A list of URLs to access the image file in external store.
      type: str
    metadata:
      description: The location metadata.
      type: str
    needs_config_drive:
      description: Specifies whether the image needs a config drive.
      type: bool
    needs_secure_boot:
      description: Whether Secure Boot is needed.
      type: bool
    os_admin_user:
      description: The operating system admin username.
      type: str
    os_command_line:
      description: The kernel command line to be used by libvirt driver.
      type: str
    os_distro:
      description: The common name of the operating system distribution
                   in lowercase.
      type: str
    os_require_quiesce:
      description: If true, require quiesce on snapshot via
                   QEMU guest agent.
      type: str
    os_shutdown_timeout:
      description: Time for graceful shutdown.
      type: str
    os_type:
      description: The operating system installed on the image.
      type: str
    os_version:
      description: The operating system version as specified by
                   the distributor.
      type: str
    owner_id:
      description: The ID of the owner, or project, of the image.
      type: str
    ramdisk_id:
      description: The ID of image stored in the Image service that should
                   be used as the ramdisk when booting an AMI-style image.
      type: str
    schema:
      description: URL for the schema describing a virtual machine image.
      type: str
    store:
      description: Glance will attempt to store the disk image data in the
                   backing store indicated by the value of the header.
      type: str
    updated_at:
      description: Image updated at timestamp.
      type: str
    url:
      description: URL to access the image file kept in external store.
      type: str
    virtual_size:
      description: The virtual size of the image.
      type: str
    vm_mode:
      description: The virtual machine mode.
      type: str
    vmware_adaptertype:
      description: The virtual SCSI or IDE controller used by the
                   hypervisor.
      type: str
    vmware_ostype:
      description: Operating system installed in the image.
      type: str
    filters:
      description: Additional properties associated with the image.
      type: dict
    min_disk:
      description: Min amount of disk space required for this image.
      type: int
    is_protected:
      description: Image protected flag.
      type: bool
    checksum:
      description: Checksum for the image.
      type: str
    owner:
      description: Owner for the image.
      type: str
    visibility:
      description: Indicates who has access to the image.
      type: str
    size:
      description: Size of the image.
      type: int
    tags:
      description: List of tags assigned to the image
      type: list
    )OpenStackModulec            
          e Zd Z ed7i d e       d ed      d ed      d e       d e       d	 ed
dg      d ed
d      d e       d ed      d ed      d ed      d edg      d edg      d edi       d e       d  ed!g d"#      d$ ed%g d&'      d( eg d)*      d+ e       d, ed
      Z ed-d.g/      Zd0Zd1 Zd2 Zd3 Z	d4 Z
d5 Zy6)8ImageModulechecksumcontainer_formatbare)defaultdisk_formatqcow2filenameidis_protectedbool	protected)typealiases	is_publicF)r   r	   kernelmin_diskint)r   min_ramnameT)requiredownerproject)r   owner_domainproject_domain
propertiesdictramdiskstatepresent)absentr"   inactive)r	   choicestagsliststr)r   r	   elements
visibility)publicprivateshared	community)r%   volume
use_import)r   r/   )r*   r   )mutually_exclusive)r   r   r   r
   r   waittimeoutr   r   r   r   r/   r&   r0   c                     | j                   d   r| j                   d   S | j                   d   | j                   d   rdS dS y)z?resolve a visibility value to be compatible with older versionsr*   r   Nr+   r,   )params)selfs    i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/image.py_resolve_visibilityzImageModule._resolve_visibility  sE    ;;|$;;|,,;;{#/#{{;78FYF    c                     | j                   D ci c]  }|| j                  |    }}|r|j                  |d<   | j                         |d<   |j	                         D ci c]  \  }}|	|| }}}|S c c}w c c}}w )Nowner_idr*   )attr_paramsr5   r   r8   items)r6   r   attrr5   kvs         r7   _build_paramszImageModule._build_params  s    6:6F6FGd$D))GG!&F:#779|#)<<>C41aQ]!Q$CC H Ds   A4
A9*A9c                 x    | j                   j                  j                  |      }|r|j                  d      }|S )NF)computed)connimage
find_imageto_dict)r6   image_name_or_idrE   s      r7   _return_valuezImageModule._return_value  s3    		**+;<MM5M1Er9   c                     d| j                         i}dD ]  }| j                  |   ||<    dD ]f  }| j                  |   sdj                  |      }| j                  j                  j                  | j                  |   d      }|j                  ||<   h |j                         D ci c]  \  }}|||   |k7  r|| }}}| j                  d   j                         D ]  \  }}||vs	||   |k7  s|||<    | j                  d   r9t        |d         t        | j                  d         k7  r| j                  d   |d<   | j                  d	   r6| j                  d
   r'| j                  d
   |d
   k7  r| j                  d
   |d
<   |S c c}}w )Nr*   )r   r   r   )r   r    z{0}_idF)
name_or_idignore_missingr   r&   r   r   )	r8   r5   formatrD   rE   rF   r   r=   set)r6   rE   update_payloadr?   k_idk_imager@   ps           r7   _build_updatezImageModule._build_update  s   &(@(@(BC8 	/A $AN1	/ ' 	.A;;q>??1%Diioo00;;q>% 1 AG#*::N4 	. ,:+?+?+A >41a]uQx1} Q$ > > KK-335 	&DAq~qQ$%q!	& KKf&#dkk&.A*BB%)[[%8N6" ;;t;;v;;v%-/%)[[%8N6"#>s   *F
c           	      z   d}| j                   d   xs | j                   d   }| j                   d   }| j                   d   }i }|r<| j                  j                  j                  |      }|r|j                  |d<   n||d<   d }|r) | j                  j                  j
                  |fddi|}d }|rH| j                  j                  |dD 	ci c]!  }	| j                   |	   |	| j                   |	   # c}		      }d}| j                   d
   dk(  r| j                  |      }
|sY | j                  j                  di |
}d}| j                   d   s,| j                  || j                  |j                               |d   dk(  r'| j                  j                  j                  |       d}| j                  |      }|r3 | j                  j                  j                  |j                  fi | d}| j                  || j                  |j                               n| j                   d
   dk(  r@|>| j                  j                  |d   | j                   d   | j                   d          d}n| j                   d
   dk(  r||d   dk(  r'| j                  j                  j!                  |       d}| j                  |      }|r3 | j                  j                  j                  |j                  fi | d}| j                  || j                  |j                               | j                  |       y c c}	w )NFr   r   r   r   	domain_idrL   )r   )filtersr!   r"   Tr2   )changedrE   statusdeactivatedr#   r3   )rK   r2   r3   r$   active)rW    )r5   rD   identityfind_domainr   find_project	get_imagerA   create_image	exit_jsonrI   rE   reactivate_imagerS   update_imagedelete_imagedeactivate_image)r6   rW   rH   owner_name_or_idowner_domain_name_or_idowner_filtersr   r   rE   r?   attrsrO   s               r7   runzImageModule.run  s   ;;t,CF0C;;w/"&++n"="99--99')L-9__k* .Ek*3DII&&33 I16I:GIE II'' ".N$++a.2L DKKN* N ( OE
 ;;w9,&&u-E
 /		..77{{6*NN7)-););EHH)E # G X-/		007!//6N,		,,UXXHHNN7$2D2DUXX2NNO[[!X-%2CII"" ;[[(I. # 0 G[[!Z/E4EX(*		007!//6N,		,,UXXHHNN7$2D2DUXX2NNOw'eNs   &L8
Nr[   )__name__
__module____qualname__r   argument_specmodule_kwargsr<   r8   rA   rI   rS   rj   r[   r9   r7   r   r   {  sq    f- ) 	
 6 v}= FE2 v 5! %  4  I;' #3"45 VR0   9.OP!" vrE:#$  LM%& v'( V$)M. "'
M!K
BJ(r9   r   c                  &    t               }  |         y )N)r   )modules    r7   mainrr   %  s    ]F
Hr9   __main__N)DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   rr   rk   r[   r9   r7   <module>rx      sL   }~$]
~ _g(/ g(T
 zF r9   