diff --git a/Modules/VMware-vCD-Module/README.md b/Modules/VMware-vCD-Module/README.md new file mode 100644 index 0000000..a691421 --- /dev/null +++ b/Modules/VMware-vCD-Module/README.md @@ -0,0 +1,23 @@ +VMware-vCD-Module PowerShell Module +=================================== + +![Invoke-MyOnBoarding](/media/Invoke-MyOnBoarding.png) + +# About + +## Project Owner: + +Markus Kraus [@vMarkus_K](https://twitter.com/vMarkus_K) + +## Project WebSite: +[mycloudrevolution.com](http://mycloudrevolution.com/) + +## Project Documentation: + +[Read the Docs](http://vmware-vcd-module.readthedocs.io/) + +## Project Description: + +The 'VMware-vCD-Module' PowerShell Module is focused on the initial craation of VMware vCloud Director Objects like Org, Org User, Org VDC. + + diff --git a/Modules/VMware-vCD-Module/VMware-vCD-Module.psd1 b/Modules/VMware-vCD-Module/VMware-vCD-Module.psd1 new file mode 100644 index 0000000..59a02de --- /dev/null +++ b/Modules/VMware-vCD-Module/VMware-vCD-Module.psd1 @@ -0,0 +1,126 @@ +# +# Modulmanifest für das Modul "PSGet_VMware-vCD-Module" +# +# Generiert von: Markus +# +# Generiert am: 6/11/2017 +# + +@{ + +# Die diesem Manifest zugeordnete Skript- oder Binärmoduldatei. +# RootModule = '' + +# Die Versionsnummer dieses Moduls +ModuleVersion = '0.2.0' + +# ID zur eindeutigen Kennzeichnung dieses Moduls +GUID = '1ef8a2de-ca22-4c88-8cdb-e00f35007d2a' + +# Autor dieses Moduls +Author = 'Markus' + +# Unternehmen oder Hersteller dieses Moduls +CompanyName = 'Unbekannt' + +# Urheberrechtserklärung für dieses Modul +Copyright = '(c) 2017 Markus. Alle Rechte vorbehalten.' + +# Beschreibung der von diesem Modul bereitgestellten Funktionen +# Description = '' + +# Die für dieses Modul mindestens erforderliche Version des Windows PowerShell-Moduls +# PowerShellVersion = '' + +# Der Name des für dieses Modul erforderlichen Windows PowerShell-Hosts +# PowerShellHostName = '' + +# Die für dieses Modul mindestens erforderliche Version des Windows PowerShell-Hosts +# PowerShellHostVersion = '' + +# Die für dieses Modul mindestens erforderliche Microsoft .NET Framework-Version +# DotNetFrameworkVersion = '' + +# Die für dieses Modul mindestens erforderliche Version der CLR (Common Language Runtime) +# CLRVersion = '' + +# Die für dieses Modul erforderliche Prozessorarchitektur ("Keine", "X86", "Amd64"). +# ProcessorArchitecture = '' + +# Die Module, die vor dem Importieren dieses Moduls in die globale Umgebung geladen werden müssen +# RequiredModules = @() + +# Die Assemblys, die vor dem Importieren dieses Moduls geladen werden müssen +# RequiredAssemblies = @() + +# Die Skriptdateien (PS1-Dateien), die vor dem Importieren dieses Moduls in der Umgebung des Aufrufers ausgeführt werden. +# ScriptsToProcess = @() + +# Die Typdateien (.ps1xml), die beim Importieren dieses Moduls geladen werden sollen +# TypesToProcess = @() + +# Die Formatdateien (.ps1xml), die beim Importieren dieses Moduls geladen werden sollen +# FormatsToProcess = @() + +# Die Module, die als geschachtelte Module des in "RootModule/ModuleToProcess" angegebenen Moduls importiert werden sollen. +NestedModules = @('functions\Invoke-MyOnBoarding.psm1', + 'functions\New-MyOrg.psm1', + 'functions\New-MyOrgAdmin.psm1', + 'functions\New-MyOrgVdc.psm1') + +# Aus diesem Modul zu exportierende Funktionen +FunctionsToExport = 'Invoke-MyOnBoarding', 'New-MyOrg', 'New-MyOrgAdmin', 'New-MyOrgVdc' + +# Aus diesem Modul zu exportierende Cmdlets +CmdletsToExport = '*' + +# Die aus diesem Modul zu exportierenden Variablen +VariablesToExport = '*' + +# Aus diesem Modul zu exportierende Aliase +AliasesToExport = '*' + +# Aus diesem Modul zu exportierende DSC-Ressourcen +# DscResourcesToExport = @() + +# Liste aller Module in diesem Modulpaket +# ModuleList = @() + +# Liste aller Dateien in diesem Modulpaket +# FileList = @() + +# Die privaten Daten, die an das in "RootModule/ModuleToProcess" angegebene Modul übergeben werden sollen. Diese können auch eine PSData-Hashtabelle mit zusätzlichen von PowerShell verwendeten Modulmetadaten enthalten. +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 = '' + + # A URL to the main website for this project. + # ProjectUri = '' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + # External dependent modules of this module + # ExternalModuleDependencies = '' + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo-URI dieses Moduls +# HelpInfoURI = '' + +# Standardpräfix für Befehle, die aus diesem Modul exportiert werden. Das Standardpräfix kann mit "Import-Module -Prefix" überschrieben werden. +# DefaultCommandPrefix = '' + +} + diff --git a/Modules/VMware-vCD-Module/examples/OnBoarding.json b/Modules/VMware-vCD-Module/examples/OnBoarding.json new file mode 100644 index 0000000..ecd1f88 --- /dev/null +++ b/Modules/VMware-vCD-Module/examples/OnBoarding.json @@ -0,0 +1,24 @@ +{ +"Org": { + "Name":"TestOrg", + "FullName": "Test Org", + "Description":"Automation Test Org" + }, +"OrgAdmin": { + "Name":"TestOrgAdmin", + "Pasword": "myPassword1!", + "FullName":"Test OrgAdmin", + "EmailAddress":"test@admin.org" + }, +"OrgVdc": { + "Name":"TestOrgVdc", + "FixedSize": "M", + "CPULimit": "1000", + "MEMLimit":"1024", + "StorageLimit":"1024", + "StorageProfile":"Standard-DC01", + "ProviderVDC":"Provider-VDC-DC01", + "NetworkPool":"Provider-VDC-DC01-NetPool", + "ExternalNetwork": "External-OrgVdcNet" + } +} \ No newline at end of file diff --git a/Modules/VMware-vCD-Module/functions/Invoke-MyOnBoarding.psm1 b/Modules/VMware-vCD-Module/functions/Invoke-MyOnBoarding.psm1 new file mode 100644 index 0000000..4b5e209 --- /dev/null +++ b/Modules/VMware-vCD-Module/functions/Invoke-MyOnBoarding.psm1 @@ -0,0 +1,172 @@ +#Requires -Version 4 +#Requires -Modules VMware.VimAutomation.Cloud, @{ModuleName="VMware.VimAutomation.Cloud";ModuleVersion="6.3.0.0"} +Function Invoke-MyOnBoarding { +<# +.SYNOPSIS + Creates all vCD Objecst for a new IAAS Customer + +.DESCRIPTION + Creates all vCD Objects for a new IAAS Customer + + All Objects are: + * Org + * Default Org Admin + * Org VDC + ** Private Catalog + ** Optional Bridged Network + + JSON Config Example: + + { + "Org": { + "Name":"TestOrg", + "FullName": "Test Org", + "Description":"Automation Test Org" + }, + "OrgAdmin": { + "Name":"TestOrgAdmin", + "Pasword": "myPassword1!", + "FullName":"Test OrgAdmin", + "EmailAddress":"test@admin.org" + }, + "OrgVdc": { + "Name":"TestOrgVdc", + "FixedSize": "M", + "CPULimit": "1000", + "MEMLimit":"1000", + "StorageLimit":"1000", + "StorageProfile":"Standard-DC01", + "ProviderVDC":"Provider-VDC-DC01", + "NetworkPool":"Provider-VDC-DC01-NetPool", + "ExternalNetwork": "External_OrgVdcNet" + } + } + +.NOTES + File Name : Invoke-MyOnBoarding.ps1 + Author : Markus Kraus + Version : 1.2 + State : Ready + +.LINK + https://mycloudrevolution.com/ + +.EXAMPLE + Invoke-MyOnBoarding -ConfigFile ".\OnBoarding.json" -Enabled:$true + +.EXAMPLE + Invoke-MyOnBoarding -ConfigFile ".\OnBoarding.json" -Enabled:$false + +.PARAMETER ConfigFile + Full Path to the JSON Config File + +.PARAMETER Enabled + Should the Customer be enabled after creation + + Default: $False + +#> + Param ( + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Full Path to the JSON Config File")] + [ValidateNotNullorEmpty()] + [String] $ConfigFile, + [Parameter(Mandatory=$False, ValueFromPipeline=$False, HelpMessage="Should the Customer be enabled after creation")] + [ValidateNotNullorEmpty()] + [Switch]$Enabled + ) + Process { + + $Valid = $true + + Write-Verbose "## Import JSON Config" + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Importing JSON Config...`n" + $Configs = Get-Content -Raw -Path $ConfigFile -ErrorAction Continue | ConvertFrom-Json -ErrorAction Continue + + if (!($Configs)) { + $Valid = $false + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Importing JSON Config Failed" -ForegroundColor Red + } + else { + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Importing JSON Config OK" -ForegroundColor Green + } + + if ($Valid) { + try{ + Write-Verbose "## Create Org" + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Creating new Org...`n" -ForegroundColor Yellow + $Trash = New-MyOrg -Name $Configs.Org.Name -FullName $Configs.Org.Fullname -Description $Configs.Org.Description -Enabled:$Enabled + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Creating new Org OK" -ForegroundColor Green + Get-Org -Name $Configs.Org.Name | Select-Object Name, FullName, Enabled | Format-Table -AutoSize + } + catch { + $Valid = $false + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Creating new Org Failed" -ForegroundColor Red + } + } + + if ($Valid) { + try{ + Write-Verbose "## Create OrgAdmin" + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Creating new OrgAdmin...`n" -ForegroundColor Yellow + $Trash = New-MyOrgAdmin -Name $Configs.OrgAdmin.Name -Pasword $Configs.OrgAdmin.Pasword -FullName $Configs.OrgAdmin.FullName -EmailAddress $Configs.OrgAdmin.EmailAddress -Org $Configs.Org.Name -Enabled:$Enabled + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Creating new OrgAdmin OK" -ForegroundColor Green + Get-CIUser -Org $Configs.Org.Name -Name $Configs.OrgAdmin.Name | Select-Object Name, FullName, Email | Format-Table -AutoSize + } + catch { + $Valid = $false + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Creating new OrgAdmin Failed" -ForegroundColor Red + } + } + if ($Valid) { + try{ + Write-Verbose "## Create OrgVdc" + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Creating new OrgVdc...`n" -ForegroundColor Yellow + + if ($Configs.OrgVdc.FixedSize){ + + Write-Host "Fixed Size (T-Shirt Size) '$($Configs.OrgVdc.FixedSize)' Org VDC Requested!" + + switch ($Configs.OrgVdc.FixedSize) { + M { + [String]$CPULimit = 36000 + [String]$MEMLimit = 122880 + [String]$StorageLimit = 1048576 + } + L { + [String]$CPULimit = 36000 + [String]$MEMLimit = 245760 + [String]$StorageLimit = 1048576 + } + default {throw "Invalid T-Shirt Size!"} + } + + } + else{ + Write-Host "Custom Org VDC Size Requested!" + + $CPULimit = $Configs.OrgVdc.CPULimit + $MEMLimit = $Configs.OrgVdc.MEMLimit + $StorageLimit = $Configs.OrgVdc.StorageLimit + + } + + if ($Configs.OrgVdc.ExternalNetwork){ + $Trash = New-MyOrgVdc -Name $Configs.OrgVdc.Name -CPULimit $CPULimit -MEMLimit $MEMLimit -StorageLimit $StorageLimit -Networkpool $Configs.OrgVdc.NetworkPool -StorageProfile $Configs.OrgVdc.StorageProfile -ProviderVDC $Configs.OrgVdc.ProviderVDC -ExternalNetwork $Configs.OrgVdc.ExternalNetwork -Org $Configs.Org.Name -Enabled:$Enabled + } + else { + $Trash = New-MyOrgVdc -Name $Configs.OrgVdc.Name -CPULimit $CPULimit -MEMLimit $MEMLimit -StorageLimit $StorageLimit -Networkpool $Configs.OrgVdc.NetworkPool -StorageProfile $Configs.OrgVdc.StorageProfile -ProviderVDC $Configs.OrgVdc.ProviderVDC -Org $Configs.Org.Name -Enabled:$Enabled + } + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Creating new OrgVdc OK" -ForegroundColor Green + Get-OrgVdc -Org $Configs.Org.Name -Name $Configs.OrgVdc.Name | Select-Object Name, Enabled, CpuAllocationGhz, MemoryLimitGB, StorageLimitGB, AllocationModel, ThinProvisioned, UseFastProvisioning, ` + @{N="StorageProfile";E={$_.ExtensionData.VdcStorageProfiles.VdcStorageProfile.Name}}, ` + @{N='VCpuInMhz';E={$_.ExtensionData.VCpuInMhz}} | Format-Table -AutoSize + } + catch { + $Valid = $false + Write-Host "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Creating new OrgVdc Failed" -ForegroundColor Red + } + } + + Write-Output "Overall Execution was Valid: $Valid" + } +} diff --git a/Modules/VMware-vCD-Module/functions/New-MyOrg.psm1 b/Modules/VMware-vCD-Module/functions/New-MyOrg.psm1 new file mode 100644 index 0000000..69565bb --- /dev/null +++ b/Modules/VMware-vCD-Module/functions/New-MyOrg.psm1 @@ -0,0 +1,107 @@ +#Requires -Version 4 +#Requires -Modules VMware.VimAutomation.Cloud, @{ModuleName="VMware.VimAutomation.Cloud";ModuleVersion="6.3.0.0"} +Function New-MyOrg { +<# +.SYNOPSIS + Creates a new vCD Org with Default Parameters + +.DESCRIPTION + Creates a new vCD Org with Default Parameters. + + Default Parameters are: + * Catalog Publishing + * Catalog Subscription + * VM Quota + * Stored VM Quota + * VM Lease Time + * Stored VM Lease Time + * Password Policy Settings + +.NOTES + File Name : New-MyOrg.ps1 + Author : Markus Kraus + Version : 1.1 + State : Ready + +.LINK + https://mycloudrevolution.com/ + +.EXAMPLE + New-MyOrg -Name "TestOrg" -FullName "Test Org" -Description "PowerCLI Test Org" + +.PARAMETER Name + Name of the New Org as String + +.PARAMETER FullName + Full Name of the New Org as String + +.PARAMETER Description + Description of the New Org as String + +.PARAMETER Enabled + Should the New Org be enabled after creation + + Default:$false + +#> + Param ( + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Name of the New Org as string")] + [ValidateNotNullorEmpty()] + [String] $Name, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Full Name of the New Org as string")] + [ValidateNotNullorEmpty()] + [String] $FullName, + [Parameter(Mandatory=$False, ValueFromPipeline=$False, HelpMessage="Description of the New Org as string")] + [ValidateNotNullorEmpty()] + [String] $Description, + [Parameter(Mandatory=$False, ValueFromPipeline=$False, HelpMessage="Should the New Org be enabled after creation")] + [ValidateNotNullorEmpty()] + [Switch]$Enabled + ) + Process { + $vcloud = $DefaultCIServers[0].ExtensionData + + ## Create Objects + $AdminOrg = New-Object VMware.VimAutomation.Cloud.Views.AdminOrg + $orgGeneralSettings = New-Object VMware.VimAutomation.Cloud.Views.OrgGeneralSettings + $orgOrgLeaseSettings = New-Object VMware.VimAutomation.Cloud.Views.OrgLeaseSettings + $orgOrgVAppTemplateLeaseSettings = New-Object VMware.VimAutomation.Cloud.Views.OrgVAppTemplateLeaseSettings + $orgOrgPasswordPolicySettings = New-Object VMware.VimAutomation.Cloud.Views.OrgPasswordPolicySettings + $orgSettings = New-Object VMware.VimAutomation.Cloud.Views.OrgSettings + + ## Admin Settings + $adminOrg.Name = $name + $adminOrg.FullName = $FullName + $adminOrg.Description = $description + $adminOrg.IsEnabled = $Enabled + + ## Org Setting + ### General Org Settings + $orgGeneralSettings.CanPublishCatalogs = $False + $orgGeneralSettings.CanPublishExternally = $False + $orgGeneralSettings.CanSubscribe = $True + $orgGeneralSettings.DeployedVMQuota = 0 + $orgGeneralSettings.StoredVmQuota = 0 + $orgSettings.OrgGeneralSettings = $orgGeneralSettings + ### vApp Org Setting + $orgOrgLeaseSettings.DeleteOnStorageLeaseExpiration = $false + $orgOrgLeaseSettings.DeploymentLeaseSeconds = 0 + $orgOrgLeaseSettings.StorageLeaseSeconds = 0 + $orgSettings.VAppLeaseSettings = $orgOrgLeaseSettings + ### vApp Template Org Setting + $orgOrgVAppTemplateLeaseSettings.DeleteOnStorageLeaseExpiration = $false + $orgOrgVAppTemplateLeaseSettings.StorageLeaseSeconds = 0 + $orgSettings.VAppTemplateLeaseSettings = $orgOrgVAppTemplateLeaseSettings + ### PasswordPolicySettings Org Setting + $orgOrgPasswordPolicySettings.AccountLockoutEnabled = $True + $orgOrgPasswordPolicySettings.InvalidLoginsBeforeLockout = 5 + $orgOrgPasswordPolicySettings.AccountLockoutIntervalMinutes = 30 + $orgSettings.OrgPasswordPolicySettings = $orgOrgPasswordPolicySettings + + $adminOrg.Settings = $orgSettings + + $CreateOrg = $vcloud.CreateOrg($adminOrg) + + Get-Org -Name $name | Format-Table -AutoSize + } +} diff --git a/Modules/VMware-vCD-Module/functions/New-MyOrgAdmin.psm1 b/Modules/VMware-vCD-Module/functions/New-MyOrgAdmin.psm1 new file mode 100644 index 0000000..26087c0 --- /dev/null +++ b/Modules/VMware-vCD-Module/functions/New-MyOrgAdmin.psm1 @@ -0,0 +1,91 @@ +#Requires -Version 4 +#Requires -Modules VMware.VimAutomation.Cloud, @{ModuleName="VMware.VimAutomation.Cloud";ModuleVersion="6.3.0.0"} +Function New-MyOrgAdmin { +<# +.SYNOPSIS + Creates a new vCD Org Admin with Default Parameters + +.DESCRIPTION + Creates a new vCD Org Admin with Default Parameters + + Default Parameters are: + * User Role + +.NOTES + File Name : New-MyOrgAdmin.ps1 + Author : Markus Kraus + Version : 1.1 + State : Ready + +.LINK + https://mycloudrevolution.com/ + +.EXAMPLE + New-MyOrgAdmin -Name "OrgAdmin" -Pasword "Anfang!!" -FullName "Org Admin" -EmailAddress "OrgAdmin@TestOrg.local" -Org "TestOrg" + +.PARAMETER Name + Name of the New Org Admin as String + +.PARAMETER FullName + Full Name of the New Org Admin as String + +.PARAMETER Password + Password of the New Org Admin as String + +.PARAMETER EmailAddress + EmailAddress of the New Org Admin as String + +.PARAMETER Enabled + Should the New Org be enabled after creation + + Default:$false + +.PARAMETER Org + Org where the new Org Admin should be created as string + +#> + Param ( + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Name of the New Org Admin as String")] + [ValidateNotNullorEmpty()] + [String] $Name, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Password of the New Org Admin as String")] + [ValidateNotNullorEmpty()] + [String] $Pasword, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Full Name of the New Org Admin as String")] + [ValidateNotNullorEmpty()] + [String] $FullName, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="EmailAddress of the New Org Admin as String")] + [ValidateNotNullorEmpty()] + [String] $EmailAddress, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Org where the new Org Admin should be created as string")] + [ValidateNotNullorEmpty()] + [String] $Org, + [Parameter(Mandatory=$False, ValueFromPipeline=$False, HelpMessage="Should the New Org be enabled after creation")] + [ValidateNotNullorEmpty()] + [Switch]$Enabled + ) + Process { + + ## Create Objects + $OrgED = (Get-Org $Org).ExtensionData + $orgAdminUser = New-Object VMware.VimAutomation.Cloud.Views.User + + ## Settings + $orgAdminUser.Name = $Name + $orgAdminUser.FullName = $FullName + $orgAdminUser.EmailAddress = $EmailAddress + $orgAdminUser.Password = $Pasword + $orgAdminUser.IsEnabled = $Enabled + + $vcloud = $DefaultCIServers[0].ExtensionData + + ## Find Role + $orgAdminRole = $vcloud.RoleReferences.RoleReference | Where-Object {$_.Name -eq "Organization Administrator"} + $orgAdminUser.Role = $orgAdminRole + + ## Create User + $user = $orgED.CreateUser($orgAdminUser) + + Get-CIUser -Org $Org -Name $Name | Format-Table -AutoSize + } +} diff --git a/Modules/VMware-vCD-Module/functions/New-MyOrgVdc.psm1 b/Modules/VMware-vCD-Module/functions/New-MyOrgVdc.psm1 new file mode 100644 index 0000000..783ad5e --- /dev/null +++ b/Modules/VMware-vCD-Module/functions/New-MyOrgVdc.psm1 @@ -0,0 +1,252 @@ +#Requires -Version 4 +#Requires -Modules VMware.VimAutomation.Cloud, @{ModuleName="VMware.VimAutomation.Cloud";ModuleVersion="6.3.0.0"} +Function New-MyOrgVdc { +<# +.SYNOPSIS + Creates a new vCD Org VDC with Default Parameters + +.DESCRIPTION + Creates a new vCD Org VDC with Default Parameters + + Default Parameters are: + * Allocation Model + * Network Quota + * VM Quota + * 'vCpu In Mhz' + * Fast Provisioning + * Thin Provisioning + * private Catalog + +.NOTES + File Name : New-MyOrgVdc.ps1 + Author : Markus Kraus + Version : 1.2 + State : Ready + +.LINK + https://mycloudrevolution.com/ + +.EXAMPLE + New-MyOrgVdc -Name "TestVdc" -CPULimit 1000 -MEMLimit 1000 -StorageLimit 1000 -StorageProfile "Standard-DC01" -NetworkPool "NetworkPool-DC01" -ProviderVDC "Provider-VDC-DC01" -Org "TestOrg" -ExternalNetwork "External_OrgVdcNet" + +.EXAMPLE + New-MyOrgVdc -Name "TestVdc" -CPULimit 1000 -MEMLimit 1000 -StorageLimit 1000 -StorageProfile "Standard-DC01" -NetworkPool "NetworkPool-DC01" -ProviderVDC "Provider-VDC-DC01" -Org "TestOrg" + +.PARAMETER Name + Name of the New Org VDC as String + +.PARAMETER CPULimit + CPU Limit (MHz) of the New Org VDC as String + +.PARAMETER MEMLimit + Memory Limit (MB) of the New Org VDC as String + +.PARAMETER StorageLimit + Storage Limit (MB) of the New Org VDC as String + +.PARAMETER StorageProfile + Storage Profile of the New Org VDC as String + +.PARAMETER NetworkPool + Network Pool of the New Org VDC as String + +.PARAMETER ExternalNetwork + Optional External Network of the New Org VDC as String + +.PARAMETER Enabled + Should the New Org VDC be enabled after creation + + Default:$false + + Note: If an External Network is requested the Org VDC will be enabled during External Network Configuration + +.PARAMETER ProviderVDC + ProviderVDC where the new Org VDC should be created as string + +.PARAMETER Org + Org where the new Org VDC should be created as string + +.PARAMETER Timeout + Timeout for teh Org VDC to get Ready + + Default: 120s + +#> + Param ( + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Name of the New Org VDC as String")] + [ValidateNotNullorEmpty()] + [String] $Name, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="CPU Limit (MHz) of the New Org VDC as String")] + [ValidateNotNullorEmpty()] + [int] $CPULimit, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Memory Limit (MB) of the New Org VDC as String")] + [ValidateNotNullorEmpty()] + [int] $MEMLimit, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Storage Limit (MB) of the New Org VDC as String")] + [ValidateNotNullorEmpty()] + [int] $StorageLimit, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Storage Profile of the New Org VDC as String")] + [ValidateNotNullorEmpty()] + [String] $StorageProfile, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Network Pool of the New Org VDC as String")] + [ValidateNotNullorEmpty()] + [String] $NetworkPool, + [Parameter(Mandatory=$False, ValueFromPipeline=$False, HelpMessage="Optional External Network of the New Org VDC as String")] + [ValidateNotNullorEmpty()] + [String] $ExternalNetwork, + [Parameter(Mandatory=$False, ValueFromPipeline=$False, HelpMessage="Should the New Org VDC be enabled after creation")] + [ValidateNotNullorEmpty()] + [Switch]$Enabled, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="ProviderVDC where the new Org VDC should be created as string")] + [ValidateNotNullorEmpty()] + [String] $ProviderVDC, + [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Org where the new Org VDC should be created as string")] + [ValidateNotNullorEmpty()] + [String] $Org, + [Parameter(Mandatory=$False, ValueFromPipeline=$False,HelpMessage="Timeout for teh Org VDC to get Ready")] + [ValidateNotNullorEmpty()] + [int] $Timeout = 120 + ) + Process { + ## Create Objects and all Settings + Write-Verbose "Create Objects and all Settings" + $adminVdc = New-Object VMware.VimAutomation.Cloud.Views.AdminVdc + $adminVdc.Name = $name + $adminVdc.IsEnabled = $Enabled + $OrgVdcproviderVdc = Get-ProviderVdc $ProviderVDC + $providerVdcRef = New-Object VMware.VimAutomation.Cloud.Views.Reference + $providerVdcRef.Href = $OrgVdcproviderVdc.Href + $adminVdc.ProviderVdcReference = $providerVdcRef + $adminVdc.AllocationModel = "AllocationPool" + $adminVdc.ComputeCapacity = New-Object VMware.VimAutomation.Cloud.Views.ComputeCapacity + $adminVdc.ComputeCapacity.Cpu = New-Object VMware.VimAutomation.Cloud.Views.CapacityWithUsage + $adminVdc.ComputeCapacity.Cpu.Units = "MHz" + $adminVdc.ComputeCapacity.Cpu.Limit = $CPULimit + $adminVdc.ComputeCapacity.Cpu.Allocated = $CPULimit + $adminVdc.ComputeCapacity.Memory = New-Object VMware.VimAutomation.Cloud.Views.CapacityWithUsage + $adminVdc.ComputeCapacity.Memory.Units = "MB" + $adminVdc.ComputeCapacity.Memory.Limit = $MEMLimit + $adminVdc.ComputeCapacity.Memory.Allocated = $MEMLimit + $adminVdc.StorageCapacity = New-Object VMware.VimAutomation.Cloud.Views.CapacityWithUsage + $adminVdc.StorageCapacity.Units = "MB" + $adminVdc.StorageCapacity.Limit = $StorageLimit + $adminVdc.NetworkQuota = 10 + $adminVdc.VmQuota = 0 + $adminVdc.VCpuInMhz = 1000 + $adminVdc.VCpuInMhz2 = 1000 + $adminVdc.UsesFastProvisioning = $false + $adminVdc.IsThinProvision = $true + + ## Create Org vDC + Write-Verbose "Create Org vDC" + $OrgED = (Get-Org $Org).ExtensionData + $orgVdc = $orgED.CreateVdc($adminVdc) + + ## Wait for getting Ready + Write-Verbose "Wait for getting Ready" + $i = 0 + while(($orgVdc = Get-OrgVdc -Name $Name).Status -eq "NotReady"){ + $i++ + Start-Sleep 2 + if($i -gt $Timeout) { Write-Error "Creating Org Failed."; break} + Write-Progress -Activity "Creating Org" -Status "Wait for Org to become Ready..." + } + Write-Progress -Activity "Creating Org" -Completed + Start-Sleep 2 + + ## Search given Storage Profile + Write-Verbose "Search given Storage Profile" + $ProVdcStorageProfile = search-cloud -QueryType ProviderVdcStorageProfile -Name $StorageProfile | Get-CIView + + ## Create Storage Profile Object with Settings + Write-Verbose "Create Storage Profile Object with Settings" + $spParams = new-object VMware.VimAutomation.Cloud.Views.VdcStorageProfileParams + $spParams.Limit = $StorageLimit + $spParams.Units = "MB" + $spParams.ProviderVdcStorageProfile = $ProVdcStorageProfile.href + $spParams.Enabled = $true + $spParams.Default = $true + $UpdateParams = new-object VMware.VimAutomation.Cloud.Views.UpdateVdcStorageProfiles + $UpdateParams.AddStorageProfile = $spParams + + ## Update Org vDC + $orgVdc = Get-OrgVdc -Name $name + $orgVdc.ExtensionData.CreateVdcStorageProfile($UpdateParams) + + ## Wait for getting Ready + Write-Verbose "Wait for getting Ready" + while(($orgVdc = Get-OrgVdc -Name $name).Status -eq "NotReady"){ + $i++ + Start-Sleep 1 + if($i -gt $Timeout) { Write-Error "Update Org Failed."; break} + Write-Progress -Activity "Updating Org" -Status "Wait for Org to become Ready..." + } + Write-Progress -Activity "Updating Org" -Completed + Start-Sleep 1 + + ## Search Any-StorageProfile + Write-Verbose "Search Any-StorageProfile" + $orgvDCAnyProfile = search-cloud -querytype AdminOrgVdcStorageProfile | Where-Object {($_.Name -match '\*') -and ($_.VdcName -eq $orgVdc.Name)} | Get-CIView + + ## Disable Any-StorageProfile + Write-Verbose "Disable Any-StorageProfile" + $orgvDCAnyProfile.Enabled = $False + $return = $orgvDCAnyProfile.UpdateServerData() + + ## Remove Any-StorageProfile + Write-Verbose "Remove Any-StorageProfile" + $ProfileUpdateParams = new-object VMware.VimAutomation.Cloud.Views.UpdateVdcStorageProfiles + $ProfileUpdateParams.RemoveStorageProfile = $orgvDCAnyProfile.href + $remove = $orgvdc.extensiondata.CreatevDCStorageProfile($ProfileUpdateParams) + + ## Wait for getting Ready + Write-Verbose "Wait for getting Ready" + while(($orgVdc = Get-OrgVdc -Name $name).Status -eq "NotReady"){ + $i++ + Start-Sleep 1 + if($i -gt $Timeout) { Write-Error "Update Org Failed."; break} + Write-Progress -Activity "Updating Org" -Status "Wait for Org to become Ready..." + } + Write-Progress -Activity "Updating Org" -Completed + Start-Sleep 1 + + ## Set NetworkPool for correct location + Write-Verbose "Set NetworkPool for correct location" + $orgVdc = Get-OrgVdc -Name $name + $ProVdcNetworkPool = Get-NetworkPool -ProviderVdc $ProviderVDC -Name $NetworkPool + $set = Set-OrgVdc -OrgVdc $orgVdc -NetworkPool $ProVdcNetworkPool -NetworkMaxCount "10" + + ## Create private Catalog + Write-Verbose "Create private Catalog Object" + $OrgCatalog = New-Object VMware.VimAutomation.Cloud.Views.AdminCatalog + $OrgCatalog.name = "$Org Private Catalog" + if (!(Get-Org $org | Get-Catalog -Name $OrgCatalog.name -ErrorAction SilentlyContinue)) { + Write-Verbose "Create private Catalog" + $CreateCatalog = (Get-Org $org | Get-CIView).CreateCatalog($OrgCatalog) + $AccessControlRule = New-CIAccessControlRule -Entity $CreateCatalog.name -EveryoneInOrg -AccessLevel ReadWrite -Confirm:$False + } + else { + Write-Output "Catalog '$($OrgCatalog.name)' aleady exists!" + } + + ## Create a direct connect network + if ($ExternalNetwork) { + Write-Verbose "Create a direct connect network" + Write-Output "Org VDC '$Name' needs to be enabled to add an external Network!" + $EnableOrgVdc = Set-OrgVdc -OrgVdc $Name -Enabled:$True + $orgVdcView = Get-OrgVdc $Name | Get-CIView + $extNetwork = $_.externalnetwork + $extNetwork = Get-ExternalNetwork | Get-CIView | Where-Object {$_.name -eq $ExternalNetwork} + $orgNetwork = new-object vmware.vimautomation.cloud.views.orgvdcnetwork + $orgNetwork.name = $ExternalNetwork + $orgNetwork.Configuration = New-Object VMware.VimAutomation.Cloud.Views.NetworkConfiguration + $orgNetwork.Configuration.FenceMode = 'bridged' + $orgNetwork.configuration.ParentNetwork = New-Object vmware.vimautomation.cloud.views.reference + $orgNetwork.configuration.ParentNetwork.href = $extNetwork.href + + $result = $orgVdcView.CreateNetwork($orgNetwork) + } + + Get-OrgVdc -Name $name | Format-Table -AutoSize + } +} diff --git a/Modules/VMware-vCD-Module/media/Invoke-MyOnBoarding.png b/Modules/VMware-vCD-Module/media/Invoke-MyOnBoarding.png new file mode 100644 index 0000000..9f60a93 Binary files /dev/null and b/Modules/VMware-vCD-Module/media/Invoke-MyOnBoarding.png differ diff --git a/Modules/VMware-vCD-Module/media/VSCode-Pester-Tests.png b/Modules/VMware-vCD-Module/media/VSCode-Pester-Tests.png new file mode 100644 index 0000000..2669d07 Binary files /dev/null and b/Modules/VMware-vCD-Module/media/VSCode-Pester-Tests.png differ diff --git a/Modules/VMware-vCD-Module/tests/VMware-vCD-Module.Tests.ps1 b/Modules/VMware-vCD-Module/tests/VMware-vCD-Module.Tests.ps1 new file mode 100644 index 0000000..ada710e --- /dev/null +++ b/Modules/VMware-vCD-Module/tests/VMware-vCD-Module.Tests.ps1 @@ -0,0 +1,35 @@ +$moduleRoot = Resolve-Path "$PSScriptRoot\.." +$moduleName = "VMware-vCD-Module" +$ConfigFile = "$moduleRoot\examples\OnBoarding.json" + +Describe "General project validation: $moduleName" { + + $scripts = Get-ChildItem $moduleRoot -Include *.ps1, *.psm1, *.psd1 -Recurse + + # TestCases are splatted to the script so we need hashtables + $testCase = $scripts | Foreach-Object {@{file = $_}} + It "Script should be valid powershell" -TestCases $testCase { + param($file) + + $file.fullname | Should Exist + + $contents = Get-Content -Path $file.fullname -ErrorAction Stop + $errors = $null + $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) + $errors.Count | Should Be 0 + } + + It "Module '$moduleName' prerequirements are met" { + {Import-Module VMware.VimAutomation.Cloud -Force} | Should Not Throw + } + + It "Module '$moduleName' can import cleanly" { + {Import-Module (Join-Path $moduleRoot "$moduleName.psd1") -force } | Should Not Throw + } + + It "Module '$moduleName' JSON example is valid" { + {Get-Content -Raw -Path $ConfigFile | ConvertFrom-Json} | Should Not Throw + } + + +}