
    Vh                        d dl mZmZmZ eZdZdZdZd dl	Z	d dl
Z
d dlmZ d dlmZmZ d dlmZmZ d d	lmZmZ d d
lm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&d Z'd Z(d Z)d Z*d Z+d Z,d  Z-d! Z.d" Z/d# Z0e1d$k(  r e0        yy)%    )absolute_importdivisionprint_functiona  
---
module: ome_profile
short_description: Create, modify, delete, assign, unassign and migrate a profile on OpenManage Enterprise
version_added: "3.1.0"
description: "This module allows to create, modify, delete, assign, unassign, and migrate a profile on OpenManage Enterprise."
extends_documentation_fragment:
  - dellemc.openmanage.ome_auth_options
options:
  command:
    description:
      - C(create) creates new profiles.
      - "C(modify) modifies an existing profile. Only I(name), I(description), I(boot_to_network_iso), and I(attributes)
      can be modified."
      - C(delete) deletes an existing profile.
      - C(assign) Deploys an existing profile on a target device and returns a task ID.
      - C(unassign) unassigns a profile from a specified target and returns a task ID.
      - C(migrate) migrates an existing profile and returns a task ID.
    choices: [create, modify, delete, assign, unassign, migrate]
    default: create
    type: str
  name_prefix:
    description:
      - The name provided when creating a profile is used a prefix followed by the number assigned to it by OpenManage Enterprise.
      - This is applicable only for a create operation.
      - This option is mutually exclusive with I(name).
    type: str
    default: Profile
  name:
    description:
      - Name of the profile.
      - This is applicable for modify, delete, assign, unassign, and migrate operations.
      - This option is mutually exclusive with I(name_prefix) and I(number_of_profiles).
    type: str
  new_name:
    description:
      - New name of the profile.
      - Applicable when I(command) is C(modify).
    type: str
  number_of_profiles:
    description:
      - Provide the number of profiles to be created.
      - This is applicable when I(name_prefix) is used with C(create).
      - This option is mutually exclusive with I(name).
      - Openmanage Enterprise can create a maximum of 100 profiles.
    type: int
    default: 1
  template_name:
    description:
      - Name of the template for creating the profile(s).
      - This is applicable when I(command) is C(create).
      - This option is mutually exclusive with I(template_id).
    type: str
  template_id:
    description:
      - ID of the template.
      - This is applicable when I(command) is C(create).
      - This option is mutually exclusive with I(template_name).
    type: int
  device_id:
    description:
      - ID of the target device.
      - This is applicable when I(command) is C(assign) and C(migrate).
      - This option is mutually exclusive with I(device_service_tag).
    type: int
  device_service_tag:
    description:
      - Identifier of the target device.
      - This is typically 7 to 8 characters in length.
      - Applicable when I(command) is C(assign), and C(migrate).
      - This option is mutually exclusive with I(device_id).
      - If the device does not exist when I(command) is C(assign) then the profile is auto-deployed.
    type: str
  description:
    description: Description of the profile.
    type: str
  boot_to_network_iso:
    description:
      - Details of the Share iso.
      - Applicable when I(command) is C(create), C(assign), and C(modify).
    type: dict
    suboptions:
      boot_to_network:
        description: Enable or disable a network share.
        type: bool
        required: true
      share_type:
        description: Type of network share.
        type: str
        choices: [NFS, CIFS]
      share_ip:
        description: IP address of the network share.
        type: str
      share_user:
        description: User name when I(share_type) is C(CIFS).
        type: str
      share_password:
        description: User password when I(share_type) is C(CIFS).
        type: str
      workgroup:
        description: User workgroup when I(share_type) is C(CIFS).
        type: str
      iso_path:
        description: Specify the full ISO path including the share name.
        type: str
      iso_timeout:
        description: Set the number of hours that the network ISO file will remain mapped to the target device(s).
        type: int
        choices: [1, 2, 4, 8, 16]
        default: 4
  filters:
    description:
      - Filters the profiles based on selected criteria.
      - This is applicable when I(command) is C(delete) or C(unassign).
      - This supports suboption I(ProfileIds) which takes a list of profile IDs.
      - This also supports OData filter expressions with the suboption I(Filters).
      - See OpenManage Enterprise REST API guide for the filtering options available.
      - I(WARNING) When this option is used in case of C(unassign), task ID is not returned for any of the profiles affected.
    type: dict
  force:
    description:
      - Provides the option to force the migration of a profile even if the source device cannot be contacted.
      - This option is applicable when I(command) is C(migrate).
    type: bool
    default: false
  attributes:
    description: Attributes for C(modify) and C(assign).
    type: dict
    suboptions:
      Attributes:
        description:
          - List of attributes to be modified, when I(command) is C(modify).
          - List of attributes to be overridden when I(command) is C(assign).
          - "Use the I(Id) If the attribute Id is available. If not, use the comma separated I (DisplayName).
          For more details about using the I(DisplayName), see the example provided."
        type: list
        elements: dict
      Options:
        description:
          - Provides the different shut down options.
          - This is applicable when I(command) is C(assign).
        type: dict
      Schedule:
        description:
          - Schedule for profile deployment.
          - This is applicable when I(command) is C(assign).
        type: dict
requirements:
    - "python >= 3.9.6"
author: "Jagadeesh N V (@jagadeeshnv)"
notes:
    - Run this module from a system that has direct access to Dell OpenManage Enterprise.
    - This module supports C(check_mode).
    - C(assign) operation on a already assigned profile will not redeploy.
a3  
---
- name: Create two profiles from a template
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    template_name: "template 1"
    name_prefix: "omam_profile"
    number_of_profiles: 2

- name: Create profile with NFS share
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    command: create
    template_name: "template 1"
    name_prefix: "omam_profile"
    number_of_profiles: 1
    boot_to_network_iso:
      boot_to_network: true
      share_type: NFS
      share_ip: "192.168.0.1"
      iso_path: "path/to/my_iso.iso"
      iso_timeout: 8

- name: Create profile with CIFS share
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    command: create
    template_name: "template 1"
    name_prefix: "omam_profile"
    number_of_profiles: 1
    boot_to_network_iso:
      boot_to_network: true
      share_type: CIFS
      share_ip: "192.168.0.2"
      share_user: "username"
      share_password: "password"
      workgroup: "workgroup"
      iso_path: "\\path\\to\\my_iso.iso"
      iso_timeout: 8

- name: Modify profile name with NFS share and attributes
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    command: modify
    name: "Profile 00001"
    new_name: "modified profile"
    description: "new description"
    boot_to_network_iso:
      boot_to_network: true
      share_type: NFS
      share_ip: "192.168.0.3"
      iso_path: "path/to/my_iso.iso"
      iso_timeout: 8
    attributes:
      Attributes:
        - Id: 4506
          Value: "server attr 1"
          IsIgnored: false
        - Id: 4507
          Value: "server attr 2"
          IsIgnored: false
        # Enter the comma separated string as appearing in the Detailed view on GUI
        # System -> Server Topology -> ServerTopology 1 Aisle Name
        - DisplayName: 'System, Server Topology, ServerTopology 1 Aisle Name'
          Value: Aisle 5
          IsIgnored: false

- name: Delete a profile using profile name
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    command: "delete"
    name: "Profile 00001"

- name: Delete profiles using filters
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    command: "delete"
    filters:
      SelectAll: true
      Filters: =contains(ProfileName,'Profile 00002')

- name: Delete profiles using profile list filter
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    command: "delete"
    filters:
      ProfileIds:
        - 17123
        - 16124

- name: Assign a profile to target along with network share
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    command: assign
    name: "Profile 00001"
    device_id: 12456
    boot_to_network_iso:
      boot_to_network: true
      share_type: NFS
      share_ip: "192.168.0.1"
      iso_path: "path/to/my_iso.iso"
      iso_timeout: 8
    attributes:
      Attributes:
        - Id: 4506
          Value: "server attr 1"
          IsIgnored: true
      Options:
        ShutdownType: 0
        TimeToWaitBeforeShutdown: 300
        EndHostPowerState: 1
        StrictCheckingVlan: true
      Schedule:
        RunNow: true
        RunLater: false

- name: Unassign a profile using profile name
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    command: "unassign"
    name: "Profile 00003"

