
    Vhv                         d dl mZmZmZ eZdZdZdZd dl	m
Z
mZ d dlZd dlZdZ	 d dlZdZd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zedk(  r e        yy# e$ r  ej$                         ZdZY Cw xY w)    )absolute_importdivisionprint_functionar*  
author:
  - Bryan Gurney (@bgurney-rh)

module: vdo

short_description: Module to control VDO


description:
  - This module controls the VDO dedupe and compression device.
  - VDO, or Virtual Data Optimizer, is a device-mapper target that provides inline block-level deduplication, compression,
    and thin provisioning capabilities to primary storage.
extends_documentation_fragment:
  - community.general.attributes

attributes:
  check_mode:
    support: none
  diff_mode:
    support: none

options:
  name:
    description:
      - The name of the VDO volume.
    type: str
    required: true
  state:
    description:
      - Whether this VDO volume should be V(present) or V(absent). If a V(present) VDO volume does not exist, it is created.
        If a V(present) VDO volume already exists, it is modified by updating the configuration, which takes effect when the
        VDO volume is restarted. Not all parameters of an existing VDO volume can be modified; the C(statusparamkeys) list
        in the code contains the parameters that can be modified after creation. If an V(absent) VDO volume does not exist,
        it is not removed.
    type: str
    choices: [absent, present]
    default: present
  activated:
    description:
      - The C(activate) status for a VDO volume. If this is set to V(false), the VDO volume cannot be started, and it will
        not start on system startup. However, on initial creation, a VDO volume with "activated" set to "off" will be running,
        until stopped. This is the default behavior of the C(vdo create) command; it provides the user an opportunity to write
        a base amount of metadata (filesystem, LVM headers, and so on) to the VDO volume prior to stopping the volume, and
        leaving it deactivated until ready to use.
    type: bool
  running:
    description:
      - Whether this VDO volume is running.
      - A VDO volume must be activated in order to be started.
    type: bool
  device:
    description:
      - The full path of the device to use for VDO storage.
      - This is required if O(state=present).
    type: str
  logicalsize:
    description:
      - The logical size of the VDO volume (in megabytes, or LVM suffix format). If not specified for a new volume, this defaults
        to the same size as the underlying storage device, which is specified in the O(device) parameter. Existing volumes
        maintain their size if the O(logicalsize) parameter is not specified, or is smaller than or identical to the current
        size. If the specified size is larger than the current size, a C(growlogical) operation is performed.
    type: str
  deduplication:
    description:
      - Configures whether deduplication is enabled. The default for a created volume is V(enabled). Existing volumes maintain
        their previously configured setting unless a different value is specified in the playbook.
    type: str
    choices: [disabled, enabled]
  compression:
    description:
      - Configures whether compression is enabled. The default for a created volume is V(enabled). Existing volumes maintain
        their previously configured setting unless a different value is specified in the playbook.
    type: str
    choices: [disabled, enabled]
  blockmapcachesize:
    description:
      - The amount of memory allocated for caching block map pages, in megabytes (or may be issued with an LVM-style suffix
        of K, M, G, or T). The default (and minimum) value is V(128M). The value specifies the size of the cache; there is
        a 15% memory usage overhead. Each 1.25G of block map covers 1T of logical blocks, therefore a small amount of block
        map cache memory can cache a significantly large amount of block map data.
      - Existing volumes maintain their previously configured setting unless a different value is specified in the playbook.
    type: str
  readcache:
    description:
      - Enables or disables the read cache. The default is V(disabled). Choosing V(enabled) enables a read cache which may
        improve performance for workloads of high deduplication, read workloads with a high level of compression, or on hard
        disk storage. Existing volumes maintain their previously configured setting unless a different value is specified
        in the playbook.
      - The read cache feature is available in VDO 6.1 and older.
    type: str
    choices: [disabled, enabled]
  readcachesize:
    description:
      - Specifies the extra VDO device read cache size in megabytes. This is in addition to a system-defined minimum. Using
        a value with a suffix of K, M, G, or T is optional. The default value is V(0). 1.125 MB of memory per bio thread is
        used per 1 MB of read cache specified (for example, a VDO volume configured with 4 bio threads has a read cache memory
        usage overhead of 4.5 MB per 1 MB of read cache specified). Existing volumes maintain their previously configured
        setting unless a different value is specified in the playbook.
      - The read cache feature is available in VDO 6.1 and older.
    type: str
  emulate512:
    description:
      - Enables 512-byte emulation mode, allowing drivers or filesystems to access the VDO volume at 512-byte granularity,
        instead of the default 4096-byte granularity.
      - Only recommended when a driver or filesystem requires 512-byte sector level access to a device.
      - This option is only available when creating a new volume, and cannot be changed for an existing volume.
    type: bool
    default: false
  growphysical:
    description:
      - Specifies whether to attempt to execute a C(growphysical) operation, if there is enough unused space on the device.
        A C(growphysical) operation is executed if there is at least 64 GB of free space, relative to the previous physical
        size of the affected VDO volume.
    type: bool
    default: false
  slabsize:
    description:
      - The size of the increment by which the physical size of a VDO volume is grown, in megabytes (or may be issued with
        an LVM-style suffix of K, M, G, or T). Must be a power of two between 128M and 32G. The default is V(2G), which supports
        volumes having a physical size up to 16T. The maximum, V(32G), supports a physical size of up to 256T. This option
        is only available when creating a new volume, and cannot be changed for an existing volume.
    type: str
  writepolicy:
    description:
      - Specifies the write policy of the VDO volume.
      - The V(sync) mode acknowledges writes only after data is on stable storage.
      - The V(async) mode acknowledges writes when data has been cached for writing to stable storage.
      - The default (and highly recommended) V(auto) mode checks the storage device to determine whether it supports flushes.
        Devices that support flushes result in a VDO volume in V(async) mode, while devices that do not support flushes run
        in V(sync) mode.
      - Existing volumes maintain their previously configured setting unless a different value is specified in the playbook.
    type: str
    choices: [async, auto, sync]
  indexmem:
    description:
      - Specifies the amount of index memory in gigabytes. The default is V(0.25). The special decimal values V(0.25), V(0.5),
        and V(0.75) can be used, as can any positive integer. This option is only available when creating a new volume, and
        cannot be changed for an existing volume.
    type: str
  indexmode:
    description:
      - Specifies the index mode of the Albireo index.
      - The default is V(dense), which has a deduplication window of 1 GB of index memory per 1 TB of incoming data, requiring
        10 GB of index data on persistent storage.
      - The V(sparse) mode has a deduplication window of 1 GB of index memory per 10 TB of incoming data, but requires 100
        GB of index data on persistent storage.
      - This option is only available when creating a new volume, and cannot be changed for an existing volume.
    type: str
    choices: [dense, sparse]
  ackthreads:
    description:
      - Specifies the number of threads to use for acknowledging completion of requested VDO I/O operations. Valid values
        are integer values from V(1) to V(100) (lower numbers are preferable due to overhead). The default is V(1). Existing
        volumes maintain their previously configured setting unless a different value is specified in the playbook.
    type: str
  biothreads:
    description:
      - Specifies the number of threads to use for submitting I/O operations to the storage device. Valid values are integer
        values from V(1) to V(100) (lower numbers are preferable due to overhead). The default is V(4). Existing volumes maintain
        their previously configured setting unless a different value is specified in the playbook.
    type: str
  cputhreads:
    description:
      - Specifies the number of threads to use for CPU-intensive work such as hashing or compression. Valid values are integer
        values from V(1) to V(100) (lower numbers are preferable due to overhead). The default is V(2). Existing volumes maintain
        their previously configured setting unless a different value is specified in the playbook.
    type: str
  logicalthreads:
    description:
      - Specifies the number of threads across which to subdivide parts of the VDO processing based on logical block addresses.
        Valid values are integer values from V(1) to V(100) (lower numbers are preferable due to overhead). The default is
        V(1). Existing volumes maintain their previously configured setting unless a different value is specified in the playbook.
    type: str
  physicalthreads:
    description:
      - Specifies the number of threads across which to subdivide parts of the VDO processing based on physical block addresses.
        Valid values are integer values from V(1) to V(16) (lower numbers are preferable due to overhead). The physical space
        used by the VDO volume must be larger than (O(slabsize) * O(physicalthreads)). The default is V(1). Existing volumes
        maintain their previously configured setting unless a different value is specified in the playbook.
    type: str
  force:
    description:
      - When creating a volume, ignores any existing file system or VDO signature already present in the storage device. When
        stopping or removing a VDO volume, first unmounts the file system stored on the device if mounted.
      - B(Warning:) Since this parameter removes all safety checks it is important to make sure that all parameters provided
        are accurate and intentional.
    type: bool
    default: false
    version_added: 2.4.0
notes:
  - In general, the default thread configuration should be used.
requirements:
  - PyYAML
  - kmod-kvdo
  - vdo
z
- name: Create 2 TB VDO volume vdo1 on device /dev/md0
  community.general.vdo:
    name: vdo1
    state: present
    device: /dev/md0
    logicalsize: 2T

- name: Remove VDO volume vdo1
  community.general.vdo:
    name: vdo1
    state: absent
#)AnsibleModulemissing_required_libNTFc                 :   | j                  |dg      \  }}}g }|dk(  r't        j                  d|t        j                        r|S |dk7  r| j	                  d|z  ||       t        j                  |      }||S |d   }|t        |j                               }|S )Nstatus   zvdoconf\.yml does not existr   zInventorying VDOs failed: %smsgrcerrVDOs)	run_commandrefindall	MULTILINE	fail_jsonyaml	safe_loadlistkeys)modulevdocmdr   vdostatusoutr   vdolistvdostatusyamlvdoyamlss           i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/vdo.pyinventory_vdosr!      s    "../ABBc G	Qw2::<c2<<P 	Qw;lJrWZ[NN<0MV$Hx}}'N    c                 j    | j                  |dg      \  }}}t        d |j                  d            }|S )Nr   
)r   filtersplit)r   r   r   
vdolistoutr   runningvdolists         r    list_running_vdosr)     s;     ,,ff-=>B
CD*"2"24"89Nr"   c                 n    | j                  |dd|z  g      \  }}}|dk(  r| j                  d|z         |S )Nstart	--name=%sr   zstarted VDO volume %sr   logr   vdonamer   r   outr   s         r    	start_vdor2     sB    %%vwg8M&NOLBS	Qw

*W45Ir"   c                 n    | j                  |dd|z  g      \  }}}|dk(  r| j                  d|z         |S )Nstopr,   r   zstopped VDO volume %sr-   r/   s         r    stop_vdor5   &  sB    %%vv{W7L&MNLBS	Qw

*W45Ir"   c                 n    | j                  |dd|z  g      \  }}}|dk(  r| j                  d|z         |S )Nactivater,   r   zactivated VDO volume %sr-   r/   s         r    activate_vdor8   -  sB    %%vz;;P&QRLBS	Qw

,w67Ir"   c                 n    | j                  |dd|z  g      \  }}}|dk(  r| j                  d|z         |S )N
deactivater,   r   zdeactivated VDO volume %sr-   r/   s         r    deactivate_vdor;   4  sB    %%v|[7=R&STLBS	Qw

.89Ir"   c                 F   g }| j                  d      |j                  d| d   z          | j                  d      |j                  d| d   z          | j                  d      dk(  r|j                  d       | j                  d      |j                  d	| d   z          | j                  d
      |j                  d| d
   z          | j                  d      r|j                  d       | j                  d      |j                  d| d   z          | j                  d      dk(  r|j                  d       | j                  d      r|j                  d       | j                  d      |j                  d| d   z          | j                  d      |j                  d| d   z          | j                  d      |j                  d| d   z          | j                  d      |j                  d| d   z          | j                  d      |j                  d| d   z          |S )Nlogicalsizez--vdoLogicalSize=blockmapcachesizez--blockMapCacheSize=	readcacheenabledz--readCache=enabledreadcachesizez--readCacheSize=slabsizez--vdoSlabSize=
emulate512z--emulate512=enabledindexmemz--indexMem=	indexmodesparsez--sparseIndex=enabledforcez--force
ackthreadsz--vdoAckThreads=
biothreadsz--vdoBioThreads=
cputhreadsz--vdoCpuThreads=logicalthreadsz--vdoLogicalThreads=physicalthreadsz--vdoPhysicalThreads=)getappend)paramsoptionss     r    add_vdooptionsrQ   ;  s   Gzz- ,*VM-BBCzz%&2-7J0KKLzz+)+,-zz/".)F?,CCDzz*)'&*<<=zz,-.zz*)}vj'99:zz+(*./zz'y! zz,+)F<,@@Azz,+)F<,@@Azz,+)F<,@@Azz"#/-7G0HHIzz#$0.8I1JJKNr"   c                  <   t        dZi dt        dd      dt        ddddg      d	t        d
      dt        d
      dt        d
