
    Vh5                         d 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  ej                  d      Z G d	 d
e      Zd Zd Zedk(  r e        yy)zG Ansible module for managing SDCs on Dell Technologies (Dell) PowerFlex    )absolute_importdivisionprint_functiona  
module: sdc
version_added: '1.0.0'
short_description: Manage SDCs on Dell PowerFlex
description:
- Managing SDCs on PowerFlex storage system includes getting details of SDC
  and renaming SDC.

author:
- Akash Shendge (@shenda1) <ansible.team@dell.com>

extends_documentation_fragment:
  - dellemc.powerflex.powerflex

options:
  sdc_name:
    description:
    - Name of the SDC.
    - Specify either I(sdc_name), I(sdc_id) or I(sdc_ip) for get/rename operation.
    - Mutually exclusive with I(sdc_id) and I(sdc_ip).
    type: str
  sdc_id:
    description:
    - ID of the SDC.
    - Specify either I(sdc_name), I(sdc_id) or I(sdc_ip) for get/rename operation.
    - Mutually exclusive with I(sdc_name) and I(sdc_ip).
    type: str
  sdc_ip:
    description:
    - IP of the SDC.
    - Specify either I(sdc_name), I(sdc_id) or I(sdc_ip) for get/rename operation.
    - Mutually exclusive with I(sdc_id) and I(sdc_name).
    type: str
  sdc_new_name:
    description:
    - New name of the SDC. Used to rename the SDC.
    type: str
  performance_profile:
    description:
    - Define the performance profile as I(Compact) or I(HighPerformance).
    - The high performance profile configures a predefined set of parameters for very high performance use cases.
    choices: ['Compact', 'HighPerformance']
    type: str
  state:
    description:
    - State of the SDC.
    choices: ['present', 'absent']
    required: true
    type: str
notes:
  - The I(check_mode) is not supported.
a  
- name: Get SDC details using SDC ip
  dellemc.powerflex.sdc:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    sdc_ip: "{{sdc_ip}}"
    state: "present"

- name: Rename SDC using SDC name
  dellemc.powerflex.sdc:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    sdc_name: "centos_sdc"
    sdc_new_name: "centos_sdc_renamed"
    state: "present"

- name: Modify performance profile of SDC using SDC name
  dellemc.powerflex.sdc:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    sdc_name: "centos_sdc"
    performance_profile: "Compact"
    state: "present"

- name: Remove SDC using SDC name
  dellemc.powerflex.sdc:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    sdc_name: "centos_sdc"
    state: "absent"
a^
  
changed:
    description: Whether or not the resource has changed.
    returned: always
    type: bool
    sample: 'false'

sdc_details:
    description: Details of the SDC.
    returned: When SDC exists
    type: dict
    contains:
        id:
            description: The ID of the SDC.
            type: str
        name:
            description: Name of the SDC.
            type: str
        sdcIp:
            description: IP of the SDC.
            type: str
        osType:
            description: OS type of the SDC.
            type: str
        mapped_volumes:
            description: The details of the mapped volumes.
            type: list
            contains:
                id:
                    description: The ID of the volume.
                    type: str
                name:
                    description: The name of the volume.
                    type: str
                volumeType:
                    description: Type of the volume.
                    type: str
        sdcApproved:
            description: Indicates whether an SDC has approved access to the
                         system.
            type: bool
    sample: {
        "id": "07335d3d00000006",
        "installedSoftwareVersionInfo": "R3_6.0.0",
        "kernelBuildNumber": null,
        "kernelVersion": "3.10.0",
        "links": [
            {
                "href": "/api/instances/Sdc::07335d3d00000006",
                "rel": "self"
            },
            {
                "href": "/api/instances/Sdc::07335d3d00000006/relationships/
                        Statistics",
                "rel": "/api/Sdc/relationship/Statistics"
            },
            {
                "href": "/api/instances/Sdc::07335d3d00000006/relationships/
                        Volume",
                "rel": "/api/Sdc/relationship/Volume"
            },
            {
                "href": "/api/instances/System::4a54a8ba6df0690f",
                "rel": "/api/parent/relationship/systemId"
            }
        ],
        "mapped_volumes": [],
        "mdmConnectionState": "Disconnected",
        "memoryAllocationFailure": null,
        "name": "LGLAP203",
        "osType": "Linux",
        "peerMdmId": null,
        "perfProfile": "HighPerformance",
        "sdcApproved": true,
        "sdcApprovedIps": null,
        "sdcGuid": "F8ECB844-23B8-4629-92BB-B6E49A1744CB",
        "sdcIp": "N/A",
        "sdcIps": null,
        "sdcType": "AppSdc",
        "sdrId": null,
        "socketAllocationFailure": null,
        "softwareVersionInfo": "R3_6.0.0",
        "systemId": "4a54a8ba6df0690f",
        "versionInfo": "R3_6.0.0"
    }
)AnsibleModule)utilssdcc                   N    e Zd ZdZd Zd Zd ZddZd Zd Z	d	 Z
d
 Zd Zd Zy)PowerFlexSdczClass with SDC operationsc                 D   t        j                         | _        | j                  j                  t	                      g dg}g dg}t        | j                  d||      | _        t        j                  | j                         	 t        j                  | j                  j                        | _
        t        j                  d       y# t        $ rM}t        j                  t        |             | j                  j!                  t        |             Y d}~yd}~ww xY w)z. Define all parameters required by this module)sdc_idsdc_ipsdc_nameF)argument_specsupports_check_modemutually_exclusiverequired_one_ofz3Got the PowerFlex system connection object instancemsgN)r   %get_powerflex_gateway_host_parametersmodule_paramsupdateget_powerflex_sdc_parametersr   moduleensure_required_libs%get_powerflex_gateway_host_connectionparamspowerflex_connLOGinfo	Exceptionerrorstr	fail_json)selfr   r   es       i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/powerflex/plugins/modules/sdc.py__init__zPowerFlexSdc.__init__   s    "HHJ!!">"@A>?;< $,, %1+	- 	""4;;/	."'"M"M""#$DHHJK 	.IIc!fKK!!c!f!--	.s   AC	 		DADDc                    	 | j                   j                  j                  ||       y# t        $ rL}d|dt	        |      }t
        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)zRename SDC
        :param sdc_id: The ID of the SDC
        :param new_name: The new name of the SDC
        :return: Boolean indicating if rename operation is successful
        )r   nameTzFailed to rename SDC  with error r   N)	r   r   renamer    r"   r   r!   r   r#   )r$   r   new_namer%   errormsgs        r&   
rename_sdczPowerFlexSdc.rename_sdc   so    	0##**&x*H 	0BHBEa&JHIIhKK!!h!//		0   '* 	A?AA::A?c                    	 | j                   j                  j                  |      }|S # t        $ rL}d|dt	        |      }t
        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)zGet volumes mapped to SDC
        :param sdc_id: The ID of the SDC
        :return: List containing volume details mapped to SDC
        )r   z(Failed to get the volumes mapped to SDC r*   r   N)	r   r   get_mapped_volumesr    r"   r   r!   r   r#   )r$   r   respr%   r-   s        r&   r1   zPowerFlexSdc.get_mapped_volumes   so    	0&&**==V=LDK 	0%+SV5HIIhKK!!h!//		0r/   Nc                 ^   |r|}n|r|}n|}	 |r)| j                   j                  j                  d|i      }nS|r)| j                   j                  j                  d|i      }n(| j                   j                  j                  d|i      }t        |      dk(  rd|z  }t        j                  |       y| j                  |d   d         |d   d<   |d   S # t        $ rL}d	|d
t        |      }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)zGet the SDC Details
            :param sdc_name: The name of the SDC
            :param sdc_ip: The IP of the SDC
            :param sdc_id: The ID of the SDC
            :return: The dict containing SDC details
        r)   )filter_fieldssdcIpidr   z%Unable to find SDC with identifier %sNmapped_volumeszFailed to get the SDC r*   r   )r   r   getlenr   r!   r1   r    r"   r   r#   )	r$   r   r   r   
id_ip_namesdc_details	error_msgr%   r-   s	            r&   get_sdczPowerFlexSdc.get_sdc  s?    !JJJ	0"115599#)8"4 : 6"115599#*F"3 : 5 #115599#'. : 2 ;1$C()			)$/3/F/FAt$0&KN+,q>! 	0CF$HIIhKK!!h!//		0s   B&C 5!C 	D, AD''D,c                 "   g d}|D ]  }| j                   j                  |   t        | j                   j                  |   j                               dk(  sQd| }t        j                  |       | j                   j                  |        y)zValidate the input parametersr   r   r   Nr   zPlease provide valid r   )r   r   r9   stripr   r!   r#   )r$   sdc_identifiersparamr   s       r&   validate_parametersz PowerFlexSdc.validate_parameters+  s~     ;$ 	/E{{!!%(4**51779:a?-eW5		#%%#%.	/    c                 2   	 t         j                  d|        | j                  j                  j	                  |       y# t
        $ rL}d| dt        |       }t         j                  |       | j                  j                  |       Y d}~yd}~ww xY w)zRemove the SDCzRemoving SDC r   T failed with error N)
r   r   r   r   deleter    r"   r!   r   r#   )r$   r   r%   r-   s       r&   removezPowerFlexSdc.remove6  s    	0HH=1H2##**62 	0&vh.A#a&JHIIhKK!!h!//	0s   >A 	B
ABBc                 4   	 t         j                  d|        | j                  j                  j	                  ||       y# t
        $ rL}d| dt        |       }t         j                  |       | j                  j                  |       Y d}~yd}~ww xY w)zSet performance profile of SDCz#Setting performance profile of SDC r   Tz%Modifying performance profile of SDC rF   N)
r   r   r   r   set_performance_profiler    r"   r!   r   r#   )r$   r   performance_profiler%   r-   s        r&   rJ   z$PowerFlexSdc.set_performance_profileA  s    	0HH>vhGHH##;;FDWX 	0>vhFYZ]^_Z`YabHIIhKK!!h!//	0s   ?A 	BABBc                     |dk(  r8|s6d|z  }t         j                  |       | j                  j                  |       |r:t	        |j                               dk(  r| j                  j                  d       y y y )Npresentz3Could not find any SDC instance with identifier %s.r   r   z$Provide valid SDC name to rename to.)r   r!   r   r#   r9   r@   )r$   r;   sdc_new_namestater:   r<   s         r&   validate_inputzPowerFlexSdc.validate_inputL  sq    Ik)+56IIIi KK!!i!0C 2 2 45:KK!!&L!M ;<rD   c                     d}|||d   k7  r| j                  |d   |      }|r||d   k7  r| j                  |d   |      }|S )NFr)   r6   perfProfile)r.   rJ   )r$   r;   rN   rK   changeds        r&   perform_modifyzPowerFlexSdc.perform_modifyV  s[    #F8K(Kook$&7FG#6+m:T#T22;t3DFYZGrD   c                    | j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }d}t        di       }| j                          | j	                  |||	      }	|xs |xs |}
| j                  |	|||
       |d
k(  r|	r| j                  |	d         }|dk(  r|	r| j                  |	||      }|r| j	                  |xs |||	      }	|	|d<   ||d<    | j                   j                  di | y)ze
        Perform different actions on SDC based on parameters passed in
        the playbook
        r   r   r   rN   rK   rO   F)rS   r;   r?   absentr6   rM   r;   rS   N )	r   r   dictrC   r=   rP   rH   rT   	exit_json)r$   r   r   r   rN   rK   rO   rS   resultr;   r:   s              r&   perform_module_operationz%PowerFlexSdc.perform_module_operation_  sj   
 ;;%%j1##H-##H-{{)).9"kk001FG""7+ 

 	  "llHV*0 # 2116
KujIHkk+d"34GI+))+|EXYG,,0H.4V ' EK +}#y''rD   )NNN)__name__
__module____qualname____doc__r'   r.   r1   r=   rC   rH   rJ   rP   rT   r[   rW   rD   r&   r
   r
      s9    #.40 0&0P	/	0	0N%(rD   r
   c                      t        t               t               t               t               t        ddg      t        ddddg      	      S )
zRThis method provide parameter required for the Ansible SDC module on
    PowerFlexCompactHighPerformance)choicesTr"   rM   rV   )requiredtyperc   )r   r   r   rN   rK   rO   )rX   rW   rD   r&   r   r     sC     vvVyJ[>\1]Duy(6KL rD   c                  8    t               } | j                          y)z` Create PowerFlex SDC object and perform actions on it
        based on user input from playbookN)r
   r[   )objs    r&   mainrh     s     .C  "rD   __main__N)r_   
__future__r   r   r   re   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Gansible_collections.dellemc.powerflex.plugins.module_utils.storage.dellr   
get_loggerr   objectr
   r   rh   r\   rW   rD   r&   <module>rs      sz    N B B3j&PU
n 5 eu}(6 }(@	# zF rD   