- 
                Notifications
    
You must be signed in to change notification settings  - Fork 53
 
python,poweshell,go example scripts for replication targets on DV #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            sdunakhe
  wants to merge
  2
  commits into
  VeritasOS:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
sdunakhe:cc_msdp_replication_targets_on_dv
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -41,13 +41,16 @@ type DataArray struct { | |
| 
     | 
||
| var mediaServerName string | ||
| const ( | ||
| port = "1556" | ||
| storageUri = "storage/" | ||
| port = "1556" | ||
| storageUri = "storage/" | ||
| storageServerUri = "storage-servers/" | ||
| storageUnitUri = "storage-units" | ||
| contentType = "application/vnd.netbackup+json;version=3.0" | ||
| storageUnitUri = "storage-units" | ||
| diskPoolUri = "disk-pools" | ||
| contentType = "application/vnd.netbackup+json;version=4.0" | ||
| replicationTargetsUri = "/replication-targets" | ||
| replicationCandidatesUri = "/target-storage-servers" | ||
| diskVolumeUri = "disk-volumes/" | ||
| 
     | 
||
| ) | ||
| 
     | 
||
| //############################################################## | ||
| 
          
            
          
           | 
    @@ -379,3 +382,351 @@ func DeleteReplicationTargets(nbmaster string, httpClient *http.Client, jwt stri | |
| } | ||
| return response.StatusCode; | ||
| } | ||
| 
     | 
