
    Vh                     z    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZmZ  G d de      Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona  
---
module: add_ldisk
version_added: "1.0.0"
author:
    - WangBaoshan (@ispim)
short_description: Create logical disk
description:
   - Create logical disk on Inspur server.
notes:
   - Does not support C(check_mode).
options:
    info:
        description:
            - Show controller and physical drive info.
        choices: ['show']
        type: str
    ctrl_id:
        description:
            - Raid controller ID.
            - Required when I(Info=None) and controller type is LSI,PMC or MV.
        type: int
    level:
        description:
            - RAID Level, 0 - RAID0, 1 - RAID1, 5 - RAID5, 6 - RAID6, 10 - RAID10.
            - Required when I(Info=None) and controller type is LSI or PMC.
        choices: [0, 1, 5, 6, 10]
        type: int
    size:
        description:
            - Strip Size, 0 - 32k, 1 - 64k, 2 - 128k, 3 - 256k, 4 - 512k, 5 - 1024k.
            - Required when I(Info=None) and controller type is LSI,PMC or MV.
            - When the controller type is MV,size is [0, 1].
            - When the controller type is LSI or PMC,size is [1, 2, 3, 4, 5].
        choices: [0, 1, 2, 3, 4, 5]
        type: int
    access:
        description:
            - Access Policy, 1 - Read Write, 2 - Read Only, 3 - Blocked.
            - Required when I(Info=None) and controller type is LSI.
        choices: [1, 2, 3]
        type: int
    r:
        description:
            - Read Policy, 1 - Read Ahead, 2 - No Read Ahead.
            - Required when I(Info=None) and controller type is LSI.
        choices: [1, 2]
        type: int
    w:
        description:
            - Write Policy, 1 - Write Through, 2 - Write Back, 3 - Write caching ok if bad BBU.
            - Required when I(Info=None) and controller type is LSI.
        choices: [1, 2, 3]
        type: int
    io:
        description:
            - IO Policy, 1 - Direct IO, 2 - Cached IO.
            - Required when I(Info=None) and controller type is LSI.
        choices: [1, 2]
        type: int
    cache:
        description:
            - Drive Cache, 1 - Unchanged, 2 - Enabled,3 - Disabled.
            - Required when I(Info=None) and controller type is LSI.
        choices: [1, 2, 3]
        type: int
    init:
        description:
            - Init State, 1 - No Init, 2 - Quick Init, 3 - Full Init.
            - Required when I(Info=None) and controller type is LSI.
        choices: [1, 2, 3]
        type: int
    select:
        description:
            - Select Size, from 1 to 100.
            - Required when I(Info=None) and controller type is LSI.
        type: int
    slot:
        description:
            - Slot Num,input multiple slotNumber like 0,1,2....
            - Required when I(Info=None) and controller type is LSI or PMC.
        type: list
        elements: int
    accelerator:
        description:
            - Driver accelerator, 1 - 1h, 2 - 2h, 3 - 3h.
            - Required when I(Info=None) and controller type is PMC.
        choices: [1, 2, 3]
        type: int
    vname:
        description:
            - Virtual drive name.
            - Required when I(Info=None) and controller type is PMC or server model is M7.
            - Required when I(Info=None) and controller type is MV.
        type: str
extends_documentation_fragment:
    - inspur.ispim.ism
am  
- name: Add ldisk test
  hosts: ism
  connection: local
  gather_facts: no
  vars:
    ism:
      host: "{{ ansible_ssh_host }}"
      username: "{{ username }}"
      password: "{{ password }}"

  tasks:

  - name: "Show pdisk information"
    inspur.ispim.add_ldisk:
      info: "show"
      provider: "{{ ism }}"

  - name: "Add LSI ldisk"
    inspur.ispim.add_ldisk:
      ctrl_id: 0
      level: 1
      size: 1
      access: 1
      r: 1
      w: 1
      io: 1
      cache: 1
      init: 2
      select: 10
      slot: 0,1
      provider: "{{ ism }}"

  - name: "Add PMC ldisk"
    inspur.ispim.add_ldisk:
      ctrl_id: 0
      level: 1
      size: 1
      accelerator: 1
      slot: 0,1
      vname: "test"
      provider: "{{ ism }}"

  - name: "Add MV ldisk"
    inspur.ispim.add_ldisk:
      ctrl_id: 0
      size: 1
      vname: "test"
      provider: "{{ ism }}"
a1  
message:
    description: Messages returned after module execution.
    returned: always
    type: str
state:
    description: Status after module execution.
    returned: always
    type: str
changed:
    description: Check to see if a change was made on the device.
    returned: always
    type: bool
)AnsibleModule)ism_argument_specget_connectionc                   *    e Zd Zd Zd Zd Zd Zd Zy)Diskc                 ^    || _         d | _        | j                          t               | _        y )N)specmoduleinit_moduledictresults)selfargument_specs     j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/inspur/ispim/plugins/modules/add_ldisk.py__init__zDisk.__init__   s%    !	v    c                 <    t        | j                  d      | _        y)zInit module objectF)r   supports_check_modeN)r   r   r   r   s    r   r   zDisk.init_module   s     $))@r   c                     d| j                   j                  d<   t        | j                         | _        | j                  d   dk(  rd| j                  d<   y y )Naddldisk
subcommandStateSuccessTchanged)r   paramsr   r   r   s    r   run_commandzDisk.run_command   sJ    +5<(%dkk2<< I-&*DLL# .r   c                 P     | j                   j                  di | j                   y)zShow resultN )r   	exit_jsonr   r   s    r   show_resultzDisk.show_result   s    --r   c                 D    | j                          | j                          y)WorkerN)r    r$   r   s    r   workz	Disk.work   s    r   N)__name__
__module____qualname__r   r   r    r$   r'   r"   r   r   r
   r
      s    @+.r   r
   c                     t        t        dddg      t        dd      t        ddg d      t        ddg d      t        ddg d	      t        ddd
dg      t        ddg d	      t        ddd
dg      t        ddg d	      t        ddg d	      t        dd      t        ddd      t        ddg d	      t        dd            } | j                  t               t        |       }|j	                          y )NstrFshow)typerequiredchoicesint)r.   r/   )r            
   )r   r2            r3   )r2   r6   r7   r2   r6   list)r.   elementsr/   )infoctrl_idlevelsizeaccessrwiocacheinitselectslotacceleratorvname)r   updater   r
   r'   )r   disk_objs     r   mainrK      s    uuvh?%%07GHuu6HI	B
EEAq6
:
EE9
=UUQF;yAuui@/v>eeYG.M  *+M"HMMOr   __main__N)
__future__r   r   r   r.   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   9ansible_collections.inspur.ispim.plugins.module_utils.ismr   r   objectr
   rK   r(   r"   r   r   <module>rU      sX    C BaF1f
 5 i6 :, zF r   