
    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_functionu  
module: beadm
short_description: Manage ZFS boot environments on FreeBSD/Solaris/illumos systems
description:
  - Create, delete or activate ZFS boot environments.
  - Mount and unmount ZFS boot environments.
author: Adam Števko (@xen0l)
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  name:
    description:
      - ZFS boot environment name.
    type: str
    required: true
    aliases: ["be"]
  snapshot:
    description:
      - If specified, the new boot environment will be cloned from the given snapshot or inactive boot environment.
    type: str
  description:
    description:
      - Associate a description with a new boot environment. This option is available only on Solarish platforms.
    type: str
  options:
    description:
      - Create the datasets for new BE with specific ZFS properties.
      - Multiple options can be specified.
      - This option is available only on Solarish platforms.
    type: str
  mountpoint:
    description:
      - Path where to mount the ZFS boot environment.
    type: path
  state:
    description:
      - Create or delete ZFS boot environment.
    type: str
    choices: [absent, activated, mounted, present, unmounted]
    default: present
  force:
    description:
      - Specifies if the unmount should be forced.
    type: bool
    default: false
a  
- name: Create ZFS boot environment
  community.general.beadm:
    name: upgrade-be
    state: present

- name: Create ZFS boot environment from existing inactive boot environment
  community.general.beadm:
    name: upgrade-be
    snapshot: be@old
    state: present

- name: Create ZFS boot environment with compression enabled and description "upgrade"
  community.general.beadm:
    name: upgrade-be
    options: "compression=on"
    description: upgrade
    state: present

- name: Delete ZFS boot environment
  community.general.beadm:
    name: old-be
    state: absent

- name: Mount ZFS boot environment on /tmp/be
  community.general.beadm:
    name: BE
    mountpoint: /tmp/be
    state: mounted

- name: Unmount ZFS boot environment
  community.general.beadm:
    name: BE
    state: unmounted

- name: Activate ZFS boot environment
  community.general.beadm:
    name: upgrade-be
    state: activated
a  
name:
  description: BE name.
  returned: always
  type: str
  sample: pre-upgrade
snapshot:
  description: ZFS snapshot to create BE from.
  returned: always
  type: str
  sample: rpool/ROOT/oi-hipster@fresh
description:
  description: BE description.
  returned: always
  type: str
  sample: Upgrade from 9.0 to 10.0
options:
  description: BE additional options.
  returned: always
  type: str
  sample: compression=on
mountpoint:
  description: BE mountpoint.
  returned: always
  type: str
  sample: /mnt/be
state:
  description: State of the target.
  returned: always
  type: str
  sample: present
force:
  description: If forced action is wanted.
  returned: always
  type: bool
  sample: false
N)AnsibleModulec                   N    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y)BEc                 h   || _         |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        t        j                         d   d	k(  | _        y )
Nnamesnapshotdescriptionoptions
mountpointstateforcer   FreeBSD)moduleparamsr
   r   r   r   r   r   r   osuname
is_freebsd)selfr   s     k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/beadm.py__init__zBE.__init__   s    MM&)	j1!==7}}Y/ --5]]7+
]]7+
((*Q-94    c                     | j                   j                  d      ddg}d| j                  v r|j                  d       | j                   j	                  |      S )Nbeadmlistz-H@z-s)r   get_bin_pathr
   appendrun_commandr   cmds     r   _beadm_listzBE._beadm_list   sJ    {{''0&$?$))JJt{{&&s++r   c                 F   d| j                   v r|j                         D ]  }| j                  r[|j                         }|g k(  r%|d   j                  d      }|g k(  r?|t	        |      dz
     |d<   |d   | j                   k(  sf|c S |j                  d      }|d   | j                   k(  s|c S  y |j                         D ]\  }| j                  r'|j                         }|d   | j                   k(  s2|c S |j                  d      }|d   | j                   k(  sZ|c S  y )Nr   r   /   ;)r
   
splitlinesr   splitlen)r   outlinecheck	full_names        r   _find_be_by_namezBE._find_be_by_name   s   $))( %?? JJLE{  %as 3I B (Y!);<E!HQx499,$ JJsOEQx499,$%2  ( %?? JJLEQx499,$ JJsOEQx499,$% r   c                 \    | j                         \  }}}|dk(  r| j                  |      ryyy)Nr   TF)r$   r0   )r   rcr,   dummys       r   existsz	BE.exists   s5    ++-S%7$$S)r   c                     | j                         \  }}}|dk(  r1| j                  |      }|y| j                  r	d|d   v ryyd|d   v ryy)Nr   FRr'   T   r$   r0   r   r   r2   r,   r3   r-   s        r   is_activatedzBE.is_activated   sc    ++-S%7((-D|$q'>
  $q'>r   c                     | j                   j                  d      d| j                  g}| j                   j                  |      S )Nr   activater   r   r
   r!   r"   s     r   activate_bezBE.activate_be   s6    {{''0*diiH{{&&s++r   c                    | j                   j                  d      dg}| j                  r|j                  d| j                  g       | j                  sR| j
                  r|j                  d| j
                  g       | j                  r|j                  d| j                  g       |j                  | j                         | j                   j                  |      S )Nr   createz-ez-dz-o)
