hpe-storage / python-3parclient

This is a python client that talks to the HPE Alletra 9000 and HPE Primera and HPE 3PAR storage array via REST.
Apache License 2.0
48 stars 70 forks source link

CREATE VVSET SNAPSHOT: VVSET PATTERNS #102

Closed mdiogene closed 2 months ago

mdiogene commented 2 months ago

Hello,

I am trying to use this library to create vvset snapshot but i getting an error : createSnapshotOfVolumeSet('@vvname@.@a@', volume_name, optional=optional) Error : 137 - Invalid volume pattern specified

Iam running my script from rundeck. I have installed the library using: pip3 install python-3parclient

Here are the functions:

def create_snapshot_for_volume(cl, volume_name, expiration_hours=None, retention_hours=None):
    """Crée un snapshot pour un volume spécifique avec expiration ou retention."""
    try:
        now = datetime.now()
        date_str = now.strftime("%Y%m%d")  # Format: YYYYMMDD
        time_str = now.strftime("%H%M")  # Format: HHMMSS

        # Générer un nom de snapshot unique pour chaque volume
        #snapshot_name = "@vvname@_D"

        logging.info(f"Début de la création du snapshot pour le volume : {volume_name}")
        logging.info(f"Nom du snapshot : {snapshot_name}")

        optional = {
            "name": snapshot_name
        }
        if expiration_hours is not None:
            optional["expirationHours"] = expiration_hours

        if retention_hours is not None:
            optional["retentionHours"] = retention_hours

        # Créer le snapshot pour les volumes du volume set spécifique
        cl.createSnapshotOfVolumeSet("@vvname@@a@", volume_name, optional=optional)

        logging.info(f"Le snapshot du volume {volume_name} a été créé avec succès : {snapshot_name} avec expiration : {expiration_hours} heures")
    except Exception as e:
        logging.error(f"Erreur lors de la création du snapshot pour le volume {volume_name} : {e}")
        raise
def create_snapshots(cl, specific_volumes=None, expiration_hours=None, retention_hours=None):
    """Crée des snapshots pour les volumes spécifiés ou pour tous les volumes disponibles."""
    try:
        volumes = cl.getVolumeSets()
        for element in volumes.get('members', []):
            if isinstance(element, dict):
                volume_name = element.get('name')
                if specific_volumes is None or volume_name in specific_volumes:
                    print(f"Volume Name GET: {volume_name}")
                    create_snapshot_for_volume(cl, volume_name, expiration_hours, retention_hours)
                    time.sleep(1)
            else:
                logging.warning(f"Type d'élément inattendu : {type(element)}, valeur : {element}")
    except Exception as e:
        logging.error(f"Erreur lors de la création des snapshots : {e}")
        raise

Is there something that I am doing wrong ? PS: The snapshot for Virtual volume is working fine using(createSnapshot) only the snapshot name must be 31 characters

Best regards,

mdiogene commented 2 months ago

I am closing the issue I found what the problem was: it is @ that is interpreted differently. For that to work, I have to double @@ (ex: "@@vvname@@_@@j@@"