
    Vhz                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
Z
d dlZd dlZd dlmZ d dlmZmZ d dlmZ d	d
ddddZddddZdZg dZddgZ G d de      Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionaM  
module: lxd_container
short_description: Manage LXD instances
description:
  - Management of LXD containers and virtual machines.
author: "Hiroaki Nakamura (@hnakamur)"
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
    version_added: 6.4.0
  diff_mode:
    support: full
    version_added: 6.4.0
options:
  name:
    description:
      - Name of an instance.
    type: str
    required: true
  project:
    description:
      - Project of an instance.
      - See U(https://documentation.ubuntu.com/lxd/en/latest/projects/).
    required: false
    type: str
    version_added: 4.8.0
  architecture:
    description:
      - The architecture for the instance (for example V(x86_64) or V(i686)).
      - See U(https://documentation.ubuntu.com/lxd/en/latest/api/#/instances/instance_get).
    type: str
    required: false
  config:
    description:
      - 'The config for the instance (for example V({"limits.cpu": "2"})).'
      - See U(https://documentation.ubuntu.com/lxd/en/latest/api/#/instances/instance_get).
      - If the instance already exists and its "config" values in metadata obtained from the LXD API
        U(https://documentation.ubuntu.com/lxd/en/latest/api/#/instances/instance_get)
        are different, then this module tries to apply the configurations U(https://documentation.ubuntu.com/lxd/en/latest/api/#/instances/instance_put).
      - The keys starting with C(volatile.) are ignored for this comparison when O(ignore_volatile_options=true).
    type: dict
    required: false
  ignore_volatile_options:
    description:
      - If set to V(true), options starting with C(volatile.) are ignored. As a result, they are reapplied for each execution.
      - This default behavior can be changed by setting this option to V(false).
      - The default value changed from V(true) to V(false) in community.general 6.0.0.
    type: bool
    required: false
    default: false
    version_added: 3.7.0
  profiles:
    description:
      - Profile to be used by the instance.
    type: list
    elements: str
  devices:
    description:
      - 'The devices for the instance (for example V({ "rootfs": { "path": "/dev/kvm", "type": "unix-char" }})).'
      - See U(https://documentation.ubuntu.com/lxd/en/latest/api/#/instances/instance_get).
    type: dict
    required: false
  ephemeral:
    description:
      - Whether or not the instance is ephemeral (for example V(true) or V(false)).
      - See U(https://documentation.ubuntu.com/lxd/en/latest/api/#/instances/instance_get).
    required: false
    type: bool
  source:
    description:
      - 'The source for the instance (for example V({ "type": "image", "mode": "pull", "server": "https://cloud-images.ubuntu.com/releases/",
        "protocol": "simplestreams", "alias": "22.04" })).'
      - See U(https://documentation.ubuntu.com/lxd/en/latest/api/) for complete API documentation.
      - 'Note that C(protocol) accepts two choices: V(lxd) or V(simplestreams).'
    required: false
    type: dict
  state:
    choices:
      - started
      - stopped
      - restarted
      - absent
      - frozen
    description:
      - Define the state of an instance.
    required: false
    default: started
    type: str
  target:
    description:
      - For cluster deployments. Will attempt to create an instance on a target node. If the instance exists elsewhere in
        a cluster, then it will not be replaced or moved. The name should respond to same name of the node you see in C(lxc
        cluster list).
    type: str
    required: false
    version_added: 1.0.0
  timeout:
    description:
      - A timeout for changing the state of the instance.
      - This is also used as a timeout for waiting until IPv4 addresses are set to the all network interfaces in the instance
        after starting or restarting.
    required: false
    default: 30
    type: int
  type:
    description:
      - Instance type can be either V(virtual-machine) or V(container).
    required: false
    default: container
    choices:
      - container
      - virtual-machine
    type: str
    version_added: 4.1.0
  wait_for_ipv4_addresses:
    description:
      - If this is V(true), the C(lxd_container) waits until IPv4 addresses are set to the all network interfaces in the instance
        after starting or restarting.
    required: false
    default: false
    type: bool
  wait_for_container:
    description:
      - If set to V(true), the tasks will wait till the task reports a success status when performing container operations.
    default: false
    type: bool
    version_added: 4.4.0
  force_stop:
    description:
      - If this is V(true), the C(lxd_container) forces to stop the instance when it stops or restarts the instance.
    required: false
    default: false
    type: bool
  url:
    description:
      - The unix domain socket path or the https URL for the LXD server.
    required: false
    default: unix:/var/lib/lxd/unix.socket
    type: str
  snap_url:
    description:
      - The unix domain socket path when LXD is installed by snap package manager.
    required: false
    default: unix:/var/snap/lxd/common/lxd/unix.socket
    type: str
  client_key:
    description:
      - The client certificate key file path.
      - If not specified, it defaults to C(${HOME}/.config/lxc/client.key).
    required: false
    aliases: [key_file]
    type: path
  client_cert:
    description:
      - The client certificate file path.
      - If not specified, it defaults to C(${HOME}/.config/lxc/client.crt).
    required: false
    aliases: [cert_file]
    type: path
  trust_password:
    description:
      - The client trusted password.
      - 'You need to set this password on the LXD server before running this module using the following command: C(lxc config
        set core.trust_password <some random password>). See U(https://www.stgraber.org/2016/04/18/lxd-api-direct-interaction/).'
      - If trust_password is set, this module send a request for authentication before sending any requests.
    required: false
    type: str
notes:
  - Instances can be a container or a virtual machine, both of them must have unique name. If you attempt to create an instance
    with a name that already existed in the users namespace the module will simply return as "unchanged".
  - There are two ways to run commands inside a container or virtual machine, using the command module or using the ansible
    lxd connection plugin bundled in Ansible >= 2.1, the later requires python to be installed in the instance which can be
    done with the command module.
  - You can copy a file from the host to the instance with the Ansible M(ansible.builtin.copy) and M(ansible.builtin.template)
    module and the P(community.general.lxd#connection) connection plugin. See the example below.
  - You can copy a file in the created instance to the localhost with C(command=lxc file pull instance_name/dir/filename filename).
    See the first example below.
  - Linuxcontainers.org has phased out LXC/LXD support with March 2024
    (U(https://discuss.linuxcontainers.org/t/important-notice-for-lxd-users-image-server/18479)).
    Currently only Ubuntu is still providing images.
a  
# An example for creating a Ubuntu container and install python
- hosts: localhost
  connection: local
  tasks:
    - name: Create a started container
      community.general.lxd_container:
        name: mycontainer
        ignore_volatile_options: true
        state: started
        source:
          type: image
          mode: pull
          server: https://cloud-images.ubuntu.com/releases/
          protocol: simplestreams
          alias: "22.04"
        profiles: ["default"]
        wait_for_ipv4_addresses: true
        timeout: 600

    - name: Check python is installed in container
      delegate_to: mycontainer
      ansible.builtin.raw: dpkg -s python
      register: python_install_check
      failed_when: python_install_check.rc not in [0, 1]
      changed_when: false

    - name: Install python in container
      delegate_to: mycontainer
      ansible.builtin.raw: apt-get install -y python
      when: python_install_check.rc == 1

# An example for creating an Ubuntu 14.04 container using an image fingerprint.
# This requires changing 'server' and 'protocol' key values, replacing the
# 'alias' key with with 'fingerprint' and supplying an appropriate value that
# matches the container image you wish to use.
- hosts: localhost
  connection: local
  tasks:
    - name: Create a started container
      community.general.lxd_container:
        name: mycontainer
        ignore_volatile_options: true
        state: started
        source:
          type: image
          mode: pull
          # Provides current (and older) Ubuntu images with listed fingerprints
          server: https://cloud-images.ubuntu.com/releases
          # Protocol used by 'ubuntu' remote (as shown by 'lxc remote list')
          protocol: simplestreams
          # This provides an Ubuntu 14.04 LTS amd64 image from 20150814.
          fingerprint: e9a8bdfab6dc
        profiles: ["default"]
        wait_for_ipv4_addresses: true
        timeout: 600

# An example of creating a ubuntu-minial container
- hosts: localhost
  connection: local
  tasks:
    - name: Create a started container
      community.general.lxd_container:
        name: mycontainer
        ignore_volatile_options: true
        state: started
        source:
          type: image
          mode: pull
         # Provides Ubuntu minimal images
          server: https://cloud-images.ubuntu.com/minimal/releases/
          protocol: simplestreams
          alias: "22.04"
        profiles: ["default"]
        wait_for_ipv4_addresses: true
        timeout: 600

# An example for creating container in project other than default
- hosts: localhost
  connection: local
  tasks:
    - name: Create a started container in project mytestproject
      community.general.lxd_container:
        name: mycontainer
        project: mytestproject
        ignore_volatile_options: true
        state: started
        source:
          protocol: simplestreams
          type: image
          mode: pull
          server: https://cloud-images.ubuntu.com/releases/
          alias: "22.04"
        profiles: ["default"]
        wait_for_ipv4_addresses: true
        timeout: 600

# An example for deleting a container
- hosts: localhost
  connection: local
  tasks:
    - name: Delete a container
      community.general.lxd_container:
        name: mycontainer
        state: absent
        type: container

# An example for restarting a container
- hosts: localhost
  connection: local
  tasks:
    - name: Restart a container
      community.general.lxd_container:
        name: mycontainer
        state: restarted
        type: container

# An example for restarting a container using https to connect to the LXD server
- hosts: localhost
  connection: local
  tasks:
    - name: Restart a container
      community.general.lxd_container:
        url: https://127.0.0.1:8443
        # These client_cert and client_key values are equal to the default values.
        # client_cert: "{{ lookup('env', 'HOME') }}/.config/lxc/client.crt"
        # client_key: "{{ lookup('env', 'HOME') }}/.config/lxc/client.key"
        trust_password: mypassword
        name: mycontainer
        state: restarted

# Note your container must be in the inventory for the below example.
#
# [containers]
# mycontainer ansible_connection=lxd
#
- hosts:
    - mycontainer
  tasks:
    - name: Copy /etc/hosts in the created container to localhost with name "mycontainer-hosts"
      ansible.builtin.fetch:
        src: /etc/hosts
        dest: /tmp/mycontainer-hosts
        flat: true

# An example for LXD cluster deployments. This example will create two new container on specific
# nodes - 'node01' and 'node02'. In 'target:', 'node01' and 'node02' are names of LXD cluster
# members that LXD cluster recognizes, not ansible inventory names, see: 'lxc cluster list'.
# LXD API calls can be made to any LXD member, in this example, we send API requests to
# 'node01.example.com', which matches ansible inventory name.
- hosts: node01.example.com
  tasks:
    - name: Create LXD container
      community.general.lxd_container:
        name: new-container-1
        ignore_volatile_options: true
        state: started
        source:
          type: image
          mode: pull
          alias: "22.04"
        target: node01

    - name: Create container on another node
      community.general.lxd_container:
        name: new-container-2
        ignore_volatile_options: true
        state: started
        source:
          type: image
          mode: pull
          alias: "22.04"
        target: node02

# An example for creating a virtual machine
- hosts: localhost
  connection: local
  tasks:
    - name: Create container on another node
      community.general.lxd_container:
        name: new-vm-1
        type: virtual-machine
        state: started
        ignore_volatile_options: true
        wait_for_ipv4_addresses: true
        profiles: ["default"]
        source:
          protocol: simplestreams
          type: image
          mode: pull
          server: ['...'] # URL to the image server
          alias: debian/11
        timeout: 600
a  
addresses:
  description: Mapping from the network device name to a list of IPv4 addresses in the instance.
  returned: when state is started or restarted
  type: dict
  sample: {"eth0": ["10.155.92.191"]}
old_state:
  description: The old state of the instance.
  returned: when state is started or restarted
  type: str
  sample: "stopped"
logs:
  description: The logs of requests and responses.
  returned: when ansible-playbook is invoked with -vvvv.
  type: list
  sample: "(too long to be placed here)"
actions:
  description: List of actions performed for the instance.
  returned: success
  type: list
  sample: ["create", "start"]
N)AnsibleModule)	LXDClientLXDClientException)	urlencode_started_stopped
_restarted
_destroyed_frozen)startedstopped	restartedabsentfrozenr   r   r   )RunningStoppedFrozenzunix:/var/lib/lxd/unix.socket)architectureconfigdevices	ephemeralprofilessourcetyper   r   c                       e Zd Zd Zd Zd Zd Zed        ZddZ	d Z
d Zd	 Zd
 Zd Zd Zd ZddZed        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)LXDContainerManagementc                 |   || _         | j                   j                  d   | _        | j                   j                  d   | _        | j	                          | j                   j                  d   | _        | j                   j                  d   | _        | j                   j                  d   | _        | j                   j                  d   | _        d| _	        | j                   j                  d   | _
        | j                   j                  d	   | _        | j                   j                  d
   | _        | j                   j                  j                  d      | _        | j                  'dj                  t         j"                  d         | _        | j                   j                  j                  d      | _        | j$                  'dj                  t         j"                  d         | _        | j                   j&                  dk\  | _        	 | j                   j                  d   t*        k7  r| j                   j                  d   | _        nt         j.                  j1                  | j                   j                  d   j3                  dd            r| j                   j                  d   | _        n| j                   j                  d   | _        	 t;        | j,                  | j                  | j$                  | j(                        | _        d| _         | j<                  jC                  ddj                  | j@                        dg      }|d   dk(  r-| j                  dk(  rd| _         n| j                  dk(  rd | _         | j                   j                  j                  d!d      | _"        g | _#        i i d"| _$        i | _%        i | _&        y# t4        $ r1}| j                   j7                  |j8                         Y d}~1d}~ww xY w# t>        $ r1}| j                   j7                  |j8                         Y d}~1d}~ww xY w)#zManagement of LXC containers via Ansible.

        :param module: Processed Ansible Module.
        :type module: ``object``
        nameprojectstatetimeoutwait_for_ipv4_addresses
force_stopNtargetwait_for_containerr   
client_keyz{0}/.config/lxc/client.keyHOMEclient_certz{0}/.config/lxc/client.crt   urlsnap_urlzunix: )msg)key_file	cert_filedebugz/1.0/instancesGETz{0}?project=  ok_error_codes
error_code	containerz/1.0/containersvirtual-machinez/1.0/virtual-machinestrust_password)beforeafter)'moduleparamsr!   r"   _build_configr#   r$   r%   r&   	addressesr'   r(   r   getr1   formatosenvironr2   
_verbosityr3   ANSIBLE_LXD_DEFAULT_URLr-   pathexistsreplace	Exception	fail_jsonr0   r   clientr   api_endpointdor;   actionsdiffold_instance_jsonold_sections)selfr>   echeck_api_endpoints       s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/lxd_container.py__init__zLXDContainerManagement.__init__  sC    KK&&v.	{{)))4[[''0
{{)))4'+{{'9'9:S'T$++,,\:kk((2"&++"4"45I"JKK&&v.	**..|<== 8??

6@RSDM++//>>>!9@@FASTDN[[++q0
	-{{!!%(,CC;;--e4 2 2: > F FwPR ST;;--j9;;--e4	-#4==DNNjjDK -![[^^E>3H3HIZIZ3[mplq^rl+s2yyK'$5!//$;!"kk00445EtL!B/	!#5  	-KK!!aee!,,	- " 	-KK!!aee!,,	-s1   CO 	<P 	O>&O99O>	P;
&P66P;c                     i | _         t        D ]:  }| j                  j                  j	                  |d       }|,|| j                   |<   < y N)r   CONFIG_PARAMSr>   r?   rB   )rT   attr	param_vals      rW   r@   z$LXDContainerManagement._build_config  sH    ! 	.D**..tT:I$$-D!	.    c                    dj                  | j                  | j                        }| j                  r/dj                  |t	        t        | j                                    }| j                  j                  d|dg      S )N{0}/{1}{0}?{1}r"   r4   r5   r6   rC   rN   r!   r"   r	   dictrM   rO   rT   r-   s     rW   _get_instance_jsonz)LXDContainerManagement._get_instance_json  s`    t00$))<<<""3	$t||2L(MNC{{~~eS#~??r^   c                    dj                  | j                  | j                        }| j                  r/dj                  |t	        t        | j                                    }| j                  j                  d|dg      S )N{0}/{1}/statera   rb   r4   r5   r6   rc   re   s     rW   _get_instance_state_jsonz/LXDContainerManagement._get_instance_state_json  s`    $$T%6%6		B<<""3	$t||2L(MNC{{~~eS#~??r^   c                 2    | d   dk(  ryt         | d   d      S )Nr   errorr   metadatastatus)ANSIBLE_LXD_STATES)	resp_jsons    rW   _instance_json_to_module_statez5LXDContainerManagement._instance_json_to_module_state  s'    V'!)J"7"ABBr^   c                 Z   dj                  | j                  | j                        }| j                  r/dj                  |t	        t        | j                                    }|| j                  d}|rd|d<   | j                  j                  s| j                  j                  d||      S y )	Nrh   ra   rb   )actionr$   TforcePUT	body_json)rC   rN   r!   r"   r	   rd   r$   r>   
check_moderM   rO   )rT   rr   r&   r-   rv   s        rW   _change_statez$LXDContainerManagement._change_state!  s    $$T%6%6		B<<""3	$t||2L(MNC%$,,?	!%Ig{{%%;;>>%	>BB &r^   c                 *   | j                   }t               }| j                  r| j                  |d<   | j                  r| j                  |d<   |rdj	                  |t        |            }| j                  j                         }| j                  |d<   | j                  | j                   vr| j                  |d<   | j                  j                  s)| j                  j                  d||| j                         | j                  j!                  d       y )	Nr'   r"   ra   r!   r   POST)r(   create)rN   rd   r'   r"   rC   r	   r   copyr!   r   r>   rw   rM   rO   r(   rP   append)rT   r-   
url_paramsr   s       rW   _create_instancez'LXDContainerManagement._create_instance+  s    V
;;#';;Jx <<$(LLJy!""3	*(=>C!!#v99D---!YYF6N{{%%KKNN634CZCZN[H%r^   c                 \    | j                  d       | j                  j                  d       y )Nstartrx   rP   r}   rT   s    rW   _start_instancez&LXDContainerManagement._start_instance<  s"    7#G$r^   c                 r    | j                  d| j                         | j                  j                  d       y )Nstoprx   r&   rP   r}   r   s    rW   _stop_instancez%LXDContainerManagement._stop_instance@  s(    64??3F#r^   c                 r    | j                  d| j                         | j                  j                  d       y )Nrestartr   r   s    rW   _restart_instancez(LXDContainerManagement._restart_instanceD  s(    9doo6I&r^   c                 `   dj                  | j                  | j                        }| j                  r/dj                  |t	        t        | j                                    }| j                  j                  s| j                  j                  d|       | j                  j                  d       y )Nr`   ra   rb   DELETEdelete)rC   rN   r!   r"   r	   rd   r>   rw   rM   rO   rP   r}   re   s     rW   _delete_instancez'LXDContainerManagement._delete_instanceH  sv    t00$))<<<""3	$t||2L(MNC{{%%KKNN8S)H%r^   c                 \    | j                  d       | j                  j                  d       y )Nfreezer   r   s    rW   _freeze_instancez'LXDContainerManagement._freeze_instanceP  s"    8$H%r^   c                 \    | j                  d       | j                  j                  d       y )Nunfreezer   r   s    rW   _unfreeze_instancez)LXDContainerManagement._unfreeze_instanceT  s"    :&J'r^   Nc                    |dgn|}| j                         xs i j                  dd       xs i }|j                  d      xs i j                         D ci c]  \  }}||vr|| }}}|j                         D ci c]%  \  }}||d   D cg c]  }|d   dk(  s|d    c}' }}}}|S c c}}w c c}w c c}}}w )Nlorl   networkrA   familyinetaddress)ri   rB   items)rT   ignore_devicesdatakvr   arA   s           rW   _instance_ipv4_addressesz/LXDContainerManagement._instance_ipv4_addressesX  s    #1#9$~--/52:::tLRPR ),299;
1& qD
 
  
 
