#Get-NcVol and advanced queries / Templates

1 messages · Page 1 of 1 (latest)

vagrant vector
#

Hi All, I need to update a PowerShell script that uses get-ncvol. I see a remark in the man (get-help) page for the function that I could do an advanced query, it seems to indicate that I first setup a template via "-Template -Fill" then I defines some attributes that are of interest i.e. to filter the results. But how do I specify the attributes e.g. how do ask for something like: all volnames matching "acme" and/or only "data" SVMs?

#

So in this case volnames such as acme_002, test_acme, ...

#

Overall is this a good approach? It seems like using the templates in the query instead of filtering the results afterwards (in PowerShell) should be more efficient, place less load on the Filers ...

modest rain
#

I have used templates with Update-NcFoo style commands since there it is mandatory. For simple queries I found it easier to just grab all items and filter in PowerShell, like

Get-NcVol  | ? { $_.State -ne "offline" } |
  { ! $_.VolumeStateAttributes.IsConstituent } |
  Set-NcVol -Offline -Confirm:$false
#

If you want to use templates with Update-NcFoo commands, you can do it like this:

$q = Get-NcVol -Template
Initialize-NcObjectProperty $q VolumeIdAttributes
$q.VolumeIdAttributes.OwningVserverName = "!Node*"
$a = Get-NcVol -Template
Initialize-NcObjectProperty $a VolumeSnapshotAttributes
$a.VolumeSnapshotAttributes.SnapshotPolicy ="none"
Update-NcVol -Query $q -Attributes $a
#

this sets the Snapshot Policy for all volumes that are not node-owned (i.e. not the system root volumes) to "none"

vagrant vector
#

So the attribute set accepts wildcards like acme

#

ah, sorry star acme star

modest rain
#

yeah. I think it should accept all wildcards that the CLI accepts, so for numers >10g or similar should also work, but I haven't tried that yet

vagrant vector
#

( need to put Discord into raw mode 😉 )

modest rain
#

you can use backticks for that 😉

#
`foo`
vagrant vector
#

I will give it a try and let you know the results!

modest rain
#

good luck. And again, you can always use PowerShell's -match operator if you just iterate over all items/volumes/vservers

#

Get-NcVol | ? { $_.Name -match "*acme*" }

PowerShell is usually more versatile with what you can do/match/filter against

vagrant vector
#

( or maybe golang )

modest rain
#

you can do that there too, there's Python and Perl bindings IIRC, and I guess you can also filter there more easily than with what ONTAP provides

#

Also, there's PowerShell for Linux too 🙂

vagrant vector
#

Just tooling around, hacking some other guys PS script ... on the typical Windows jumpserver, where I have no admin rights ... Another day in paradise 🙄

#

You wrote: " ... OwningVserverName = "!Node*" ..."

#

Where is "Node" coming from there?

#

Your own local var, or built into the netapp lib/toolkit?

modest rain
#

the name of our nodes. "Node01", "Node02", etc.

#

(it was just a direct copy/paste from one of our cleanup scripts... we're not very creative with naming our lab systems 😄 )

vagrant vector
#

🙂

#

I see, actually I meant does the netapp library provide values for "Node" automatically, based on the cluster you are connect to, or did you create the var "Node" and assign it as part of you own PS code. (I guess it's the latter)

modest rain
#

yeah it's a fixed string in the script. It's not a variable

#

but you could get the nodes first ( Get-NcNodes) and put them in a variable or something