Exemples d’utilisation de la Public API

Modifier des propriétés d’équipement, un mot de passe par exemple

Exemple avec curl, pour changer le mot de passe des baies de la famille IBM Storwize par notre Public API REST :
Il faut d’abord récupérer la clé d’API, comme dans cet exemple :
curl --location 'https://localhost:8443/api/public/v1/auth' \
     --header 'Content-Type: application/json' \
     --data '{
              "username": "xormon",
              "password": "xormon"
}'
Vous recevez alors une réponse contenant la clé d’API, au format json :
{
    "statusCode": 200,
    "data": {
        "apiKey": "b2c9bcf8a16c29d50a73dd52bdcc44a6",
        "expiration": "2025-06-06T08:39:44.640Z"
    }
}
Vous employez ensuite cette clé dans l’en-tête, ainsi :
curl --location 'https://localhost:8443/api/public/v1/hostcfg/' \ 
     --header 'apiKey: b2c9bcf8a16c29d50a73dd52bdcc44a6'
Cette requête retourne toutes vos configurations d’équipement, sous cette forme :
[
    {
            "hostcfg_id": "a7ac3eb5-95de-42c4-ba81-494835fa9ab0",
            "label": "storwize",
            "hw_type": "swiz",
            "disabled": true,
            "target": false,
            "ignore_health_status": false,
            "ignore_health_status_reason": null,
            "data": {
                "host": "",
                "alias": "storwize",
                "radio": "ssh-key-option",
                "device": "IBM__STORWIZE_FAMILY",
                "vendor": "IBM",
                "created": "2022-11-03T09:31:30Z",
                "sshPort": 22,
                "updated": "2023-10-24T09:22:36Z",
                "isKeyFile": true,
                "sampleRate": 5,
                "sshKeyFile": "",
                "sshPassword": null,
                "sshUsername": "stor2rrd"
            },
            "createdAt": "2024-08-02T13:42:16.905Z",
            "updatedAt": "2024-08-09T10:21:12.753Z",
            "hw_type_label": "Storwize",
            "limited": false
        },
]
Vous pouvez filtrer le tableau sur les baies IBM Storwize : elles portent toujours "device": "IBM__STORWIZE_FAMILY" dans data : {}, ainsi que hw_type: storwize
Passons à la mise à jour du mot de passe. La configuration se met à jour par un appel à l’API REST, ainsi :
curl --location 'https://localhost:8443/api/public/v1/hostcfg/' \
     --header 'apiKey: b2c9bcf8a16c29d50a73dd52bdcc44a6' \
     --header 'Content-Type: application/json' \
     --data '{
            "hostcfg_id": "a7ac3eb5-95de-42c4-ba81-494835fa9ab0",
            "label": "storwize",
            "hw_type": "swiz",
            "disabled": true,
            "target": false,
            "ignore_health_status": false,
            "ignore_health_status_reason": null,
            "data": {
                "host": "",
                "alias": "storwize",
                "radio": "ssh-key-option",
                "device": "IBM__STORWIZE_FAMILY",
                "vendor": "IBM",
                "created": "2022-11-03T09:31:30Z",
                "sshPort": 22,
                "updated": "2023-10-24T09:22:36Z",
                "isKeyFile": true,
                "sampleRate": 5,
                "sshKeyFile": "",
                "sshPassword": "YOUR NEW PASSWORD AS STRING HERE",
                "sshUsername": "stor2rrd"
            },
        }'
Vous n’êtes pas non plus obligé d’inclure toutes les clés ; voici l’exemple minimal qui fonctionne, mais vous devrez toujours inclure « hostcfg_id » et chacune des clés contenues dans la clé data ! Comme ceci :
curl --location 'https://localhost:8443/api/public/v1/hostcfg/' \
     --header 'apiKey: b2c9bcf8a16c29d50a73dd52bdcc44a6' \
     --header 'Content-Type: application/json' \
     --data '{
            "hostcfg_id": "a7ac3eb5-95de-42c4-ba81-494835fa9ab0",
            "data": {
                "host": "",
                "alias": "storwize",
                "radio": "ssh-key-option",
                "device": "IBM__STORWIZE_FAMILY",
                "vendor": "IBM",
                "created": "2022-11-03T09:31:30Z",
                "sshPort": 22,
                "updated": "2023-10-24T09:22:36Z",
                "isKeyFile": true,
                "sampleRate": 5,
                "sshKeyFile": "",
                "sshPassword": "YOUR NEW PASSWORD AS STRING HERE",
                "sshUsername": "stor2rrd"
            },
        }'
La clé du changement de mot de passe pour les baies IBM Storwize est sshPassword, dans l’objet data.