1 anN(v8M)NN
	 
 
 O
s$   B.>B9B4B4#B94B9c                 b    t        |       dkD  xr  t        d | j                         D              S )Nr   c              3   8   K   | ]  }t        |      d kD    yw)r   N)len).0r   s     rW   	<genexpr>zALXDContainerManagement._has_all_ipv4_addresses.<locals>.<genexpr>h  s     )Q#a&1*)Qs   )r   allvalues)rA   s    rW   _has_all_ipv4_addressesz.LXDContainerManagement._has_all_ipv4_addressesf  s*    9~!Qc)Qi>N>N>P)Q&QQr^   c                    	 t         j                   j                         t        j                  | j                        z   }t         j                   j                         |k  rwt	        j
                  d       | j                         }| j                  |      s| j                  j                  r|| _
        y t         j                   j                         |k  rvy y # t        $ r}d|_         d }~ww xY w)N)seconds   z"timeout for getting IPv4 addresses)datetimenow	timedeltar$   timesleepr   r   r>   rw   rA   r   r0   )rT   duerA   rU   s       rW   _get_addressesz%LXDContainerManagement._get_addressesj  s    
	##'')H,>,>t||,TTC##'')C/

1 99;	//	:dkk>T>T%.DN ##'')C/ " 	8AE	s   B3C 6!C 	C0#C++C0c                 \   | j                   dk(  r!| j                          | j                          n_| j                   dk(  r| j                          n| j                   dk(  r| j                          | j	                         r| j                          | j                  r| j                          y y Nr   r   r   )	old_stater   r   r    _needs_to_apply_instance_configs_apply_instance_configsr%   r   r   s    rW   r
   zLXDContainerManagement._startedw  s    >>X%!!#  "~~)'')9,$$&446,,.''! (r^   c                    | j                   dk(  r| j                          y | j                   dk(  rB| j                         r1| j                          | j	                          | j                          y y | j                   dk(  r| j                          | j                         r| j	                          | j                          y )Nr   r   r   )r   r   r   r   r   r   r   r   s    rW   r   zLXDContainerManagement._stopped  s    >>X%!!#~~*88:((*002'') ;
 >>X-++-88:002##%r^   c                 <   | j                   dk(  r!| j                          | j                          nO| j                   dk(  r| j                          | j	                         r| j                          | j                          | j                  r| j                          y y )Nr   r   )	r   r   r   r   r   r   r   r%   r   r   s    rW   r   z!LXDContainerManagement._restarted  s|    >>X%!!#  "~~)'')446,,.""$''! (r^   c                     | j                   dk7  rO| j                   dk(  r| j                          | j                   dk7  r| j                          | j                          y y r   )r   r   r   r   r   s    rW   r   z!LXDContainerManagement._destroyed  sO    >>X%~~)'')~~*##%!!# &r^   c                 "   | j                   dk(  r1| j                          | j                          | j                          y | j                   dk(  r| j                          | j	                         r| j                          | j                          y )Nr   r   )r   r   r   r   r   r   r   s    rW   r   zLXDContainerManagement._frozen  sn    >>X%!!#  "!!#~~*$$&446,,.!!#r^   c                 D   || j                   vry|dk(  r_t        | j                  j                  |d       xs i       }| j                   d   j	                         D ]  \  }}||vr y||   |k7  s y y| j                  j                  |i       }| j                   |   |k7  S )NFr   T)r   rd   rS   rB   r   )rT   keyold_configsr   r   s        rW    _needs_to_change_instance_configz7LXDContainerManagement._needs_to_change_instance_config  s    dkk!(?t0044S$?E2FKH-335  1K'q>Q&	 
 ++//R8K;;s#{22r^   c                 r    t        t              t        t              z
  D ]  }| j                  |      s y y)NTF)setr[   CONFIG_CREATION_PARAMSr   )rT   params     rW   r   z7LXDContainerManagement._needs_to_apply_instance_configs  s7    '#.D*EE 	E44U;	 r^   c                 2   t        j                  | j                        j                  dd       xs i }i }t	        t
              t	        t              z
  D ]~  }||v r||   ||<   | j                  |      s!|dk(  rG|j                  dd       xs i |d<   | j                  d   j                         D ]  \  }}||d   |<    m| j                  |   ||<    || j                  d   d<   dj                  | j                  | j                        }| j                  r/dj                  |t        t!        | j                                    }| j"                  j$                  s| j&                  j)                  d||	       | j*                  j-                  d
       y )Nrl   r   r=   instancer`   ra   rb   rt   ru   apply_instance_configs)r|   deepcopyrR   rB   r   r[   r   r   r   r   rQ   rC   rN   r!   r"   r	   rd   r>   rw   rM   rO   rP   r}   )rT   old_metadatarv   r   r   r   r-   s          rW   r   z.LXDContainerManagement._apply_instance_configs  sk   }}T%;%;<@@TRXVX	'#.D*EE 
	:E$#/#6	% 44U;H$*3--$*G*M2Ih' $H 5 ; ; = 3112	(+A.3 (,{{5'9Ie$
	: *3		':&t00$))<<<""3	$t||2L(MNC{{%%KKNN5#N;45r^   c           	           fd}	  j                   % j                  j                   j                           j                  j                  j                  d       _         j                          _         j                  j                  d      xs i j                         D ci c]/  \  }}|t        t              t        t              z
  v r	| ||      1 c}} _         j                   j                  d   d<    j                   j                  d   d<    j!                   j                         _         j"                   j                  d   d<    j$                   j                  d   d<   t'         t(         j$                           } |        t+         j,                        d	kD  } j                  j.                  | j"                   j,                   j                  d
} j                  j0                  r j                  j2                  |d<    j4                   j4                  |d<     j                  j6                  di | yc c}}w # t8        $ r}t+         j,                        d	kD  }|j:                  | j,                   j                  d} j                  j0                  r|j<                  d   |d<     j                  j>                  di | Y d}~yd}~ww xY w)zRun the main method.c                     t        | t              s| S | j                         D ci c]&  \  }}j                  r|j	                  d      r$||( c}}S c c}}w )Nz	volatile.)
isinstancerd   r   ignore_volatile_options
startswith)contentr   r   rT   s      rW   adjust_contentz2LXDContainerManagement.run.<locals>.adjust_content  sY    ",Wd";7 !(BA9U9UZ[ZfZfgrZs1B  Bs   %AANr   rl   r<   r   r=   r#   r   )log_verbositychangedr   rP   rQ   logsrA   )r0   r   rP   rQ    ) r;   rM   authenticater>   r?   rB   r   rf   rR   r   r   r[   r   rS   rQ   r   rp   r   r#   getattrLXD_ANSIBLE_STATESr   rP   rF   r3   r   rA   	exit_jsonr   r0   kwargsrL   )	rT   r   sectionr   rr   state_changedresult_jsonrU   fail_paramss	   `        rW   runzLXDContainerManagement.run  si   	
.	1"".(()<)<=+/;;+=+=+A+AB[+\D(%)%<%<%>D" *.)?)?)C)CJ)O)USU(\(\(^!$GWc-037M3NNN 00!D /3.?.?DIIh
+-1[[DIIgz*!@@AWAWXDN+/>>DIIh(*.**DIIgw'T#5djj#ABFH-1M!%!7!7(!^^<<		K {{  &*kk&6&6F#~~)+/>>K(!DKK!!0K0;!< " 
	1-1Muu(<<			K {{  &'hhv&6F#!DKK!!0K0
	1s,   B I (4IE5I I 	K,!BK''K,)FrZ   )__name__
__module____qualname__rX   r@   rf   ri   staticmethodrp   rx   r   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r^   rW   r   r     s    ?B.@@ C C
C&"%$'&&( R R"& "$
$3"6,61r^   r   c                     t        t        d0i dt        dd      dt        d      dt        d      dt        d	      d
t        dd      dt        d	      dt        d      dt        dd      dt        d	      dt        t        t        j	                               d      dt        d      dt        dd      dt        ddddg      dt        dd      d t        dd      d!t        dd      d"t        dt
              d#t        dd$      d%t        d&d'g(      d)t        d&d*g(      d+t        dd,      d-      } t        | .      }|j                          y/)1zAnsible Main module.r!   strT)r   requiredr"   )r   r   r   rd   r   boolF)r   defaultr   r   r   list)r   elementsr   r#   r   )choicesr   r'   r$   int   r   r9   r:   )r   r   r   r(   r%   r&   r-   r.   z)unix:/var/snap/lxd/common/lxd/unix.socketr)   rH   r1   )r   aliasesr+   r2   r;   )r   no_log)argument_specsupports_check_mode)r>   Nr   )r   rd   r   r   keysrG   r   r   )r>   
lxd_manages     rW   mainr     s     L
L

 L
 L
 L
 %)%L
$ %L
* +L
0 1L
8 9L
> /4467!?L
F GL
L ML
T #$&78UL
^  $ _L
f %)%gL
n oL
v /wL
~ CL
F #GL
N $OL
V  U48WL
Z !]OFb (v6JNNr^   __main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNr|   r   rD   r   ansible.module_utils.basicr   >ansible_collections.community.general.plugins.module_utils.lxdr   r   +ansible.module_utils.six.moves.urllib.parser	   r   rn   rG   r[   r   objectr   r   r   r   r^   rW   <module>r      s    A @vpAF
.   	  4 h A
     :  #F+ S1V S1l
Up zF r^   