Skip to content
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

python,poweshell,go example scripts for replication targets on DV #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions recipes/go/storage/AIRAPIs/AIRAPIs.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,19 @@ func main() {
os.Exit(0)
}
storageHelper.DeleteReplicationTargets(*nbmaster, httpClient, jwt, stsName, tarId)


// TODO: (KEEP THIS OR NOT) Create Storage Unit and DP/DV
//if ( storageHelper.CreateMSDPDiskPool(*nbmaster, httpClient, jwt) != 201 ) {
// panic("CreateMSDPDiskPool Failed. Exiting.\n")
//}

// TODO: (KEEP THIS OR NOT) Create Storage Unit and DP/DV
//if ( storageHelper.CreateMSDPStorageUnit(*nbmaster, httpClient, jwt) != 201 ) {
// panic("CreateMSDPStorageUnit Failed. Exiting.\n")
//}

if ( storageHelper.AddReplicationTargetToDV(*nbmaster, httpClient, jwt, stsName) != 201 ) {
panic("AddReplicationTarget Failed. Exiting.\n")
}
}
1 change: 1 addition & 0 deletions recipes/go/storage/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ The script can also create new MSDP storage server (with creds as a/a) depending
Further lists the replication candidates based on the no of trusted master servers and storage server (MSDP and CC) on them.
User need to select one of the replication candidate to create AIR relationship on the earlier created MSDP/CC sts or existing one.
User can delete any existing AIR relationship as well.
User can also add replication targets on diskvolume level and manage the entitiy with desired ADD/GET/GET ALL/DELETE operations.

359 changes: 355 additions & 4 deletions recipes/go/storage/StorageHelper/StorageHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ type DataArray struct {

var mediaServerName string
const (
port = "1556"
storageUri = "storage/"
port = "1556"
storageUri = "storage/"
Comment on lines -44 to +45
Copy link
Collaborator

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.

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/"

)

//##############################################################
Expand Down Expand Up @@ -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{}[,
Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
}


Loading