def create_update_network_config(client_obj, name, state, iscsi_automatic_connection_method, iscsi_connection_rebalancing, mgmt_ip, change_name, **kwargs): if utils.is_null_or_empty(name): return (False, False, "Create network config failed as name is not present.", {}, {}) try: network_resp = client_obj.network_configs.get(id=None, name=name) if utils.is_null_or_empty(network_resp): params = utils.remove_null_args(**kwargs) network_resp = client_obj.network_configs.create( name=name, iscsi_automatic_connection_method= iscsi_automatic_connection_method, iscsi_connection_rebalancing=iscsi_connection_rebalancing, mgmt_ip=mgmt_ip, **params) return (True, True, f"Network config '{name}' created successfully.", {}, network_resp.attrs) else: if state == "create": return ( False, False, f"Network config '{name}' cannot be created as it is already present in given state.", {}, network_resp.attrs) # update case kwargs['name'] = change_name changed_attrs_dict, params = utils.remove_unchanged_or_null_args( network_resp, **kwargs) # even though some of the attributes have not changed but it still has to be passed in case of update. params = utils.remove_null_args(**kwargs) if changed_attrs_dict.__len__() > 0: network_resp = client_obj.network_configs.update( id=network_resp.attrs.get("id"), name=name, iscsi_automatic_connection_method= iscsi_automatic_connection_method, iscsi_connection_rebalancing=iscsi_connection_rebalancing, mgmt_ip=mgmt_ip, **params) return ( True, True, f"Network config '{name}' already present. Modified the following attributes '{changed_attrs_dict}'", changed_attrs_dict, network_resp.attrs) else: return ( True, False, f"Network config '{network_resp.attrs.get('name')}' already present in given state.", {}, network_resp.attrs) except Exception as ex: return (False, False, f"Network config creation failed |'{ex}'", {}, {})
def create_snapcoll(client_obj, snapcoll_name, volcoll_name, **kwargs): if utils.is_null_or_empty(snapcoll_name): return ( False, False, "Create snapshot collection failed. snapshot collection name is not present.", {}, {}) try: snapcoll_resp = client_obj.snapshot_collections.get( id=None, name=snapcoll_name, volcoll_name=volcoll_name) if utils.is_null_or_empty(snapcoll_resp): params = utils.remove_null_args(**kwargs) snapcoll_resp = client_obj.snapshot_collections.create( name=snapcoll_name, **params) return ( True, True, f"Created snapshot collection '{snapcoll_name}' for volume collection '{volcoll_name}' successfully.", {}, snapcoll_resp.attrs) else: return ( False, False, f"Snapshot collection '{snapcoll_name}' for volume collection '{volcoll_name}' cannot be created" "as it is already present in given state.", {}, snapcoll_resp.attrs) except Exception as ex: return (False, False, f"Snapshot collection creation failed | {ex}", {}, {})
def merge_pool( client_obj, pool_name, target, **kwargs): if utils.is_null_or_empty(pool_name): return (False, False, "Merge pool failed as pool name is not present.", {}, {}) if utils.is_null_or_empty(target): return (False, False, "Delete pool failed as target pool name is not present.", {}, {}) try: pool_resp = client_obj.pools.get(id=None, name=pool_name) if utils.is_null_or_empty(pool_resp): return (False, False, f"Merge pools failed as source pool '{pool_name}' is not present.", {}, {}) target_pool_resp = client_obj.pools.get(id=None, name=target) if utils.is_null_or_empty(target_pool_resp): return (False, False, f"Merge pools failed as target pool '{target}' is not present.", {}, {}) params = utils.remove_null_args(**kwargs) resp = client_obj.pools.merge(id=pool_resp.attrs.get("id"), target_pool_id=target_pool_resp.attrs.get("id"), **params) if hasattr(resp, 'attrs'): resp = resp.attrs return (True, True, f"Merged target pool '{target}' to pool '{pool_name}' successfully.", {}, resp) except Exception as ex: return (False, False, f"Merge pool failed | {ex}", {}, {})
def update_disk( client_obj, slot, shelf_location, **kwargs): if utils.is_null_or_empty(shelf_location): return (False, False, "Disk update failed as no shelf location provided.", {}, {}) try: # get the details of the disk for a given slot and shelf_location disk_resp = client_obj.disks.list(detail=True) if disk_resp is None: return (False, False, "No Disk is present on array.", {}, {}) else: disk_id = None changed_attrs_dict = {} for disk_obj in disk_resp: if slot == disk_obj.attrs.get("slot") and shelf_location == disk_obj.attrs.get("shelf_location"): disk_id = disk_obj.attrs.get("id") break params = utils.remove_null_args(**kwargs) disk_resp = client_obj.disks.update(id=disk_id, **params) if hasattr(disk_resp, 'attrs'): disk_resp = disk_resp.attrs changed_attrs_dict['slot'] = slot changed_attrs_dict['shelf_location'] = shelf_location return (True, True, f"Successfully updated disk to slot '{slot}' at shelf location '{shelf_location}'.", changed_attrs_dict, disk_resp) except Exception as ex: return (False, False, f"Disk update failed |'{ex}'", {}, {})
def create_perf_policy(client_obj, perf_policy_name, **kwargs): if utils.is_null_or_empty(perf_policy_name): return ( False, False, "Create performance policy failed. Performance policy name is not present.", {}, {}) try: perf_policy_resp = client_obj.performance_policies.get( id=None, name=perf_policy_name) if utils.is_null_or_empty(perf_policy_resp): params = utils.remove_null_args(**kwargs) perf_policy_resp = client_obj.performance_policies.create( name=perf_policy_name, **params) if perf_policy_resp is not None: return ( True, True, f"Created performance policy '{perf_policy_name}' successfully.", {}, perf_policy_resp.attrs) else: return ( False, False, f"Cannot create Performance policy '{perf_policy_name}' as it is already present", {}, {}) except Exception as ex: return (False, False, f"Performance policy creation failed | {ex}", {}, {})
def create_volcoll(client_obj, volcoll_name, **kwargs): if utils.is_null_or_empty(volcoll_name): return ( False, False, "Create volume collection failed as volume collection is not present.", {}, {}) try: volcoll_resp = client_obj.volume_collections.get(id=None, name=volcoll_name) if utils.is_null_or_empty(volcoll_resp): params = utils.remove_null_args(**kwargs) volcoll_resp = client_obj.volume_collections.create( name=volcoll_name, **params) return ( True, True, f"Created volume collection '{volcoll_name}' successfully.", {}, volcoll_resp.attrs) else: return ( False, False, f"Volume collection '{volcoll_name}' cannot be created as it is already present in given state.", {}, {}) except Exception as ex: return (False, False, f"Volume collection creation failed | {ex}", {}, {})
def delete_acr(client_obj, initiator_group, volume, **kwargs): if utils.is_null_or_empty(initiator_group): return ( False, False, "Access control record deletion failed. No initiator group provided." ) if utils.is_null_or_empty(volume): return (False, False, "Access control record deletion failed. No volume provided.") params = utils.remove_null_args(**kwargs) try: acr_list_resp = client_obj.access_control_records.list( vol_name=volume, initiator_group_name=initiator_group, **params) if acr_list_resp is not None and acr_list_resp.__len__() > 0: for acr_resp in acr_list_resp: client_obj.access_control_records.delete( acr_resp.attrs.get("id")) return ( True, True, f"Successfully deleted access control record for initiator group '{initiator_group}' associated with volume '{volume}'." ) else: return ( True, False, f"No access control record for initiator group '{initiator_group}' associated with volume '{volume}' found." ) except Exception as ex: return (False, False, f"Access control record deletion failed | {ex}")
def create_snapshot(client_obj, vol_name, snapshot_name, **kwargs): if utils.is_null_or_empty(snapshot_name): return (False, False, "Create snapshot failed as snapshot is not present.", {}, {}) if utils.is_null_or_empty(vol_name): return (False, False, "Create snapshot failed as volume is not present.", {}, {}) try: vol_resp = client_obj.volumes.get(id=None, name=vol_name) if utils.is_null_or_empty(vol_resp): return ( False, False, f"Volume '{vol_name}' not present on array for taking snapshot.", {}, {}) snap_resp = client_obj.snapshots.get(id=None, vol_name=vol_name, name=snapshot_name) if utils.is_null_or_empty(snap_resp): params = utils.remove_null_args(**kwargs) snap_resp = client_obj.snapshots.create( name=snapshot_name, vol_id=vol_resp.attrs.get("id"), **params) if snap_resp is not None: return (True, True, f"Snapshot '{snapshot_name}' created successfully.", {}, snap_resp.attrs) else: return ( False, False, f"Snapshot '{snapshot_name}' cannot be created as it is already present in given state.", {}, {}) except Exception as ex: return (False, False, f"Snapshot creation failed | {ex}", {}, {})
def handover_volcoll(client_obj, volcoll_name, **kwargs): if utils.is_null_or_empty(volcoll_name): return ( False, False, "Handover of volume collection failed as volume collection name is null.", {}) try: volcoll_resp = client_obj.volume_collections.get(id=None, name=volcoll_name) params = utils.remove_null_args(**kwargs) if utils.is_null_or_empty(volcoll_resp): return ( False, False, f"Volume collection '{volcoll_name}' not present for handover.", {}) else: client_obj.volume_collections.handover( id=volcoll_resp.attrs.get("id"), **params) return ( True, True, f"Handover of volume collection '{volcoll_name}' done successfully.", {}) except Exception as ex: return (False, False, f"Handover of volume collection failed | {ex}", {})
def create_igroup(client_obj, initiator_group_name, **kwargs): if utils.is_null_or_empty(initiator_group_name): return ( False, False, "Initiator group creation failed. Initiator group name is null.", {}, {}) try: ig_resp = client_obj.initiator_groups.get(id=None, name=initiator_group_name) if utils.is_null_or_empty(ig_resp): # remove unchanged and null arguments from kwargs params = utils.remove_null_args(**kwargs) ig_resp = client_obj.initiator_groups.create( name=initiator_group_name, **params) return ( True, True, f"Created initiator Group '{initiator_group_name}' successfully.", {}, ig_resp.attrs) else: return ( False, False, f"Cannot create initiator Group '{initiator_group_name}' as it is already present in given state.", {}, {}) except Exception as ex: return (False, False, f"Initiator group creation failed | {ex}", {}, {})
def create_partner( client_obj, downstream_hostname, # downstream **kwargs): if utils.is_null_or_empty(downstream_hostname): return (False, False, "Create replication partner failed as name is not present.", {}) try: upstream_repl_resp = client_obj.replication_partners.get( id=None, hostname=downstream_hostname) if utils.is_null_or_empty(upstream_repl_resp): params = utils.remove_null_args(**kwargs) upstream_repl_resp = client_obj.replication_partners.create( hostname=downstream_hostname, **params) return ( True, True, f"Replication partner '{downstream_hostname}' created successfully.", {}, upstream_repl_resp.attrs) else: return ( False, False, f"Replication partner '{downstream_hostname}' cannot be created as it is already present in given state.", {}, upstream_repl_resp.attrs) except Exception as ex: return (False, False, f"Replication partner creation failed |{ex}", {}, {})
def create_prot_template(client_obj, prot_template_name, **kwargs): if utils.is_null_or_empty(prot_template_name): return ( False, False, "Create protection template failed as protection template name is not present.", {}, {}) try: prot_template_resp = client_obj.protection_templates.get( id=None, name=prot_template_name) if utils.is_null_or_empty(prot_template_resp): params = utils.remove_null_args(**kwargs) prot_template_resp = client_obj.protection_templates.create( name=prot_template_name, **params) return ( True, True, f"Protection template '{prot_template_name}' created successfully.", {}, prot_template_resp.attrs) else: return ( False, False, f"Protection template '{prot_template_name}' cannot be created as it is already present in given state.", {}, prot_template_resp.attrs) except Exception as ex: return (False, False, f"Protection template creation failed | {ex}", {}, {})
def create_prot_schedule(client_obj, prot_schedule_name, **kwargs): if utils.is_null_or_empty(prot_schedule_name): return ( False, False, "Create protection schedule failed as protection schedule name is not present.", {}, {}) try: prot_schedule_resp = client_obj.protection_schedules.get( id=None, name=prot_schedule_name, volcoll_or_prottmpl_type=kwargs['volcoll_or_prottmpl_type'], volcoll_or_prottmpl_id=kwargs['volcoll_or_prottmpl_id']) if utils.is_null_or_empty(prot_schedule_resp): params = utils.remove_null_args(**kwargs) prot_schedule_resp = client_obj.protection_schedules.create( name=prot_schedule_name, **params) return ( True, True, f"Created protection schedule '{prot_schedule_name}' successfully.", {}, prot_schedule_resp.attrs) else: return ( False, False, f"Cannot create protection schedule '{prot_schedule_name}' as it is already present in given state.", {}, prot_schedule_resp.attrs) except Exception as ex: return (False, False, f"Protection schedule creation failed | {ex}", {}, {})
def create_user(client_obj, user_name, password, **kwargs): if utils.is_null_or_empty(user_name): return (False, False, "Create user failed as user is not present.", {}, {}) if utils.is_null_or_empty(password): return (False, False, "Create user failed as password is not present.", {}, {}) try: user_resp = client_obj.users.get(id=None, name=user_name) if utils.is_null_or_empty(user_resp): params = utils.remove_null_args(**kwargs) user_resp = client_obj.users.create(name=user_name, password=password, **params) return (True, True, f"User '{user_name}' created successfully.", {}, user_resp.attrs) else: return ( False, False, f"User '{user_name}' cannot be created as it is already present in given state.", {}, {}) except Exception as ex: return (False, False, f"User creation failed | {ex}", {}, {})
def create_acr(client_obj, state, initiator_group, volume, **kwargs): if utils.is_null_or_empty(initiator_group): return ( False, False, "Access control record creation failed. No initiator group provided.", {}) if utils.is_null_or_empty(volume): return ( False, False, "Access control record creation failed. No volume name provided.", {}) try: # see if the igroup is already present ig_resp = client_obj.initiator_groups.get(id=None, name=initiator_group) if ig_resp is None: return ( False, False, f"Initiator Group '{initiator_group}' is not present on array.", {}) vol_resp = client_obj.volumes.get(id=None, name=volume) if vol_resp is None: return (False, False, f"Volume name '{volume}' is not present on array.", {}) acr_resp = client_obj.access_control_records.get( vol_name=volume, initiator_group_name=initiator_group, apply_to=kwargs['apply_to']) if utils.is_null_or_empty(acr_resp) is False: changed_attrs_dict, params = utils.remove_unchanged_or_null_args( acr_resp, **kwargs) else: params = utils.remove_null_args(**kwargs) if acr_resp is None or changed_attrs_dict.__len__() > 0: acr_resp = client_obj.access_control_records.create( initiator_group_id=ig_resp.attrs.get("id"), vol_id=vol_resp.attrs.get("id"), **params) # params['volume'] = volume # params['initiator_group'] = initiator_group return (True, True, "Successfully created access control record.", acr_resp.attrs) else: # if state is set to present, we pass if state == "present": return ( True, False, f"Access control record for volume '{volume}' with initiator group '{initiator_group}' is already present.", acr_resp.attrs) return ( False, False, f"Access control record for volume '{volume}' with initiator group '{initiator_group}' cannot " "be created as it is already present.", {}) except Exception as ex: return (False, False, f"Access control record creation failed | {ex}", {})
def create_acr(client_obj, initiator_group, volume, state, **kwargs): if utils.is_null_or_empty(initiator_group): return ( False, False, "Access control record creation failed. No initiator group provided." ) if utils.is_null_or_empty(volume): return ( False, False, "Access control record creation failed. No volume name provided.") try: # see if the igroup is already present ig_resp = client_obj.initiator_groups.get(id=None, name=initiator_group) if ig_resp is None: return ( False, False, f"Initiator Group '{initiator_group}' is not present on array." ) vol_resp = client_obj.volumes.get(id=None, name=volume) if vol_resp is None: return (False, False, f"Volume name '{volume}' is not present on array.") acr_resp = client_obj.access_control_records.get(id=None, vol_name=volume) if utils.is_null_or_empty(acr_resp) is False: changed_attrs_dict, params = utils.remove_unchanged_or_null_args( acr_resp, **kwargs) else: params = utils.remove_null_args(**kwargs) if acr_resp is None or acr_resp.attrs.get( "initiator_group_id") != ig_resp.attrs.get("id"): acr_resp = client_obj.access_control_records.create( initiator_group_id=ig_resp.attrs.get("id"), vol_id=vol_resp.attrs.get("id"), **params) return ( True, True, f"Successfully created access control record for volume '{volume}'." ) else: # check the state. if it is set to present ,we pass else if it is 'create' then we will fail if state == "present": return ( True, False, f"Access control record is already present for volume '{volume}'." ) return ( False, False, f"Access control record for volume '{volume}' cannot be created as it is already present." ) except Exception as ex: return (False, False, f"Access control record creation failed | {ex}")
def halt_group(client_obj, group_name, **kwargs): if utils.is_null_or_empty(group_name): return (False, False, "Halt group failed as it is not present.", {}) try: group_resp = client_obj.groups.get(id=None, name=group_name) if utils.is_null_or_empty(group_resp): return ( False, False, f"Group '{group_name}' cannot be halted as it is not present.", {}) params = utils.remove_null_args(**kwargs) client_obj.groups.halt(id=group_resp.attrs.get("id"), **params) return (True, True, f"Halted group '{group_name}' successfully.", {}) except Exception as ex: return (False, False, f"Halt group failed | '{ex}'", {})
def purge_inactive_key( client_obj, master_key, **kwargs): if utils.is_null_or_empty(master_key): return (False, False, "Purge inactive master key failed as master key is not present.", {}) try: master_key_resp = client_obj.master_key.get(id=None, name=master_key) if utils.is_null_or_empty(master_key_resp): return (False, False, f"Master key '{master_key}' cannot be purged as it is not present.", {}) params = utils.remove_null_args(**kwargs) client_obj.master_key.purge_inactive(id=master_key_resp.attrs.get("id"), **params) return (True, True, f"Purged inactive master key '{master_key}' successfully.", {}) except Exception as ex: return (False, False, f"Purge inactive master key failed |{ex}", {})
def create_volume( client_obj, vol_name, **kwargs): if utils.is_null_or_empty(vol_name): return (False, False, "Volume creation failed as volume name is null.", {}, {}) try: vol_resp = client_obj.volumes.get(id=None, name=vol_name) # remove unchanged and null arguments from kwargs params = utils.remove_null_args(**kwargs) if utils.is_null_or_empty(vol_resp): resp = client_obj.volumes.create(vol_name, **params) return (True, True, f"Created volume '{vol_name}' successfully.", {}, resp.attrs) else: return (False, False, f"Volume '{vol_name}' cannot be created as it is already present in given state.", {}, {}) except Exception as ex: return (False, False, f"Volume creation failed '{ex}'", {}, {})
def failover_array(client_obj, array_name, **kwargs): if utils.is_null_or_empty(array_name): return (False, False, "Failover array failed as array name is not present.", {}) try: array_resp = client_obj.arrays.get(id=None, name=array_name) if utils.is_null_or_empty(array_resp): return ( False, False, f"Array '{array_name}' cannot failover as it is not present.", {}) else: params = utils.remove_null_args(**kwargs) array_resp = client_obj.arrays.failover( id=array_resp.attrs.get("id"), **params) return (True, True, f"Failover array '{array_name}' successfully.", {}) except Exception as ex: return (False, False, f"Array failover failed |{ex}", {})
def create_pool( client_obj, pool_name, **kwargs): if utils.is_null_or_empty(pool_name): return (False, False, "Create pool failed as pool name is not present.", {}, {}) try: pool_resp = client_obj.pools.get(id=None, name=pool_name) if utils.is_null_or_empty(pool_resp): params = utils.remove_null_args(**kwargs) pool_resp = client_obj.pools.create(name=pool_name, **params) if pool_resp is not None: return (True, True, f"Created pool '{pool_name}' successfully.", {}, pool_resp.attrs) else: return (False, False, f"Pool '{pool_name}' cannot be created as it is already present in given state.", {}, pool_resp.attrs) except Exception as ex: return (False, False, f"Pool creation failed | {ex}", {}, {})
def create_array(client_obj, array_name, **kwargs): if utils.is_null_or_empty(array_name): return (False, False, "Create array failed as array name is not present.", {}, {}) try: array_resp = client_obj.arrays.get(id=None, name=array_name) if utils.is_null_or_empty(array_resp): params = utils.remove_null_args(**kwargs) array_resp = client_obj.arrays.create(name=array_name, **params) if array_resp is not None: return (True, True, f"Created array '{array_name}' successfully.", {}, array_resp.attrs) else: return ( False, False, f"Array '{array_name}' cannot be created as it is already present", {}, array_resp.attrs) except Exception as ex: return (False, False, f"Array creation failed |{ex}", {}, {})
def merge_group(client_obj, group_name, **kwargs): if utils.is_null_or_empty(group_name): return (False, False, "Merge for group failed as it is not present.", {}, {}) try: group_resp = client_obj.groups.get(id=None, name=group_name) if utils.is_null_or_empty(group_resp): return ( False, False, f"Merge for group '{group_name}' cannot be done as it is not present.", {}, {}) params = utils.remove_null_args(**kwargs) merge_resp = client_obj.groups.merge(id=group_resp.attrs.get("id"), **params) if hasattr(merge_resp, 'attrs'): merge_resp = merge_resp.attrs return (True, True, f"Merged group '{group_name}' successfully.", {}, merge_resp) except Exception as ex: return (False, False, f"Merge for group failed | '{ex}'", {}, {})
def validate_merge_group(client_obj, group_name, **kwargs): if utils.is_null_or_empty(group_name): return (False, False, "Validate merge for group failed as it is not present.", {}, {}) try: group_resp = client_obj.groups.get(id=None, name=group_name) if utils.is_null_or_empty(group_resp): return ( False, False, f"Validate merge for group '{group_name}' cannot be done as it is not present.", {}, {}) params = utils.remove_null_args(**kwargs) validate_merge_resp = client_obj.groups.validate_merge( id=group_resp.attrs.get("id"), **params) if hasattr(validate_merge_resp, 'attrs'): validate_merge_resp = validate_merge_resp.attrs if utils.is_null_or_empty( validate_merge_resp.get("validation_error_msg")): return ( True, False, f"Validate merge operation for group '{group_name}' done successfully.", {}, validate_merge_resp) else: msg = validate_merge_resp.get("validation_error_msg") return ( False, False, f"Validate merge operation for group '{group_name}' failed with error '{msg}'", {}, validate_merge_resp) except Exception as ex: return (False, False, f"Validate merge for group failed | '{ex}'", {}, {})