03-25-2019 07:22 AM
I have been trying to find more details on the api's exposed as we are starting to work more with that now. I was hoping to find a dedicated fourm on VOX for api's, is this not where the veritas user community is discussing thier work in the api's?
For our first intiative we are looking to automate the generation of aws account to netbackup that will be used with cloudpoint. We have 100's of accounts to add and would rather build it out to be repeatable. The issuie i am having is the payload is complex and i am not finding good example or walk throughs on how we can populate the data to the layout that is expected.
I have found this is what is expected, but have trouble when looping through a csv of account data to get the payload correct.
"configurationRequest": {
"data": {
"id": "string",
"type": "plugininstance",
"attributes": {
"cloudpointHostname": "string",
"configurationAttributes": [
{
"name": "string",
"singlevalue": "string",
"multivalue": [
"string"
]
}
]
}
}
}
How have others done this? I am using powershell. What resources have you found helpfull?
03-25-2019 08:10 AM
03-26-2019 07:06 AM
powershell has the equilevient to curl as invoke-rest or in newer versions you can use curl, its really all the same.
I understand what i posted is a json payload, but what i cant find is what the expected value and syntax is for each object in the payload.
What i have is a csv file like:
aws_account_id,aws_account_alias,aws_account_name,veritascloudpoint_aws_iam_access_key_id,veritascloudpoint_aws_iam_access_key_secret,regions
1111,uat,UAT ENV,key,skey,us-east-1
2222,ops,OPS ENV,key,skey,"eu-west-1, us-east-1"
Where i would want to loop through the values provided and create the aws account in netbackup for cloudpoint to utilize.
To do this against the cloudpoint apis - which was much nicer to see how it worked since thats using swagger. is this:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[System.Net.ServicePointManager]::CheckCertificateRevocationList = $false;
#Vars
$CSVFilename = 'C:\users\nbritton\desktop\Book2.csv' #input for aws accounts
#Login Section
$login = @{
email='admin'
password='' #Fill something in here
}
$json = $login |ConvertTo-Json
#curl -X POST "https://led36461/cloudpoint/api/v2/idm/login" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"email\": \"admin\", \"password\": \"2014Cr3w!\"}"
$accesstoken = Invoke-RestMethod -uri 'https://led36461/cloudpoint/api/v2/idm/login' -Method Post -Body $json -ContentType 'application/json'
$auth = @{ Authorization = $accesstoken }
$token=$accesstoken.accessToken
#Login section completed, acess token stored.
#Get agentID where on host is false
$agentid_arr=Invoke-RestMethod -uri 'https://led36461/cloudpoint/api/v2/agents' -Headers @{"Authorization" = "Bearer $token"} -Method Get -ContentType 'application/json'
$agentid=$agentid_arr|Where-Object {$_.onHost -like "False"}|Select-Object agentid
$agentid=$agentid.agentid
#Add AWS Account
$AccountList = Import-Csv $CSVFilename
foreach ($Account in $AccountList) {
$JSON = @{
accesskey = $Account.veritascloudpoint_aws_iam_access_key_id
secretkey = $Account.veritascloudpoint_aws_iam_access_key_secret
regions = $Account.Region.Split(',').Trim() -as [String[]]
} | ConvertTo-Json
$JSON
Invoke-RestMethod -uri "https://led36461/cloudpoint/api/v2/agents/$agentid/plugins/aws/configs" -Headers @{"Authorization" = "Bearer $token"} -Method Post -ContentType 'application/json' -Body $JSON
sleep 60
}
To do this on the netbackup side is a little more completd becouse the payload looks to have different layers to it, and i am not sure how i am going to take the vars from the input file and populate them to generate the correct syntax to then convert to json, which powershell does nicley.
03-26-2019 10:56 AM
Confused now, do you want to add the accounts to cloudpoint or NetBackup? I don't see any cloudpoint related API's in netbackup. Please share what you're talking about.
03-26-2019 01:39 PM
Its done throug netbackup using this in netbackup:
Here is what support sent me: ( but this seems wrong on the example since its targetting a cp host.
POST /config/snapshotproviders/configuredplugins/{pluginType}/instances
Description
Adds a new configuration instance for the plug-in for Integrated Snapshot Management.
Requires Permission: [Manage Cloud Appservers]
Parameters
Type | Name | Description | Schema |
Path | pluginType | The type of plug-in. This value can be retrieved from GET /config/snapshotproviders/supportedplugins API. For example, "aws" or "azure". | string |
Body | configurationRequest | The details of the configuration instance for the plug-in. |
configurationRequest
{
"data": {
"id": "string",
"type": "plugininstance",
"attributes": {
"cloudpointHostname": "string",
"configurationAttributes": [
{
"name": "string",
"singlevalue": "string",
"multivalue": [
"string"
]
}
]
}
}
}
Example -
POST https://cloudpointhost/netbackup/config/snapshotproviders/configuredplugins/aws/instances
configurationRequest
{
"data":{
"id":"ConfigurationName",
"type":"plugininstance",
"attributes":{
"configurationAttributes":[
{
"name":"accesskey",
"singlevalue":"AccessKeyHere"
},
{
"name":"secretkey",
"singlevalue":"SecretKeyHere"
},
{
"name":"regions",
"multivalue":[
"ap-northeast-1",
"ap-northeast-2"
]
}
]
}
}
}
Here is the link to the 8.1.2 documentation for this call. But its not providing me enough insight.
03-26-2019 09:29 PM
Hi,
To access the components of the JSON you'll need to figure out what you want. There is a mix of dictionary and list object that make out the JSON. I've assigned the JSON example to a variable called body. You can then pick out the pieces you want by accessing a combination of the dictionary or list references in the object (see below)
Inside body there is a data dict, and inside that there is a attributes dict, and then again a configurationAttributes dict. Then it changes up to a list. Not sure why they did it but we'll assume that the order of items the list remain consistent so we can access them by number.
So by accessing body['data']['attributes']['configurationAttributes'] we then get to list of items that we want to work with.
[{'name': 'accesskey', 'singlevalue': 'AccessKeyHere'}, {'name': 'secretkey', 'singlevalue': 'SecretKeyHere'}, {'name': 'regions', 'multivalue': ['ap-northeast-1', 'ap-northeast-2']}]
First list items houses a dict with the access key, the second houses a dict with the secret key, the final items contains a dict with another list of the regions.
I've got no clue how you'd do this in powershell but maybe this python example can help in some way. Python is really easy so give it a shot.