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

Initialize-IntersightBulkSubRequest and New-IntersightBulkRequest documentation/examples #126

Open
zj-92 opened this issue Oct 26, 2023 · 5 comments

Comments

@zj-92
Copy link

zj-92 commented Oct 26, 2023

Good morning!

I'm attempting to create something that would allow me to bulk-assign, bulk-deploy, and bulk-activate multiple Server Profiles at once. While the provided examples for doing this using Scheduled Actions are excellent for one-off Assign/Deploy/Activate actions, I'm having trouble working out a bulk process.

I've attempted using Initialize-IntersightBulkSubRequest with New-IntersightBulkRequest, but I haven't had much success.

Is there any further documentation on how these functions work? There don't appear to be any examples in the project.

@Ghufz
Copy link
Collaborator

Ghufz commented Oct 27, 2023

It would be good to understand the error message and cmdlet usage if you provide the cmdlet details along with error message,
If you are facing issue for Body parameter of the cmdlet Initailze-IntersightBulkSubRequest and get the exception message like "Initialize-IntersightBulkRestSubRequest: Cannot bind parameter 'Body'. Cannot convert the "

The issue which I have referred above is due to the body parameter type which is of type MoBaseMo. and when you use Initialize-Intersight-MoBaseMo there is no property of your choice to configure it. Here is the work around to resolve the type issue.

# Initialize a dotnet dictionary and add all the property with the respective value 

$d = [System.Collections.Generic.Dictionary[String,Object]]::new()
 $d.Add("AutoAllowOnUplinks",$true)
 $d.Add("EthNetworkPolicy","78654367900345676543")
$d.Add("IsNative",$false)
$d.Add("MulticastPolicy","7589876234567")
$d.Add("PrimaryVlanId",0)
$d.Add("VlanId",15)

# cmdlet Initailze-IntersightMoBaseMo.
$moBase = Initialize-IntersightMoBaseMo -AdditionalProperties $d

# Now pass the object received from Initialize-IntersightMoBaseMo to Initailze-IntersightBulkRestSubRequest Body parameter.
 $Requests13 = Initialize-IntersightBulkRestSubRequest -Body $moBase -ObjectType "BulkRestSubRequest" -Clas
sId "BulkRestSubRequest"

$result. = New-IntersightBulkRequest -Requests @($Requests13) -Uri "/v1/fabric/Vlans" -Verb "POST"

Please try this workaround.

@zj-92
Copy link
Author

zj-92 commented Nov 1, 2023

Thanks! I'll give this a try.

Another couple of questions based on your example:
Should the URI Parameter be the fully-qualified URI (https://[FQDN]/api/v1/ServerProfile/[MoId]), or should I be utilizing the shorter version, as you did in your example? ("/v1/ServerProfile/[MoId]")?

Additionally, should the URI also be specified in the Initialize-IntersightMoBaseMo and Initialize-IntersightBulkRestSubRequest functions?

I need to ensure that I'm 100% targeting only the Intersight Appliance containing the targeted profile, as we have multiple appliances.

@Ghufz
Copy link
Collaborator

Ghufz commented Nov 2, 2023

Provide shorter Uri like : /v1/ServerProfile.
Uri can be specified in Initialize-IntersightBulkRestSubRequest, because it has parameter named Uri and Use Verb parameter to specify the specific operation Like Get,Post,Patch,Delete.

Use TargetMoid parameter to specify the Moid (In your case ServerProfile Moid).

@zj-92
Copy link
Author

zj-92 commented Nov 6, 2023

Okay; another quick question based on my attempts thus far.

I'm setting up my SubRequests as follows
$ServerMoMoRef is a variable holding the results of running Get-IntersightMoMoRef against the Server Object.
$ScheduledAction1 is an initialized Action to Deploy the Server Profile, which works on its own.
$ScheduledAction2 is an initialized Action to Activate (and reboot) the Server Profile, which also works on its own or in conjunction with $ScheduledAction1.

$d = [System.Collections.Generic.Dictionary[String,Object]]::new()
$d.Add("AssignedServer",$ServerMoMoRef)
$d.Add("ScheduledActions",@($ScheduledAction1,$ScheduledAction2))

$moBase = Initialize-IntersightMoBaseMo -AdditionalProperties $d

$SubRequest = Initialize-IntersightBulkRestSubRequest -Body $moBase -ObjectType "BulkRestSubRequest" -Clas
sId "BulkRestSubRequest" -Uri "/v1/server/Profiles" -Verb "PATCH" -TargetMoId $ProfileMoId

I then add each Profile's SubRequest to a Hash Table where the name of the Intersight CVA is the Key and the Value is all of the SubRequests for that Intersight Appliance, for instance:
$BulkRequests["$IntersightName"] = ($SubRequest1,$SubRequest2,...,$SubRequest#)

However, when I attempt to run New-IntersightBulkRequest -Requests $BulkRequests["$IntersightName"] I get an error indicating that the JSON is malformed. I can provide a screenshot tomorrow with sensitive data redacted, but until then do you see anything immediate that would indicate why I'm getting the malformed JSON error?

@zj-92
Copy link
Author

zj-92 commented Nov 21, 2023

@Ghufz Apologies for the long delay; I have examples!

Here is an attempt to Assign a profile to a Server, Deploy the profile, and Activate with Reboot:
image

Here is an attempt to only Assign a profile to a Server:
image

Given your examples, I know there's a difference - the primary one being that I'm using a Managed Object reference for one Dictionary entry, and two Policy Scheduled Action objects in another. Any insight?

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

2 participants