r   r   r   extendr   r   r   r    r
   r!   r"   s     r   	create_bezBE.create_be   s    {{''0(;==JJdmm,-

D$"2"234||

D$,,/0

499{{&&s++r   c                     | j                   j                  d      dd| j                  g}| j                   j                  |      S )Nr   destroyz-Fr=   r"   s     r   
destroy_bezBE.destroy_be   s8    {{''0)T499M{{&&s++r   c                     | j                         \  }}}|dk(  r8| j                  |      }|y| j                  r|d   dk7  r	|d   dk7  ryy|d   ryy)Nr   Fr7   -r&   T   r8   r9   s        r   
is_mountedzBE.is_mounted   sk    ++-S%7((-D| 7c>d1gn
  7r   c                     | j                   j                  d      d| j                  g}| j                  r|j	                  | j                         | j                   j                  |      S )Nr   mount)r   r   r
   r   r    r!   r"   s     r   mount_bezBE.mount_be  sM    {{''0'499E??JJt'{{&&s++r   c                     | j                   j                  d      dg}| j                  r|j                  d       |j                  | j                         | j                   j                  |      S )Nr   unmountz-f)r   r   r   r    r
   r!   r"   s     r   
unmount_bezBE.unmount_be  sS    {{''0)<::JJt

499{{&&s++r   N)__name__
__module____qualname__r   r$   r0   r4   r:   r>   rB   rE   rI   rL   rO    r   r   r   r      s9    
5,:	 ,,,&,,r   r   c                  6   t        t        t        dddg      t        d      t        d      t        d      t        d      t        ddg d	      t        d
d            d      } t        |       }d }d}d}i }|j                  |d<   |j                  |d<   |j
                  r|j
                  |d<   |j                  r|j                  |d<   |j                  r|j                  |d<   |j                  r|j                  |d<   |j                  dk(  r|j                         r|j                         s| j                  r| j                  d       |j                  r"|j                         r| j                  d       |j!                         \  }}}|dk7  rN| j                  d|z  |j                  ||       n*| j                  d       n|j                  dk(  rm|j                         s| j                  r| j                  d       |j#                         \  }}}|dk7  r| j                  d|z  |j                  ||       n|j                  dk(  r|j                         sz| j                  r| j                  d       |j                  r"|j                         r| j                  d        |j%                         \  }}}|dk7  r| j                  d!|z  |j                  ||       n|j                  d"k(  rj|j                         s| j                  r| j                  d       |j'                         \  }}}|dk7  r| j                  d#|z  |j                  ||       nx|j                  d$k(  ri|j                         rY| j                  r| j                  d       |j)                         \  }}}|dk7  r"| j                  d%|z  |j                  ||       |d|d&<   nd|d&<   |r||d'<   |r||d(<    | j                  d)i | y )*NstrTbe)typerequiredaliases)rW   pathpresent)absent	activatedmountedr[   	unmounted)rW   defaultchoicesboolF)rW   r`   )r
   r   r   r   r   r   r   )argument_specsupports_check_mode r
   r   r   r   r   r   r\   )changedzUnable to remove active BE!)msgr   zError while destroying BE: "%s")rg   r
   stderrr2   z%Unable to remove BE as it is mounted!zError while creating BE: "%s"r]   zUnable to activate mounted BE!zError while activating BE: "%s"r^   zError while mounting BE: "%s"r_   zError while unmounting BE: "%s"rf   stdoutrh   rS   )r   dictr   r
   r   r   r   r   r   r4   rI   
check_mode	exit_jsonr   r:   	fail_jsonrE   rB   r>   rL   rO   )r   rV   r2   r,   errresults         r   mainrp     s   54$@u%%(e$(E9>xyFE2
 !F 
FB	B
C
CFWWF6NhhF7O	{{[[z	~~ "}	zzJJy	}}!}}|	xx8 99;==?$$$$T$2==(((-J(K!#S#7$$)JS)P*,'',/(* % ,
   %L M	Y	yy{     .\\^NRcQw  %Ds%J&(gg(+$& ! (
 
[	       . }}==?$$)I$J^^-NRcQw  %F%L&(gg(+$& ! ( 
Y	}}     .[[]NRcQw  %Ds%J&(gg(+$& ! (
 
[	 ==?     .]]_NRcQw  %F%L&(gg(+$& ! (
 
z!y y
x
xFvr   __main__)
__future__r   r   r   rW   __metaclass__DOCUMENTATIONEXAMPLESRETURNr   ansible.module_utils.basicr   objectr   rp   rP   rS   r   r   <module>ry      s]    A @2h'R$
L 
 4C, C,LD zF r   