jakkulabs / powervra Goto Github PK
View Code? Open in Web Editor NEW:rocket: :wrench: vRealize Automation PowerShell Toolkit
License: MIT License
:rocket: :wrench: vRealize Automation PowerShell Toolkit
License: MIT License
Error in variable name "AlertFrequencyReminder" in function "Set-vRAReservation".
@jonathanmedd What do you think about this? I was doing similar things in PowervRO.
Import functions have a File parameter (Import-Something -File file.zip)
Export functions have a Path parameter and the file name will equal the name of the object being exported plus it's file extension. (Export-Something -Path C:\Exports OR Get-Something | Export-Something)
Take a look at this for an example:
https://github.com/jakkulabs/PowervRO/blob/development/PowervRO/Functions/actions-service/Export-vROAction.psm1
Add support for resource actions where feasable
Remove Networkpath from reservation.
Add Pipeline support to Export-vRAContentPackage. Not sure why it is not there, looks straightforward to implement.
Should be able to do:
Get-vRAContentPackage -Name ContentPackage01 | Export-vRAContentPackage -File C:\Packages\ContentPackage01.zip
Add force switch to Import-Module to ensure that if the module being downloaded is newer than the one installed the new cmdlets are used.
Feature request to support New-vRANetworkProfile
site_name is being set to xRequires PowervRA.
site_name should be PowervRA
When the response is over a certain size you the cmdlet will return nothing.
Examining the response object shows that it is returned as a large string.
Trying to run ConvertFrom-Json on that string produces the following error:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Options:
Some api endpoints are case sensitive for tenant id... We can get around this by Getting the id of the tenant passed when connecting and updating the vRAConnection variable
This is because some API endpoints that require the tenantId are case sensitive.
Calling Get-Tenant will ensure that $GLOBAL:vRAConnection.Tenant is updated with the correct value.
Add the following section:
PrivateData = @{
PSData = @{
# Tags applied to this module. These help with module discovery in online galleries.
# Tags = @()
# A URL to the license for this module.
LicenseUri = 'https://github.com/jakkulabs/PowervRA/blob/master/LICENSE'
# A URL to the main website for this project.
ProjectUri = 'https://github.com/jakkulabs/PowervRA'
# A URL to an icon representing this module.
# IconUri = ''
# ReleaseNotes of this module
# ReleaseNotes = ''
} # End of PSData hashtable
} # End of PrivateData hashtable
The TenantId parameter should pick up the current tenant if one is not specified:
Taken from Get-vRABusinessGroup:
[String]$TenantId = $Global:vRAConnection.Tenant
Start to organise public functions in to api endpoint folders as we did for PowervRO
@jonathanmedd I've already started this with the catalog-svc branch that im working on.
You'll also notice that in the feature-networkprofiles branch there will be Functions\Public\iaas-proxy-provider which contains the functions for the feature.
Add headers parameter to cmdlet allow overwriting the default headers
Would be interested to see if Invoke-RestMethod returns any headers from a POST... then see if we can pass them back up to Invoke-vRARestMethod.
The location header is some times passed back with the url of a created resource
Hello,
after I've successfully created an Entitlement using the New-VRAEntitlement and JSON I found, via GUI and also via Get-VRAEntitlement, that the EntitledCatalogitems and EntitledResourceOperations, values are blank.
I tried some other test, but because I don't want to smudge the Entitlements table ( no delete in 7.0.1 ...) I stop my tentatives.
I think also that some error can be in my JSON; I tried to test only using "| ConvertFrom-Json" and it seems correct.
This is a sample (some id/label/name/value deleted):
$JSON = @"
{
"description": "",
"entitledcatalogitems": {
"approvalPolicyId": null,
"active": false,
"catalogItemRef": {
"id" : "fkjhksdhfk",
"label" : "fdslkjlkfjfds"
}
},
"entitledresourceoperations": [
{
"approvalPolicyId": null,
"active": true,
"externalId": "csp.places.iaas.item.window.ConnectViaVmrc",
"resourceOperationType": "EXTENSION",
"resourceOperationRef": {
"id":"110c13a5-8faf-4964-ab1e-db4e26d25841",
"label":"Connect to Remote Console"
},
"targetResourceTypeRef": {
"id":"Infrastructure.Machine",
"label":"Machine"
}
},
{
"approvalPolicyId": null,
"active": true,
"externalId": "csp.places.iaas.item.nowindow.ConnectViaNativeVmrc",
"resourceOperationType": "EXTENSION",
"resourceOperationRef": {
"id":"de2ad362-bf59-4943-b776-671dca98139b",
"label":"Connect using VMRC"
},
"targetResourceTypeRef": {
"id":"Infrastructure.Machine",
"label":"Machine"
}
},
{
"approvalPolicyId": null,
"active": true,
"externalId": "fdsfdsfdsf!::!518ccf4a-6921-46b0-a2eb-99050806d30e",
"resourceOperationType": "ACTION",
"resourceOperationRef": {
"id":"b01828b3-140a-4344-aca2-3562f40eef08",
"label":"Mount ISO to CD-ROM drive"
},
"targetResourceTypeRef": {
"id":"Infrastructure.Virtual",
"label":"Virtual Machine"
}
},
{
"approvalPolicyId": null,
"active": true,
"externalId": "fdsfdsfsfds!::!50c11716-2e81-49cb-a9b5-6572544ba17e",
"resourceOperationType": "ACTION",
"resourceOperationRef": {
"id":"a88dcb3b-0bd4-440d-9ea5-edd299eed17f",
"label":"Mount tools installer"
},
"targetResourceTypeRef": {
"id":"Infrastructure.Virtual",
"label":"Virtual Machine"
}
},
{
"approvalPolicyId": null,
"active": true,
"externalId": "Infrastructure.Machine.Action.Reset",
"resourceOperationType": "ACTION",
"resourceOperationRef": {
"id":"48bdc460-60a6-4f9f-a34a-41e5a6fa0c07",
"label":"Power Cycle"
},
"targetResourceTypeRef": {
"id":"Infrastructure.Machine",
"label":"Machine"
}
},
{
"approvalPolicyId": null,
"active": true,
"externalId": "Infrastructure.Machine.Action.PowerOff",
"resourceOperationType": "ACTION",
"resourceOperationRef": {
"id":"3e273b78-08ee-479a-925c-095bafb0761c",
"label":"Power Off"
},
"targetResourceTypeRef": {
"id":"Infrastructure.Machine",
"label":"Machine"
}
},
{
"approvalPolicyId": null,
"active": true,
"externalId": "Infrastructure.Machine.Action.PowerOn",
"resourceOperationType": "ACTION",
"resourceOperationRef": {
"id":"20ac9d76-30d2-4040-a435-32e9a117fb31",
"label":"Power On"
},
"targetResourceTypeRef": {
"id":"Infrastructure.Machine",
"label":"Machine"
}
},
{
"approvalPolicyId": null,
"active": true,
"externalId": "Infrastructure.Machine.Action.Reboot",
"resourceOperationType": "ACTION",
"resourceOperationRef": {
"id":"6634de52-dce5-42e6-9bcd-f2fd5526d69f",
"label":"Reboot"
},
"targetResourceTypeRef": {
"id":"Infrastructure.Machine",
"label":"Machine"
}
},
{
"approvalPolicyId": null,
"active": true,
"externalId": "Infrastructure.Machine.Action.Shutdown",
"resourceOperationType": "ACTION",
"resourceOperationRef": {
"id":"31555e50-43f5-45ed-a82a-b8c03c4f724e",
"label":"Shutdown"
},
"targetResourceTypeRef": {
"id":"Infrastructure.Machine",
"label":"Machine"
}
},
{
"approvalPolicyId": null,
"active": true,
"externalId": "fdsfdsfdsfsdfs!::!b1fd3802-6f63-4e3f-a30b-a4c031866e19",
"resourceOperationType": "ACTION",
"resourceOperationRef": {
"id":"94aa9cdc-c783-4521-bb31-7c369b167cff",
"label":"Unmount tools installer"
},
"targetResourceTypeRef": {
"id":"Infrastructure.Virtual",
"label":"Virtual Machine"
}
}
],
"entitledservices": null,
"expirydate": null,
"name": "APITEST3",
"organization": {
"tenantRef": "sdfdsfdfsfds",
"tenantLabel": "dfsdfsfds",
"subtenantRef": "dsfdsfdfs",
"subtenantLabel": "SOME LABEL"
},
"principals": [
{
"tenantName": "fdsafafdafds",
"ref": "[email protected]",
"type": "SSO_GROUP",
"value": "SOME VALUE"
},
{
"tenantName": "fsafdfasdfds",
"ref": "[email protected]",
"type": "SSO_GROUP",
"value": "SOME OTHER VALUE"
}
],
"priorityorder": 1,
"status": "ACTIVE",
"statusname": "Active",
"localscopeforactions": true,
"version": 1
}
"@
$JSON | New-vRAEntitlement -Verbose
Get-vRAEntitlement -Name APITEST3
Description :
EntitledCatalogItems :
EntitledResourceOperations :
EntitledServices :
ExpiryDate :
Id : 6fsdfasfddaeec2b05931
LastUpdatedBy : dasdasdas
LastUpdatedDate : sadsadasd
Name : APITEST3
Organization : @{CORRECT VALUE}
Principals : {@{CORRECT VALUE}, @{CORRECT VALUE}}
PriorityOrder : CORRECT VALUE
Status : CORRECT VALUE
StatusName : CORRECT VALUE
LocalScopeForActions : CORRECT VALUE
Version : 1
Use filter for name instead of Where-Object
The help has a typo:
.PARAMETER ReservationSizeGB
The network profile
Also, could the parameter name be changed to NetworkProfile?
Request-vRAConsumerCatalogItem calls an incorrect function:
$JSON = Get-vRAEntitledCatalogItemRequestTemplate -Id $Id
This should be:
$JSON = Get-vRAConsumerCatalogItemRequestTemplate -Id $Id
Error code output is:
Get-vRAEntitledCatalogItemRequestTemplate : The term 'Get-vRAEntitledCatalogItemRequestTemplate' is not recognized as
the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At C:\Users\a615307\Documents\WindowsPowerShell\Modules\PowervRA\Functions\Request-vRAConsumerCatalogItem.psm1:106
char:25
+ $JSON = Get-vRAEntitledCatalogItemRequestTemplate -Id $Id
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-vRAEntitled...RequestTemplate:String) [], ParentContainsErrorRecord
Exception
+ FullyQualifiedErrorId : CommandNotFoundException
After talking the other week I understand why this is important. But maybe it should take the value of the current tenant for a default value. I always think of business groups being managed from within the current tenant.
Also I rememer that tenantid is case sensitive, Would it be worth doing a get-vRATenant to ensure that the TenantId is correct.
I do something similar in New-vRAEntitlement:
Ensure the correct tenant name is used in Get-vRABusinessGroup
$TenantName = (Get-vRATenant $Global:vRAConnection.Tenant).Id
I cant see in the API doco where this could be done...
Implement New-vRAUserPrincipal so that local horizon users can be created for a tenant:
/identity/api/docs/resource_Principal.html#POST
Also see Get-vRAUserPrincipal for reference
Get the API version in connect-vraserver
$APIVersion = (Get-vRAVersion).APIVersion
Connect to vIDM /SAAS API and trigger directory sync
This should be optional but default to true:
/content-management-service/api/docs/content/resource_[Consumer]%20Package.html#path__api_packages_validate.html
From the docs:
"At this point, we don't support any form of rollback strategies. A failed import may potentially leave the system in an inconsistent state. Hence, its highly recommend to run a precheck/dry-run before the import to validate the package.
See HTTP POST /api/packages/validate for more details. This will help catch most of the errors upfront.
Although the API looks similar to create package API but differs in the 'Content-Type' header where it expects 'multipart/form-data'."
I was having a play around with some PS stuff and thought it could be cool to implement the API Verison check with a declarative helper function.. e.g:
function Get-Example {
# This function does not support API versions lower than Version 7
xRequires -Version 7 -Context $MyInvocation
}
The code
function xRequires {
<#
.SYNOPSIS
Sets the required API Version for the current function
.DESCRIPTION
Sets the required API Version for the current function
.PARAMETER Version
The API Version that the function supports
.PARAMETER Context
The functions execution context. This shold alwasy be $MyInvocation
.INPUTS
System.Int
System.Management.Automation.PSObject.
.OUTPUTS
None
.EXAMPLE
function Get-Example {
# This function does not support API versions lower than Version 7
xRequires -Version 7 -Context $MyInvocation
}
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)]
[Int]$Version,
[Parameter(Mandatory=$true)]
[PSCustomobject]$Context
)
if ($Global:vRAConnection.APIVersion) {
if ($Global:vRAConnection.APIVersion -lt $Version) {
throw "$($Context.MyCommand) is not supported with vRA API version $($Global:vRAConnection.APIVersion)"
}
}
}
@jonathanmedd Working on the build scripts and wondering if this would make more sense:
Functions\Private
Functions\Public
Rather than:
Functions
Functions\Private Functions
What do you think
Use id endpoint instead of filter param
Set-vRAUserPrincipal -Id Should have an alias of PrincipalId so it can accept Get-vRAUserPrincipal from the pipeline
.DESCRIPTION is currently incorrect.
The current test for API version in various functions is this at the beginning of the function:
# --- Test for vRA API version
if ($Global:vRAConnection.APIVersion -lt 7){
throw "$($MyInvocation.MyCommand) is not supported with vRA API version $($Global:vRAConnection.APIVersion)"
}
However, if $Global:vRAConnection does not exist yet, then the user will receive an error that the API version is not supported, rather than the usual error to go run Connect-vRAServer
It appears that xRequires is no longer evaluating some APIVersions as expected.
When passing a single digit it appears to work however when you pass a value with a decimal the test fails.
I think this is because the parameter type is an Int and values such as 7.1 are doubles...
Example:
APIVersion = 7.0
RequiredVersion = 7.1
xRequires -Version 7.1 will PASS.
Solution:
Further explanation can be found http://www.powershellmagazine.com/2014/01/03/pstip-validating-version-numbers-without-regex/.
Was looking at how you were building the arrays for the content property...
See attached for an alternative way :-)
Currently references Get-TestModule instead of Get-PowervRA
There are a few functions that will return a different PSCustomObject based on the type that comes back from the API.
I think when this happens we should separate out in to different functions. E.g.:
Get-vRAExternalNetworkProfile
Get-vRARoutedNetworkProfile
Request-vRACatalogItem also returns either an Id or a deployed resource depending on whether the wait switch has been passed... a reasonable solution would be for it to return the REQUEST object.
I'll update this issue with functions and solutions as i find them
We currently do this to avoid generating an error for username / password with ScriptAnalyzer
$Exclusions = "PSAvoidUsingUserNameAndPassWordParams"
$Results = Invoke-ScriptAnalyzer -Path $ModuleDirectory -Severity Error -ExcludeRule $Exclusions -Recurse -Verbose:$VerbosePreference
However, we still get the error when the tests are run in the PS Gallery. Adding a Add PSScriptAnalyzerSettings.psd1 will stop this:
https://github.com/PowerShell/psscriptanalyzer#settings-support-in-scriptanalyzer
The cmdlet 'Get-vRAResourceMetrics' uses a plural noun. A singular noun should be used instead.
Should be Get-vRAResourceMetric
The by id block needs updating to the following:
'ById' {
foreach ($ReservationId in $Id) {
if ($PSCmdlet.ShouldProcess($ReservationId)){
$URI = "/reservation-service/api/reservations/$($ReservationId)"
Write-Verbose -Message "Preparing DELETE to $($URI)"
$Response = Invoke-vRARestMethod -Method DELETE -URI "$($URI)"
Write-Verbose -Message "SUCCESS"
}
Default parameters set is currently Standard and the Id param is ById.
The cmdlet should not work without the id switch, however because of the differences in param set name it allows the user to run the command.
Following the merge of the reservation-service branch, we need to complete the following tasks:
@jonathanmedd Am assigning this to you just for awareness just in case i go AWOL ;-)
New vRAReservation fail with error 10101 "Illegal GUID Fromat null".
Info and example:
Get-vRAVersion
BuildNumber : 3621464
BuildDate : 2016-03-04 06:35
ProductVersion : 7.0.1-SNAPSHOT
APIVersion : 7.0
ProductBuildNumber : 7.0.1-SNAPSHOT-3621464
$ComputeResource = Get-vRAReservationComputeResource -Type vSphere -Name "CLUSTER (abc)"
$NetworkDefinitionArray = @()
$Network1 = New-vRAReservationNetworkDefinition -Type vSphere -ComputeResourceId $ComputeResource.Id -NetworkPath "PG_CLCUSTER-IP"
$NetworkDefinitionArray += $Network1
$StorageDefinitionArray = @()
$Storage1 = New-vRAReservationStorageDefinition -Type vSphere -ComputeResourceId $ComputeResource.Id -Path "DS_LUN_CLUSTER" -ReservedSizeGB 3200 -Priority 0
$StorageDefinitionArray += $Storage1
$Param = @{
Type = "vSphere"
Name = "XXXXXXX"
Tenant = "tenant"
BusinessGroup = "XXXXX"
Priority = 0
ComputeResourceId = $ComputeResource.Id
MemoryGB = 18
Storage = $StorageDefinitionArray
Network = $NetworkDefinitionArray
EnableAlerts = $false
}
New-vRAReservation @param -Verbose
New-vRAReservation @param -Verbose
VERBOSE: Preparing reservation payload
VERBOSE: Reservation name is RES_CL01_MIBER_AUPP
VERBOSE: ReservationTypeId for vSphere is Infrastructure.Reservation.Virtual.vSphere
VERBOSE: Tenant is nfvi-automation
VERBOSE: BusinessGroupId for XXXXX is c71c2d5f-f165-4672-9921-e0de467d6751
VERBOSE: ReservationPolicyId for is null
VERBOSE: Priority is 0
VERBOSE: Alerts enabled: false
VERBOSE: Email business group manager: false
VERBOSE: Adding extensionData for type vSphere
VERBOSE: Found compute resource XXXXXXXXX with id c83e77ca-9305-4418-b4cd-d887593c7581
VERBOSE: Setting machine quota to 0
VERBOSE: Setting reservation networks
VERBOSE: Setting reservation storage
VERBOSE: Setting reservation memory
VERBOSE: Performing the operation "New-vRAReservation" on target "XXXXXXXXXX".
VERBOSE: Preparing POST to /reservation-service/api/reservations
Invoke-RestMethod : {"errors":[{"code":10101,"message":"Invalid argument.","systemMessage":"Illegal GUID format null","moreInfoUrl":null}]}
At C:\Program Files\WindowsPowerShell\Modules\PowervRA\1.3.1\Functions\Public\Invoke-vRARestMethod.psm1:117 char:25
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Add support for the reservation-service.
Get-vRARequest.psm1 is a duplicate of Get-vRAConsumerRequest.psm1 and should be removed as there is no admin api equivalent
Ensure that all Invoke-vRARestMethod calls have -Verbose:$VerbosePreference.
Add Remove-Module PowervRA -Force -ErrorAction SilentlyContinue before Import-Module
For by name query, use $filter param instead of where-object
How do you feel about having them in the project?
Starting to see how they could be useful.
This will enable single tenant users to use:
Connect-vRAServer -Server test.vra.local -Credential (Get-Credential) -IgnoreCertRequirements
Rather than having to pass "-Tenant vsphere.local"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.