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 update_group(client_obj, group_name, **kwargs):

    if utils.is_null_or_empty(group_name):
        return (False, False, "Update 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 updated as it is not present.",
                {}, {})

        changed_attrs_dict, params = utils.remove_unchanged_or_null_args(
            group_resp, **kwargs)
        if changed_attrs_dict.__len__() > 0:
            group_resp = client_obj.groups.update(
                id=group_resp.attrs.get("id"), **params)
            return (
                True, True,
                f"Group '{group_name}' already present. Modified the following attributes '{changed_attrs_dict}'",
                changed_attrs_dict, group_resp.attrs)
        else:
            return (
                True, False,
                f"Group '{group_resp.attrs.get('name')}' already present in given state.",
                {}, group_resp.attrs)
    except Exception as ex:
        return (False, False, f"Group update failed | '{ex}'", {}, {})
def delete_snapshot(client_obj, vol_name, snapshot_name):

    if utils.is_null_or_empty(snapshot_name):
        return (False, False,
                "Delete snapshot failed as snapshot is not present.", {})
    if utils.is_null_or_empty(vol_name):
        return (False, False, "Delete snapshot failed. 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}' is not present on Array for deleting snapshot.",
                {})
        snap_resp = client_obj.snapshots.get(id=None,
                                             vol_name=vol_name,
                                             name=snapshot_name)
        if utils.is_null_or_empty(snap_resp):
            return (
                False, False,
                f"Snapshot '{snapshot_name}' cannot be deleted as it is not present in given volume '{vol_name}'.",
                {})
        else:
            client_obj.snapshots.delete(id=snap_resp.attrs.get("id"))
            return (True, True,
                    f"Deleted snapshot '{snapshot_name}' successfully.", {})
    except Exception as ex:
        return (False, False, f"Snapshot deletion 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}", {}, {})
Exemple #5
0
def delete_prot_template(client_obj, prot_template_name):

    if utils.is_null_or_empty(prot_template_name):
        return (
            False, False,
            "Protection template deletion 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):
            return (
                False, False,
                f"Protection template '{prot_template_name}' not present to delete.",
                {})
        else:
            client_obj.protection_templates.delete(
                id=prot_template_resp.attrs.get("id"))
            return (
                True, True,
                f"Deleted protection template '{prot_template_name}' successfully.",
                {})
    except Exception as ex:
        return (False, False, f"Protection template deletion failed | {ex}",
                {})
Exemple #6
0
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 delete_volcoll(client_obj, volcoll_name):

    if utils.is_null_or_empty(volcoll_name):
        return (
            False, False,
            "Delete volume collection failed as volume collection name is null.",
            {})

    try:
        volcoll_resp = client_obj.volume_collections.get(id=None,
                                                         name=volcoll_name)
        if utils.is_null_or_empty(volcoll_resp):
            return (
                False, False,
                f"Volume collection '{volcoll_name}' not present to delete.",
                {})
        else:

            client_obj.volume_collections.delete(
                id=volcoll_resp.attrs.get("id"))
            return (
                True, True,
                f"Deleted volume collection '{volcoll_name}' successfully.",
                {})
    except Exception as ex:
        return (False, False, f"Volume collection deletion failed | {ex}", {})
Exemple #8
0
def resume_partner(client_obj, downstream_hostname):

    if utils.is_null_or_empty(downstream_hostname):
        return (
            False, False,
            "Resume replication partner failed as no downstream partner is provided.",
            {})

    try:
        upstream_repl_resp = client_obj.replication_partners.get(
            id=None, hostname=downstream_hostname)
        if utils.is_null_or_empty(upstream_repl_resp):
            return (
                False, False,
                f"Replication partner '{downstream_hostname}' cannot be resumed as it is not present.",
                {})

        client_obj.replication_partners.resume(
            id=upstream_repl_resp.attrs.get("id"))
        return (
            True, True,
            f"Resumed replication partner '{downstream_hostname}' successfully.",
            {})
    except Exception as ex:
        return (False, False, f"Resume replication partner 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 update_chap_user(client_obj, user_name, **kwargs):

    if utils.is_null_or_empty(user_name):
        return (False, False,
                "Update chap user failed as user is not present.", {}, {})

    try:
        user_resp = client_obj.chap_users.get(id=None, name=user_name)
        if utils.is_null_or_empty(user_resp):
            return (
                False, False,
                f"Chap user '{user_name}' cannot be updated as it is not present.",
                {}, {})

        changed_attrs_dict, params = utils.remove_unchanged_or_null_args(
            user_resp, **kwargs)
        if changed_attrs_dict.__len__() > 0:
            user_resp = client_obj.chap_users.update(
                id=user_resp.attrs.get("id"), **params)
            return (
                True, True,
                f"Chap user '{user_name}' already present. Modified the following attributes '{changed_attrs_dict}'",
                changed_attrs_dict, user_resp.attrs)
        else:
            return (
                True, False,
                f"Chap user '{user_resp.attrs.get('name')}' already present in given state.",
                {}, user_resp.attrs)
    except Exception as ex:
        return (False, False, f"Chap user update failed |{ex}", {}, {})
Exemple #11
0
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}",
                {}, {})
