Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struggling with Syntax #96

Open
tbrock47 opened this issue May 18, 2023 · 5 comments
Open

Struggling with Syntax #96

tbrock47 opened this issue May 18, 2023 · 5 comments

Comments

@tbrock47
Copy link

tbrock47 commented May 18, 2023

I'm really struggling with the Intersight PowerShell syntax after working with UCSM and VMware for so long.
It just does not seem very intuitive.

I'm really trying to perform a simple task right now by requesting a server profile by name, and retrieving all of its assigned vNICs/vHBAs (a laughably simple task in UCSM).

For example, just trying to pull the WWPNs from a server profile with Get-IntersightVnicFcIf is proving overly complicated. I can't even seem to pass the correct information to the -Profile parameter on some of these commands.
Should it not work as simple as this?

$ServerProfile = Get-IntersightServerProfile -Name ProfileName
$VnicFcIf = Get-IntersightVnicFcIf -Profile $ServerProfile

I'm also not used to the json style payloads that are loaded into these properties.
And why does "ActualInstance" even exist. All these nested properties are unnecessarily complicated.
If I expand $intersightVnicFcIf.WwpnPool, then take me straight to the "ActualInstance"...
And what's with "AdditionalProperties"? Why does that even exist. Just put ALL the properties in the object...

I'm no schema architect by any means, just a heavy user, and this is just not user friendly whatsoever, so much so that I guarantee I'm not the only one with these same opinions.

Sorry for venting, but it really shouldn't be this hard to transition from the UCSPowertool.

@tbrock47
Copy link
Author

tbrock47 commented May 19, 2023

Also, when I attempt to pull records for any object type, it appears that results are limited to a count of 100.

PS C:\> (Get-IntersightVnicFcIf).Count
100
PS C:\> Get-IntersightVnicFcIf -InlineCount allpages

Count Results
----- -------
  712 {class VnicFcIf {…

PS C:\> (Get-IntersightVnicFcIf -InlineCount allpages).Results.Count
100
PS C:\>

If I want to sort my results locally, it doesn't look like it is possible if we are limited to a 100 object return.

In theory, this would have worked, but the objects im trying to find don't happen to be in the first 100 objects.

$ServerProfile = Get-IntersightServerProfile -Name ProfileName
$Result = (Get-IntersightVnicFcIf -InlineCount allpages).Results
$Result | Where-Object {$_.Profile.ActualInstance.Moid -eq $ServerProfile.Moid}

HERE IS WHAT ACTUALLY WORKED

(Which has a ridiculous number of extra steps)

$ServerProfile = Get-IntersightServerProfile -Name ProfileName
$array = @()
for ($i = 0; $i -lt (Get-IntersightVnicFcIf -InlineCount allpages).Count; $i=$i+100) {
    $array += (Get-IntersightVnicFcIf -Skip $i).Results
}
$array | Where-Object {$_.Profile.ActualInstance.Moid -eq $ServerProfile.Moid}

Can the above be simplified in this strange syntax this module is using?

@dsoper2
Copy link
Contributor

dsoper2 commented May 23, 2023

Sorry for the challenges in using the module. We'll be adding more examples soon to intersight.com/apidocs on query operations like the above and there are currently a few examples including paging through the API at https://github.com/CiscoDevNet/intersight-powershell-utils . Here's a hopefully simpler example of finding vHBAs tied to a profile:
$ServerProfile = Get-IntersightServerProfile -Name ProfileName
$filter = "Profile.Moid eq '" + $ServerProfile.Moid + "'"
$vHBAs = Get-IntersightVnicFcIf -Filter $filter
$vHBAs.Results | Select-Object Name

@tbrock47
Copy link
Author

tbrock47 commented May 24, 2023

I haven't tried that yet for myself, but I'll give it a go this week. I've moved on with my prior findings which seem to work well enough.

How would one use the -Profile parameter? I would have though (Get-IntersightVnicFcIf -Profile $ServerProfile) would have worked, or am I misunderstanding the usage of that parameter?
Seems that should be the simple path forward as the -Filter option is not exactly intuitive.

In UCSM the code was too simple. Are we reinventing the wheel here or are these changes required by Intersight design?
Get-UcsServiceProfile -Name ProfileName | Get-UcsVhba

@dsoper2
Copy link
Contributor

dsoper2 commented May 24, 2023

The -Profile parameter can also be used, although it takes a Managed Object (MO) Ref so there's 1 extra call to convert ServerProfile to a MORef:
$ServerProfile = Get-IntersightServerProfile -Name B26-SP-Template_DERIVED-3
$MORef = Get-IntersightMoMoRef -ManagedObject $ServerProfile
$vHBAs = Get-IntersightVnicFcIf -Profile $MORef
$vHBAs | Select-Object Name

Much of the module is auto-generated from Intersight's OpenAPI spec and the params like -Profile are typically queries behind the scenes where the module is handling the specific query and required types based on the spec.

@wgjhstt247
Copy link

The Cisco Intersight API is much more powerful than the UCSM XML API. With the Cisco Intersight API, we are able to filter, select, expand, and select or expand on the expanded object all on the server side. With these query options, we get exactly the properties we want and no more. This reduces the amount of data sent over the network. A single query is limited to 1000 results. If you have more than 1000 results, you'll need to paginate/loop the same command until all results have been pulled into powershell. Here's a way to get the same information in a single api call.

# Expand the Profile property on VnicFcIf objects and only return the profile's name property after the expansion in addition to all of the VnicFcIf properties
# This is one api call to Intersight
# Without Top parameter, by default, the commands return 100 objects
$results = Get-IntersightVnicFcIf -Top 1000 -Expand 'Profile($select=Name)' | Select-Object -ExpandProperty Results
# Pull out only the properties we are interested in, in powershell
$results | Select-Object @{n='Profile';e={$_.Profile.ActualInstance.Name}},@{n='Vhba';e={$_.Name}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants