-
Notifications
You must be signed in to change notification settings - Fork 4
/
Create-StorSimpleCloudAppliance.ps1
182 lines (153 loc) · 8.01 KB
/
Create-StorSimpleCloudAppliance.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<#
.DESCRIPTION
This script creates a StorSimple 8010/8020 cloud appliance.
This quick start requires the Azure PowerShell module version 3.6 or later.
Run "Get-Module -ListAvailable AzureRM"" to find the version.
If you need to install or upgrade, see Install Azure PowerShell module from https://docs.microsoft.com/en-us/powershell/azure/install-azurerm-ps.
Steps to execute the script:
----------------------------
1. Open powershell, create a new folder & change directory to the folder.
mkdir C:\scripts\StorSimpleSDKTools
cd C:\scripts\StorSimpleSDKTools
2. Download & execute the script from github.
wget https://raw.githubusercontent.com/anoobbacker/storsimpledevicemgmttools/master/Create-StorSimpleCloudAppliance.ps1 -Out Create-StorSimpleCloudAppliance.ps1
.\Create-StorSimpleCloudAppliance.ps1 -CloudEnv [AzureCloud| -SubscriptionId [subcription id] -ResourceGroupVM [virtual machine resource group] -Name [appliance name] -ModelNumber [8010|8020] -VirtualNetwork [vnet] -Subnet [subnet] -StorageAccount [storage name] -VmSize [vmsize] -RegistrationKey [key]
----------------------------
.PARAMS
CloudEnv: Input the Azure Cloud Environment.
SubscriptionId: Input the ID of the subscription.
ResourceGroupVM: Input the name of the resource group in which the virtual machine and nic would be created.
Name: Input the name of the cloud appliance.
ModelNumber: Input the appliance model number.
VirtualNetwork: Input the name of the virtual network.
Subnet: Input the name of the subnet of given virtual network.
StorageAccount: Input the name of the storage account where the 8010/8020 appliance needs to be created.
VmSize: Input the VM size. Possible values: Standard_DS3, Standard_DS3_v2, Standard_A3
RegistrationKey: Input the registration key.
#>
param(
[parameter(Mandatory = $true, HelpMessage = "Input the Azure Cloud Environment.")]
[ValidateSet('AzureCloud', 'AzureChinaCloud','AzureUSGovernment', 'AzureGermanCloud')]
[String] $CloudEnv,
[parameter(Mandatory = $true, HelpMessage = "Input the ID of the subscription.")]
[String] $SubscriptionId,
[parameter(Mandatory=$true, HelpMessage="Input the name of the resource group where VM will get created.")]
[string] $ResourceGroupVM,
[parameter(Mandatory=$true, HelpMessage="Input the name of the cloud appliance.")]
[string] $Name,
[parameter(Mandatory=$true, HelpMessage="Input the appliance model number.")]
[ValidateSet('8010', '8020')]
[string] $ModelNumber,
[parameter(Mandatory=$true, HelpMessage="Input the name of the virtual network.")]
[string] $VirtualNetwork,
[parameter(Mandatory=$true, HelpMessage="Input the name of the subnet of given virtual network.")]
[string] $Subnet,
[parameter(Mandatory=$true, HelpMessage="Input the name of the storage account.")]
[string] $StorageAccount,
[parameter(Mandatory=$true, HelpMessage="Input the VM size.")]
[ValidateSet('Standard_DS3', 'Standard_DS3_v2', 'Standard_A3')]
[string] $VmSize,
[parameter(Mandatory=$true, HelpMessage="Input the Registration key.")]
[string] $RegistrationKey
)
function ValidateInputs()
{
$vnetLocation = $vnet.Location
$saLocation = $storageAcc.Location
if ($vnetLocation -notlike $saLocation)
{
#throw [System.ArgumentException] "Location of virtual netowrk is not same as of storage account"
}
if(!($vnet.Subnets | foreach {$_.Name -like $Subnet}))
{
throw [System.ArgumentException] "Subnet name passed could not be found in the virtual network"
}
if($ModelNumber -eq "8010")
{
if($storageAcc.Sku.Name -like "PremiumLRS")
{
throw [System.ArgumentException] "Premium LRS storage account type is not supported for 8010 model"
}
if($VmSize -notlike "Standard_A3")
{
throw [System.ArgumentException] "Only Standard A3 VM size is supported for 8010 model"
}
}
if($ModelNumber -eq "8020")
{
if($storageAcc.Sku.Name -notlike "PremiumLRS")
{
throw [System.ArgumentException] "Only Premium LRS storage account type is supported for 8020 model"
}
if($VmSize -notlike "Standard_DS3" -and $VmSize -notlike "Standard_DS3_v2")
{
throw [System.ArgumentException] "Only Standard DS3 VM size(s) are supported for 8020 model"
}
}
}
# Print method
Function PrettyWriter($Content, $Color = "Yellow") {
Write-Host $Content -Foregroundcolor $Color
}
# Logon to Azure ARM
$AzureCloudenv = Get-AzureRmEnvironment $CloudEnv
$AzureAcct = Add-AzureRmAccount -Environment $AzureCloudenv
# Set context
$AzureRmCtx = Set-AzureRmContext -SubscriptionId $SubscriptionId
$vnetList = Get-AzureRmVirtualNetwork | where Name -EQ $VirtualNetwork
$storageAcc = Get-AzureRmStorageAccount | where StorageAccountName -EQ $StorageAccount
if($vnetList.length -eq 0){
throw [System.ArgumentException] "Vnet with $VirtualNetwork not found in subscription $SubscriptionId"
}
elseif($vnetList.length -gt 1){
$vnet = $vnetList[0]
$vnetresourcegroupname = $vnet.ResourceGroupName
PrettyWriter "More than one vnet with $VirtualNetwork found in subscription $SubscriptionId. Using virtual network in resource group $vnetresourcegroupname"
}
else {
$vnet = $vnetList[0]
}
# Validate
ValidateInputs
$location = $vnet.Location
$subnetObj = $vnet.Subnets | where {$_.Name -like $Subnet}
$random = Get-Random
$nicName = $Name+$random
$containerName = $Name+$random
$availableIpAddr = $vnet | Test-AzureRmPrivateIPAddressAvailability -IPAddress $subnetObj.AddressPrefix.Split('/')[0]
$avaialbleIp = $availableIpAddr.AvailableIPAddresses[0]
$subnetId = $subnetObj.Id
$iPconfig = New-AzureRmNetworkInterfaceIpConfig -Name "ipconfig1" -PrivateIpAddressVersion IPv4 -PrivateIpAddress $avaialbleIp -SubnetId $subnetId
$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroup $ResourceGroupVM -Location $location -IpConfiguration $iPconfig
$nicId = $nic.Id
if($RegistrationKey.LastIndexOf(':') -ne -1)
{
$TrimmedRegKey=$RegistrationKey.Substring(0, $RegistrationKey.LastIndexOf(':'))
}
else
{
$TrimmedRegKey=$RegistrationKey
}
$customData = ""
$customData += "`r`nModelNumber=$ModelNumber"
$customData += "`r`nRegistrationKey=$TrimmedRegKey"
$customData += "`r`nTrackingId=$random"
$secpasswd = ConvertTo-SecureString "StorSim1StorSim1" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("hcstestuser", $secpasswd)
$vmConfig = New-AzureRmVMConfig -VMName $Name -VMSize $VmSize | `
Set-AzureRmVMOperatingSystem -ComputerName $Name -Credential $cred -CustomData $customData -Windows | `
Set-AzureRmVMOSDisk -Name "os" -VhdUri ($storageAcc.PrimaryEndpoints.Blob.ToString() + $containerName + "\os.vhd") -CreateOption FromImage | `
Add-AzureRmVMDataDisk -Name "datadisk1" -DiskSizeInGB 1023 -VhdUri ($storageAcc.PrimaryEndpoints.Blob.ToString() + $containerName + "\datadisk1.vhd") -CreateOption empty -Lun 0 | `
Add-AzureRmVMDataDisk -Name "datadisk2" -DiskSizeInGB 1023 -VhdUri ($storageAcc.PrimaryEndpoints.Blob.ToString() + $containerName + "\datadisk2.vhd") -CreateOption empty -Lun 1 | `
Add-AzureRmVMDataDisk -Name "datadisk3" -DiskSizeInGB 1023 -VhdUri ($storageAcc.PrimaryEndpoints.Blob.ToString() + $containerName + "\datadisk3.vhd") -CreateOption empty -Lun 2 | `
Add-AzureRmVMDataDisk -Name "datadisk4" -DiskSizeInGB 1023 -VhdUri ($storageAcc.PrimaryEndpoints.Blob.ToString() + $containerName + "\datadisk4.vhd") -CreateOption empty -Lun 3 | `
Set-AzureRmVMSourceImage -PublisherName MicrosoftHybridCloudStorage -Offer StorSimple -Skus StorSimple-Garda-8000-Series -Version 9600.17845.170810 | `
Add-AzureRmVMNetworkInterface -Id $nicId | Set-AzureRmVMBootDiagnostics -Disable
try {
$vm = New-AzureRmVM -ResourceGroupName $ResourceGroupVM -Location $location -VM $vmConfig
PrettyWriter "$Name successfully got created."
} catch {
# Print error details
Write-Error $_.Exception.Message
break
}