
    Vh#                     r    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ  G d de      Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona6  
module: swupd
short_description: Manages updates and bundles in ClearLinux systems
description:
  - Manages updates and bundles with the swupd bundle manager, which is used by the Clear Linux Project for Intel Architecture.
author: Alberto Murillo (@albertomurillo)
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  contenturl:
    description:
      - URL pointing to the contents of available bundles. If not specified, the contents are retrieved from clearlinux.org.
    type: str
  format:
    description:
      - The format suffix for version file downloads. For example V(1), V(2), V(3), and so on, or the special value V(staging).
        If not specified, the default format is used.
    type: str
  manifest:
    description:
      - The manifest contains information about the bundles at certain version of the OS. Specify a Manifest version to verify
        against that version or leave unspecified to verify against the current version.
    aliases: [release, version]
    type: int
  name:
    description:
      - Name of the (I)bundle to install or remove.
    aliases: [bundle]
    type: str
  state:
    description:
      - Indicates the desired (I)bundle state. V(present) ensures the bundle is installed while V(absent) ensures the (I)bundle
        is not installed.
    default: present
    choices: [present, absent]
    type: str
  update:
    description:
      - Updates the OS to the latest version.
    type: bool
    default: false
  url:
    description:
      - Overrides both O(contenturl) and O(versionurl).
    type: str
  verify:
    description:
      - Verify content for OS version.
    type: bool
    default: false
  versionurl:
    description:
      - URL for version string download.
    type: str
a  
- name: Update the OS to the latest version
  community.general.swupd:
    update: true

- name: Installs the "foo" bundle
  community.general.swupd:
    name: foo
    state: present

- name: Removes the "foo" bundle
  community.general.swupd:
    name: foo
    state: absent

- name: Check integrity of filesystem
  community.general.swupd:
    verify: true

- name: Downgrade OS to release 12920
  community.general.swupd:
    verify: true
    manifest: 12920
z
stdout:
  description: C(stdout) of C(swupd).
  returned: always
  type: str
stderr:
  description: C(stderr) of C(swupd).
  returned: always
  type: str
N)AnsibleModulec                   X    e Zd ZdZdZdZdZd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zy)Swupdzfiles did not matchzmissing files were replacedzfiles were fixedzfiles were deletedc                 B   || _         |j                  dd      | _        | j                  s|j                  d       |j                  j                         D ]  }t        | ||j                  |           d| _        d| _        d | _	        d | _
        d| _        d| _        y )NswupdFzCould not find swupd.)msg )moduleget_bin_path	swupd_cmd	fail_jsonparamskeyssetattrchangedfailedr   rcstderrstdout)selfr   keys      k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/swupd.py__init__zSwupd.__init__x   s    ,,We<~~!89 ==%%' 	3CD#v}}S12	3     c                 d    | j                   j                  |d      \  | _        | _        | _        y )NF)check_rc)r   run_commandr   r   r   r   cmds     r   _run_cmdzSwupd._run_cmd   s)    ,0KK,C,CCRW,C,X)dkr   c                 b   | j                   d|}| j                  r|d| j                  z  z  }| j                  r|d| j                  z  z  }| j                  r|d| j                  z  z  }|S | j                  r|dk7  r|d| j                  z  z  }| j
                  r|d| j
                  z  z  }|S )N z --format=%sz --manifest=%sz	 --url=%scheck-updatez --contenturl=%sz --versionurl=%s)r   formatmanifesturl
contenturl
versionurl)r   commandr"   s      r   _get_cmdzSwupd._get_cmd   s    1;;>DKK//C==#dmm33C88;))C 
 7n#<)DOO;;)DOO;;
r   c                 T    	 t        j                  d|z         y# t        $ r Y yw xY w)Nz/usr/share/clear/bundles/%sFT)osstatOSError)r   bundles     r   _is_bundle_installedzSwupd._is_bundle_installed   s2    	GG1F:;   		s    	''c                     | j                  d      }| j                  |       | j                  dk(  ry| j                  dk(  ryd| _        d| _        y )Nr&   r   T   FFailed to check for updates)r-   r#   r   r   r   r!   s     r   _needs_updatezSwupd._needs_update   sF    mmN+c77a<77a<0r   c                     | j                  d      }| j                  |       | j                  dk7  rd| _        d| _        | j
                  | j                  v ryy)Nverifyr   Tz/Failed to check for filesystem inconsistencies.F)r-   r#   r   r   r   FILES_NOT_MATCHr   r!   s     r   _needs_verifyzSwupd._needs_verify   sM    mmH%c77a<DKHDH4;;.r   c                 n   | j                   j                  r,| j                   j                  | j                  |              | j                  |      rd|z  | _        y| j                  d|z        }| j                  |       | j                  dk(  rd| _        d|z  | _        yd| _	        d|z  | _        y)	z0Installs a bundle with `swupd bundle-add bundle`r   zBundle %s is already installedNzbundle-add %sr   TzBundle %s installedzFailed to install bundle %s
r   
check_mode	exit_jsonr3   r   r-   r#   r   r   r   r   r2   r"   s      r   install_bundlezSwupd.install_bundle   s    ;;!!KK!!d.G.G.O*O!P$$V,7&@DHmmOf45c77a<DL,v5DH069r   c                 f   | j                   j                  r+| j                   j                  | j                  |             | j                  |      sd| _        y| j                  d|z        }| j                  |       | j                  dk(  rd| _        d|z  | _        yd| _	        d|z  | _        y)	z2Removes a bundle with `swupd bundle-remove bundle`r=   zBundle %s not installedNzbundle-remove %sr   TzBundle %s removedzFailed to remove bundle %sr>   rA   s      r   remove_bundlezSwupd.remove_bundle   s    ;;!!KK!!$*C*CF*K!L((00DHmm.78c77a<DL*V3DH/&8r   c                 P   | j                   j                  r*| j                   j                  | j                                | j                         sd| _        y| j                  d      }| j                  |       | j                  dk(  rd| _        d| _        yd| _	        d| _        y)	z"Updates the os with `swupd update`r=   zThere are no updates availableNupdater   TzUpdate successfulr6   )
r   r?   r@   r7   r   r-   r#   r   r   r   r!   s     r   	update_oszSwupd.update_os   s    ;;!!KK!!$*<*<*>!?!!#7DHmmH%c77a<DL*DH0r   c                    | j                   j                  r*| j                   j                  | j                                | j                         sd| _        y| j                  d      }| j                  |       | j                  dk(  rW| j                  | j                  v s0| j                  | j                  v s| j                  | j                  v rd| _        d| _        yd| _        d| _        y)	z8Verifies filesystem against specified or current versionr=   zNo files where changedNzverify --fixr   TzFix successfulzFailed to verify the OS)r   r?   r@   r;   r   r-   r#   r   FILES_REPLACEDr   FILES_FIXEDFILES_DELETEDr   r   r!   s     r   	verify_oszSwupd.verify_os   s    ;;!!KK!!$*<*<*>!?!!#/DHmmN+c77a<T00DKK?4CSCSW[WbWbCbfjfxfx  }A  }H  }H  gHDL'DH,r   N)__name__
__module____qualname__r:   rI   rJ   rK   r   r#   r-   r3   r7   r;   rB   rD   rG   rL    r   r   r   r   r   sI    +O2N$K(M&Y"1:(9(1(-r   r   c                  X   t        t        t        d      t        d      t        ddgd      t        dgd      t        ddd	gd
      t        dd      t        d      t        dd      t        d      	      g dgg dgd      } t        |       }| j                  d   }| j                  d   }| j                  d   }| j                  d   }|r|j	                          nH|r|j                          n5|dk(  r|j                  |       n|d	k(  r|j                  |       nd|_        |j                  r3| j                  |j                  |j                  |j                         y| j                  |j                  |j                  |j                  |j                         y)zThe main function.str)typereleaseversionint)aliasesrS   r2   presentabsent)defaultchoicesrS   Fbool)rZ   rS   )	r*   r'   r(   namestaterF   r)   r9   r+   )r]   rF   r9   T)argument_specrequired_one_ofmutually_exclusivesupports_check_moder]   r^   rF   r9   )r   r   r   )r   r   r   r   N)r   dictr   r   rG   rL   rB   rD   r   r   r   r   r   r@   r   )r   r
   r]   r^   rF   r9   s         r   mainrd     sg   'U#9i"8uExju5y9h2GeTF3% F3'

 6689 F" &ME== DMM'"E]]8$F]]8$F		)	T"	(	D!||UYYu||ELLQEIIell[`[g[ghr   __main__)
__future__r   r   r   rS   __metaclass__DOCUMENTATIONEXAMPLESRETURNr/   ansible.module_utils.basicr   objectr   rd   rM   rP   r   r   <module>rm      s[    A @;z2	
 
 4]-F ]-@(iV zF r   