Exemple #12
0
def delete_perf_policy(client_obj, perf_policy_name):

    if utils.is_null_or_empty(perf_policy_name):
        return (
            False, False,
            "Delete 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):
            return (
                False, False,
                f"Cannot delete Performance policy '{perf_policy_name}' as it is not present ",
                {})
        else:
            perf_policy_resp = client_obj.performance_policies.delete(
                id=perf_policy_resp.attrs.get("id"))
            return (
                True, True,
                f"Deleted performance policy '{perf_policy_name}' successfully.",
                {})
    except Exception as ex:
        return (False, False, f"Performance policy deletion failed | {ex}", {})
def create_chap_user(client_obj, user_name, password, **kwargs):

    if utils.is_null_or_empty(user_name):
        return (False, False,
                "Create chap user failed as user is not present.", {}, {})
    if utils.is_null_or_empty(password):
        return (False, False,
                "Create chap user failed as password is not present.", {}, {})

    try:
        user_resp = client_obj.chap_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.chap_users.create(name=user_name,
                                                     password=password,
                                                     **params)
            return (True, True,
                    f"Chap user '{user_name}' created successfully.", {},
                    user_resp.attrs)
        else:
            return (
                False, False,
                f"Chap user '{user_name}' cannot be created as it is already present in given state.",
                {}, user_resp.attrs)
    except Exception as ex:
        return (False, False, f"Chap user creation failed |{ex}", {}, {})
Exemple #14
0
def validate_volcoll(client_obj, volcoll_name):

    if utils.is_null_or_empty(volcoll_name):
        return (
            False, False,
            "Validate volume collection failed as volume collection name is null.",
            {}, {})

    try:
        volcoll_resp = client_obj.volume_collections.get(id=None,
                                                         name=volcoll_name)
        if utils.is_null_or_empty(volcoll_resp):
            return (
                False, False,
                f"Volume collection '{volcoll_name}' not present for validation.",
                {}, {})
        else:
            volcoll_validate_resp = client_obj.volume_collections.validate(
                id=volcoll_resp.attrs.get("id"))
            if hasattr(volcoll_validate_resp, 'attrs'):
                volcoll_validate_resp = volcoll_validate_resp.attrs
            return (
                True, False,
                f"Validation of volume collection '{volcoll_name}' done successfully.",
                {}, volcoll_validate_resp)
    except Exception as ex:
        return (False, False, f"Validation of volume collection failed | {ex}",
                {}, {})
Exemple #15
0
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}",
                {}, {})
Exemple #16
0
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}",
                {})