d      dt        d      dt        d      dt        dddg      dt        dddg      dt        d      dt        dddg      dt        d      dt        d
d      dt        d      dt        dg d      dt        d      dt        dd d!g      d"t        d      d#t        d      d$t        d      d%t        d      d&t        d      d't        d
d      } t        d(      }t        | d)      }t        s |j                  t	        d*      t
        +       |j                  d,d-      }|s |j                  dZd.d/i| t        ||      }t        ||      }|j                  d   }|j                  d   }||vrJ|dk(  rD|j                  d   }||j                  d01       t        |j                        }	|j                  |d2d3|z  d4|z  g|	z         \  }
}}|
d5k(  rd|d6<   n|j                  d7|z  |
|8       |j                  d   dk(  r|j                  |d9d3|z  g      \  }
}}|j                  d   dk(  r|j                  |d:d3|z  g      \  }
}}|j                  d	   du rt        |||       |j                  d   du rt        |||       t        ||      }|j                  d;|z          |j                  dZi | ||v r|dk(  r|j                  |d<g      \  }
}}t!        j"                  |      }i }|d=   }||}g d>}dddddddd"d#d$d%d&d?}i }i }|D ]  }|||   v r||   |   ||<   ||   ||<    i }|j%                         D ]  }||   |||   <    i }|j%                         D ]C  }|j                  |   t'        ||         |j                  |   k7  s2|j                  |   ||<   E |r_t        |      }	|	r@|j                  |d@d3|z  g|	z         \  }
}}|
d5k(  rd|d6<   n|j                  dA|z  |
|8       d|j%                         v rK|d   }|dk(  rd:ndB}|j                  ||d3|z  g      \  }
}}|
d5k(  rd|d6<   n|j                  dC|z  |
|8       d|j%                         v rK|d   }|dk(  rd9ndD}|j                  ||d3|z  g      \  }
}}|
d5k(  rd|d6<   n|j                  dE|z  |
|8       d|j%                         v rF|d   }|j                  |dFd3|z  dG|z  g      \  }
}}|
d5k(  rd|d6<   n|j                  dH|z  |
|8       dIg}i } i }!|D ]  }||   |   | |<   ||   |!|<    i }"| j%                         D ]  }| |   |"|!|   <    i }#|"j%                         D ]C  }|j                  |   t'        |"|         |j                  |   k7  s2|j                  |   |#|<   E |j                  d   r|j                  d   }$|j                  |j                  dJ      dK|$g      \  }
}%}t)        |%      dLz  }&dM|z   }'||   dN   |'   }(|(dO   })|&dPz   }*|)|*kD  r d|d6<   |j                  |dQd3|z  g      \  }
}}d|#j%                         v r'd|d6<   |j                  |dRd3|z  dS|#d   z  g      \  }
}}||   dT   }+|j                  d	   du r|+dk(  rt        |||       |d6   sd|d6<   |j                  d	   r|+dk(  rt+        |||       |d6   sd|d6<   |j                  d   du r||v rt        |||       |d6   sd|d6<   |+dk(  s|j                  d	   r*|j                  d   r||vrt-        |||       |d6   sd|d6<   t        ||      }|r|j                  dU|z          |j                  dZi | ||v rt|dk(  ro|j                  |dVd3|z  g      \  }
}}|
d5k(  rd|d6<   n|j                  dW|z  |
|8       t        ||      }|j                  dX|z          |j                  dZi | t        ||      }|j                  dY|z          |j                  dZi | y )[NnamestrT)typerequiredstatepresentabsent)rU   defaultchoices	activatedbool)rU   runninggrowphysicalF)rU   rZ   devicer=   deduplicationdisabledr@   )rU   r[   compressionr>   r?   rA   rC   rB   writepolicy)asyncautosyncrD   rE   denserF   rH   rI   rJ   rK   rL   rG   )changed)argument_specsupports_check_modePyYAML)r   	exceptionvdo)rV   r   zVDO is not installed.zECreating a VDO volume requires specifying a 'device' in the playbook.)r   creater,   z--device=%sr   ri   zCreating VDO %s failed.r   disableCompressiondisableDeduplicationzcreated VDO volume %sr
   r   )Acknowledgement threadsBio submission threadsBlock map cache sizeCPU-work threadsLogical threadsPhysical threads
