Skip to content

Commit

Permalink
fixed Remove-OciApplicationsFromVolume
Browse files Browse the repository at this point in the history
  • Loading branch information
ffeldhaus committed Mar 9, 2017
1 parent 915fa20 commit d39c25c
Showing 1 changed file with 27 additions and 56 deletions.
83 changes: 27 additions & 56 deletions src/OnCommand-Insight.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -29094,27 +29094,15 @@ function Global:Update-OciAnnotationsByVolume {

<#
.SYNOPSIS
Bulk un-assign applications from asset
Bulk un-assign applications from volume
.DESCRIPTION
Request body should contain a list of valid application ids, example: <br/>

<pre>
[
{
"id":"12345"
},
{
"id":"67890"
}
]
</pre>

Bulk un-assign applications from volume
.PARAMETER id
Id of object to update
.PARAMETER computeResources
Return list of related Compute resources
.PARAMETER storageResources
Return list of related Storage resources
Id of volume to remove applications from
.PARAMETER computeResources
Return list of related Compute resources
.PARAMETER storageResources
Return list of related Storage resources
#>
function Global:Remove-OciApplicationsFromVolume {
[CmdletBinding()]
Expand All @@ -29125,11 +29113,9 @@ function Global:Remove-OciApplicationsFromVolume {
HelpMessage="Id of object to update",
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)][Long[]]$id,
[parameter(Mandatory=$True,
[parameter(Mandatory=$False,
Position=1,
HelpMessage="List of application IDs",
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)][String[]]$applicationId,
HelpMessage="List of application IDs")][String[]]$applicationId,
[parameter(Mandatory=$False,
Position=2,
HelpMessage="Return list of related Compute resources")][Switch]$computeResources,
Expand Down Expand Up @@ -29161,42 +29147,27 @@ function Global:Remove-OciApplicationsFromVolume {
}

Process {
$id = @($id)
foreach ($id in $id) {
$Uri = $Server.BaseUri + "/rest/v1/assets/volumes/$id/applications"

if ($fromTime -or $toTime -or $expand) {
$Uri += '?'
$Separator = ''
if ($fromTime) {
$Uri += "fromTime=$($fromTime | ConvertTo-UnixTimestamp)"
$Separator = '&'
}
if ($toTime) {
$Uri += "$($Separator)toTime=$($toTime | ConvertTo-UnixTimestamp)"
$Separator = '&'
}
if ($expand) {
$Uri += "$($Separator)expand=$expand"
}
}
$Uri = $Server.BaseUri + "/rest/v1/assets/volumes/$id/applications"

try {
$Body = ConvertTo-Json @($applicationId | % { @{id=$_} }) -Compress
Write-Verbose "Body: $Body"
$Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method DELETE -Uri $Uri -Headers $Server.Headers -Body $Body -ContentType 'application/json'
}
catch {
$ResponseBody = ParseExceptionBody $_.Exception.Response
Write-Error "DELETE to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
}

if (([String]$Result).Trim().startsWith('{') -or ([String]$Result).toString().Trim().startsWith('[')) {
$Result = ParseJsonString($Result.Trim())
}
if (!$applicationId) {
$applicationId = Get-OciApplicationsByVolume -id $id | select -ExpandProperty id
}

Write-Output $Result
try {
$Body = ConvertTo-Json @($applicationId | % { @{id=$_} }) -Compress
Write-Verbose "Body: $Body"
$Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method DELETE -Uri $Uri -Headers $Server.Headers -Body $Body -ContentType 'application/json'
}
catch {
$ResponseBody = ParseExceptionBody $_.Exception.Response
Write-Error "DELETE to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
}

if (([String]$Result).Trim().startsWith('{') -or ([String]$Result).toString().Trim().startsWith('[')) {
$Result = ParseJsonString($Result.Trim())
}

Write-Output $Result
}
}

Expand Down

0 comments on commit d39c25c

Please sign in to comment.