Exemple #17
0
def abort_handover_volcoll(client_obj, volcoll_name):

    if utils.is_null_or_empty(volcoll_name):
        return (
            False, False,
            "Abort handover of volume collection failed as volume collection name is null.",
            {})

    try:
        volcoll_resp = client_obj.volume_collections.get(id=None,
                                                         name=volcoll_name)
        if utils.is_null_or_empty(volcoll_resp):
            return (
                False, False,
                f"Volume collection '{volcoll_name}' not present for abort handover.",
                {})
        else:
            client_obj.volume_collections.abort_handover(
                id=volcoll_resp.attrs.get("id"))
            return (
                True, True,
                f"Abort handover of volume collection '{volcoll_name}' done successfully.",
                {})
    except Exception as ex:
        return (False, False,
                f"Abort handover of volume collection failed | {ex}", {})
Exemple #18
0
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_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}",
                {}, {})
Exemple #20
0
def delete_snapcoll(client_obj, snapcoll_name, volcoll_name):

    if utils.is_null_or_empty(snapcoll_name):
        return (
            False, False,
            "Snapshot collection deletion failed as 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):
            return (
                False, False,
                f"Snapshot collection '{snapcoll_name}' for volume collection '{volcoll_name}' not present to delete.",
                {})
        else:
            client_obj.snapshot_collections.delete(
                id=snapcoll_resp.attrs.get("id"))
            return (
                True, True,
                f"Snapshot collection '{snapcoll_name}' for volume collection '{volcoll_name}' deleted successfully.",
                {})
    except Exception as ex:
        return (False, False, f"Snapshot collection deletion failed | {ex}",
                {})
Exemple #21
0
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}", {},
                {})
Exemple #22
0
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 update_fc_interface(client_obj, array_name_or_serial, fc_name, controller,
                        online):

    if utils.is_null_or_empty(array_name_or_serial):
        return (
            False, False,
            "Fibre channel interface update failed as no array name is provided.",
            {}, {})
    if utils.is_null_or_empty(fc_name):
        return (
            False, False,
            "Fibre channel interface update failed as no interface name is provided.",
            {}, {})
    if utils.is_null_or_empty(controller):
        return (
            False, False,
            "Fibre channel interface update failed as no controller name is provided.",
            {}, {})
    if utils.is_null_or_empty(online):
        return (
            False, False,
            "Fibre channel interface update failed as online flag is not provided.",
            {}, {})
    try:
        # get the details of the fc
        fc_resp = client_obj.fibre_channel_interfaces.list(
            detail=True, array_name_or_serial=array_name_or_serial)
        if fc_resp is None:
            return (
                False, False,
                f"No fibre channel is present for array '{array_name_or_serial}'.",
                {}, {})
        else:
            fc_result = None
            for fc_interface_obj in fc_resp:
                if fc_interface_obj.attrs.get(
                        "name") == fc_name and fc_interface_obj.attrs.get(
                            "controller_name") == controller:
                    fc_result = fc_interface_obj
                    break
            if fc_result is not None:
                changed_attrs_dict, params = utils.remove_unchanged_or_null_args(
                    fc_result, online=online)
                if changed_attrs_dict.__len__() > 0:
                    fc_result = client_obj.fibre_channel_interfaces.update(
                        id=fc_result.attrs.get("id"), online=online)
                    if hasattr(fc_result, 'attrs'):
                        fc_result = fc_result.attrs
                    return (True, True, "Updated fibre channel interface.", {},
                            fc_result)
                else:
                    if hasattr(fc_result, 'attrs'):
                        fc_result = fc_result.attrs
                    return (True, False,
                            "Fibre channel interface already in given state.",
                            {}, fc_result)
    except Exception as ex:
        return (False, False, f"Fibre channel update failed |'{ex}'", {}, {})
