@@ -49,11 +49,47 @@ type interClusterLifsAddress struct {
4949}
5050
5151type snapMirrorStatusResponse struct {
52- Destination destination `structs:"destination"`
52+ Source relationshipEndpoint `json:"source"`
53+ Destination relationshipEndpoint `json:"destination"`
54+ Policy string `json:"policy"`
55+ Schedule string `json:"schedule"`
56+ MaxTransferRate sizeUnit `json:"maxTransferRate"`
5357}
5458
55- type destination struct {
56- VolumeName string `structs:"volumeName"`
59+ type relationshipEndpoint struct {
60+ WorkingEnvironmentID string `json:"workingEnvironmentId"`
61+ SvmName string `json:"svmName"`
62+ VolumeName string `json:"volumeName"`
63+ AggregateName string `json:"aggregateName"`
64+ ProviderVolumeType string `json:"providerVolumeType"`
65+ CapacityTier string `json:"capacityTier"`
66+ // Add more fields that might be in the actual response
67+ WorkingEnvironmentType string `json:"workingEnvironmentType"`
68+ WorkingEnvironmentStatus string `json:"workingEnvironmentStatus"`
69+ ClusterName string `json:"clusterName"`
70+ Region string `json:"region"`
71+ AvailabilityZone string `json:"availabilityZone"`
72+ SvmPeerAliasName string `json:"svmPeerAliasName"`
73+ NodeName string `json:"nodeName"`
74+ }
75+
76+ type sizeUnit struct {
77+ Size int `json:"size"`
78+ Unit string `json:"unit"`
79+ }
80+
81+ // Basic relationship structure from all-relationships endpoint
82+ type allRelationshipsResponse struct {
83+ Relationships []basicRelationship `json:"relationships"`
84+ }
85+
86+ type basicRelationship struct {
87+ Source relationshipEndpointBasic `json:"source"`
88+ Target relationshipEndpointBasic `json:"target"`
89+ }
90+
91+ type relationshipEndpointBasic struct {
92+ ID string `json:"id"`
5793}
5894
5995func (c * Client ) getInterclusterlifs (snapMirror snapMirrorRequest , clientID string , isSaas bool , connectorIP string ) (interclusterlif , error ) {
@@ -319,6 +355,105 @@ func (c *Client) deleteSnapMirror(snapMirror snapMirrorRequest, clientID string,
319355 return err
320356}
321357
358+ // getAllSnapMirrorRelationships queries all SnapMirror relationships to find one by destination volume name
359+ func (c * Client ) getAllSnapMirrorRelationships (clientID string , isSaas bool , connectorIP string ) ([]snapMirrorStatusResponse , error ) {
360+ accessTokenResult , err := c .getAccessToken ()
361+ if err != nil {
362+ log .Print ("in getAllSnapMirrorRelationships request, failed to get AccessToken" )
363+ return nil , err
364+ }
365+ c .Token = accessTokenResult .Token
366+
367+ hostType := "CloudManagerHost"
368+ if ! isSaas {
369+ hostType = "http://" + connectorIP
370+ }
371+
372+ baseURL := "/occm/api/replication/all-relationships"
373+
374+ statusCode , response , _ , err := c .CallAPIMethod ("GET" , baseURL , nil , c .Token , hostType , clientID )
375+ if err != nil {
376+ log .Print ("getAllSnapMirrorRelationships request failed " , statusCode )
377+ return nil , err
378+ }
379+ responseError := apiResponseChecker (statusCode , response , "getAllSnapMirrorRelationships" )
380+ if responseError != nil {
381+ return nil , responseError
382+ }
383+
384+ var allRelationships allRelationshipsResponse
385+ if err := json .Unmarshal (response , & allRelationships ); err != nil {
386+ log .Print ("Failed to unmarshall response from getAllSnapMirrorRelationships " , err )
387+ return nil , err
388+ }
389+
390+ log .Printf ("Found %d basic relationships" , len (allRelationships .Relationships ))
391+
392+ // Now get detailed information for each relationship
393+ var result []snapMirrorStatusResponse
394+ for _ , basicRel := range allRelationships .Relationships {
395+ // Query detailed status for this source working environment
396+ detailedRelationships , err := c .getSnapMirrorStatusForSourceWE (basicRel .Source .ID , clientID , isSaas , connectorIP )
397+ if err != nil {
398+ log .Printf ("Failed to get detailed status for source WE %s: %v" , basicRel .Source .ID , err )
399+ continue
400+ }
401+
402+ // Filter relationships for this specific target
403+ for _ , detailed := range detailedRelationships {
404+ if detailed .Destination .WorkingEnvironmentID == basicRel .Target .ID {
405+ result = append (result , detailed )
406+ }
407+ }
408+ }
409+
410+ return result , nil
411+ }
412+
413+ // getSnapMirrorStatusForSourceWE gets detailed snapmirror status for a specific source working environment
414+ func (c * Client ) getSnapMirrorStatusForSourceWE (sourceWEID string , clientID string , isSaas bool , connectorIP string ) ([]snapMirrorStatusResponse , error ) {
415+ hostType := "CloudManagerHost"
416+ if ! isSaas {
417+ hostType = "http://" + connectorIP
418+ }
419+
420+ baseURL := fmt .Sprintf ("/occm/api/replication/status/%s" , sourceWEID )
421+
422+ statusCode , response , _ , err := c .CallAPIMethod ("GET" , baseURL , nil , c .Token , hostType , clientID )
423+ if err != nil {
424+ log .Printf ("getSnapMirrorStatusForSourceWE request failed for %s: %d" , sourceWEID , statusCode )
425+ return nil , err
426+ }
427+ responseError := apiResponseChecker (statusCode , response , "getSnapMirrorStatusForSourceWE" )
428+ if responseError != nil {
429+ return nil , responseError
430+ }
431+
432+ var result []snapMirrorStatusResponse
433+ if err := json .Unmarshal (response , & result ); err != nil {
434+ log .Printf ("Failed to unmarshall response from getSnapMirrorStatusForSourceWE for %s: %v" , sourceWEID , err )
435+ return nil , err
436+ }
437+
438+ return result , nil
439+ }
440+
441+ // findSnapMirrorByDestinationVolume finds a snapmirror relationship by destination volume name
442+ func (c * Client ) findSnapMirrorByDestinationVolume (destinationVolumeName string , clientID string , isSaas bool , connectorIP string ) (* snapMirrorStatusResponse , error ) {
443+ relationships , err := c .getAllSnapMirrorRelationships (clientID , isSaas , connectorIP )
444+ if err != nil {
445+ return nil , err
446+ }
447+
448+ for _ , relationship := range relationships {
449+ if relationship .Destination .VolumeName == destinationVolumeName {
450+ return & relationship , nil
451+ }
452+ }
453+
454+ return nil , fmt .Errorf ("snapmirror relationship not found for destination volume: %s" , destinationVolumeName )
455+ }
456+
322457func (c * Client ) getSnapMirror (snapMirror snapMirrorRequest , vol string , clientID string , isSaas bool , connectorIP string ) (string , error ) {
323458
324459 var result []snapMirrorStatusResponse
0 commit comments