- name: Unassign profiles using filters
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    command: "unassign"
    filters:
      SelectAll: true
      Filters: =contains(ProfileName,'Profile 00003')

- name: Unassign profiles using profile list filter
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    command: "unassign"
    filters:
      ProfileIds:
        - 17123
        - 16123

- name: Migrate a profile
  dellemc.openmanage.ome_profile:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "/path/to/ca_cert.pem"
    command: "migrate"
    name: "Profile 00001"
    device_id: 12456
a  
---
msg:
  description: Overall status of the profile operation.
  returned: always
  type: str
  sample: "Successfully created 2 profile(s)."
profile_ids:
  description: IDs of the profiles created.
  returned: when I(command) is C(create)
  type: list
  sample: [1234, 5678]
job_id:
  description:
    - Task ID created when I(command) is C(assign), C(migrate) or C(unassign).
    - C(assign) and C(unassign) operations do not trigger a task if a profile is auto-deployed.
  returned: when I(command) is C(assign), C(migrate) or C(unassign)
  type: int
  sample: 14123
error_info:
  description: Details of the HTTP Error.
  returned: on HTTP error
  type: dict
  sample: {
    "error": {
      "code": "Base.1.0.GeneralError",
      "message": "A general error has occurred. See ExtendedInfo for more information.",
      "@Message.ExtendedInfo": [
        {
          "MessageId": "GEN1234",
          "RelatedProperties": [],
          "Message": "Unable to process the request because an error occurred.",
          "MessageArgs": [],
          "Severity": "Critical",
          "Resolution": "Retry the operation. If the issue persists, contact your system administrator."
        }
      ]
    }
  }
N)SSLError)RestOMEOmeAnsibleModule)URLError	HTTPError)ConnectionErrorSSLValidationError)recursive_diffzProfileService/ProfileszTemplateService/TemplateszDeviceService/DeviceszJobService/Jobs({job_id})z.ProfileService/Actions/ProfileService.{action}z6ProfileService/Profiles({profile_id})/AttributeDetailsz)Profile with the name '{name}' not found.zChanges found to be applied.zNo changes found to be applied.,c                     | j                   j                  d      }ddj                  |      i}d}|s0| j                   j                  d      }ddj                  |      i}d}|j                  dt        |	      }|j
                  rV|j                  j                  d
      r;|j                  j                  d
g       }|D ]  }|j                  |      |k(  s|c S  | j                  dj                  ||             y )Ntemplate_id$filter	Id eq {0}Idtemplate_namezName eq '{0}'NameGETquery_paramvaluez"Template with {0} '{1}' not found.msg)paramsgetformatinvoke_requestTEMPLATE_VIEWsuccess	json_data	fail_jsonmodulerest_objidr   srchresptlistxtypes           r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/openmanage/plugins/modules/ome_profile.pyget_template_detailsr-     s    			=	)Bk0045KD]]/ /"8"8"<=""5-["QD||**73""7B/ 	Eyy"$	 =DDT2NO    c                    | j                   j                  d      }ddj                  |      i}d}|s0| j                   j                  d      }ddj                  |      i}d}|j                  dt        |	      }|j
                  rV|j                  j                  d
      r;|j                  j                  d
g       }|D ]  }|j                  |      |k(  s|c S  dj                  ||      S )N	device_idr   r   r   device_service_tagzIdentifier eq '{0}'
Identifierr   r   r   z Target with {0} '{1}' not found.)r   r   r   r   DEVICE_VIEWr!   r"   r$   s           r,   get_target_detailsr4     s    			;	'Bk0045KD]]34 "7">">r"BC""5+;"OD||**73""7B/ 	Eyy"$	 .44T2>>r.   c                     |j                   d   }d}ddj                  |      i}| j                  dt        |      }|j                  j                  d      D ]  }|d   |k(  s|} |S  |S )	z/Get profile id based on requested profile name.nameNr   zProfileName eq '{0}'r   r   r   ProfileName)r   r   r   PROFILE_VIEWr"   r   )r&   r%   profile_nameprofiler   profile_reqeachs          r,   get_profiler=     s    ==(LG4;;LIJK))%;)WK%%))'2 ,.GN	 Nr.   c                 F   | j                   j                  d      }i }|r ddi}|j                  d      rd|d<   |j                  d      }||d<   i }|j                  d      }||d	<   ||d
<   |j                  d      |d<   |j                  d      |d<   |j                  d      |d<   ||d<   t        |j                  d            j                         j	                  d      r|j                  d      |d<   n| j                  d       |j                  d      |d<   |S )Nboot_to_network_isoBootToNetworkFboot_to_networkT
share_type	ShareTypeshare_ip	IpAddress	ShareName
share_userUsershare_passwordPassword	workgroup	WorkGroupShareDetailiso_pathz.isoIsoPathz'ISO path does not have extension '.iso'r   iso_timeout
IsoTimeout)r   r   strlowerendswithr#   )r%   boot_iso_dictiso_payloadrB   share_detailsh_ips         r,   get_network_iso_payloadrY     s8   MM%%&;<MK&../+/K(&**<8J'1K$L!%%j1E(-L%(-L%#0#4#4\#BL '4'8'89I'JL$(5(9(9+(FL%)5K&=$$Z01779BB6J)6):)::)FI&  %N O(5(9(9-(HK%r.   c                 r   t        | t              r| D ]  }dj                  |t        |j	                  d            }|j	                  d      rt        |j	                  d      ||||       Y|j	                  d      D ]5  }||d<   dj                  |t        |d         }||v r|d   ||<   |||d   <   7  y y )Nz	{0}{1}{2}DisplayNameSubAttributeGroups
AttributesprefixAttributeId)
isinstancelistr   SEPRTRr   recurse_subattr_list)	subgroupr^   attr_detailedattr_mapadv_listeach_subnprfxattrconstrs	            r,   rc   rc     s    (D!  	9H&&vvx||M7RSE||01$X\\2F%GP]_giqr$LL6 9D%*DN(//vtM?RSF)04]0Cf-48HT-019	9 "r.   c                 z    i }i }| D ]/  }t        |j                  d      |j                  d      |||       1 ||fS )Nr\   r[   )rc   r   )	attr_dtlsrg   re   rf   r<   s        r,   get_subattr_allrn     sN    MH yTXX&:;TXXm=TVcemowxy(""r.   c                    d}	 |j                  dt        j                  |            }|j                  }|j	                  di       }g }|D ]  }	|	j	                  d      st        |	j	                  d            j                  t              }
t        t
        j                  |
      }t        j                  |      }|j                  |        t        |j	                  d      |      \  }}|j	                  dg       }g }|D ]!  }	|	j	                  d      rt        |	j	                  d            j                  t              }
t        t
        j                  |
      }t        j                  |      }|j	                  |d      }||	d<   |	j                  dd        n|	j	                  d      }|s|j	                  |i       }|s|j                  |	       |	j	                  d	      |j	                  d	      k7  s%|	j	                  d
      |j	                  d
      k7  s|dz   }$ |D ]  }|j                  |        	 |S # t        $ r d}Y |S w xY w)Nr   r   )
profile_idr]   r[   AttributeGroups r   Value	IsIgnored   )r   PROFILE_ATTRIBUTESr   r"   r   rR   splitrb   mapstripjoinappendrn   popremove	Exception)r%   r&   inp_attrrp   diffr)   rm   disp_adv_listrg   rj   split_ktrimmedn_kre   rf   payload_attr	rem_attrsr'   ex_valrems                       r,   attributes_checkr     s   D#&&u.@.G.GS].G.^_NN	 \26! 	%Dxx&dhh}56<<VDcii1kk'*$	% #2)--@Q2RT\"]x||L"5	  	$Dxx&dhh}56<<VDcii1kk'*"&&sB/T
-XXd^!b"-$$T*88G$

7(;;txx?TX^XbXbcnXo?o!8D!	$"  	%C$	%
 K  Ks&   AI !EI 3A,I ! I IIc                    | j                   }i }|j                  d      rLt        ||       }|r	|d   |d<   n5| j                  t        j                  |j                  d                   t        | |      }t        |t              r|d   |d<   d   dk(  rB|d   |d   k(  r%| j                  dj                  |d                n| j                  d	       d
}d}	 |j                  dt        j                  d      d|d   i      }|d   t        |j                        v r| j                  d       g d}	n|j                  d      r| j                  |       d}d}|j                  d      |d<   d   dk(  rB|d   |d   k(  r%| j                  dj                  |d                n| j                  d       dg}	t        |       }
|
r|
|d<   |j                  d      }|	D ]<  }|s|j                  |      st!        | |||d          |j                  |      ||<   > | j"                  r| j                  t$        d       |j                  dt        j                  |      |      }|dd}|d
k(  rL	 t        ||       }t'        j(                  d       |j                  d       r|j                  d       |d!<   d"|d#<    | j                  d%i | y # t        $ r d }Y w xY w# t        $ r d$|d#<   Y 5w xY w)&Nr6   r   r6   r   TargetIdProfileState   z*The profile is assigned to the target {0}.zThe profile is assigned to a different target. Use the migrate command or unassign the profile and then proceed with assigning the profile to the target.AssignProfilez*Successfully applied the assign operation.POST!GetInvalidTargetsForAssignProfileactiondata3The target device is invalid for the given profile.r]   OptionsScheduler0   AssignProfileForAutoDeployz>Successfully applied the assign operation for auto-deployment.r1   r2   ru   
TargetNamez~The profile is assigned to a different target. Unassign the profile and then proceed with assigning the profile to the target.r]   NetworkBootToIso
attributesTr   changed   DeploymentTaskIdjob_idz8Successfully triggered the job for the assign operation.r   zGSuccessfully applied the assign operation. Failed to fetch job details. )r   r   r=   r#   PROFILE_NOT_FOUNDr   r4   r`   dict	exit_jsonr   PROFILE_ACTIONra   r"   r
   rY   r   
check_modeCHANGES_MSGtimesleep)r%   r&   mparampayloadproftargetr   r   r)   ad_opts_listrU   ad_optsoptres_dictres_profs                  r,   assign_profiler   +  s:   ]]FGzz&8V, JGDM!2!9!9vzz&?Q!9!RS1F&$$Tl
1$J6$</  %Q%X%XY_`dYe%f g   &w  x :	**6>3H3HPs3H3t15tDz0B + DDd|tDNN33  %Z [ =::k"(-N &

+? @1$L!W\%::  %Q%X%XY`amYn%o p   &w  x$~+F3M&3"#jj&G ,w{{3'VXwT
C";;s+GCL, [$7""6>+@+@+@+OV]"^Dt,H 	h"8V4HJJqM||./%-\\2D%E""\ F x K  	D	F  	hgHUO	hs&   AK ?AK/ K,+K,/L ?L c                    | j                   }i }|j                  d      ri }t        ||       }|r|d   dk(  r| j                  d       |d   rm	 |j	                  dt
        j                  |d               }|j                  }|j                  d	      }|j                  d
      dk(  r| j                  d       |d   g|d<   n5| j                  t        j                  |j                  d                   |j                  d      r|j                  d      }| j                  r| j                  t        d       d}|j	                  dt        j                  d            }|dd}		 t        ||       }
t        j                  d       |
j                  d      r|
j                  d      |	d<   d|	d<    | j                  di |	 y # t        $ r d}Y  w xY w# t        $ r d|	d<   Y 5w xY w)Nr6   r   r   z"Profile is in an unassigned state.r   r   r   )r   LastRunStatusr   RunningzCProfile deployment task is in progress. Wait for the job to finish.z;Unable to fetch job details. Applied the unassign operationr   
ProfileIdsr   filtersTr   zBSuccessfully applied the unassign operation. No job was triggered.r   UnassignProfilesr   r      r   z8Successfully triggered a job for the unassign operation.r   zYSuccessfully triggered a job for the unassign operation. Failed to fetch the job details.r   )r   r   r=   r   r   JOB_URIr   r"   r#   r
   r   r   r   r   r   r   )r%   r&   r   r   r   r)   job_dict
job_statusr   r   r   s              r,   unassign_profiler   l  s   ]]FDzz&8V,N#q(  %I J&'X#225'..PTUgPh.:ijD#~~H!)o!>J!~~f-:((-r(s &*$ZLGL!!2!9!9vzz&?Q!9!RSzz)**Y'[$7
NC""6>+@+@HZ+@+[bi"jDt,Hvx0

1<<*+!).@!AHXXHUO F x ) ! XWCX$  vuvs&   A,G 0AG  GG G10G1c                    | j                   }i }t        | |      }|d   |d<   |j                  d      |d<   |d   |d<   |j                  d      r|d   |d<   t        |       }|r||d	<   | j                  r| j                  t        d
       |j                  dt        |      }|j                  }| j                  dj                  t        |            d
|       y )Nr   
TemplateIdname_prefix
NamePrefixnumber_of_profilesNumberOfProfilesToCreatedescriptionDescriptionr   Tr   r   r   z$Successfully created {0} profile(s).)r   r   profile_ids)r   r-   r   rY   r   r   r   r   r8   r"   r   len)r%   r&   r   r   templaterU   r)   profile_id_lists           r,   create_profiler     s    ]]FG#FH5H$TNGL"JJ}5GL*01E*FG&'zz- !'!6+F3M&3"#[$7""6<g"FDnnO
?FFs?G[\!  @r.   c                    | j                   }i }t        ||       }|s5| j                  t        j	                  |j                  d                   d}|j                  d      }|r|n|d   |d<   |r||d   k7  r|dz  }|j                  d	      }|r||d
   k7  r
||d<   |dz  }t        |       }|j                  d      r|j                  d      ni }	|rt        ||	      }
|
r
|
d   r|dz  }||d<   |j                  d      }|rJ|j                  d      r9|t        | |||d         z   }|j                  d      r|j                  d      |d<   |d   |d<   |rc| j                  r| j                  t        d       |j                  dt        dj	                  |d         z   |       | j                  dd       | j                  t               y )Nr6   r   r   r   new_namer7   r   ru   r   ProfileDescriptionr   r   r   r]   r   Tr   PUT({0})r   z"Successfully modified the profile.)r   r=   r#   r   r   r   rY   r   r   r   r   r   r   r8   NO_CHANGES_MSG)r%   r&   r   r   r   r   r   descrU   rdict	nest_diffr   s               r,   modify_profiler     s   ]]FGx(D.556::f;M5NODzz*%H"*h]0CGFOH] 33	::m$D122!%	+F3M,0HH5G,HDHH'(bE"=%8	|	&3"#jj&G7;;|,&vx$t*MM;;|$$+KK$=GL!JGDMd;|gnnWT]6S'SZabA4P
(r.   c                    | j                   }|j                  d      rt        ||       }|r||d   dkD  r| j                  d       | j                  r| j                  t        d       |j                  dt        d	j                  |d
         z          | j                  dd       n5| j                  t        j                  |j                  d                   |j                  d      rp|j                  d      }| j                  r| j                  t        d       |j                  dt        j                  d      |       | j                  dd       y y )Nr6   r   r   z>Profile has to be in an unassigned state for it to be deleted.r   Tr   DELETEr   r   z!Successfully deleted the profile.r   r   r   Deleter   r   z,Successfully completed the delete operation.)r   r   r=   r#   r   r   r   r   r8   r   r   r   )r%   r&   r   r   r   s        r,   delete_profiler     s5   ]]Fzz&8V,N#a'  %e f    [$ ?##HlW^^DQUJ=W.WX!DdS!2!9!9vzz&?Q!9!RSzz)**Y'd;(=(=X(=(NU\]KUYZ r.   c                 &   | j                   }i }|j                  d      |d<   t        | |      }t        |t              s| j                  |       |d   |d<   t        ||       }|rO|d   |d   k(  r| j                  t               	 |j                  dt        j                  d      d|d   i	      }|d   t        |j                        v r| j                  d
       |d   dk(  r|d   |d<   | j                  r| j                  t         d       |j                  dt        j                  d      |	      }d}|dd}	 t#        j$                  d       t        ||       }	|	j                  d      r|	j                  d      |d<   d|d<    | j                  di | y | j                  d       y | j                  t&        j                  |j                  d                   y # t        $ r d }Y w xY w# t        $ r d|d<   Y ~w xY w)NforceForceMigrater   r   r   r   r   r   r   r   r   r   	ProfileIdTr   MigrateProfilez+Successfully applied the migrate operation.r   r   r   z9Successfully triggered the job for the migrate operation.r   zHSuccessfully applied the migrate operation. Failed to fetch job details.z@Profile needs to be in a deployed state for a migrate operation.r6   r   r   )r   r   r4   r`   r   r#   r=   r   r   r   r   r   ra   r"   r
   r   r   r   r   r   )
r%   r&   r   r   r   r   r)   r   r   r   s
             r,   migrate_profiler     s!   ]]FG$jj1GN1Ffd#V$ ,GJx(D$<4
++0	**6>3H3HPs3H3t15tDz0B + DDd|tDNN33  %Z [ 1$#':GK     [$ ?**6>3H3HP`3H3aho*pD?C"t4Hm

1&x8<< 23)16H)IHX&&aHUO F(x(!cd.556::f;M5NO+  	D	  m"lms&   
AG- AG? -G<;G<?HHc                    | j                   j                  d      }|dk(  rt        | |       |dk(  rt        | |       |dk(  rt	        | |       |dk(  rt        | |       |dk(  rt        | |       |dk(  rt        | |       y y )Ncommandcreatemodifydeleteassignunassignmigrate)r   r   r   r   r   r   r   r   )r%   r&   r   s      r,   profile_operationr     s    mm	*G(vx((vx((vx((vx(**)) r.   c                     ddddddgiddiddiddd	ddiddid
dg ddd} dddddiddid}dg dddddddiddidd
dddidd
idd
iddiddid| ddg dgddddgggdddid|dd ddd!}t        |d"dd#d$gdgd"d%d&ggd"d%g d'dgd"d(d&ggd"d(d)d*gdgd"d+d&d,gdgd"d-d&d,gdgd"d.d&ggd"d.d)d*gdgg	d&d/gd&d0gd&d,gd)d*gd#d$ggd1      }	 t        |j                  d2      5 }t        ||       d d d        y # 1 sw Y   y xY w# t        $ r9}|j                  t        |      t        j                  |      3       Y d }~y d }~wt        $ r&}|j                  t        |      d4       Y d }~y d }~wt        t        t        t        t        t         t"        f$ r%}|j                  t        |      5       Y d }~y d }~ww xY w)6NTbool)requiredtypechoicesNFSCIFSr   rR   )r   no_logintr   )ru      r         )r   defaultr   )rA   rB   rD   rG   rI   rK   rN   rP   ra   r   )r   elementsr   r   )r   r   r   r   r   r   )r   r   Profile)r   r   ru   rA   )rB   rD   rN   rB   rG   rI   )r   optionsrequired_if)r   r   F)r   r   r6   r   r   r   r   r0   r1   r   r?   r   r   r   r   r   r   r   r6   )r   r   r   r?   r   r0   r1   r   r   r   r   r   r   )argument_specr   mutually_exclusivesupports_check_mode)req_session)r   
error_info)r   unreachabler   )r   r   r   r   r
   r#   rR   jsonloadr	   r   IOError
ValueError	TypeErrorr   r   r   OSError)network_iso_specassign_specspecsr%   r&   errs         r,   mainr    s   8<f+M'05&/&B%+UO'-uo38D*I&,e_%+UO05!3C(EF +1f!E%v. &/1K  (^`#,e<UO*+U; %e_%uo(.;K%6>d$e%16LJZ;[$\0" #
 F#%+>"F3'E, ?M"BDI6(+"bdhi6(+;0D"EtL
VY$7>69"5t<	F8,	K1E#FM

 ]#)*Y./m,. !'"F('V]]5 	0fh/	0 	0 	0 BSX$))C.AA 9SX488ZHoGY[bc 'SX&&'sN   D "C8/D 8D=D D 	F>/EF>E..+F>F99F>__main__)2
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNr  r   sslr   ?ansible_collections.dellemc.openmanage.plugins.module_utils.omer   r   +ansible.module_utils.six.moves.urllib.errorr	   r
   ansible.module_utils.urlsr   r   0ansible.module_utils.common.dict_transformationsr   r8   r    r3   r   r   rv   r   r   r   rb   r-   r4   r=   rY   rc   rn   r   r   r   r   r   r   r   r   r  __name__r   r.   r,   <module>r     s    C BZxun'
R    e K I K(+%
%AM ? ,2	P"?"
49 #&R>!B$!N@(#)L[*&PR* ?'D zF r.   