Hi,
Here is the PowerShell code from a WFA workflow i've used in my environment to successfully set OCI annotations on internal volumes.
Param(
[Parameter(Mandatory = $True, HelpMessage="The OCI hostname to poll")]
[String]$Host,
[Parameter(Mandatory = $True, HelpMessage="The OCI port number (default: 443)")]
[Int]$Port=443,
[Parameter(Mandatory = $True, HelpMessage="The cluster name or IP Address")]
[String]$ClusterName,
[Parameter(Mandatory = $True, HelpMessage="The volume name")]
[String]$VolumeName,
[Parameter(Mandatory = $True, HelpMessage="The vserver name")]
[String]$VserverName,
[Parameter(Mandatory = $True, HelpMessage="The OCI annotation name")]
[String]$AnnotationName,
[Parameter(Mandatory = $True, HelpMessage="The OCI annotation value")]
[String]$AnnotationValue
)
#'------------------------------------------------------------------------------
#'Function to create an OCI connection
#'------------------------------------------------------------------------------
Function New-OCIConnection{
Param(
[parameter(mandatory = $False, position=0)]
[String]$Hostname,
[parameter(Mandatory = $False, position=1)]
[String]$Port,
[parameter(Mandatory = $False, position=2)]
[String]$Username,
[parameter(Mandatory = $False, position=3)]
[String]$Password
)
#'---------------------------------------------------------------------------
#'use command line paramters if specified
#'---------------------------------------------------------------------------
If($Username -And $Password){
$AuthInfo = ( "{0}:{1}" -f $Username, $Password )
}Else{
Try{
$Hostname = Get-WfaRestParameter "host"
$Port = Get-WfaRestParameter "port"
$Credentials = Get-WfaCredentials -Host $HostName
}Catch{
Throw "Failed enumerating data source credentials for ""$HostName"""
}
$AuthInfo = ("{0}:{1}" -f $Credentials.Username, $Credentials.Password )
}
#'---------------------------------------------------------------------------
#'Build authentication header
#'---------------------------------------------------------------------------
$AuthInfo = [System.Text.Encoding]::UTF8.GetBytes( $AuthInfo )
$AuthInfo = [System.Convert]::ToBase64String( $AuthInfo )
$Headers = @{ Authorization=( "Basic {0}" -f $AuthInfo ) }
#'---------------------------------------------------------------------------
#'Ignore not trusted certificate - from OCI PS samples
#'---------------------------------------------------------------------------
Add-Type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class OCIDontCarePolicy : ICertificatePolicy {
public OCIDontCarePolicy() {}
public bool CheckValidationResult(
ServicePoint sPoint, X509Certificate cert,
WebRequest wRequest, int certProb) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object OCIDontCarePolicy
$BaseUri = $( "https://" + $Hostname + ":" + $Port )
If($Port -eq 80 -or $Port -eq 8080 ) {
$BaseUri = $( "http://" + $Hostname + ":" + $Port )
}
#'---------------------------------------------------------------------------
#'return the values
#'---------------------------------------------------------------------------
$BaseUri, $Headers
}
#'------------------------------------------------------------------------------
#'Function to set the OCI annotation value.
#'------------------------------------------------------------------------------
Function Set-OCIAnnotationFields{
Param(
[Parameter(Mandatory = $True, position=0)]
[String]$AnnotationName,
[Parameter(Mandatory = $True, position=1)]
[String]$AnnotationValue
)
$objDefinition = [PSCustomObject]@{"name"=$AnnotationName}
$objList = [PSCustomObject]@{"rawValue"=$AnnotationValue; "definition"=$objDefinition}
$OCIList = [PSCustomObject]@($objList)
ConvertTo-Json @($OCIList)
}
#'------------------------------------------------------------------------------
#'Enumerate the OCI credentials
#'------------------------------------------------------------------------------
Try{
$Credentials = Get-WfaCredentials -Host $Host
$Username = $Credentials.Username
$Password = ConvertFromSecureToPlain -SecurePassword $Credentials.Password
}Catch{
Throw "Failed enumerating credentials for ""$Host"""
}
#'------------------------------------------------------------------------------
#'create initial OCI connection.
#'------------------------------------------------------------------------------
($BaseUri, $Headers) = New-OCIConnection $Host $Port $Username $Password
#'------------------------------------------------------------------------------
#'Enumerate the the API version.
#'------------------------------------------------------------------------------
Try{
$Uri = $BaseUri + "/rest/v1/login"
$Login = Invoke-RestMethod -Method POST -Uri $Uri -Headers $Headers
}Catch{
Throw $("Failed enumerating API login information from OCI server ""$Host"". Error " + $_.Exception.Message)
}
#'------------------------------------------------------------------------------
#'Save it as a double so we get the minor version
#'------------------------------------------------------------------------------
$APIVersion = [double]$Login.apiVersion
Try{
Get-WFALogger -Info -Message "Enumerating storage information on OCI server ""$Host"""
$Uri = $BaseUri + "/rest/v1/assets/storages"
$S = Invoke-RestMethod -Uri $Uri -Headers $Headers
}Catch{
Throw $("Failed enumerating storage asset information from OCI server ""$Host"". Error " + $_.Exception.Message)
}
#'------------------------------------------------------------------------------
#'now we have to rotate through the entire list with extensions
#'------------------------------------------------------------------------------
For($i = 0; $i -lt $S.count; $i++){
If($S[$i].name -eq $ClusterName){
Try{
Get-WFALogger -Info -Message "Enumerating internal volume information"
$Uri = $($BaseUri + "/rest/v1/assets/storages/" + $S[$i].id + "/internalVolumes")
$IVs = Invoke-RestMethod -Uri $Uri -Headers $Headers
}Catch{
Throw $("Failed enumerating internal volume information from OCI server ""$Host"". Error " + $_.Exception.Message)
}
#'------------------------------------------------------------------------
#'match the internal volume
#'------------------------------------------------------------------------
If(-Not($VolumeName.Contains(":"))){
$Name = $($ClusterName + ":" + $VserverName + ":" + $VolumeName)
}Else{
$Name = $VolumeName
}
Get-WFALogger -Debug -Message "The internal volume name is`: $Name"
For($j = 0; $j -lt $IVs.count; $j++){
If($IVs[$j].name -eq $Name){
#'------------------------------------------------------------------
#'found the internal volume - set the annotation
#'------------------------------------------------------------------
Try{
Get-WFALogger -Info -Message "Setting the annotation name ""$AnnotationName"" to value ""$AnnotationValue"""
$Uri = $($BaseUri + "/rest/v1/assets/internalVolumes/" + $IVs[$j].id + "/annotations")
$A = Invoke-RestMethod -Method PUT -Uri $Uri -Headers $Headers -Body (Set-OCIAnnotationFields $AnnotationName $AnnotationValue)
}Catch{
Throw $("Failed setting annotation ""$AnnotationName"" to value ""$AnnotationValue"". Error " + $_.Exception.Message)
}
$j = $IVs.count
}Else{
Get-WFALogger -Debug -Message $("The volume """ + $IVs[$j].name + """ does not match internal volume ""$Name""")
}
}
$i = $S.count
}
}
#'------------------------------------------------------------------------------
Hope that helps
/matt
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.