dell / PyU4V

PyU4V is a Python module that simplifies interaction with the Unisphere for PowerMax REST API. It wraps REST calls with simple APIs that abstracts the HTTP request and response handling.
Apache License 2.0
41 stars 37 forks source link

link from the existing snapshot and attach the snapshot to the existing StorageGroup #194

Closed johndanielk closed 1 month ago

johndanielk commented 1 month ago

hi I have a PowerMax 8500 ver 10.1

I want to do a link from the existing snapshot and attach the snapshot to the existing StorageGroup I see your script in Python from this site https://infohub.delltechnologies.com/en-us/p/local-replication-with-the-powermax-rest-api-working-with-snapvx-snapshots/ from my GUI everything works fine but on the Rest API, it is not

this is my Javascript and I will be glad to help me ( my first request in GitHub)
noted - all parameters I can take with other scripts that I wrote my script runs from VRA automation so some of the parameters are on the var input this is my script and the symmetric is like 111111111111 // start script function linkSnapshot(restHost, srcStorageGrpId, tgtStorageGrpId, snapName, snapId) { var url = "/univmax/restapi/101/replication/symmetrix/111111111111/storagegroup/" + srcStorageGrpId + "/snapshot/" + snapName + "/snapid/" + snapId; System.log("Link URL " + url) ;

var body = {
    "link": {
        "storage_group_name": tgtStorageGrpId,
        "force": false, 
        "copy": false,
        "remote": false 
     }
};

var req = restHost.createRequest("POST", url, JSON.stringify(body));

var authHeader = "Basic " + basicAuto; // input from VRA 

req.setHeader("Authorization", authHeader); req.setHeader("Accept", "application/json"); req.setHeader("Content-Type", "application/json");

// Execute the request
var res = req.execute();

// Log response details
System.log("Response Status Code: " + res.statusCode);
System.log("Response AllHeaders Link: " + res.getAllHeaders());

if (res.statusCode != 200) {
    System.log("~~~~ Error: Failed to link snapshot ~~~");
    throw("Couldn't link snapshot: " + res.contentAsString);
}

// Parse and return the response body as JSON
var responseJson = JSON.parse(res.contentAsString);

return responseJson;

}

var srcStorageGrpId = "sg_PMAX"; var tgtStorageGrpId = "sg_PMAX_LNK_SG_002"; var snapName = "sg_pmax-03092024"; var snapId = '75526250497';

var linkResponse = linkSnapshot(restHost, srcStorageGrpId, tgtStorageGrpId, snapName, snapId); System.log("Snapshot Link Response: " + JSON.stringify(linkResponse)); // end script

the error message I get is Couldn't link snapshot: {"message":"Parameter [link] value is not valid, expecting non null: [SnapVxLinkOptions]"} any help will be great

thanks

rawstorage commented 1 month ago

you are using POST instead of PUT. Also the payload is wrong. The body below should work for you once you change the method to PUT

{ "action": "Link", "link": { "storage_group_name": tgtStorageGrpId } }

Let me know the result after making these changes.

johndanielk commented 1 month ago

Thank you/ its works !!

rawstorage commented 1 month ago

Glad to help. if you're not using it https://github.com/rawstorage/reSTclient10/ the rest client is very good, be sure to read the readme you need JDK 11 or higher to run.