Skip to content

Commit

Permalink
Profile commandlets
Browse files Browse the repository at this point in the history
  • Loading branch information
U-AMERICAS\Trevor_Squillario authored and U-AMERICAS\Trevor_Squillario committed Oct 20, 2023
1 parent dbfc7fa commit d5d0230
Show file tree
Hide file tree
Showing 9 changed files with 888 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.6.3]() - 2023-
## [3.7.0]() - 2023-
### Added
- Get-OMEProfile
- Remove-OMEProfile
- New-OMEProfile
- Invoke-OMEProfileAssign
- Invoke-OMEDeviceReseat
- Invoke-OMEProfileRename

### Fixed
- Wait-OnJob MAX_RETRIES calculation is set based on the SLEEP_INTERVAL

Expand Down
26 changes: 26 additions & 0 deletions DellOpenManage/Classes/Profile.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Class Profile {
[Int]$Id
[String]$ProfileName
[String]$ProfileDescription
[Int]$TemplateId
[String]$TemplateName
[Int]$DataSchemaId
[Int]$TargetId
[String]$TargetName
[Int]$TargetTypeId
[Int]$DeviceIdInSlot
[Int]$ChassisId
[String]$ChassisName
[Int]$GroupId
[String]$GroupName
[PSCustomObject]$NetworkBootToIso
[Int]$ProfileState
[Int]$DeploymentTaskId
[Int]$LastRunStatus
[Int]$ProfileModified
[String]$CreatedBy
[String]$EditedBy
[DateTime]$CreatedDate
[DateTime]$LastEditDate
[nullable[DateTime]]$LastDeployDate
}
40 changes: 40 additions & 0 deletions DellOpenManage/Private/New-ProfileFromJson.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using module ..\Classes\Profile.psm1
function New-ProfileFromJson {
Param(
[PSCustomObject]$Profile
)
$LastDeployDate = $null
if ($Profile.LastDeployDate -eq "") {
$LastDeployDate = $null
} else {
$LastDeployDate = $Profile.LastDeployDate
}
$ProfileObj = [Profile]@{
Id = $Profile.Id
ProfileName = $Profile.ProfileName
ProfileDescription = $Profile.ProfileDescription
TemplateId = $Profile.TemplateId
TemplateName = $Profile.TemplateName
DataSchemaId = $Profile.DataSchemaId
TargetId = $Profile.TargetId
TargetName = $Profile.TargetName
TargetTypeId = $Profile.TargetTypeId
DeviceIdInSlot = $Profile.DeviceIdInSlot
ChassisId = $Profile.ChassisId
ChassisName = $Profile.ChassisName
GroupId = $Profile.GroupId
GroupName = $Profile.GroupName
NetworkBootToIso = $Profile.NetworkBootToIso
ProfileState = $Profile.ProfileState
DeploymentTaskId = $Profile.DeploymentTaskId
LastRunStatus = $Profile.LastRunStatus
ProfileModified = $Profile.ProfileModified
CreatedBy = $Profile.CreatedBy
EditedBy = $Profile.EditedBy
CreatedDate = $Profile.CreatedDate
LastEditDate = $Profile.LastEditDate
LastDeployDate = $LastDeployDate
}
return $ProfileObj
}

139 changes: 139 additions & 0 deletions DellOpenManage/Public/OME/Get-OMEProfile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using module ..\..\Classes\Group.psm1

function Get-OMEProfile {
<#
Copyright (c) 2018 Dell EMC Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>

<#
.SYNOPSIS
Get Profiles managed by OpenManage Enterprise
.DESCRIPTION
Get Profiles. Returns all Profiles if no input received.
.PARAMETER Value
String containing search value. Use with -FilterBy parameter
.PARAMETER FilterBy
Filter the results by (Default="ServiceTag", "Name", "Id", "Model", "Type")
.INPUTS
String[]
.EXAMPLE
"ProfileName" | Get-OMEProfile
Get Profile by ProfileName
.EXAMPLE
Get-OMEProfile | Where-Object { $_.ProfileName -eq "Profile from template 'Test Template 01' 00001" }
Get Profile by ProfileName where ProfileName includes single quotes. Use for Profiles deployed from Templates on the MX platform
.EXAMPLE
"TemplateName" | Get-OMEProfile -FilterBy TemplateName
Get Profile by TemplateName
#>

[CmdletBinding()]
param(
[Parameter(Mandatory=$false, ValueFromPipeline)]
[String[]]$Value,

[Parameter(Mandatory=$false)]
[ValidateSet("Name", "TemplateName", "ChassisName", "TargetName", "ProfileState")]
[String]$FilterBy = "Name"
)

Begin {}
Process {
if (!$(Confirm-IsAuthenticated)){
Return
}
Try {
if ($SessionAuth.IgnoreCertificateWarning) { Set-CertPolicy }
$BaseUri = "https://$($SessionAuth.Host)"
$NextLinkUrl = $null
$Type = "application/json"
$Headers = @{}
$FilterMap = @{
'Name'='ProfileName'
'TemplateName'='TemplateName'
'ChassisName'='ChassisName'
'TargetName'='TargetName'
'ProfileState'='ProfileState'
}
# TargetTypeId,LastRunStatus,ProfileModified
$FilterExpr = $FilterMap[$FilterBy]

$Headers."X-Auth-Token" = $SessionAuth.Token
$ProfileData = @()

$ProfileCountUrl = $BaseUri + "/api/ProfileService/Profiles"
$Filter = ""
if ($Value) { # Filter By
if ($FilterBy -eq 'ProfileState') {
$Filter += "`$filter=$($FilterExpr) eq $($Value)"
}
else {
$Filter += "`$filter=$($FilterExpr) eq '$($Value)'"
}
}
$ProfileCountUrl = $ProfileCountUrl + "?" + $Filter
Write-Verbose $ProfileCountUrl
$ProfileResponse = Invoke-WebRequest -Uri $ProfileCountUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if ($ProfileResponse.StatusCode -eq 200)
{
$ProfileCountData = $ProfileResponse.Content | ConvertFrom-Json
foreach ($Profile in $ProfileCountData.'value') {
$ProfileData += New-ProfileFromJson -Profile $Profile
}
if($ProfileCountData.'@odata.nextLink')
{
$NextLinkUrl = $BaseUri + $ProfileCountData.'@odata.nextLink' + "&" + $Filter
}
while($NextLinkUrl)
{
Write-Verbose $NextLinkUrl
$NextLinkResponse = Invoke-WebRequest -Uri $NextLinkUrl -UseBasicParsing -Method Get -Headers $Headers -ContentType $Type
if($NextLinkResponse.StatusCode -eq 200)
{
$NextLinkData = $NextLinkResponse.Content | ConvertFrom-Json
foreach ($Profile in $NextLinkData.'value') {
$ProfileData += New-ProfileFromJson -Profile $Profile
}
if($NextLinkData.'@odata.nextLink')
{
$NextLinkUrl = $BaseUri + $NextLinkData.'@odata.nextLink' + "&" + $Filter
}
else
{
$NextLinkUrl = $null
}
}
else
{
Write-Warning "Unable to get nextlink response for $($NextLinkUrl)"
$NextLinkUrl = $null
}
}
}

return $ProfileData
}
Catch {
Resolve-Error $_
}
}

End {}

}

146 changes: 146 additions & 0 deletions DellOpenManage/Public/OME/Invoke-OMEDeviceReseat.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using module ..\..\Classes\Device.psm1

function Get-VirtualReseatPayload($Name, $TargetPayload) {
$Payload = '{
"JobName": "Virtual_Reseat",
"JobDescription": " Virtual_Reseat ",
"Schedule": "startnow",
"State":"Enabled",
"Targets": [
{
"Id": 50115,
"Data": "",
"TargetType": {
"Id": 1000,
"Name": "DEVICE"
}
}
],
"Params": [
{
"Key": "override",
"Value": "true"
},
{
"Key": "operationName",
"Value": "VIRTUAL_RESEAT"
},
{
"Key": "deviceTypes",
"Value": "1000"
}
],
"JobType": {
"Id": 3,
"Name": "DeviceAction_Task",
"Internal": false
}}' | ConvertFrom-Json

$Payload.Targets = $TargetPayload
$Payload.JobName = $Name
return $payload
}

function Invoke-OMEDeviceReseat {
<#
Copyright (c) 2018 Dell EMC Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>

<#
.SYNOPSIS
Virtual reseat device in OpenManage Enterprise
.DESCRIPTION
This will submit a job to do a virtual reseat on a Compute device in an MX Chassis
.PARAMETER Name
Name of the inventory refresh job
.PARAMETER Devices
Array of type Device returned from Get-OMEDevice function.
.INPUTS
Device
.EXAMPLE
"PowerEdge R640" | Get-OMEDevice -FilterBy "Model" | Invoke-OMEInventoryRefresh -Verbose
Create separate inventory refresh job for each device in list
.EXAMPLE
,$("PowerEdge R640" | Get-OMEDevice -FilterBy "Model") | Invoke-OMEInventoryRefresh -Verbose
Create one inventory refresh job for all devices in list. Notice the preceeding comma before the device list.
#>

[CmdletBinding()]
param(
[Parameter(Mandatory=$false)]
[String]$Name = "Virtual Reseat $((Get-Date).ToString('yyyyMMddHHmmss'))",

[Parameter(Mandatory=$false, ValueFromPipeline)]
[Device[]] $Devices,

[Parameter(Mandatory=$false)]
[Switch]$Wait,

[Parameter(Mandatory=$false)]
[int]$WaitTime = 3600
)

Begin {}
Process {
if (!$(Confirm-IsAuthenticated)){
Return
}
Try {
if ($SessionAuth.IgnoreCertificateWarning) { Set-CertPolicy }
$BaseUri = "https://$($SessionAuth.Host)"
$Type = "application/json"
$Headers = @{}
$Headers."X-Auth-Token" = $SessionAuth.Token

$DeviceIds = @()
foreach ($Device in $Devices) {
$DeviceIds += $Device.Id
}
if ($DeviceIds.Length -gt 0) {
$TargetPayload = Get-JobTargetPayload $DeviceIds
$JobPayload = Get-VirtualReseatPayload -Name $Name -TargetPayload $TargetPayload
# Submit job
$JobURL = $BaseUri + "/api/JobService/Jobs"
$JobPayload = $JobPayload | ConvertTo-Json -Depth 6
Write-Verbose $JobPayload
$JobResp = Invoke-WebRequest -Uri $JobURL -UseBasicParsing -Headers $Headers -ContentType $Type -Method POST -Body $JobPayload
if ($JobResp.StatusCode -eq 201) {
Write-Verbose "Job creation successful..."
$JobInfo = $JobResp.Content | ConvertFrom-Json
$JobId = $JobInfo.Id
Write-Verbose "Created job $($JobId) to refresh inventory..."
if ($Wait) {
$JobStatus = $($JobId | Wait-OnJob -WaitTime $WaitTime)
return $JobStatus
} else {
return $JobId
}
}
else {
Write-Error "Job creation failed"
}
} else {
Write-Warning "No devices found"
return "Completed"
}
}
Catch {
Resolve-Error $_
}
}

End {}

}
Loading

0 comments on commit d5d0230

Please sign in to comment.