Microsoft Virtualization Discussions

Possible Bug in Get-NaNetRoute

SeanLuce
8,050 Views

I think I may have found a possible bug in Get-NaNetRoute.  The output of the command is not consistent with other commands like Get-NaLun or Get-NaVolume.

$RouteList = Get-NaNetRoute

($RouteList[0]).Destination

Returns the following:

Address

-------

default

$LunList = Get-NaLun

($LunList[0]).Path

Returns the following:

/vol/volume/lun

In the case of Get-NaLun (or Get-NaVol, GetNaAggr), the output is a single line string.  However, for Get-NaNetRoute, the output is 3 lines including the column heading.

write-host ($RouteList[0]).Destination

Returns the following:

default

However, I am trying to write the string "default" to a variable, and I have not found a way to do that with write-host.

Is this a bug in Get-NaNetRoute?

Is there another way to get the desired output?

Thank you,

Sean

1 ACCEPTED SOLUTION

sizemore
8,050 Views

Hi Sean,

That's not a bug it's an artifact of working with objects not text.  What's happening is Address isn't a string it's a IPAddressorHostname object with an address property.

[0:36]≥ Get-NaNetRoute

Destination                    Type Prefix Gateway                        Metric Vfiler          Ipspace
-----------                    ---- ------ -------                        ------ ------          -------
default                        net         10.58.92.1                       1    vfiler0         default-ipspace


[0:37]≥ Get-NaNetRoute | Select-Object -ExpandProperty Destination

Address
-------
default


[0:38]≥ Get-NaNetRoute | Select-Object -ExpandProperty Destination | gm


   TypeName: DataONTAP.Types.Net.IpAddressOrHostname

Name        MemberType Definition
----        ---------- ----------
Equals      Method     bool Equals(System.Object obj)
GetHashCode Method     int GetHashCode()
GetType     Method     type GetType()
ToString    Method     string ToString()
Validate    Method     System.Void Validate()
Address     Property   string Address {get;set;}


[0:39]≥ Get-NaNetRoute | Select-Object -ExpandProperty Destination | Select-Object -ExpandProperty Address
default

Does that make sense?

~Glenn

View solution in original post

5 REPLIES 5

sizemore
8,051 Views

Hi Sean,

That's not a bug it's an artifact of working with objects not text.  What's happening is Address isn't a string it's a IPAddressorHostname object with an address property.

[0:36]≥ Get-NaNetRoute

Destination                    Type Prefix Gateway                        Metric Vfiler          Ipspace
-----------                    ---- ------ -------                        ------ ------          -------
default                        net         10.58.92.1                       1    vfiler0         default-ipspace


[0:37]≥ Get-NaNetRoute | Select-Object -ExpandProperty Destination

Address
-------
default


[0:38]≥ Get-NaNetRoute | Select-Object -ExpandProperty Destination | gm


   TypeName: DataONTAP.Types.Net.IpAddressOrHostname

Name        MemberType Definition
----        ---------- ----------
Equals      Method     bool Equals(System.Object obj)
GetHashCode Method     int GetHashCode()
GetType     Method     type GetType()
ToString    Method     string ToString()
Validate    Method     System.Void Validate()
Address     Property   string Address {get;set;}


[0:39]≥ Get-NaNetRoute | Select-Object -ExpandProperty Destination | Select-Object -ExpandProperty Address
default

Does that make sense?

~Glenn

JGPSHNTAP
8,050 Views

Glenn,

you can correct me if i'm wrong, but i believe he has to iterate through the objects with a for loop

so for example

foreach ($route in $routelist) {

write-host "destination:"  $route.destination

}

If you want it as a variable, you need to set it like $var = $route.destination and then if you want to do an if statement it would be

if ($var -eq "default") {

"put code here"

}

Hope I didn't confuse you

SeanLuce
8,050 Views

Your example is how I would expect it to work.  However, in you example $route.destination =

Address

-------

default

$route.destination will never be equal to "default" and your expression will never be true.

Instead you have to use "$route.destination.address"

My goal was to create a script to get the default gateway/route of a particular controller:

$routelist = get-nanetroute

foreach ($route in $routelist) {

     $var = $route.destination.address

     if ($var -eq "default") {

          $gateway = $route.destination.address

          write-host "The Default Route is $gateway"

     }

}

It makes sense, but why not just put the values in the "destination" and "gateway" properties respectively...

SeanLuce
8,050 Views

That makes sense.  I was able to get the result I was looking for.  However, it just seems like I have to dig one layer deeper with Get-NaNetRoute than I do compared to other commands.

If you compare it to Get-NaVol:

Name     State     TotalSize     Etc.

----     -----     ---------     ----

vol0     online     809.9 MB    

To get the output of "vol0": "get-navol | select-object -expandproperty Name"

I only need to "-expandproperty" once.  Is there some particular reason why I need to go another layer for Get-NaNetRoute?

Destination only contains one sub-property called "Address".  I would understand the extra layer if 'Destination' had more than one property.

Thanks again for your response.

-Sean

cknight
8,050 Views

Hi, Sean.  The Toolkit attempts to minimize the changes between the data structures returned from Data ONTAP and the objects it emits on the pipeline.  Some structures are far more deeply nested than the RouteInfo class, and that can seem cumbersome, but it does give the OS developers more room for compatible changes over time.

Public