||
| //####################################################################### | ||
| // Create a MSDP Disk Pool | ||
| //####################################################################### | ||
| func CreateMSDPDiskPool(nbmaster string, httpClient *http.Client, jwt string)(int, string) { | ||
| fmt.Printf("\nSending a POST request to create with defaults...\n") | ||
| if strings.Compare(apiUtil.TakeInput("Want to create new MSDP storage Pool?(Or you can use existing)(Yes/No):"), "Yes") != 0 { | ||
| dpName := apiUtil.TakeInput("Enter MSDP Disk Pool Name for other operations:") | ||
| return 201, dpName; | ||
| } | ||
| 
     | 
||
| dpName := apiUtil.TakeInput("Enter Disk Pool Name:") | ||
| 
     | 
||
| // Creating Disl Pool with rest of the parameters with default settings, you may choose to change them as per use. | ||
| 
     | 
||
| MSDPstorageUnit := map[string]interface{}{ | ||
| "data": map[string]interface{}{ | ||
| "type": "diskPool", | ||
| "attributes": map[string]interface{}{ | ||
| "name":dpName, | ||
| "diskVolumes":map[string]interface{}[, | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comma looks like a syntax error. Am I mistaken?  | 
||
| { | ||
| "name":"PureDiskVolume" | ||
| } | ||
| ], | ||
| "maximumIoStreams": map[string]interface{}{ | ||
| "limitIoStreams": true, | ||
| "streamsPerVolume": 2 | ||
| } | ||
| }, | ||
| "relationships": map[string]interface{}{ | ||
| "storageServers": map[string]interface{}{ | ||
| "data": map[string]interface{}{ | ||
| "type": "storageServer", | ||
| "id": "PureDisk" + ":" + stsName | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| 
     | 
||
| 
     | 
||
| stsRequest, _ := json.Marshal(MSDPstorageUnit) | ||
| 
     | 
||
| uri := "https://" + nbmaster + ":" + port + "/netbackup/" + storageUri + diskPoolUri | ||
| 
     | 
||
| request, _ := http.NewRequest(http.MethodPost, uri, bytes.NewBuffer(stsRequest)) | ||
| request.Header.Add("Content-Type", contentType); | ||
| request.Header.Add("Authorization", jwt); | ||
| 
     | 
||
| response, err := httpClient.Do(request) | ||
| 
     | 
||
| if err != nil { | ||
| fmt.Printf("The HTTP request failed with error: %s\n", err) | ||
| panic("Unable to create storage unit.\n") | ||
| } else { | ||
| if response.StatusCode != 201 { | ||
| responseBody, _ := ioutil.ReadAll(response.Body) | ||
| fmt.Printf("%s\n", responseBody) | ||
| panic("Unable to create MSDP storage unit.\n") | ||
| } else { | ||
| fmt.Printf("%s created successfully.\n", stuName); | ||
| //responseDetails, _ := httputil.DumpResponse(response, true); | ||
| apiUtil.AskForResponseDisplay(response.Body) | ||
| } | ||
| } | ||
| 
     | 
||
| return response.StatusCode, stuName; | ||
| } | ||
| 
     | 
||
| 
     | 
||
| //####################################################################### | ||
| // Create a MSDP Storage Unit | ||
| //####################################################################### | ||
| func CreateMSDPStorageUnit(nbmaster string, httpClient *http.Client, jwt string)(int, string) { | ||
| fmt.Printf("\nSending a POST request to create with defaults...\n") | ||
| if strings.Compare(apiUtil.TakeInput("Want to create new MSDP storage Unit?(Or you can use existing)(Yes/No):"), "Yes") != 0 { | ||
| stuName := apiUtil.TakeInput("Enter MSDP/CloudCatalyst Storage Unit Name for other operations:") | ||
| return 201, stuName; | ||
| } | ||
| 
     | 
||
| stuName := apiUtil.TakeInput("Enter Storage Unit Name:") | ||
| if strings.Compare(apiUtil.TakeInput("Want to create new MSDP Disk Pool?(Or you can use existing)(Yes/No):"), "Yes") != 0 { | ||
| dpName := apiUtil.TakeInput("Enter MSDP/CloudCatalyst Disk Pool Name for other operations:") | ||
| } else { | ||
| dpName := apiUtil.TakeInput("Enter Disk Pool Name:") | ||
| CreateMSDPDiskPool(); | ||
| } | ||
| 
     | 
||
| // Creating Storage Unit with rest of the parameters with default settings, you may choose to change them as per use. | ||
| 
     | 
||
| MSDPstorageUnit := map[string]interface{}{ | ||
| "data": map[string]interface{}{ | ||
| "type": "storageUnit", | ||
| "id": stuName, | ||
| "attributes": map[string]interface{}{ | ||
| "name":stuName, | ||
| "useAnyAvailableMediaServer": true, | ||
| "maxFragmentSizeMegabytes": 50000, | ||
| "maxConcurrentJobs": 10, | ||
| "onDemandOnly": true | ||
| }, | ||
| "relationships": map[string]interface{}{ | ||
| "diskPool": map[string]interface{}{ | ||
| "data": map[string]interface{}{ | ||
| "type": "diskPool", | ||
| "id": "PureDisk" + ":" + dpName | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| 
     | 
||
| 
     | 
||
| stsRequest, _ := json.Marshal(MSDPstorageUnit) | ||
| 
     | 
||
| uri := "https://" + nbmaster + ":" + port + "/netbackup/" + storageUri + storageUnitUri | ||
| 
     | 
||
| request, _ := http.NewRequest(http.MethodPost, uri, bytes.NewBuffer(stsRequest)) | ||
| request.Header.Add("Content-Type", contentType); | ||
| request.Header.Add("Authorization", jwt); | ||
| 
     | 
||
| response, err := httpClient.Do(request) | ||
| 
     | 
||
| if err != nil { | ||
| fmt.Printf("The HTTP request failed with error: %s\n", err) | ||
| panic("Unable to create storage unit.\n") | ||
| } else { | ||
| if response.StatusCode != 201 { | ||
| responseBody, _ := ioutil.ReadAll(response.Body) | ||
| fmt.Printf("%s\n", responseBody) | ||
| panic("Unable to create MSDP storage unit.\n") | ||
| } else { | ||
| fmt.Printf("%s created successfully.\n", stuName); | ||
| //responseDetails, _ := httputil.DumpResponse(response, true); | ||
| apiUtil.AskForResponseDisplay(response.Body) | ||
| } | ||
| } | ||
| 
     | 
||
| return response.StatusCode, stuName; | ||
| } | ||
| 
     | 
||
| 
     | 
||
| //####################################################################### | ||
| // Add replication target to MSDP Disk Volume | ||
| //####################################################################### | ||
| func AddReplicationTargetToDV(nbmaster string, httpClient *http.Client, jwt string, stsName string)(int) { | ||
| fmt.Printf("\nSending a POST request to create with defaults...\n") | ||
| 
     | 
||
| 
     | 
||
| candId := apiUtil.TakeInput("Enter target storage server Id:") | ||
| IdSlice := strings.Split(candId, ":") | ||
| 
     | 
||
| candId := apiUtil.TakeInput("Enter target storage disk volume name:") | ||
| dvName := strings.Split(diskVolumeId, ":"); | ||
| username := apiUtil.TakeInput("Enter target storage server username:") | ||
| password := apiUtil.TakeInput("Enter target storage server password:") | ||
| 
     | 
||
| replicationtarget := map[string]interface{}{ | ||
| "data": map[string]interface{}{ | ||
| "type": "volumeReplicationTarget", | ||
| "attributes": map[string]interface{}{ | ||
| "operationType": "SET_REPLICATION", | ||
| "targetVolumeName": dvName, | ||
| "targetStorageServerDetails": map[string]interface{}{ | ||
| "masterServerName": IdSlice[3], | ||
| "storageServerName": IdSlice[1], | ||
| "storageServerType": IdSlice[0], | ||
| "mediaServerName": IdSlice[2]}, | ||
| "credentials": map[string]interface{}{ | ||
| "userName": username, | ||
| "password": password | ||
| }}}} | ||
| 
     | 
||
| 
     | 
||
| 
     | 
||
| stsRequest, _ := json.Marshal(replicationtarget) | ||
| 
     | 
||
| uri := "https://" + nbmaster + ":" + port + "/netbackup/" + storageUri + storageServerUri + "PureDisk:" + stsName + diskVolumeUri + diskVolumeId + replicationTargetsUri | ||
| 
     | 
||
| request, _ := http.NewRequest(http.MethodPost, uri, bytes.NewBuffer(stsRequest)) | ||
| request.Header.Add("Content-Type", contentType); | ||
| request.Header.Add("Authorization", jwt); | ||
| 
     | 
||
| fmt.Println ("Firing request: POST: " + uri) | ||
| response, err := httpClient.Do(request) | ||
| 
     | 
||
| if err != nil { | ||
| fmt.Printf("The HTTP request failed with error: %s\n", err) | ||
| panic("Unable to add replication target.\n") | ||
| } else { | ||
| if response.StatusCode != 204 { | ||
| responseBody, _ := ioutil.ReadAll(response.Body) | ||
| fmt.Printf("%s\n", responseBody) | ||
| panic("Unable to add replication target.\n") | ||
| } else { | ||
| fmt.Printf("%s created successfully.\n", ""); | ||
| //responseDetails, _ := httputil.DumpResponse(response, true); | ||
| apiUtil.AskForResponseDisplay(response.Body) | ||
| } | ||
| } | ||
| 
     | 
||
| return response.StatusCode; | ||
| } | ||
| 
     | 
||
| //####################################################################### | ||
| // Get all replication targets on MSDP Disk Volume | ||
| //####################################################################### | ||
| func GetAllReplicationTargetsToDV(nbmaster string, httpClient *http.Client, jwt string, stsName string)(int) { | ||
| fmt.Printf("\nSending a POST request to delete with defaults...\n") | ||
| 
     | 
||
| 
     | 
||
| candId := apiUtil.TakeInput("Enter target storage server Id:") | ||
| IdSlice := strings.Split(candId, ":") | ||
| 
     | 
||
| candId := apiUtil.TakeInput("Enter target storage disk volume name:") | ||
| dvName := strings.Split(diskVolumeId, ":"); | ||
| username := apiUtil.TakeInput("Enter target storage server username:") | ||
| password := apiUtil.TakeInput("Enter target storage server password:") | ||
| 
     | 
||
| 
     | 
||
| stsRequest, _ := json.Marshal(replicationtarget) | ||
| 
     | 
||
| uri := "https://" + nbmaster + ":" + port + "/netbackup/" + storageUri + storageServerUri + "PureDisk:" + stsName + diskVolumeUri + diskVolumeId + replicationTargetsUri | ||
| 
     | 
||
| request, _ := http.NewRequest(http.MethodGet, uri, nil) | ||
| request.Header.Add("Content-Type", contentType); | ||
| request.Header.Add("Authorization", jwt); | ||
| 
     | 
||
| fmt.Println ("Firing request: GET: " + uri) | ||
| response, err := httpClient.Do(request) | ||
| 
     | 
||
| if err != nil { | ||
| fmt.Printf("The HTTP request failed with error: %s\n", err) | ||
| panic("Unable to get replication targets for disk volume.\n") | ||
| } else { | ||
| if response.StatusCode == 200 { | ||
| responseBody, _ := ioutil.ReadAll(response.Body) | ||
| fmt.Printf("%s\n", responseBody) | ||
| } | ||
| } | ||
| 
     | 
||
| return response.StatusCode; | ||
| } | ||
| 
     | 
||
| //####################################################################### | ||
| // Get replication target by ID on MSDP Disk Volume | ||
| //####################################################################### | ||
| func GetReplicationTargetByIdToDV(nbmaster string, httpClient *http.Client, jwt string, stsName string)(int) { | ||
| fmt.Printf("\nSending a POST request to delete with defaults...\n") | ||
| 
     | 
||
| candId := apiUtil.TakeInput("Enter target storage server Id:") | ||
| IdSlice := strings.Split(candId, ":") | ||
| 
     | 
||
| candId := apiUtil.TakeInput("Enter target storage disk volume name:") | ||
| dvName := strings.Split(diskVolumeId, ":"); | ||
| username := apiUtil.TakeInput("Enter target storage server username:") | ||
| password := apiUtil.TakeInput("Enter target storage server password:") | ||
| 
     | 
||
| repTargetId := apiUtil.TakeInput("Enter replication target ID:") | ||
| 
     | 
||
| stsRequest, _ := json.Marshal(replicationtarget) | ||
| 
     | 
||
| uri := "https://" + nbmaster + ":" + port + "/netbackup/" + storageUri + storageServerUri + "PureDisk:" + stsName + | ||
| diskVolumeUri + diskVolumeId + replicationTargetsUri + repTargetId | ||
| 
     | 
||
| request, _ := http.NewRequest(http.MethodGet, uri, nil) | ||
| request.Header.Add("Content-Type", contentType); | ||
| request.Header.Add("Authorization", jwt); | ||
| 
     | 
||
| fmt.Println ("Firing request: GET: " + uri) | ||
| response, err := httpClient.Do(request) | ||
| 
     | 
||
| if err != nil { | ||
| fmt.Printf("The HTTP request failed with error: %s\n", err) | ||
| panic("Unable to get replication targets for disk volume.\n") | ||
| } else { | ||
| if response.StatusCode == 200 { | ||
| responseBody, _ := ioutil.ReadAll(response.Body) | ||
| fmt.Printf("%s\n", responseBody) | ||
| } | ||
| } | ||
| return response.StatusCode; | ||
| } | ||
| 
     | 
||
| //####################################################################### | ||
| // Delete replication target on MSDP Disk Volume | ||
| //####################################################################### | ||
| func DeleteReplicationTargetToDV(nbmaster string, httpClient *http.Client, jwt string, stsName string)(int) { | ||
| fmt.Printf("\nSending a POST request to delete with defaults...\n") | ||
| 
     | 
||
| 
     | 
||
| candId := apiUtil.TakeInput("Enter target storage server Id:") | ||
| IdSlice := strings.Split(candId, ":") | ||
| 
     | 
||
| candId := apiUtil.TakeInput("Enter target storage disk volume name:") | ||
| dvName := strings.Split(diskVolumeId, ":"); | ||
| username := apiUtil.TakeInput("Enter target storage server username:") | ||
| password := apiUtil.TakeInput("Enter target storage server password:") | ||
| 
     | 
||
| replicationtarget := map[string]interface{}{ | ||
| "data": map[string]interface{}{ | ||
| "type": "volumeReplicationTarget", | ||
| "attributes": map[string]interface{}{ | ||
| "operationType": "DELETE_REPLICATION", | ||
| "targetVolumeName": dvName, | ||
| "targetStorageServerDetails": map[string]interface{}{ | ||
| "masterServerName": IdSlice[3], | ||
| "storageServerName": IdSlice[1], | ||
| "storageServerType": IdSlice[0], | ||
| "mediaServerName": IdSlice[2]}, | ||
| "credentials": map[string]interface{}{ | ||
| "userName": username, | ||
| "password": password | ||
| }}}} | ||
| 
     | 
||
| 
     | 
||
| 
     | 
||
| stsRequest, _ := json.Marshal(replicationtarget) | ||
| 
     | 
||
| uri := "https://" + nbmaster + ":" + port + "/netbackup/" + storageUri + storageServerUri + "PureDisk:" + stsName + diskVolumeUri + diskVolumeId + replicationTargetsUri | ||
| 
     | 
||
| request, _ := http.NewRequest(http.MethodPost, uri, bytes.NewBuffer(stsRequest)) | ||
| request.Header.Add("Content-Type", contentType); | ||
| request.Header.Add("Authorization", jwt); | ||
| 
     | 
||
| fmt.Println ("Firing request: POST: " + uri) | ||
| response, err := httpClient.Do(request) | ||
| 
     | 
||
| if err != nil { | ||
| fmt.Printf("The HTTP request failed with error: %s\n", err) | ||
| panic("Unable to delete replication target.\n") | ||
| } else { | ||
| if response.StatusCode != 204 { | ||
| responseBody, _ := ioutil.ReadAll(response.Body) | ||
| fmt.Printf("%s\n", responseBody) | ||
| panic("Unable to add replication target.\n") | ||
| } else { | ||
| fmt.Printf("%s deleted successfully.\n", ""); | ||
| //responseDetails, _ := httputil.DumpResponse(response, true); | ||
| apiUtil.AskForResponseDisplay(response.Body) | ||
| } | ||
| } | ||
| 
     | 
||
| return response.StatusCode; | ||
| } | ||
| 
     | 
||
| 
     | 
||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file now uses a mix of tabs and spaces for indentation. Can you please fix it to be consistent? I thought gofmt was supposed to make this kind of comment unnecessary.