Last active
August 8, 2025 18:19
-
-
Save dstamen/7618b9c1ff4df3394786d7523c22d83a to your computer and use it in GitHub Desktop.
Blog Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| param ([Parameter(Mandatory)]$PureManagementIP,$PureManagementUser,$PureManagementPassword) | |
| #Variables | |
| $arrayendpoint = $PureManagementIP | |
| $pureuser = $PureManagementUser | |
| $purepass = ConvertTo-SecureString $PureManagementPassword -AsPlainText -Force | |
| $purecred = New-Object System.Management.Automation.PSCredential -ArgumentList ($pureuser, $purepass) | |
| $computername = [System.Net.Dns]::GetHostName() | |
| #Install Pure Powershell Module | |
| Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | |
| Install-Module PureStoragePowershellSDK2 -Confirm:$false -Force | |
| #Enable ISCSI | |
| Set-Service -Name msiscsi -StartupType Automatic | |
| Start-Service -Name msiscsi | |
| #Confgure Static Initiator Name | |
| $iqn = (Get-InitiatorPort).NodeAddress | |
| # Connect to Cloud Block Store | |
| $array = Connect-Pfa2Array -Endpoint $arrayendpoint -Credential $purecred -IgnoreCertificateError | |
| #Create Host and Volume | |
| $purehost = New-Pfa2Host -Array $array -Name $computername -Iqns $iqn | |
| $purevolume = New-Pfa2Volume -Array $array -Name $computername'-SQLData' -Provisioned 50GB | |
| $purevolume2 = New-Pfa2Volume -Array $array -Name $computername'-SQLLogs' -Provisioned 20GB | |
| $purevolume3 = New-Pfa2Volume -Array $array -Name $computername'-SQLTemp' -Provisioned 10GB | |
| New-Pfa2Connection -Array $array -HostNames $purehost.name -VolumeNames $purevolume.name,$purevolume2.name,$purevolume3.name | |
| #Get iSCSI Information | |
| $iscsiInterface = Get-Pfa2NetworkInterface|Where-Object {$_.Services -eq 'iscsi'} | |
| $ct0iscsi = $iscsiInterface[0].Eth.Address | |
| $ct1iscsi = $iscsiInterface[1].Eth.Address | |
| #Configure ISCSI to CBS | |
| if ((Get-IscsiTargetPortal).TargetPortalAddress -notcontains $ct0iscsi){ | |
| New-IscsiTargetPortal -TargetPortalAddress $ct0iscsi | |
| Get-IscsiTarget | Connect-IscsiTarget -InitiatorPortalAddress (Get-NetIPAddress |Where-Object {$_.InterfaceAlias -like "Ethernet*" -and $_.AddressFamily -like "IPv4"}).IPAddress -IsPersistent $true -TargetPortalAddress $ct0iscsi | |
| } | |
| if ((Get-IscsiTargetPortal).TargetPortalAddress -notcontains $ct1iscsi){ | |
| New-IscsiTargetPortal -TargetPortalAddress $ct1iscsi | |
| Get-IscsiTarget | Connect-IscsiTarget -InitiatorPortalAddress (Get-NetIPAddress |Where-Object {$_.InterfaceAlias -like "Ethernet*" -and $_.AddressFamily -like "IPv4"}).IPAddress -IsPersistent $true -TargetPortalAddress $ct1iscsi | |
| } | |
| #Initialize and Format Disk | |
| Update-HostStorageCache #Rescan for Disks | |
| Get-Disk|Where-Object {$_.NumberOfPartitions -eq '0'}|Initialize-Disk -PartitionStyle 'GPT' #Initialize Disk in GPT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Copy-VCSAUpdate -Version "6.7.0.20100" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git clone https://github.com/dstamen/Terraform.git #Clone the Github Repository | |
| cd Terraform/deploy-nested-esxi #Change to Runbook Directory | |
| vi modules/deploy-nested-esxi/main.tf #Update the configuration file to provide your vCenter Server and Appliance Settings and then Save the file | |
| terraform init #Initialize and install the provider if needed | |
| terraform plan #Validate the run book will work | |
| terraform apply #Deploy your VMs! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $vcname = "vc01.my.lab" | |
| $vcuser = "administrator@vsphere.local" | |
| $vcpass = "VMware1!" | |
| $ovffile = "C:\share\VMware\SRM\VMware-srm-va-8.3.0.4135-15929234\bin\srm-va_OVF10.ovf" | |
| $cluster = "MyCluster" | |
| $vmnetwork = "MyNetwork" | |
| $datastore = "MyDatastore" | |
| $vmfolder = "MyFolder" | |
| $vm1name = "srm1.my.lab" | |
| $vm2name = "srm2.my.lab" | |
| $vm1ip = "10.21.230.58" | |
| $vm2ip = "10.21.230.59" | |
| $addrfamily = "ipv4" | |
| $networkmode = "static" | |
| $gateway = "10.21.230.1" | |
| $domain = "my.lab" | |
| $searchpath = "my.lab" | |
| $dns = "10.21.230.6" | |
| $prefix = "24" | |
| $ntp = "us.pool.ntp.org" | |
| $password = "VMware1!" | |
| $enablessh = $true | |
| $vcenter = Connect-VIServer $vcname -User $vcuser -Password $vcpass -WarningAction SilentlyContinue | |
| $datastore_ref = Get-Datastore -Name $datastore | |
| $network_ref = Get-VirtualPortGroup -Name $vmnetwork | |
| $cluster_ref = Get-Cluster -Name $cluster | |
| $vmhost_ref = $cluster_ref | Get-VMHost | Select -First 1 | |
| $ovfconfig = Get-OvfConfiguration $ovffile | |
| $ovfconfig.NetworkMapping.Network_1.value = $vmnetwork | |
| $ovfconfig.network.VMware_Site_Recovery_Manager_Appliance.addrfamily.value = $addrfamily | |
| $ovfconfig.network.VMware_Site_Recovery_Manager_Appliance.netmode.value = $networkmode | |
| $ovfconfig.network.VMware_Site_Recovery_Manager_Appliance.gateway.value = $gateway | |
| $ovfconfig.network.VMware_Site_Recovery_Manager_Appliance.domain.value = $domain | |
| $ovfconfig.network.VMware_Site_Recovery_Manager_Appliance.searchpath.value = $searchpath | |
| $ovfconfig.network.VMware_Site_Recovery_Manager_Appliance.DNS.value = $dns | |
| $ovfconfig.network.VMware_Site_Recovery_Manager_Appliance.netprefix0.value = $prefix | |
| $ovfconfig.common.ntpserver.value = $ntp | |
| $ovfconfig.common.varoot_password.value = $password | |
| $ovfconfig.common.vaadmin_password.value = $password | |
| $ovfconfig.common.dbpassword.value = $password | |
| $ovfconfig.common.enable_sshd.value = $enablessh | |
| #Deploy SRM1 | |
| $ovfconfig.network.VMware_Site_Recovery_Manager_Appliance.ip0.value = $vm1ip | |
| $ovfconfig.common.vami.hostname.value = $vm1ip | |
| Import-VApp -Source $ovffile -OvfConfiguration $ovfconfig -Name $vm1name -InventoryLocation $VMFolder -Location $cluster_ref -VMHost $vmhost_ref -Datastore $datastore_ref | |
| #Deploy SRM2 | |
| $ovfconfig.network.VMware_Site_Recovery_Manager_Appliance.ip0.value = $vm2ip | |
| Import-VApp -Source $ovffile -OvfConfiguration $ovfconfig -Name $vm2name -InventoryLocation $VMFolder -Location $cluster_ref -VMHost $vmhost_ref -Datastore $datastore_ref | |
| $vms = get-vm $vm1name,$vm2name | |
| $vm | Start-Vm -RunAsync | Out-Null | |
| Disconnect-VIServer $vcenter -Confirm:$false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @description('The name of the VM') | |
| param virtualMachineName string | |
| @description('The management IP of Cloud Block Store') | |
| param PureManagementIP string | |
| @description('The management User of Cloud Block Store') | |
| param PureManagementUser string | |
| @description('The management Password of Cloud Block Store') | |
| param PureManagementPassword string | |
| @description('The virtual machine size.') | |
| param virtualMachineSize string = 'Standard_D2s_v5' | |
| @description('Specify the name of an existing VNet in the same resource group') | |
| param existingVirtualNetworkName string | |
| @description('Specify the resrouce group of the existing VNet') | |
| param existingVnetResourceGroup string | |
| @description('Specify the name of the Subnet Name') | |
| param existingSubnetName string | |
| @description('The admin user name of the VM') | |
| param adminUsername string | |
| @description('The admin password of the VM') | |
| @secure() | |
| param adminPassword string | |
| @description('Location for all resources.') | |
| param location string = resourceGroup().location | |
| var networkInterfaceName = '${virtualMachineName}-nic' | |
| var networkSecurityGroupName = '${virtualMachineName}-nsg' | |
| var networkSecurityGroupRules = [ | |
| { | |
| name: 'RDP' | |
| properties: { | |
| priority: 300 | |
| protocol: 'Tcp' | |
| access: 'Allow' | |
| direction: 'Inbound' | |
| sourceAddressPrefix: '*' | |
| sourcePortRange: '*' | |
| destinationAddressPrefix: '*' | |
| destinationPortRange: '3389' | |
| } | |
| } | |
| ] | |
| var publicIpAddressName = '${virtualMachineName}-publicip-${uniqueString(virtualMachineName)}' | |
| var publicIpAddressType = 'Dynamic' | |
| var publicIpAddressSku = 'Basic' | |
| var nsgId = networkSecurityGroup.id | |
| var subnetRef = resourceId(existingVnetResourceGroup, 'Microsoft.Network/virtualNetWorks/subnets', existingVirtualNetworkName, existingSubnetName) | |
| resource publicIpAddress 'Microsoft.Network/publicIPAddresses@2022-01-01' = { | |
| name: publicIpAddressName | |
| location: location | |
| sku: { | |
| name: publicIpAddressSku | |
| } | |
| properties: { | |
| publicIPAllocationMethod: publicIpAddressType | |
| } | |
| } | |
| resource networkSecurityGroup 'Microsoft.Network/networkSecurityGroups@2022-01-01' = { | |
| name: networkSecurityGroupName | |
| location: location | |
| properties: { | |
| securityRules: networkSecurityGroupRules | |
| } | |
| } | |
| resource networkInterface 'Microsoft.Network/networkInterfaces@2022-01-01' = { | |
| name: networkInterfaceName | |
| location: location | |
| properties: { | |
| ipConfigurations: [ | |
| { | |
| name: 'ipconfig1' | |
| properties: { | |
| subnet: { | |
| id: subnetRef | |
| } | |
| privateIPAllocationMethod: 'Dynamic' | |
| publicIPAddress: { | |
| id: publicIpAddress.id | |
| } | |
| } | |
| } | |
| ] | |
| enableAcceleratedNetworking: true | |
| networkSecurityGroup: { | |
| id: nsgId | |
| } | |
| } | |
| } | |
| resource virtualMachine 'Microsoft.Compute/virtualMachines@2022-03-01' = { | |
| name: virtualMachineName | |
| location: location | |
| properties: { | |
| hardwareProfile: { | |
| vmSize: virtualMachineSize | |
| } | |
| storageProfile: { | |
| osDisk: { | |
| createOption: 'FromImage' | |
| managedDisk: { | |
| storageAccountType: 'Premium_LRS' | |
| } | |
| } | |
| imageReference: { | |
| publisher: 'MicrosoftSQLServer' | |
| offer: 'sql2019-ws2019' | |
| sku: 'Standard' | |
| version: 'latest' | |
| } | |
| } | |
| networkProfile: { | |
| networkInterfaces: [ | |
| { | |
| id: networkInterface.id | |
| } | |
| ] | |
| } | |
| osProfile: { | |
| computerName: virtualMachineName | |
| adminUsername: adminUsername | |
| adminPassword: adminPassword | |
| windowsConfiguration: { | |
| enableAutomaticUpdates: true | |
| provisionVMAgent: true | |
| } | |
| } | |
| } | |
| } | |
| resource customScriptExtension 'Microsoft.Compute/virtualMachines/extensions@2023-03-01' = { | |
| name: '${virtualMachineName}-CustomScriptExtension' | |
| location: location | |
| parent: virtualMachine | |
| properties: { | |
| type: 'CustomScriptExtension' | |
| typeHandlerVersion: '1.9' | |
| publisher: 'Microsoft.Compute' | |
| settings: { | |
| fileUris: split('https://gist.githubusercontent.com/dstamen/7618b9c1ff4df3394786d7523c22d83a/raw/cb01dfc831634e643010bc66715c4718dbf27912/ConfigureAzureCBS-Bicep.ps1', ' ') | |
| } | |
| protectedSettings: { | |
| commandToExecute: 'powershell.exe -Command "./ConfigureAzureCBS-Bicep.ps1 -PureManagementIP ${PureManagementIP} -PureManagementUser ${PureManagementUser} -PureManagementPassword ${PureManagementPassword}; exit 0;"' | |
| } | |
| } | |
| } | |
| var diskConfigurationType = 'NEW' | |
| var tempDbPath = 'J:\\SQLTemp' | |
| var logPath = 'I:\\SQLLog' | |
| var dataPath = 'H:\\SQLData' | |
| var storageWorkloadType = 'General' | |
| resource sqlVirtualMachine 'Microsoft.SqlVirtualMachine/sqlVirtualMachines@2022-07-01-preview' = { | |
| dependsOn: [ | |
| customScriptExtension | |
| ] | |
| name: virtualMachineName | |
| location: location | |
| properties: { | |
| virtualMachineResourceId: virtualMachine.id | |
| sqlManagement: 'Full' | |
| sqlServerLicenseType: 'PAYG' | |
| storageConfigurationSettings: { | |
| diskConfigurationType: diskConfigurationType | |
| storageWorkloadType: storageWorkloadType | |
| sqlDataSettings: { | |
| luns: [1] | |
| defaultFilePath: dataPath | |
| } | |
| sqlLogSettings: { | |
| luns: [2] | |
| defaultFilePath: logPath | |
| } | |
| sqlTempDbSettings: { | |
| luns: [3] | |
| defaultFilePath: tempDbPath | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @description('The name of the VM') | |
| param virtualMachineName string | |
| @description('The virtual machine size.') | |
| param virtualMachineSize string = 'Standard_D2s_v5' | |
| @description('Specify the name of an existing VNet in the same resource group') | |
| param existingVirtualNetworkName string | |
| @description('Specify the resrouce group of the existing VNet') | |
| param existingVnetResourceGroup string | |
| @description('Specify the name of the Subnet Name') | |
| param existingSubnetName string | |
| @description('The Windows version for the VM. This will pick a fully patched image of this given Windows version.') | |
| @allowed([ | |
| '2016-datacenter-gensecond' | |
| '2016-datacenter-server-core-g2' | |
| '2016-datacenter-server-core-smalldisk-g2' | |
| '2016-datacenter-smalldisk-g2' | |
| '2016-datacenter-with-containers-g2' | |
| '2016-datacenter-zhcn-g2' | |
| '2019-datacenter-core-g2' | |
| '2019-datacenter-core-smalldisk-g2' | |
| '2019-datacenter-core-with-containers-g2' | |
| '2019-datacenter-core-with-containers-smalldisk-g2' | |
| '2019-datacenter-gensecond' | |
| '2019-datacenter-smalldisk-g2' | |
| '2019-datacenter-with-containers-g2' | |
| '2019-datacenter-with-containers-smalldisk-g2' | |
| '2019-datacenter-zhcn-g2' | |
| '2022-datacenter-azure-edition' | |
| '2022-datacenter-azure-edition-core' | |
| '2022-datacenter-azure-edition-core-smalldisk' | |
| '2022-datacenter-azure-edition-smalldisk' | |
| '2022-datacenter-core-g2' | |
| '2022-datacenter-core-smalldisk-g2' | |
| '2022-datacenter-g2' | |
| '2022-datacenter-smalldisk-g2' | |
| ]) | |
| param OSVersion string = '2019-datacenter-smalldisk-g2' | |
| @description('The admin user name of the VM') | |
| param adminUsername string | |
| @description('The admin password of the VM') | |
| @secure() | |
| param adminPassword string | |
| @description('Location for all resources.') | |
| param location string = resourceGroup().location | |
| var networkInterfaceName = '${virtualMachineName}-nic' | |
| var networkSecurityGroupName = '${virtualMachineName}-nsg' | |
| var networkSecurityGroupRules = [ | |
| { | |
| name: 'RDP' | |
| properties: { | |
| priority: 300 | |
| protocol: 'Tcp' | |
| access: 'Allow' | |
| direction: 'Inbound' | |
| sourceAddressPrefix: '*' | |
| sourcePortRange: '*' | |
| destinationAddressPrefix: '*' | |
| destinationPortRange: '3389' | |
| } | |
| } | |
| ] | |
| var publicIpAddressName = '${virtualMachineName}-publicip-${uniqueString(virtualMachineName)}' | |
| var publicIpAddressType = 'Dynamic' | |
| var publicIpAddressSku = 'Basic' | |
| var nsgId = networkSecurityGroup.id | |
| var subnetRef = resourceId(existingVnetResourceGroup, 'Microsoft.Network/virtualNetWorks/subnets', existingVirtualNetworkName, existingSubnetName) | |
| resource publicIpAddress 'Microsoft.Network/publicIPAddresses@2022-01-01' = { | |
| name: publicIpAddressName | |
| location: location | |
| sku: { | |
| name: publicIpAddressSku | |
| } | |
| properties: { | |
| publicIPAllocationMethod: publicIpAddressType | |
| } | |
| } | |
| resource networkSecurityGroup 'Microsoft.Network/networkSecurityGroups@2022-01-01' = { | |
| name: networkSecurityGroupName | |
| location: location | |
| properties: { | |
| securityRules: networkSecurityGroupRules | |
| } | |
| } | |
| resource networkInterface 'Microsoft.Network/networkInterfaces@2022-01-01' = { | |
| name: networkInterfaceName | |
| location: location | |
| properties: { | |
| ipConfigurations: [ | |
| { | |
| name: 'ipconfig1' | |
| properties: { | |
| subnet: { | |
| id: subnetRef | |
| } | |
| privateIPAllocationMethod: 'Dynamic' | |
| publicIPAddress: { | |
| id: publicIpAddress.id | |
| } | |
| } | |
| } | |
| ] | |
| enableAcceleratedNetworking: true | |
| networkSecurityGroup: { | |
| id: nsgId | |
| } | |
| } | |
| } | |
| resource virtualMachine 'Microsoft.Compute/virtualMachines@2022-03-01' = { | |
| name: virtualMachineName | |
| location: location | |
| properties: { | |
| hardwareProfile: { | |
| vmSize: virtualMachineSize | |
| } | |
| storageProfile: { | |
| osDisk: { | |
| createOption: 'FromImage' | |
| managedDisk: { | |
| storageAccountType: 'Premium_LRS' | |
| } | |
| } | |
| imageReference: { | |
| publisher: 'MicrosoftWindowsServer' | |
| offer: 'WindowsServer' | |
| sku: OSVersion | |
| version: 'latest' | |
| } | |
| } | |
| networkProfile: { | |
| networkInterfaces: [ | |
| { | |
| id: networkInterface.id | |
| } | |
| ] | |
| } | |
| osProfile: { | |
| computerName: virtualMachineName | |
| adminUsername: adminUsername | |
| adminPassword: adminPassword | |
| windowsConfiguration: { | |
| enableAutomaticUpdates: true | |
| provisionVMAgent: true | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/bash | |
| _regional_instances_file="/tmp/instances.txt" | |
| _sorted_regional_instances_file="/tmp/sorted-instances.txt" | |
| _regional_vpcs_subnets_file="/tmp/instances-vpc-subnet.txt" | |
| _regional_ebs_volumes_file="/tmp/ebs-volume-details.txt" | |
| echo -n > $_regional_instances_file | |
| echo -n > $_sorted_regional_instances_file | |
| echo -n > $_regional_vpcs_subnets_file | |
| echo -n > $_regional_ebs_volumes_file | |
| # get all instance ids, their AZ, volumes and volume sizes saved to /tmp/instances-$_region.txt | |
| echo "Gathering Volumes" | |
| for REGION in $(aws ec2 describe-regions --output text --query 'Regions[].[RegionName]') ; do aws ec2 describe-volumes --filter Name=attachment.status,Values=attached --query 'Volumes[*].{VolumeID:VolumeId,Size:Size,Type:VolumeType,Iops:Iops,Throughput:Throughput,AvailabilityZone:AvailabilityZone,State:State,Device:Attachments[0].Device,InstanceId:Attachments[0].InstanceId}' $_profile --region $REGION --output text --no-cli-pager >> $_regional_instances_file;done | |
| sort --reverse $_regional_instances_file > $_sorted_regional_instances_file | |
| # put all the instance ids into a string variable | |
| aws_instances="$(cat $_sorted_regional_instances_file | cut -f 3)" | |
| aws_instances_region="$(cat $_sorted_regional_instances_file | cut -f 1 | sed 's/.$//')" | |
| # convert the string variable to an array | |
| aws_instances_array=($aws_instances) | |
| aws_instances_region_array=($aws_instances_region) | |
| echo "Gathering Instances" | |
| if [ ${#aws_instances_array[@]} -ne 0 ]; then | |
| for (( i=0; i<${#aws_instances_array[@]}; i++ ));do aws ec2 describe-instances --instance-ids "${aws_instances_array[$i]}" --output text --query 'Reservations[*].Instances[*].{Type:InstanceType,RootDevice:RootDeviceName}' $_profile --region "${aws_instances_region_array[$i]}" >> $_regional_vpcs_subnets_file; done | |
| fi | |
| # combine the columns from /tmp/instances-$_region.txt and /tmp/instances_vpc_subnet-$_region.txt into /tmp/ebs-volume-details-$_region.txt | |
| paste $_sorted_regional_instances_file $_regional_vpcs_subnets_file > $_regional_ebs_volumes_file | |
| rm -rf $_regional_vpcs_subnets_file $_sorted_regional_instances_file $_regional_instances_file | |
| echo "results located in $_regional_ebs_volumes_file" | |
| cat $_regional_ebs_volumes_file | |
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/bash | |
| print_help() { | |
| echo Usage: | |
| echo -e " get-all-ebs region|help [aws-profile]" | |
| exit $1 | |
| } | |
| if [ "$#" -eq 0 ] || [ "$1" == "help" ]; then | |
| print_help 0 | |
| elif [[ ! -z "$2" ]]; then | |
| _profile="--profile $2" | |
| fi | |
| _region="$1" | |
| _volumes_file="/tmp/volumes-$_region.txt" | |
| _sorted_volumes_file="/tmp/sorted-volumes-$_region.txt" | |
| _instances_file="/tmp/instances-$_region.txt" | |
| _volumes_and_instances="/tmp/volume-and-instance-details-$_region.txt" | |
| echo -n > $_volumes_file | |
| echo -n > $_sorted_volumes_file | |
| echo -n > $_instances_file | |
| echo -n > $_volumes_and_instances | |
| #Gather Volumes | |
| echo "Gathering Volumes" | |
| aws ec2 describe-volumes --filter Name=attachment.status,Values=attached --query 'Volumes[*].{VolumeID:VolumeId,Size:Size,Type:VolumeType,Iops:Iops,Throughput:Throughput,AvailabilityZone:AvailabilityZone,State:State,Device:Attachments[0].Device,InstanceId:Attachments[0].InstanceId}' $_profile --region $_region --output text --no-cli-pager > $_volumes_file | |
| sort --reverse $_volumes_file > $_sorted_volumes_file | |
| # put all the instance ids into a string variable | |
| aws_instances="$(cat $_sorted_volumes_file | cut -f 3)" | |
| # convert the string variable to an array | |
| aws_instances_array=($aws_instances) | |
| echo "Gathering Instances" | |
| if [ ${#aws_instances_array[@]} -ne 0 ]; then | |
| # get the VpcId and SubnetId for each instance id in the aws_instances_array saved to /tmp/instances_vpc_subnet-$_region.txt | |
| for (( i=0; i<${#aws_instances_array[@]}; i++ )); do aws ec2 describe-instances --instance-ids "${aws_instances_array[$i]}" --output text --query 'Reservations[*].Instances[*].{Type:InstanceType,RootDevice:RootDeviceName}' $_profile --region $_region >> $_instances_file; done | |
| fi | |
| # combine the columns from /tmp/instances-$_region.txt and /tmp/instances_vpc_subnet-$_region.txt into /tmp/ebs-volume-details-$_region.txt | |
| paste $_sorted_volumes_file $_instances_file > $_volumes_and_instances | |
| rm -rf $_regional_vpcs_subnets_file $_sorted_regional_instances_file $_regional_instances_file | |
| echo "results located in $_volumes_and_instances" | |
| cat $_volumes_and_instances | |
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/bash | |
| print_help() { | |
| echo Usage: | |
| echo -e " get-s3-bucket-objects bucket|help [aws-profile]" | |
| exit $1 | |
| } | |
| if [ "$#" -eq 0 ] || [ "$1" == "help" ]; then | |
| print_help 0 | |
| elif [[ ! -z "$2" ]]; then | |
| _profile="--profile $2" | |
| fi | |
| _bucket="$1" | |
| _objects_file="/tmp/s3_bucket_objects.txt" | |
| _sorted_objects_file="/tmp/sorted_s3_bucket_objects.txt" | |
| echo -n > $_objects_file | |
| echo -n > $_sorted_objects_file | |
| # get all objects within the s3 bucket. saved to | |
| echo "Gathering Objects" | |
| aws s3api list-objects --bucket $_bucket --query 'Contents[].{Key: Key, Size: Size,Class:StorageClass,LastModified:LastModified}' --no-cli-pager --output text > $_objects_file | |
| sort -k1 -k3 $_objects_file > $_sorted_objects_file | |
| #sort -k1 -k3 c:\temp\aws-ai.txt > c:\temp\sorted-aws-ai.txt | |
| #remove files | |
| rm -rf $_objects_file | |
| echo "results located in $_sorted_objects_file" | |
| cat $_sorted_objects_file | |
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Get-VCSAUpdate | |
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Get-VCSAUpdate -Source "Online" | |
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Get-VCSAUpdate -Source "Local" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Get-VCSAUpdateDetail -Version "6.7.0.20100" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Get-VCSAUpdatePolicy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Get-VCSAUpdateStaged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Get-VCSAUpdateStatus |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Param ( | |
| [Parameter(Mandatory)]$Region, | |
| [Parameter(Mandatory)]$NumberofNodes | |
| ) | |
| $hourspermonth = "730" | |
| $avsrequest = Invoke-WebRequest -Uri "https://azure.microsoft.com/api/v2/pricing/azure-vmware/calculator/" | |
| $avsoffers = $avsrequest.Content | ConvertFrom-Json | |
| $av36payg = $avsoffers.offers.'av36-payg'.prices.$region.value * $hourspermonth * $NumberofNodes | |
| $av36oneyear = $avsoffers.offers.'av36-one-year'.prices.$region.value * $hourspermonth * $NumberofNodes | |
| $av36threeyear = $avsoffers.offers.'av36-three-year'.prices.$region.value * $hourspermonth * $NumberofNodes | |
| $av36ppayg = $avsoffers.offers.'av36p-payg'.prices.$region.value * $hourspermonth * $NumberofNodes | |
| $av36poneyear = $avsoffers.offers.'av36p-one-year'.prices.$region.value * $hourspermonth * $NumberofNodes | |
| $av36pthreeyear = $avsoffers.offers.'av36p-three-year'.prices.$region.value * $hourspermonth * $NumberofNodes | |
| $av52payg = $avsoffers.offers.'av52-payg'.prices.$region.value * $hourspermonth * $NumberofNodes | |
| $av52oneyear = $avsoffers.offers.'av52-one-year'.prices.$region.value * $hourspermonth * $NumberofNodes | |
| $av52threeyear = $avsoffers.offers.'av52-three-year'.prices.$region.value * $hourspermonth * $NumberofNodes | |
| $av36paygcost = '{0:C}' -f $av36payg | |
| $av36oneyearcost = '{0:C}' -f $av36oneyear | |
| $av36threeyearcost = '{0:C}' -f $av36threeyear | |
| $av36ppaygcost = '{0:C}' -f $av36ppayg | |
| $av36poneyearcost = '{0:C}' -f $av36poneyear | |
| $av36pthreeyearcost = '{0:C}' -f $av36pthreeyear | |
| $av52paygcost = '{0:C}' -f $av52payg | |
| $av52oneyearcost= '{0:C}' -f $av52oneyear | |
| $av52threeyearcost = '{0:C}' -f $av52threeyear | |
| if ($av36paygcost) {Write-Host -ForegroundColor Green "Ondemand AV36 Cost per Month:" $av36paygcost} else {(Write-Host -ForegroundColor Red "AV36 Not available in $region")} | |
| if ($av36oneyearcost) {Write-Host -ForegroundColor Green "1year AV36 Cost per Month" $av36oneyearcost} else {(Write-Host -ForegroundColor Red "AV36 Not available in $region")} | |
| if ($av36threeyearcost) {Write-Host -ForegroundColor Green "3year AV36 Cost per Month" $av36threeyearcost} else {(Write-Host -ForegroundColor Red "AV36 Not available in $region")} | |
| if ($av36ppaygcost) {Write-Host -ForegroundColor Green "Ondemand AV36P Cost per Month" $av36ppaygcost} else {(Write-Host -ForegroundColor Red "AV36P Not available in $region")} | |
| if ($av36poneyearcost) {Write-Host -ForegroundColor Green "1year AV36P Cost per Month" $av36poneyearcost} else {(Write-Host -ForegroundColor Red "AV36P Not available in $region")} | |
| if ($av36pthreeyearcost) {Write-Host -ForegroundColor Green "3year AV36P Cost per Month" $av36pthreeyearcost} else {(Write-Host -ForegroundColor Red "AV36P Not available in $region")} | |
| if ($av52paygcost) {Write-Host -ForegroundColor Green "Ondemand AV52 Cost per Month" $av52paygcost} else {(Write-Host -ForegroundColor Red "AV52 Not available in $region")} | |
| if ($av52oneyearcost) {Write-Host -ForegroundColor Green "1year AV52 Cost per Month" $av52oneyearcost} else {(Write-Host -ForegroundColor Red "AV52 Not available in $region")} | |
| if ($av52threeyearcost) {Write-Host -ForegroundColor Green "3year AV52 Cost per Month" $av52threeyearcost} else {(Write-Host -ForegroundColor Red "AV52 Not available in $region")} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| provider "aws" { | |
| region = var.aws_region | |
| } | |
| variable "aws_region" { | |
| type = string | |
| default = "us-west-2" | |
| } | |
| variable "instance_type" { | |
| type = string | |
| default = "t3.small" | |
| } | |
| variable "key_name" { | |
| type = string | |
| default = "mykeypair" | |
| } | |
| variable "vpc_security_group_ids" { | |
| type = list(string) | |
| default = ["sg-0916e0106ABCD"] | |
| } | |
| variable "subnet_id" { | |
| type = string | |
| default = "subnet-0fba5ABCD" | |
| } | |
| variable "ami_id" { | |
| type = string | |
| default = "ami-0c12cfdf054acb297" | |
| } | |
| resource "aws_instance" "ubuntu1" { | |
| ami = var.ami_id | |
| instance_type = var.instance_type | |
| vpc_security_group_ids = var.vpc_security_group_ids | |
| subnet_id = var.subnet_id | |
| key_name = var.key_name | |
| user_data = file("${path.module}/userdata.sh") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| provider "aws" { | |
| region = var.aws_region | |
| } | |
| variable "aws_region" { | |
| type = string | |
| default = "us-west-2" | |
| } | |
| variable "instance_type" { | |
| type = string | |
| default = "t3.small" | |
| } | |
| variable "key_name" { | |
| type = string | |
| default = "mykeypair" | |
| } | |
| variable "vpc_security_group_ids" { | |
| type = list(string) | |
| default = ["sg-abcd1234"] | |
| } | |
| variable "subnet_id" { | |
| type = string | |
| default = "subnet-abcd1234" | |
| } | |
| variable "ami_id" { | |
| type = string | |
| default = "ami-067a0fad89512f721" | |
| } | |
| variable "tags" { | |
| type = map(string) | |
| default = { | |
| Name = "ubuntu1" | |
| } | |
| } | |
| resource "aws_instance" "ubuntu1" { | |
| ami = var.ami_id | |
| instance_type = var.instance_type | |
| vpc_security_group_ids = var.vpc_security_group_ids | |
| subnet_id = var.subnet_id | |
| key_name = var.key_name | |
| user_data = file("${path.module}/userdata2.sh") | |
| tags = var.tags | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| variable "aws_region" { | |
| type = string | |
| default = "us-west-2" | |
| } | |
| variable "instance_type" { | |
| type = string | |
| default = "t3.small" | |
| } | |
| variable "key_name" { | |
| type = string | |
| default = "mykey" | |
| } | |
| variable "vpc_security_group_ids" { | |
| type = list(string) | |
| default = ["sg-abcd1234"] | |
| } | |
| variable "subnet_id" { | |
| type = string | |
| default = "subnet-abcd1234" | |
| } | |
| variable "ami_id" { | |
| type = string | |
| default = "ami-abcd1234" | |
| } | |
| variable "tags" { | |
| type = map(string) | |
| default = { | |
| Name = "ubuntu2" | |
| } | |
| } | |
| variable "purestorage_target" { | |
| type = string | |
| default = "1.1.1." # IP of your CBS Array | |
| } | |
| variable "purestorage_apitoken" { | |
| type = string | |
| default = "1111-1111-111-111" # API Token for your CBS Array | |
| } | |
| variable "purestorage_host" { | |
| type = string | |
| default = "ubuntu2" | |
| } | |
| variable "purestorage_iqn" { | |
| type = list(string) | |
| default = ["iqn.2010-04.org.ipxe:ubuntu2"] | |
| } | |
| variable "purestorage_source_vol" { | |
| type = string | |
| default = "ubuntu24-goldtemplate" | |
| } | |
| terraform { | |
| required_providers { | |
| purestorage = { | |
| source = "devans10/flash" | |
| } | |
| aws = { | |
| source = "hashicorp/aws" | |
| } | |
| } | |
| } | |
| provider "aws" { | |
| region = var.aws_region | |
| } | |
| provider "purestorage" { | |
| target = var.purestorage_target | |
| api_token = var.purestorage_apitoken | |
| } | |
| resource "purestorage_host" "ubuntu2" { | |
| name = var.purestorage_host | |
| iqn = var.purestorage_iqn | |
| provider = purestorage | |
| volume { | |
| vol = purestorage_volume.boot.name | |
| lun = 1 | |
| } | |
| volume { | |
| vol = purestorage_volume.data1.name | |
| lun = 2 | |
| } | |
| } | |
| resource "purestorage_volume" "boot" { | |
| name = "${var.purestorage_host}-boot" | |
| source = var.purestorage_source_vol | |
| provider = purestorage | |
| } | |
| resource "purestorage_volume" "data1" { | |
| name = "${var.purestorage_host}-data1" | |
| size = 10737418240 | |
| provider = purestorage | |
| } | |
| resource "aws_instance" "ubuntu2" { | |
| ami = var.ami_id | |
| instance_type = var.instance_type | |
| vpc_security_group_ids = var.vpc_security_group_ids | |
| subnet_id = var.subnet_id | |
| key_name = var.key_name | |
| user_data = file("${path.module}/userdata3.sh") | |
| tags = var.tags | |
| depends_on = [purestorage_host.ubuntu2] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # PowerCLI Script to move a VM to a vVol Datastore and Apply a Policy and Replication Group | |
| # @davidstamen | |
| # https://davidstamen.com | |
| #Variables | |
| $vcname = "vcenter.fqdn" | |
| $vcusername = "administrator@vsphere.local" | |
| $vcpassword = "VMware1!" | |
| $vmname = "vm-vvol01" #Name of VM to Move | |
| $datastore = "vvol-ds" #Name of vVol Datastore | |
| $storagepolicy = "FlashArray Snap 1 HOURS" #Name of Storage Policy | |
| $replicationgroup = "arrayname:protectiongroupname" #Name of Replication Group (FlashArray Protection Group) preceeded by arrayname. Can be found using Get-SpbmReplicationGroup | |
| #Connect to vCenter Server | |
| $vc = Connect-VIServer -Server $vcname -user $vcusername -password $vcpassword -WarningAction SilentlyContinue -Force | |
| #Move VM to vVol | |
| $vm = Get-VM $vmname -Server $vc | |
| $ds = Get-Datastore $datastore -Server $vc | |
| Move-VM -VM $vm -Datastore $ds | |
| $disks = get-harddisk -VM $vm | |
| $policy = $vm, $disks | Get-SpbmEntityConfiguration | |
| $policy | Set-SpbmEntityConfiguration -StoragePolicy $storagepolicy -ReplicationGroup (Get-SpbmReplicationGroup -Server $vc -Name $replicationgroup) -Confirm:$false | |
| #Disconnect from vCenter Server | |
| Disconnect-VIServer * -Confirm:$false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Remove-VCSAUpdate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Set-VCSAUpdatePolicy -AutoStage $True | |
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Set-VCSAUpdatePolicy -CustomURL https://myinternalURL.com | |
| Set-VCSAUpdatePolicy -CustomURL Clear | |
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Set-VCSAUpdatePolicy -UsernameURL admin | |
| Set-VCSAUpdatePolicy -PasswordURL Password | |
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Set-VCSAUpdatePolicy -CheckSchedule Daily | |
| Set-VCSAUpdatePolicy -CheckSchedule WeeklySunday | |
| Set-VCSAUpdatePolicy -CheckSchedule WeeklyMonday | |
| Set-VCSAUpdatePolicy -CheckSchedule WeeklyTuesday | |
| Set-VCSAUpdatePolicy -CheckSchedule WeeklyWednesday | |
| Set-VCSAUpdatePolicy -CheckSchedule WeeklyThursday | |
| Set-VCSAUpdatePolicy -CheckSchedule WeeklyFriday | |
| Set-VCSAUpdatePolicy -CheckSchedule WeeklySaturday |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Start-VCSAUpdateInstall -Version "6.7.0.20100" -SSODomainPass "VMware1!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Start-VCSAUpdatePrecheck -Version "6.7.0.20100" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Start-VCSAUpdateStageandInstall -Version "6.7.0.20100" -SSODomainPass "VMware1!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Start-VCSAUpdateValidate -Version "6.7.0.20100" -SSODomainPass "VMware1!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1! | |
| Stop-VCSAUpdate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!ipxe | |
| # --- iPXE Variables --- | |
| set initiator-iqn iqn.2010-04.org.ipxe:ubuntu1 | |
| set target-ip1 172.18.10.68 | |
| set target-ip2 172.18.10.92 | |
| set array-iqn iqn.2010-06.com.purestorage:flasharray.22a52e281e6dbb52 | |
| # --- iPXE Boot Commands --- | |
| dhcp | |
| sanboot iscsi:${target-ip1}:::1:${array-iqn} iscsi:${target-ip2}:::1:${array-iqn} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MIME-Version: 1.0 | |
| Content-Type: multipart/mixed; boundary="==BOUNDARY==" | |
| --==BOUNDARY== | |
| MIME-Version: 1.0 | |
| Content-Type: text/ipxe; charset="utf-8" | |
| #!ipxe | |
| #============================================================================== | |
| # | |
| # Pre-Boot iSCSI Script | |
| # | |
| # This script is intended to handle the iPXE Boot to Allow Boot From SAN | |
| # | |
| #============================================================================== | |
| # --- iPXE Variables --- | |
| set initiator-iqn iqn.2010-04.org.ipxe:ubuntu1 | |
| set target-ip1 172.18.10.68 | |
| set target-ip2 172.18.10.92 | |
| set array-iqn iqn.2010-06.com.purestorage:flasharray.22a52e281e6dbb52 | |
| # --- iPXE Boot Commands --- | |
| dhcp | |
| sanboot iscsi:${target-ip1}:::1:${array-iqn} iscsi:${target-ip2}:::1:${array-iqn} | |
| --==BOUNDARY== | |
| MIME-Version: 1.0 | |
| Content-Type: text/x-shellscript; charset="utf-8" | |
| #!/bin/bash | |
| #============================================================================== | |
| # | |
| # Post-Boot Setup Script | |
| # | |
| # This script is intended to run after an OS has been SAN-booted via iPXE. | |
| # It configures the OS and Installs Packages | |
| # | |
| #============================================================================== | |
| # --- Helper function for logging --- | |
| log() { | |
| echo "=> $(date '+%Y-%m-%d %H:%M:%S') - $1" | |
| } | |
| # --- Initial System and User Setup --- | |
| log "Updating system and installing necessary packages..." | |
| apt update -y && apt upgrade -y | |
| apt install -y nginx | |
| log "Script finished" | |
| --==BOUNDARY==-- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MIME-Version: 1.0 | |
| Content-Type: multipart/mixed; boundary="==BOUNDARY==" | |
| --==BOUNDARY== | |
| MIME-Version: 1.0 | |
| Content-Type: text/ipxe; charset="utf-8" | |
| #!ipxe | |
| # --- iPXE Variables --- | |
| set initiator-iqn iqn.2010-04.org.ipxe:ubuntu2 | |
| set target-ip1 172.18.10.68 | |
| set target-ip2 172.18.10.92 | |
| set array-iqn iqn.2010-06.com.purestorage:flasharray.22a52e281e6dbb52 | |
| # --- iPXE Boot Commands --- | |
| dhcp | |
| sanboot iscsi:${target-ip1}:::1:${array-iqn} iscsi:${target-ip2}:::1:${array-iqn} | |
| --==BOUNDARY== | |
| MIME-Version: 1.0 | |
| Content-Type: text/x-shellscript; charset="utf-8" | |
| #!/bin/bash | |
| #============================================================================== | |
| # | |
| # Post-Boot iSCSI LUN Setup Script for Non-MPIO Environments | |
| # | |
| # This script is intended to run after an OS has been SAN-booted via iPXE. | |
| # It configures the OS to connect to a data LUN, format it, and mount it | |
| # using a persistent device name provided by the system. | |
| # | |
| #============================================================================== | |
| # --- Configuration --- | |
| # These variables should align with the iPXE script and your environment. | |
| ISCSI_TARGET_IP1="172.18.10.68" | |
| ISCSI_TARGET_IP2="172.18.10.92" | |
| INITIATOR_IQN="iqn.2010-04.org.ipxe:ubuntu2" | |
| VOLUME_MNT="/data" | |
| # --- End Configuration --- | |
| # --- Helper function for logging --- | |
| log() { | |
| echo "=> $(date '+%Y-%m-%d %H:%M:%S') - $1" | |
| } | |
| # --- Initial System and User Setup --- | |
| log "Updating system and installing necessary packages..." | |
| apt update -y && apt upgrade -y | |
| apt install -y open-iscsi multipath-tools fio | |
| # --- iSCSI Configuration and Login --- | |
| log "Starting and enabling iSCSI services..." | |
| systemctl enable --now iscsid.service | |
| log "Configuring initiator IQN to ${INITIATOR_IQN}..." | |
| echo "InitiatorName=${INITIATOR_IQN}" > /etc/iscsi/initiatorname.iscsi | |
| systemctl restart iscsid.service | |
| log "Discovering iSCSI targets..." | |
| iscsiadm -m discovery -t st -p ${ISCSI_TARGET_IP1} | |
| iscsiadm -m discovery -t st -p ${ISCSI_TARGET_IP2} | |
| log "Logging into iSCSI targets..." | |
| iscsiadm -m node -p ${ISCSI_TARGET_IP1} --login | |
| iscsiadm -m node -p ${ISCSI_TARGET_IP2} --login | |
| log "Setting iSCSI sessions to log in automatically on boot..." | |
| iscsiadm -m node -L automatic | |
| log "Increase iSCSI Sessions..." | |
| # | |
| log "Rescanning for new devices..." | |
| rescan-scsi-bus.sh | |
| log "Updating multipath configuration..." | |
| systemctl enable multipathd | |
| systemctl restart multipathd | |
| log "Mounting multipath device..." | |
| mkdir -p ${VOLUME_MNT} | |
| # Find the multipath device name | |
| disk=$(multipath -ll | head -n 1 | awk '{print $1}') | |
| log "Found multipath device: /dev/mapper/${disk}" | |
| # Check if a filesystem already exists on the device | |
| log "Checking for existing filesystem on /dev/mapper/${disk}..." | |
| if ! blkid /dev/mapper/${disk} > /dev/null 2>&1; then | |
| # No filesystem was found, so it's safe to format | |
| log "No filesystem detected. Formatting device with ext4..." | |
| mkfs.ext4 /dev/mapper/${disk} | |
| else | |
| # A filesystem already exists, so skip formatting | |
| log "Filesystem already exists on /dev/mapper/${disk}. Skipping format." | |
| fi | |
| # Check if an entry for the mount point already exists before adding it | |
| if ! grep -q " ${VOLUME_MNT} " /etc/fstab; then | |
| echo "Adding fstab entry for ${VOLUME_MNT}..." | |
| echo "/dev/mapper/${disk} ${VOLUME_MNT} ext4 defaults,nofail 0 2"| tee -a /etc/fstab | |
| systemctl daemon-reload | |
| else | |
| echo "fstab entry for ${VOLUME_MNT} already exists. Skipping." | |
| fi | |
| # Mount the device using the new fstab entry | |
| log "Mounting device..." | |
| mount -a | |
| log "Script finished. Multipath device mounted at ${VOLUME_MNT} and configured for persistence." | |
| --==BOUNDARY==-- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Install-Module -Name VMware.Community.VCSA.Update #Install the Module | |
| Get-VCSAUpdate #Check for Updates | |
| Copy-VCSAUpdate -Version "7.0.0.10300" #Stages the Update | |
| Get-VCSAUpdateStatus #Check status until `UPDATE_PENDING` | |
| Start-VCSAUpdatePrecheck -Version 7.0.0.10300 #Run Update Precheck | |
| Start-VCSAUpdateValidate -Version 7.0.0.10300 -SSODomainPass VMware1! #Run Update Validate | |
| Start-VCSAUpdateInstall -Version 7.0.0.10300 -SSODomainPass VMware1! #Run Update Install | |
| Get-VCSAUpdateStatus` # Check status until `UPDATE_COMPLETE` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Process function Secrets passed in | |
| $VC_CONFIG_FILE = "/var/openfaas/secrets/vc-ds-config" | |
| $VC_CONFIG = (Get-Content -Raw -Path $VC_CONFIG_FILE | ConvertFrom-Json) | |
| if($env:function_debug -eq "true") { | |
| Write-host "DEBUG: `"$VC_CONFIG`"" | |
| } | |
| # Process payload sent from vCenter Server Event | |
| $json = $args | ConvertFrom-Json | |
| if($env:function_debug -eq "true") { | |
| Write-Host "DEBUG: json=`"$($json | Format-List | Out-String)`"" | |
| } | |
| # import and configure Slack | |
| Import-Module PSSlack | Out-Null | |
| Import-module purestoragepowershellsdk| Out-Null | |
| #script | |
| $alarmName = ($json.data.alarm.name -replace "\n"," ") | |
| $datastoreName = $json.data.ds.name | |
| $alarmStatus = $json.data.to | |
| $vcenter = ($json.source -replace "/sdk","") | |
| $datacenter = $json.data.datacenter.name | |
| if($env:function_debug -eq "true") { | |
| Write-Host "DEBUG: alarmName: `"$alarmName`"" | |
| Write-host "DEBUG: datastoreName: `"$datastoreName`"" | |
| Write-Host "DEBUG: alarmStatus: `"$alarmStatus`"" | |
| Write-Host "DEBUG: vcenter: `"$vcenter`"" | |
| } | |
| if( ("$alarmName" -match "$($VC_CONFIG.VC_ALARM_NAME)") -and ([bool]($VC_CONFIG.DATASTORE_NAMES -match "$datastoreName")) -and ($alarmStatus -eq "yellow" -or $alarmStatus -eq "red" -or $alarmStatus -eq "green") ) { | |
| # Warning Email Body | |
| if($alarmStatus -eq "yellow") { | |
| $subject = ":warning: $($VC_CONFIG.SUBJECT)" | |
| $threshold = "warning" | |
| #takeaction | |
| $username = "$($VC_CONFIG.PURE_USERNAME)" | |
| $password = ConvertTo-SecureString "$($VC_CONFIG.PURE_PASSWORD)" -AsPlainText -Force | |
| $cred = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $password) | |
| $fa1 = New-PfaConnection -endpoint {myflasharray.lab.local} -credentials $cred -defaultarray -ignoreCertificateError | |
| $fa2 = New-PfaConnection -endpoint {myflasharray2.lab.local} -credentials $cred -nonDefaultArray -ignoreCertificateError | |
| Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings $false -ParticipateInCeip $false -Confirm:$false -Scope AllUsers| Out-Null | |
| $Server = Connect-VIServer $($VC_CONFIG.VC) -User $($VC_CONFIG.VC_USERNAME) -Password $($VC_CONFIG.VC_PASSWORD) -Force | out-null | |
| $datastore = Get-Datastore $datastoreName -Server $Server | |
| write-host "This is the " $datastore | |
| $connection = Get-PfaConnectionOfDatastore2 -flasharrays $fa1,$fa2 -datastore $datastore | |
| write-host "this is the Array" $connection.Endpoint | |
| $volume = get-pfaVolfromVMFS2 -datastore $datastore -flasharray $connection | |
| Write-Host $Datastore "is on" $connection.endpoint "and is" ($volume.size/1024/1024/1024) "GB" | |
| Resize-PfaVolume -Array $connection -VolumeName $volume.name -NewSize ($volume.size + 10737418240) -ErrorAction SilentlyContinue | |
| $volume = get-pfaVolfromVMFS2 -datastore $datastore -flasharray $connection | |
| $esxi = Get-View -Id ($Datastore.ExtensionData.Host |Select-Object -last 1 | Select-Object -ExpandProperty Key) | |
| $datastoreSystem = Get-View -Id $esxi.ConfigManager.DatastoreSystem | |
| $expandOptions = $datastoreSystem.QueryVmfsDatastoreExpandOptions($datastore.ExtensionData.MoRef) | |
| $expandOptions = $datastoreSystem.QueryVmfsDatastoreExpandOptions($datastore.ExtensionData.MoRef) | |
| $datastoreSystem.ExpandVmfsDatastore($datastore.ExtensionData.MoRef,$expandOptions.spec) | Out-Null | |
| Write-Host $Datastore "is now"($volume.size/1024/1024/1024) "GB" | |
| Disconnect-viserver * -confirm:$false | |
| $Body = "Datastore usage on $datastoreName has reached $threshold threshold.`r`n" | |
| $Body = $Body + @" | |
| vCenter Server: $vcenter | |
| Datacenter: $datacenter | |
| Datastore: $datastoreName | |
| $Datastore has been automatically expanded by 10GB | |
| "@ | |
| } | |
| elseif($alarmStatus -eq "red") { | |
| $subject = ":rotating_light: $($VC_CONFIG.SUBJECT)" | |
| $threshold = "error" | |
| #takeaction | |
| $username = "$($VC_CONFIG.PURE_USERNAME)" | |
| $password = ConvertTo-SecureString "$($VC_CONFIG.PURE_PASSWORD)" -AsPlainText -Force | |
| $cred = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $password) | |
| $fa1 = New-PfaConnection -endpoint {myflasharray.lab.local} -credentials $cred -defaultarray -ignoreCertificateError | |
| $fa2 = New-PfaConnection -endpoint {myflasharray2.lab.local} -credentials $cred -nonDefaultArray -ignoreCertificateError | |
| Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings $false -ParticipateInCeip $false -Confirm:$false -Scope AllUsers| Out-Null | |
| $Server = Connect-VIServer $($VC_CONFIG.VC) -User $($VC_CONFIG.VC_USERNAME) -Password $($VC_CONFIG.VC_PASSWORD) -Force | out-null | |
| $datastore = Get-Datastore $datastoreName -Server $Server | |
| write-host "This is the " $datastore | |
| $connection = Get-PfaConnectionOfDatastore2 -flasharrays $fa1,$fa2 -datastore $datastore | |
| write-host "this is the Array" $connection.Endpoint | |
| $volume = get-pfaVolfromVMFS2 -datastore $datastore -flasharray $connection | |
| Write-Host $Datastore "is on" $connection.endpoint "and is" ($volume.size/1024/1024/1024) "GB" | |
| Resize-PfaVolume -Array $connection -VolumeName $volume.name -NewSize ($volume.size + 21474836480) -ErrorAction SilentlyContinue | |
| $volume = get-pfaVolfromVMFS2 -datastore $datastore -flasharray $connection | |
| $esxi = Get-View -Id ($Datastore.ExtensionData.Host |Select-Object -last 1 | Select-Object -ExpandProperty Key) | |
| $datastoreSystem = Get-View -Id $esxi.ConfigManager.DatastoreSystem | |
| $expandOptions = $datastoreSystem.QueryVmfsDatastoreExpandOptions($datastore.ExtensionData.MoRef) | |
| $expandOptions = $datastoreSystem.QueryVmfsDatastoreExpandOptions($datastore.ExtensionData.MoRef) | |
| $datastoreSystem.ExpandVmfsDatastore($datastore.ExtensionData.MoRef,$expandOptions.spec) | Out-Null | |
| Write-Host $Datastore "is now"($volume.size/1024/1024/1024) "GB" | |
| Disconnect-viserver * -confirm:$false | |
| $Body = "Datastore usage on $datastoreName has reached $threshold threshold.`r`n" | |
| $Body = $Body + @" | |
| vCenter Server: $vcenter | |
| Datacenter: $datacenter | |
| Datastore: $datastoreName | |
| $Datastore has been automatically expanded by 20GB | |
| "@ | |
| } | |
| elseif($alarmStatus -eq "green") { | |
| $subject = "$($VC_CONFIG.SUBJECT)" | |
| $threshold = "normal" | |
| $Body = "Datastore usage on $datastoreName has reached $threshold threshold.`r`n" | |
| $Body = $Body + @" | |
| vCenter Server: $vcenter | |
| Datacenter: $datacenter | |
| Datastore: $datastoreName | |
| "@ | |
| } | |
| New-SlackMessageAttachment -Color $([System.Drawing.Color]::red) ` | |
| -Title "$Subject" ` | |
| -Text "$Body" ` | |
| -Fallback "$Subject" | | |
| New-SlackMessage -Channel $($VC_CONFIG.SLACK_CHANNEL) ` | |
| -IconEmoji :veba: | | |
| Send-SlackMessage -Uri $($VC_CONFIG.SLACK_URL) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| provider: | |
| name: openfaas | |
| gateway: https://veba.lab.local | |
| functions: | |
| veba-powercli-increaseds-pure: | |
| lang: powercli | |
| handler: ./handler | |
| image: {yourimagehere}:latest | |
| environment: | |
| write_debug: true | |
| read_debug: true | |
| function_debug: true | |
| secrets: | |
| - vc-ds-config | |
| annotations: | |
| topic: AlarmStatusChangedEvent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "SLACK_URL" : "https://hooks.slack.com/services/yourwebhookurl", | |
| "SLACK_CHANNEL" : "veba", | |
| "VC" : "vc01.lab.local", | |
| "VC_USERNAME" : "veba@lab.local", | |
| "VC_PASSWORD" : "VMware1!", | |
| "VC_ALARM_NAME" : "Datastore usage on disk", | |
| "DATASTORE_NAMES" : ["david-veba-01","david-veba-02"], | |
| "SUBJECT" : "Datastore Notification Alarm", | |
| "PURE_USERNAME" : "pureuser", | |
| "PURE_PASSWORD" : "SomethingSecure" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment