def __init__(self): self._argument_spec = dellemc_pmax_argument_spec() self._argument_spec.update( dict(sgname=dict(type='str', required=True), new_sgname=dict(type='str', required=False), slo=dict(type='str', choices=[ 'Diamond', 'Platinum', 'Gold', 'Silver', 'Bronze' ], required=False, default=None), luns=dict(type='list', required=False), state=dict(type='str', choices=['present', 'absent'], required=True), no_compression=dict(type='bool', required=False))) self._module = AnsibleModule(argument_spec=self._argument_spec) self._conn = pmaxapi(self._module) self._changed = False self._lun_request = [] self._message = [] self._sg_name = self._module.params['sgname'] # Parsing the lun_request if exists if self._module.params['luns']: self._parsing_lun_request()
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update(dict( sgname=dict(type='str', required=True), host_or_cluster=dict(type='str', required=True), portgroup_id=dict(type='str', required=True), maskingview_name=dict(type='str', required=True) ) ) module = AnsibleModule(argument_spec=argument_spec) # Create Connection to Unisphere Server to Make REST calls conn = pmaxapi(module) dellemc = conn.provisioning # Make REST call to Unisphere Server and execute create masking view mvlist = dellemc.get_masking_view_list() # Check if Storage Group already exists if module.params['maskingview_name'] not in mvlist: dellemc.create_masking_view_existing_components( port_group_name=module.params['portgroup_id'], masking_view_name=module.params['maskingview_name'], host_name=module.params['host_or_cluster'], storage_group_name=module.params['sgname']) changed = True else: module.fail_json(msg='Masking View Already Exists') module.exit_json(changed=changed)
def __init__(self): self._argument_spec = dellemc_pmax_argument_spec() self._argument_spec.update( dict(host_id=dict(type='str', required=True), new_host_id=dict(type='str', required=False, default=None), initiator_list=dict(type='list', required=False), state=dict(type='str', required=True, choices=['present', 'absent']), wwn_state=dict(type='str', required=False, choices=['present', 'absent']), host_type=dict(type='str', required=False, default='default'), consistent_lun=dict(type='bool', required=False, default=False))) self._module = AnsibleModule(argument_spec=self._argument_spec) self._conn = pmaxapi(self._module) self._changed = False # Will gives the final status of execution self._message = [] # Contains the returned messages to the user self._host_id = self._module.params['host_id'] self._initiators = self._module.params['initiator_list'] # Host flags initialization try: self._host_flags = HOST_FLAGS[self._module.params['host_type']] self._host_flags['consistent_lun'] = self._module.params[ 'consistent_lun'] except KeyError: self._module.fail_json( msg="{} is not a valid or supported host " "type".format(self._module.params['host_flags']))
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update(dict( parent_sg=dict(type='str', required=True), child_sg=dict(type='str', required=True) ) ) module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import provisioning modules. conn = pmaxapi(module) dellemc = conn.provisioning # Compile a list of existing stroage groups. sglist = dellemc.get_storage_group_list() # Check if Storage Group already exists if module.params['parent_sg'] and module.params['child_sg'] in sglist: # Check that parent SG is either of type parent or standalone with # no volumes if dellemc.get_storage_group(module.params['parent_sg'])["type"]== "Standalone" and dellemc.get_storage_group(module.params['parent_sg'])[ "num_of_vols"]=0: dellemc.add_child_sg_to_parent_sg(child_sg=module.params[ 'child_sg'], parent_sg=module.params['parent_sg']) changed = True elif dellemc.get_storage_group(module.params['parent_sg'])["type"]==\ "Parent": dellemc.add_child_sg_to_parent_sg(child_sg=module.params[ 'child_sg'], parent_sg=module.params['parent_sg']) changed = True else: module.fail_json(msg='Both Parent and Child SG must exist for module ' 'to run sucessfully', changed=False) module.exit_json(changed=changed)
def __init__(self): self._argument_spec = dellemc_pmax_argument_spec() self._argument_spec.update(dict( volumes=dict(type='list', options=dict( device_id=dict(default=True, type="str", required=True), vol_name=dict(default=False, type="str", required=False), cap_gb=dict(default=True, type="float", required=False) ), required=True), sgname=dict(type='list', required=False, default=[]), in_sg=dict(type='str', choices=['present', 'absent'], required=False, ), freeing=dict(type='bool', required=False, default=False), delete=dict(type='bool', required=False, default=False), )) self._module = AnsibleModule(argument_spec=self._argument_spec) # Convert cap_gb to float ( in case cap_gb is filled using var_prompts). # sub-level options are always converted to str. Type doesn't matter try: for v in self._module.params['volumes']: if 'cap_gb' in v.keys(): v['cap_gb'] = float(v['cap_gb']) except ValueError: self._module.fail_json(msg="Cannot convert cap_gb to float (field volumes).") self._conn = pmaxapi(self._module) self._changed = False self._facts = None self._message = [] # Runs pre-checks self._mode_resizing = False self._modes_pre_checks()
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update(dict( maskingview_name=dict(type='str', required=True) ) ) module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import modules. conn = pmaxapi(module) dellemc = conn.provisioning mvlist = dellemc.get_masking_view_list() # Check if Masking View Exists if module.params['maskingview_name'] in mvlist: dellemc.delete_masking_view( maskingview_name=module.params['maskingview_name'] ) changed = True else: module.fail_json(msg='Masking View Does Not Exist, Please verify the ' 'input parameters', changed=changed) module.exit_json(changed=changed) facts = "some facts to help user in task" result = {'state': 'info', 'changed': changed} module.exit_json(ansible_facts={'some_detail': facts}, **result)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update( dict( cluster_name=dict(type='str', required=True), host_list=dict(type='list', required=True), )) module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import provisioning modules. conn = pmaxapi(module) dellemc = conn.provisioning # Check for each host in the host list that it exists, otherwise fail # module. configuredhostlist = dellemc.get_host_list() hostgrouplist = dellemc.get_hostgroup_list() host_exists = True if module.params['cluster_name'] not in hostgrouplist: for host in module.params["host_list"]: if host not in configuredhostlist: module.fail_json(msg='Host %s does not exist, failing task' % (host), changed=changed) host_exists = False if module.params['cluster_name'] not in hostgrouplist and host_exists: dellemc.create_hostgroup(hostgroup_id=module.params['cluster_name'], host_list=module.params['host_list']) changed = True module.exit_json(changed=changed) else: module.fail_json(msg="Cluster Name Already Exists", changed=False)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update( dict( sgname=dict(type='str', required=True), srp_id=dict(type='str', required=False), slo=dict(type='str', required=False), volumeIdentifier=dict(type='str', required=False), )) module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import provisioning modules. conn = pmaxapi(module) dellemc = conn.provisioning # Compile a list of existing storage groups. sglist = dellemc.get_storage_group_list() # Check if Storage Group already exists. if module.params['sgname'] not in sglist: dellemc.create_storage_group( srp_id='SRP_1', sg_id=module.params['sgname'], slo=module.params['slo'], vol_name=module.params['volumeIdentifier']) changed = True else: module.fail_json(msg='Storage Group Already Exists') facts = dellemc.get_storage_group( storage_group_name=module.params['sgname']) result = {'state': 'info', 'changed': changed} module.exit_json(ansible_facts={'storagegroup_detail': facts}, **result)
def __init__(self): self._argument_spec = dellemc_pmax_argument_spec() self._argument_spec.update( dict(parent_sg=dict(type='str', required=True), child_sg_list=dict(type='list', required=False), parent_state=dict(type='str', choices=['present', 'absent'], required=True), child_state=dict(type='str', choices=['present', 'absent'], required=True))) self._module = AnsibleModule(argument_spec=self._argument_spec) self._conn = pmaxapi(self._module) self._parent_sg = self._module.params['parent_sg'] self._child_sg_list = self._module.params['child_sg_list'] self._sglist = self._conn.provisioning.get_storage_group_list() if self._parent_sg in self._sglist: self._parent_sg_detail = self._conn.provisioning.get_storage_group( storage_group_name=self._parent_sg) else: self._parent_sg_detail = None self._changed = False self._message = "" self._error_message = ""
def __init__(self): self.argument_spec = dellemc_pmax_argument_spec() self. argument_spec.update(dict( volumes=dict(type='list', required=True), sgname=dict(type='str', required=True), in_sg=dict(type='str', choices=['present', 'absent'], required=True))) self.module = AnsibleModule(argument_spec=self.argument_spec) self.conn = pmaxapi(self.module)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update( dict(sg_source=dict(type='str', required=True), sg_target=dict(type='str', required=True), force=dict(type='bool', required=True), delete_source=dict(type='bool', required=False, default=False))) module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import modules. conn = pmaxapi(module) pmax_prov = conn.provisioning sg_source = module.params['sg_source'] sg_target = module.params['sg_target'] delete_source = module.params['delete_source'] # Compile a list of existing storage groups # Test if source and target storage groups exists sg_list = pmax_prov.get_storage_group_list() if sg_source not in sg_list: module.fail_json(msg=f'SG {sg_source} not exists') if sg_target not in sg_list: module.fail_json(msg=f'SG {sg_target} not exists') volumes_source = pmax_prov.get_vols_from_storagegroup(sg_source) volumes_target = pmax_prov.get_vols_from_storagegroup(sg_target) output_message = f'TDEV {",".join(volumes_source)} moved from {sg_source} ' \ f'to {sg_target}' # Check if some TDEVs are already in the target SG. If yes, updating the # move list with the remaining TDEVs intersection = set(volumes_source).intersection(set(volumes_target)) if intersection: volumes_source = set(volumes_source).difference(set(volumes_source)) output_message = f'Moved only TDEV {volumes_source} to {sg_target}, ' \ f'TDEVs {intersection} alrealdy in {sg_target}' # If there is still have TDEVs to move, move them if volumes_source: pmax_prov.move_volumes_between_storage_groups( device_ids=volumes_source, source_storagegroup_name=sg_source, target_storagegroup_name=sg_target, force=module.params['force']) changed = True if delete_source: pmax_prov.delete_storagegroup(storagegroup_id=sg_source) output_message += f' (source SG {sg_source} deleted)' module.exit_json(changed=changed, output=output_message) # Even if there is no TDEVs to move exit without error module.exit_json( output=f'Nothing to move from {sg_source} to {sg_target} or ' f'TDEVs already in the target SG')
def main(): argument_spec = dellemc_pmax_argument_spec() argument_spec.update( dict(gather_subset=dict(default=['all'], type='list'), )) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) ### Get the Subset of objects to collect d = Dellpmax_Gather_Facts(module) facts = d.get_data() result = {'state': 'info', 'changed': False} module.exit_json(ansible_facts={'dellemc_pmax_facts': facts}, **result)
def __init__(self): self.argument_spec = dellemc_pmax_argument_spec() self.argument_spec.update( dict(sgname=dict(type='str', required=True), host_or_cluster=dict(type='str', required=True), portgroup_id=dict(type='str', required=True), maskingview_name=dict(type='str', required=True), state=dict(type='str', choices=['present', 'absent'], required=True))) self.module = AnsibleModule(argument_spec=self.argument_spec) self.conn = pmaxapi(self.module)
def __init__(self): self.argument_spec = dellemc_pmax_argument_spec() self.argument_spec.update(dict( sgname=dict(type='str', required=True), slo=dict(type='str', choices=['Diamond', 'Platinum', 'Gold', 'Silver', 'Bronze', 'None'], required=True), luns=dict(type='list', required=False), state=dict(type='str', choices=['present', 'absent'], required=True), no_compression=dict(type='bool', required=False) )) self.module = AnsibleModule(argument_spec=self.argument_spec) self.conn = pmaxapi(self.module)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update( dict(valuesneededforthismodule=dict(type='str', required=True), )) module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import modules. conn = pmaxapi(module) pmax_prov = conn.provisioning # Compile a list of existing storage groups. #Your Code here facts = "some facts to help user in task" result = {'state': 'info', 'changed': changed} module.exit_json(ansible_facts={'some_detail': facts}, **result)
def __init__(self): self.argument_spec = dellemc_pmax_argument_spec() self.argument_spec.update( dict( portgroup_id=dict(type='str', required=True), state=dict(type='str', required=True, choices=['absent', 'present']), array_ports=dict(type='list', default=[]), port_state=dict(type='str', required=True, choices=['in_pg', 'out_of_pg']), )) self.module = AnsibleModule(argument_spec=self.argument_spec) self.conn = pmaxapi(self.module)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update( dict(sgname=dict(type='str', required=True), action=dict(type='str', choices=[ 'Establish', 'Suspend', 'Split', 'Failover', 'Failback' ], required=True))) # Make REST call to Unisphere Server and execute SRDF control operation module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import replicaiton functions. conn = pmaxapi(module) rep = conn.replication rdf_sglist = rep.get_storage_group_rep_list(has_srdf=True) if module.params['sgname'] in rdf_sglist: rdfg_list = rep.get_storagegroup_srdfg_list(module.params['sgname']) if len(rdfg_list) <= 1: rdfg = rdfg_list[0] rep.modify_storagegroup_srdf( storagegroup_id=module.params['sgname'], action=module.params['action'], rdfg=rdfg) changed = True else: module.fail_json( changed=changed, msg='Specified Storage Group has mult-site RDF Protection ' 'Ansible Module currently supports single Site SRDF ' 'please use Unishpere for PowerMax UI for SRDF group ' 'managment') else: module.fail_json(msg='Specified Storage Group is not currently SRDF ' 'Protected') rdfstate = rep.get_storagegroup_srdf_details( storagegroup_id=module.params['sgname'], rdfg_num=rdfg) facts = rdfstate result = {'state': 'info', 'changed': changed} module.exit_json(ansible_facts={'rdfstate': facts}, **result)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update( dict(sgname=dict(type='str', required=True), action=dict(type='str', choices=[ 'Establish', 'Suspend', 'Split', 'Failover', 'Failback' ], required=True))) # Make REST call to Unisphere Server and execute SRDF control operation module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import replicaiton functions. conn = pmaxapi(module) rep = conn.replication rdf_state = "Unknown" message = "No Changes" rdf_sglist = rep.get_storage_group_rep_list(has_srdf=True) if module.params['sgname'] in rdf_sglist: rdfg_list = rep.get_storagegroup_srdfg_list(module.params['sgname']) if len(rdfg_list) <= 1: rdfg = rdfg_list[0] try: rep.modify_storagegroup_srdf( storagegroup_id=module.params['sgname'], action=module.params['action'], rdfg=rdfg) changed = True rdf_state = rep.get_storagegroup_srdf_details( storagegroup_id=module.params['sgname'], rdfg_num=rdfg) except Exception: message = "A problem occured with the SRDF operation, " \ "please verify the storage group is not already in " \ "the requested state" else: message = 'Specified Storage Group has mult-site RDF Protection ' \ 'Ansible Module currently supports single Site SRDF ' \ 'please use Unishpere for PowerMax UI for SRDF group ' \ 'managment' else: message = 'Specified Storage Group is not SRDF Protected' facts = rdf_state result = ({'state': 'info', 'changed': changed, 'message': message}) module.exit_json(ansible_facts={'rdfstate': facts}, **result)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update(dict(host_id=dict(type='str', required=True))) module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import provisioning modules. conn = pmaxapi(module) dellemc = conn.provisioning # Compile a list of existing hosts. hostlist = dellemc.get_host_list() # Check if Host Name already exists. if module.params['host_id'] in hostlist: dellemc.delete_host(host_id=module.params['host_id']) changed = True else: module.fail_json(msg='Host Name Does not exist, Failing Task') module.exit_json(changed=changed)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update( dict(sgname=dict(type='str', required=True), num_vols=dict(type='int', required=True), vol_size=dict(type='int', required=True), cap_unit=dict(type='str', default='GB', choices=['GB', 'TB', 'MB', 'CYL']), volumeIdentifier=dict(type='str', required=True))) # Create Connection to Unisphere Server to Make REST calls # Setting connection shortcut to Provisioning modules to simplify code module = AnsibleModule(argument_spec=argument_spec) conn = pmaxapi(module) dellemc = conn.provisioning # Compile a list of existing storage groups. sglist = dellemc.get_storage_group_list() # Check if Storage Group already exists, if storage group does not exist # module will fail. if module.params['sgname'] not in sglist: module.fail_json(msg='Storage group does not Exist, Failing Task', changed=changed) else: # If storage group exists module can proceed # Build a list of the existing volumes in the storage group sgvols_before = dellemc.get_volume_list( filters={'storageGroupId': module.params['sgname']}) dellemc.add_new_vol_to_storagegroup( sg_id=module.params['sgname'], num_vols=module.params['num_vols'], cap_unit=module.params['cap_unit'], vol_size=module.params['vol_size'], vol_name=module.params['volumeIdentifier']) changed = True # Build a list of volumes in storage group after being modified sgvols_after = dellemc.get_volume_list( filters={'storageGroupId': module.params['sgname']}) newvols = (list(set(sgvols_after) - set(sgvols_before))) facts = ({ 'storagegroup_name': module.params['sgname'], 'new_volumes': newvols }) result = {'state': 'info', 'changed': changed} module.exit_json(ansible_facts={'sg_volume_detail': facts}, **result)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update(dict(portgroup_id=dict(type='str', required=True))) module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import modules. conn = pmaxapi(module) dellemc = conn.provisioning # Build a list of port groups. pglist = dellemc.get_portgroup_list() # Check group exists before trying to delete if module.params['portgroup_id'] in pglist: dellemc.delete_portgroup(portgroup_id=module.params['portgroup_id']) changed = True else: module.fail_json(msg='Port Group does not exist') facts = "some facts to help user in task" result = {'state': 'info', 'changed': changed} module.exit_json(ansible_facts={'some_detail': facts}, **result)
def __init__(self): self._argument_spec = dellemc_pmax_argument_spec() self._argument_spec.update( dict( portgroup_id=dict(type='str', required=True), new_portgroup_id=dict(type='str', required=False), state=dict(type='str', required=True, choices=['absent', 'present']), array_ports=dict(type='list', required=False, default=[]), port_state=dict(type='str', required=False, choices=['in_pg', 'out_of_pg']), )) self._module = AnsibleModule(argument_spec=self._argument_spec) self._conn = pmaxapi(self._module) self._portgroup_id = self._module.params.get('portgroup_id') self._array_ports = self._module.params.get('array_ports') self._changed = False self._message = []
def __init__(self): self._argument_spec = dellemc_pmax_argument_spec() self._argument_spec.update( dict(sgname=dict(type='str', required=False), host_or_cluster=dict(type='str', required=False), portgroup_id=dict(type='str', required=False), maskingview_name=dict(type='str', required=True), new_maskingview_name=dict(type='str', required=False), state=dict(type='str', choices=['present', 'absent'], required=True))) self._module = AnsibleModule(argument_spec=self._argument_spec) self._conn = pmaxapi(self._module) self._changed = False self._message = '' self._portgroup_id = self._module.params['portgroup_id'] self._maskingview_name = self._module.params['maskingview_name'] self._host_or_cluster = self._module.params['host_or_cluster'] self._sgname = self._module.params['sgname']
def __init__(self): self._argument_spec = dellemc_pmax_argument_spec() self._argument_spec.update( dict(cluster_name=dict(type='str', required=True), host_list=dict(type='list', required=True), state=dict(type='str', required=True, choices=['present', 'absent']), host_state=dict(type='str', required=True, choices=['in_cluster', 'not_in_cluster']))) self._module = AnsibleModule(argument_spec=self._argument_spec) self._conn = pmaxapi(self._module) self._changed = False self._message = '' self._cluster_name = self._module.params['cluster_name'] self._host_list = self._module.params['host_list'] self._host_state = self._module.params['host_state']
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update(dict(sgname=dict(type='str', required=True))) module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import modules. conn = pmaxapi(module) dellemc = conn.provisioning # Compile a list of existing storage groups that are currently not part # of a masking view. sglist = dellemc.get_storage_group_list(filters="num_of_masking_views=0") # Check if Storage Group already exists if module.params['sgname'] in sglist: dellemc.delete_storagegroup(storagegroup_id=module.params['sgname']) changed = True else: module.fail_json(msg='Storage Group Does not exist or is part of ' 'Part of a Masking view unable to proceed') facts = "some facts to help user in task" result = {'state': 'info', 'changed': changed} module.exit_json(ansible_facts={'some_detail': facts}, **result)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update( dict( sgname=dict(type='str', required=True), ttl=dict(type='int', required=True), snapshotname=dict(type='str', required=True), timeinhours=dict(type='bool', required=True), )) # Make REST call to Unisphere Server and execute create snapshot. module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import provisioning and replication modules. conn = pmaxapi(module) prov = conn.provisioning rep = conn.replication # Create a list of storage groups on the array. sglist = prov.get_storage_group_list() # Check Storage Group exist for snapshot to succeed. if module.params['sgname'] not in sglist: module.fail_json(msg='Storage Group Does Not Exist', changed=changed) else: rep.create_storagegroup_snap(sg_name=module.params['sgname'], snap_name=module.params['snapshotname'], ttl=module.params['ttl'], hours=module.params['timeinhours']) changed = True facts = ({ 'active_generations': rep.get_storagegroup_snapshot_generation_list( storagegroup_id=module.params['sgname'], snap_name=module.params['snapshotname']), "storage_group": module.params['sgname'], 'snapshotname': module.params['snapshotname'] }) result = {'state': 'info', 'changed': changed} module.exit_json(ansible_facts={'snap_detail': facts}, **result)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update( dict(device_id=dict(type='str', required=True), newsizegb=dict(type='int', required=True))) module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import modules. conn = pmaxapi(module) dellemc = conn.provisioning if dellemc.get_volume(device_id=module.params['device_id'] )['cap_gb'] < module.params['newsizegb']: dellemc.extend_volume(new_size=module.params['newsizegb'], device_id=module.params['device_id']) changed = True else: module.exit_json(msg="new volume size must be greater " "than current size", changed=changed) facts = dellemc.get_volume(device_id=module.params['device_id']) result = {'state': 'info', 'changed': changed} module.exit_json(ansible_facts={'vol_detail': facts}, **result)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update( dict( portgroup_id=dict(type='str', required=True), port_list=dict(type='list', required=True), )) module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import provisioning modules. conn = pmaxapi(module) dellemc = conn.provisioning pglist = dellemc.get_portgroup_list() if module.params['portgroup_id'] in pglist: module.fail_json(msg='Portgroup already exists, failing task') else: dellemc.create_multiport_portgroup( portgroup_id=module.params['portgroup_id'], ports=module.params['port_list']) changed = True module.exit_json(changed=changed)
def main(): changed = False argument_spec = dellemc_pmax_argument_spec() argument_spec.update(dict( sgname=dict(type='str', required=True), snapshotname=dict(type='str', required=True), target_sgname=dict(type='str', required=False), time_to_live_hrs=dict(type='str', required=False), action=dict(type='str', choices=['create', 'link', 'relink', 'unlink'], required=True) ) ) # Make REST call to Unisphere Server and execute create snapshot/ snapshotdetails = "unknown" module = AnsibleModule(argument_spec=argument_spec) # Setup connection to API and import modules. conn = pmaxapi(module) # Import provisioning and replication functions prov = conn.provisioning rep = conn.replication sglist = prov.get_storage_group_list() message = "" if module.params['action'] == 'create': if module.params['sgname'] in sglist: rep.create_storagegroup_snap(sg_name=module.params['sgname'], snap_name=module.params[ 'snapshotname'], ttl=module.params[ 'time_to_live_hrs'], hours=True) changed = True message = "Snapshot Created" else: message = " Storage Group not found" else: snaplist = rep.get_storagegroup_snapshot_list(module.params['sgname']) if module.params['sgname'] in sglist and module.params['snapshotname'] \ in snaplist: if module.params['action'] == 'link': rep.modify_storagegroup_snap(source_sg_id=module.params['sgname'], snap_name=module.params[ 'snapshotname'], target_sg_id=module.params[ 'target_sgname'], link=True, new_name=None, gen_num=0, async=True) changed = True elif module.params['action'] == 'relink': rep.modify_storagegroup_snap(source_sg_id=module.params['sgname'], snap_name=module.params[ 'snapshotname'], target_sg_id=module.params[ 'target_sgname'], relink=True, gen_num=0, async=True) changed = True elif module.params['action'] == 'unlink': rep.modify_storagegroup_snap(source_sg_id=module.params['sgname'], snap_name=module.params[ 'snapshotname'], target_sg_id=module.params[ 'target_sgname'], unlink=True, gen_num=0, _async=True) changed = True snapshotdetails = rep.get_snapshot_generation_details( sg_id=module.params[ 'sgname'], snap_name=module.params['snapshotname'], gen_num=0) else: message = 'No Snapshot found with the supplied Parameters' facts = snapshotdetails result = {'state': 'info', 'message': message, 'changed': changed} module.exit_json(ansible_facts={'snapdetail': facts}, **result)