@@ -16010,28 +16010,17 @@ function Global:Get-OciQtree {
1601016010
1601116011<#
1601216012 .SYNOPSIS
16013- Delete annotations from object
16013+ Remove annotations by qtree
1601416014 .DESCRIPTION
16015- Request body should be like JSON below: <br/>
16016-
16017- <pre>
16018-
16019- [
16020- {
16021- "definition":{"id":"5001"}
16022- },
16023- {
16024- "definition":{"id":"5002"}
16025- }
16026- ]
16027- </pre>
16028-
16015+ Remove annotations by qtree
1602916016 .PARAMETER id
1603016017 Id of object to delete
16018+ .PARAMETER Annotations
16019+ List of annotations to remove
1603116020 .PARAMETER definition
1603216021 Return related Definition
1603316022#>
16034- function Global:Remove-OciByTypeAndId {
16023+ function Global:Remove-OciAnnotationsByQtree {
1603516024 [CmdletBinding()]
1603616025
1603716026 PARAM (
@@ -16042,9 +16031,12 @@ function Global:Remove-OciByTypeAndId {
1604216031 ValueFromPipelineByPropertyName=$True)][Long[]]$id,
1604316032 [parameter(Mandatory=$False,
1604416033 Position=1,
16034+ HelpMessage="List of annotations to remove")][PSObject[]]$Annotations,
16035+ [parameter(Mandatory=$False,
16036+ Position=2,
1604516037 HelpMessage="Return related Definition")][Switch]$definition,
1604616038 [parameter(Mandatory=$False,
16047- Position=2 ,
16039+ Position=3 ,
1604816040 HelpMessage="OnCommand Insight Server.")]$Server=$CurrentOciServer
1604916041 )
1605016042
@@ -16053,73 +16045,46 @@ function Global:Remove-OciByTypeAndId {
1605316045 if (!$Server) {
1605416046 throw "Server parameter not specified and no global OCI Server available. Run Connect-OciServer first!"
1605516047 }
16056-
16057- $switchparameters=@("definition")
16058- foreach ($parameter in $switchparameters) {
16059- if ((Get-Variable $parameter).Value) {
16060- if ($expand) {
16061- $expand += ",$($parameter -replace 'performancehistory','performance.history' -replace 'hostswitch','host')"
16062- }
16063- else {
16064- $expand = $($parameter -replace 'performancehistory','performance.history' -replace 'hostswitch','host')
1606516048 }
16066- }
16067- }
16068- }
1606916049
1607016050 Process {
16071- $id = @($id)
16072- foreach ($id in $id) {
16073- $Uri = $Server.BaseUri + "/rest/v1/assets/qtrees/$id/annotations"
16051+ $Uri = $Server.BaseUri + "/rest/v1/assets/qtrees/$id/annotations"
1607416052
16075- if ($fromTime -or $toTime -or $expand) {
16076- $Uri += '?'
16077- $Separator = ''
16078- if ($fromTime) {
16079- $Uri += "fromTime=$($fromTime | ConvertTo-UnixTimestamp)"
16080- $Separator = '&'
16081- }
16082- if ($toTime) {
16083- $Uri += "$($Separator)toTime=$($toTime | ConvertTo-UnixTimestamp)"
16084- $Separator = '&'
16085- }
16086- if ($expand) {
16087- $Uri += "$($Separator)expand=$expand"
16088- }
16089- }
16090-
16091- try {
16092- $Body = ""
16093- Write-Verbose "Body: $Body"
16094- $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method DELETE -Uri $Uri -Headers $Server.Headers -Body ([System.Text.Encoding]::UTF8.GetBytes($Body)) -ContentType 'application/json'
16095- }
16096- catch {
16097- $ResponseBody = ParseExceptionBody -Response $_.Exception.Response
16098- Write-Error "DELETE to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
16099- }
16053+ if ($Definition) {
16054+ $Uri += "?expand=definition"
16055+ }
1610016056
16101- if (([String]$Result).Trim().startsWith('{') -or ([String]$Result).toString().Trim().startsWith('[') ) {
16102- $Result = ParseJsonString -json $Result.Trim()
16103- }
16057+ if (!$Annotations ) {
16058+ $Annotations = Get-OciAnnotationsByQtree -id $id -definition -Server $Server
16059+ }
1610416060
16105- Write-Output $Result
16061+ try {
16062+ $Body = ConvertTo-Json @($Annotations | ConvertTo-AnnotationValues) -Compress
16063+ Write-Verbose "Body: $Body"
16064+ $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method DELETE -Uri $Uri -Headers $Server.Headers -Body ([System.Text.Encoding]::UTF8.GetBytes($Body)) -ContentType 'application/json'
16065+ }
16066+ catch {
16067+ $ResponseBody = ParseExceptionBody -Response $_.Exception.Response
16068+ Write-Error "DELETE to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
1610616069 }
16070+
16071+ Write-Output $Result
1610716072 }
1610816073}
1610916074
1611016075<#
1611116076 .SYNOPSIS
16112- Retrieve annotations for object
16077+ Retrieve annotations of qtree
1611316078 .DESCRIPTION
16114-
16079+ Retrieve annotations of qtree
1611516080 .PARAMETER id
1611616081 Id of object to retrieve
1611716082 .PARAMETER expand
1611816083 Expand parameter for underlying JSON object (e.g. expand=definition)
1611916084 .PARAMETER definition
1612016085 Return related Definition
1612116086#>
16122- function Global:Get-OciByTypeAndId {
16087+ function Global:Get-OciAnnotationsByQtree {
1612316088 [CmdletBinding()]
1612416089
1612516090 PARAM (
@@ -16144,40 +16109,14 @@ function Global:Get-OciByTypeAndId {
1614416109 if (!$Server) {
1614516110 throw "Server parameter not specified and no global OCI Server available. Run Connect-OciServer first!"
1614616111 }
16147-
16148- $switchparameters=@("definition")
16149- foreach ($parameter in $switchparameters) {
16150- if ((Get-Variable $parameter).Value) {
16151- if ($expand) {
16152- $expand += ",$($parameter -replace 'performancehistory','performance.history' -replace 'hostswitch','host')"
16153- }
16154- else {
16155- $expand = $($parameter -replace 'performancehistory','performance.history' -replace 'hostswitch','host')
1615616112 }
16157- }
16158- }
16159- }
1616016113
1616116114 Process {
16162- $id = @($id)
16163- foreach ($id in $id) {
1616416115 $Uri = $Server.BaseUri + "/rest/v1/assets/qtrees/$id/annotations"
1616516116
16166- if ($fromTime -or $toTime -or $expand) {
16167- $Uri += '?'
16168- $Separator = ''
16169- if ($fromTime) {
16170- $Uri += "fromTime=$($fromTime | ConvertTo-UnixTimestamp)"
16171- $Separator = '&'
16172- }
16173- if ($toTime) {
16174- $Uri += "$($Separator)toTime=$($toTime | ConvertTo-UnixTimestamp)"
16175- $Separator = '&'
16176- }
16177- if ($expand) {
16178- $Uri += "$($Separator)expand=$expand"
16179- }
16180- }
16117+ if ($Definition) {
16118+ $Uri += "?expand=definition"
16119+ }
1618116120
1618216121 try {
1618316122 $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method GET -Uri $Uri -Headers $Server.Headers
@@ -16194,32 +16133,20 @@ function Global:Get-OciByTypeAndId {
1619416133 Write-Output $Result
1619516134 }
1619616135 }
16197- }
1619816136
1619916137<#
1620016138 .SYNOPSIS
16201- Update annotations for object
16139+ Update Annotations of Qtree
1620216140 .DESCRIPTION
16203- Request body should be like JSON below: <br/>
16204-
16205- <pre>
16206-
16207- [
16208- {
16209- "rawValue": "Bronze",
16210- "definition": {
16211- "id": "4992",
16212- }
16213- }
16214- ]
16215- </pre>
16216-
16141+ Update Annotations of Qtree
1621716142 .PARAMETER id
1621816143 Id of object to update
16219- .PARAMETER definition
16220- Return related Definition
16144+ .PARAMETER Annotations
16145+ Annotations to be updated
16146+ .PARAMETER definition
16147+ Return related Definition
1622116148#>
16222- function Global:Update-OciByTypeAndId {
16149+ function Global:Update-OciAnnotationsByQtree {
1622316150 [CmdletBinding()]
1622416151
1622516152 PARAM (
@@ -16228,11 +16155,14 @@ function Global:Update-OciByTypeAndId {
1622816155 HelpMessage="Id of object to update",
1622916156 ValueFromPipeline=$True,
1623016157 ValueFromPipelineByPropertyName=$True)][Long[]]$id,
16231- [parameter(Mandatory=$False ,
16158+ [parameter(Mandatory=$True ,
1623216159 Position=1,
16160+ HelpMessage="Annotations to be updated")][PSObject[]]$Annotations,
16161+ [parameter(Mandatory=$False,
16162+ Position=2,
1623316163 HelpMessage="Return related Definition")][Switch]$definition,
1623416164 [parameter(Mandatory=$False,
16235- Position=2 ,
16165+ Position=3 ,
1623616166 HelpMessage="OnCommand Insight Server.")]$Server=$CurrentOciServer
1623716167 )
1623816168
@@ -16241,57 +16171,30 @@ function Global:Update-OciByTypeAndId {
1624116171 if (!$Server) {
1624216172 throw "Server parameter not specified and no global OCI Server available. Run Connect-OciServer first!"
1624316173 }
16244-
16245- $switchparameters=@("definition")
16246- foreach ($parameter in $switchparameters) {
16247- if ((Get-Variable $parameter).Value) {
16248- if ($expand) {
16249- $expand += ",$($parameter -replace 'performancehistory','performance.history' -replace 'hostswitch','host')"
16250- }
16251- else {
16252- $expand = $($parameter -replace 'performancehistory','performance.history' -replace 'hostswitch','host')
16253- }
16254- }
16255- }
1625616174 }
1625716175
1625816176 Process {
16259- $id = @($id)
16260- foreach ($id in $id) {
16261- $Uri = $Server.BaseUri + "/rest/v1/assets/qtrees/$id/annotations"
16177+ $Uri = $Server.BaseUri + "/rest/v1/assets/qtrees/$id/annotations"
1626216178
16263- if ($fromTime -or $toTime -or $expand) {
16264- $Uri += '?'
16265- $Separator = ''
16266- if ($fromTime) {
16267- $Uri += "fromTime=$($fromTime | ConvertTo-UnixTimestamp)"
16268- $Separator = '&'
16269- }
16270- if ($toTime) {
16271- $Uri += "$($Separator)toTime=$($toTime | ConvertTo-UnixTimestamp)"
16272- $Separator = '&'
16273- }
16274- if ($expand) {
16275- $Uri += "$($Separator)expand=$expand"
16276- }
16277- }
16278-
16279- try {
16280- $Body = ""
16281- Write-Verbose "Body: $Body"
16282- $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method PUT -Uri $Uri -Headers $Server.Headers -Body ([System.Text.Encoding]::UTF8.GetBytes($Body)) -ContentType 'application/json'
16283- }
16284- catch {
16285- $ResponseBody = ParseExceptionBody -Response $_.Exception.Response
16286- Write-Error "PUT to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
16287- }
16179+ if ($Definition) {
16180+ $Uri += "?expand=definition"
16181+ }
1628816182
16289- if (([String]$Result).Trim().startsWith('{') -or ([String]$Result).toString().Trim().startsWith('[')) {
16290- $Result = ParseJsonString -json $Result.Trim()
16291- }
16183+ try {
16184+ $Body = ConvertTo-Json -InputObject @($Annotations | ForEach-Object { @{rawValue=$_.rawValue;definition=@{id=$_.definition.id}} } ) -Compress
16185+ Write-Verbose "Body: $Body"
16186+ $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method PUT -Uri $Uri -Headers $Server.Headers -Body ([System.Text.Encoding]::UTF8.GetBytes($Body)) -ContentType 'application/json'
16187+ }
16188+ catch {
16189+ $ResponseBody = ParseExceptionBody -Response $_.Exception.Response
16190+ Write-Error "PUT to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
16191+ }
1629216192
16293- Write-Output $Result
16193+ if (([String]$Result).Trim().startsWith('{') -or ([String]$Result).toString().Trim().startsWith('[')) {
16194+ $Result = ParseJsonString -json $Result.Trim()
1629416195 }
16196+
16197+ Write-Output $Result
1629516198 }
1629616199}
1629716200
@@ -25714,7 +25617,7 @@ function Global:Remove-OciAnnotationsByVirtualMachine {
2571425617 }
2571525618
2571625619 try {
25717- $Body = ConvertTo-Json @($Annotations | Where-Object { $_.definition } | ForEach-Object { @{definition=@{id=$_.definition.id}} } ) -Compress
25620+ $Body = ConvertTo-Json @($Annotations | ConvertTo-AnnotationValues ) -Compress
2571825621 Write-Verbose "Body: $Body"
2571925622 $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method DELETE -Uri $Uri -Headers $Server.Headers -Body ([System.Text.Encoding]::UTF8.GetBytes($Body)) -ContentType 'application/json'
2572025623 }
0 commit comments