Read cacheRead cache sizeConfigured write policyCompressionDeduplication)Logical sizer{   r|   rt   rx   ry   rz   rr   rs   ru   rv   rw   modifyzModifying VDO %s failed.enableDeduplicationz/Changing deduplication on VDO volume %s failed.enableCompressionz-Changing compression on VDO volume %s failed.changeWritePolicyz--writePolicy=%sz.Changing write policy on VDO volume %s failed.r}   blockdevz--getsz   z/dev/mapper/zVDO statisticszphysical blocksi   growPhysicalgrowLogicalz--vdoLogicalSize=%sActivatez$modified parameters of VDO volume %sremovezRemoving VDO %s failed.zremoved VDO volume %sz5received request to remove non-existent VDO volume %s )dictr   HAS_YAMLr   r   YAML_IMP_ERRget_bin_pathr!   r)   rO   rQ   r   r;   r5   r.   	exit_jsonr   r   r   rT   intr8   r2   ),module_argsresultr   r   r   r(   
desiredvdorW   r`   vdocmdoptionsr   r1   r   vdostatusoutputr   processedvdosr   statusparamkeysvdokeytranscurrentvdoparamsmodtrans	statfieldcurrentparamsparamkey
diffparamskey	dedupemoddedupeparamcompressmodcompressparamwritepolmodsizeparamkeyscurrentsizeparams	sizetrans
sizeparamsdiffsizeparams
physdevice
devsectors	devblocks	dmvdonamecurrentvdostatscurrentphysblocks
growthreshvdoactivatestatuss,                                               r    
run_moduler   q  s
     ut,y8Y:OP F# &!	
 vu5  e$ 
I/FG ej)-DE E* EJ	+BC & VU3 5! e-FG  5!!" EGX+>?#$ U#%& U#'( U#)* '+, %(-. ./K: F !!F
 1(;|T   6F?4?? VV,G&vv6N v&JMM'"E 	'!(:x(> "? @ 'v}}5))X{Z79OPS``bC7 $F9!:Z!GBTWX==':5!--v7K[[eMe.fgLBS==)Z7!--v7M{]gOg.hiLBS==%.6:v6==#u,VZ0 !0

*Z78"6" W)!3#)#5#5vx6H#I OS7  ($M
," *(,$7%.'4'3&2 ,/ 1
"  ( 	9IM*55.;J.G	.R +"-i"8HY		9   	CH080BM(8,-	C 
 !%%' 	9C}}S!-}S)*fmmC.@@&,mmC&8JsO	9
 *:6M%1168[S]E]2^an2noC7(,F9%$$)C'1*268c % C *//"33&7	8AZ8O4Uj%116;V`H`2abC7(,F9%$$)Z]g)glntw$x
 11(78Cz8Q 4Wj%116=+XbJb2cdC7(,F9%$$)X[e)ejlru$v
 11(7%11'*,&4	3  C 7(,F9%$$)Y\f)fkmsv$w (*	& 	:I+8+DY+Oi(#.y#9Ii 	: 
)..0 	JH.?.IJy*+	J ??$ 	9C}}S!-#jo2F&--X[J\2\&,mmC&8s#	9 ==(x0J"("4"4f6I6I*6UW`bl5m"nB
CZ1,I'*4I+J78HI)TO /0A B #X-J :-$(y!%116>;YcKc2deCN//11 $F9!--v}kT^F^`u  yG  HU  yV  aV  /W  XLBS)*5jA==%.3D	3Q6:v6)$$(y!==%*;z*IV4)$$(y!==#u,~1MVZ0)$$(y! *fmmK.Hfmm\eNfku  ~L  lLfj&1)$$(y! !0JJ=
JK"6" W(!2))68[:=U*VWC7 $F9!:Z!GBTWX !0

*Z78"6" VV,G
JJFSTFvr"   c                      t                y )N)r   r   r"   r    mainr     s    Lr"   __main__)
__future__r   r   r   rU   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   r   r   	tracebackr   r   r   ImportError
format_excr!   r)   r2   r5   r8   r;   rQ   r   r   __name__r   r"   r    <module>r      s    A @DL 
 J 	 H:3lAH
 zF a  '9'')LHs   A A0/A0