Exemple #24
0
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_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 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}'", {}, {})
Exemple #27
0
def delete_igroup(client_obj, initiator_group_name):

    if utils.is_null_or_empty(initiator_group_name):
        return (False, False,
                "Initiator group deletion failed as it is not present.", {})

    try:
        # see if the igroup is already present
        ig_resp = client_obj.initiator_groups.get(id=None,
                                                  name=initiator_group_name)
        if ig_resp is not None:
            client_obj.initiator_groups.delete(ig_resp.attrs.get("id"))
            return (
                True, True,
                f"Successfully deleted initiator group '{initiator_group_name}'.",
                {})
        elif ig_resp is None:
            return (
                False, False,
                f"Initiator group '{initiator_group_name}' is not present on array.",
                {})
        else:
            return (
                False, False,
                f"Failed to delete initiator group '{initiator_group_name}'.",
                {})
    except Exception as ex:
        return (False, False, f"Initiator group deletion failed | {ex}", {})
def update_snapshot(client_obj, snap_resp, **kwargs):

    if utils.is_null_or_empty(snap_resp):
        return (False, False,
                "Update snapshot failed as snapshot is not present.", {}, {})

    try:
        snapshot_name = snap_resp.attrs.get("name")
        changed_attrs_dict, params = utils.remove_unchanged_or_null_args(
            snap_resp, **kwargs)
        if changed_attrs_dict.__len__() > 0:
            snap_resp = client_obj.snapshots.update(
                id=snap_resp.attrs.get("id"), **params)
            return (
                True, True,
                f"Snapshot '{snapshot_name}' already present. Modified the following attributes '{changed_attrs_dict}'",
                changed_attrs_dict, snap_resp.attrs)
        else:
            return (
                True, False,
                f"Snapshot '{snapshot_name}' already present in given state.",
                {}, snap_resp.attrs)

    except Exception as ex:
        return (False, False, f"Snapshot update failed | {ex}", {}, {})
Exemple #29
0
def update_volcoll(client_obj, volcoll_resp, **kwargs):

    if utils.is_null_or_empty(volcoll_resp):
        return (
            False, False,
            "Update volume collection failed as volume collection is not present.",
            {}, {})
    try:
        volcoll_name = volcoll_resp.attrs.get("name")
        changed_attrs_dict, params = utils.remove_unchanged_or_null_args(
            volcoll_resp, **kwargs)
        if changed_attrs_dict.__len__() > 0:
            volcoll_resp = client_obj.volume_collections.update(
                id=volcoll_resp.attrs.get("id"), **params)
            return (
                True, True,
                f"Volume collection '{volcoll_name}' already present. Modified the following attributes '{changed_attrs_dict}'",
                changed_attrs_dict, volcoll_resp.attrs)
        else:
            return (
                True, False,
                f"Volume collection '{volcoll_name}' already present in given state.",
                {}, volcoll_resp.attrs)
    except Exception as ex:
        return (False, False, f"Volume collection update failed | {ex}", {},
                {})
def update_volume(client_obj, vol_resp, **kwargs):

    if utils.is_null_or_empty(vol_resp):
        return (False, False, "Invalid volume to update.", {}, {})
    try:
        changed_attrs_dict, params = utils.remove_unchanged_or_null_args(
            vol_resp, **kwargs)

        if 'volcoll_name' in kwargs:
            if kwargs['volcoll_name'] == "" and vol_resp.attrs.get(
                    'volcoll_id') != "":
                params['volcoll_id'] = ""
                changed_attrs_dict['volcoll_id'] = ""
            else:
                if 'volcoll_name' in params:
                    params.pop('volcoll_name')
                    changed_attrs_dict.pop('volcoll_name')

        if changed_attrs_dict.__len__() > 0:
            resp = client_obj.volumes.update(id=vol_resp.attrs.get("id"),
                                             **params)
            return (
                True, True,
                f"Volume '{vol_resp.attrs.get('name')}' already present. Modified the following attributes '{changed_attrs_dict}'",
                changed_attrs_dict, resp.attrs)
        else:
            return (
                True, False,
                f"Volume '{vol_resp.attrs.get('name')}' already present in given state.",
                {}, vol_resp.attrs)
    except Exception as ex:
        return (False, False, f"Volume update failed '{ex}'", {}, {})