Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.31 KB | None | 0 0
  1. ###########################################################################################################################
  2. # Cisco UCS automated Configuration and Provisioning Script Version 0.9 #
  3. # #
  4. # Planned Enhancements
  5. # * Add FC Trunking #
  6. # * Chassis acknowledge after discovery #
  7. # * After successful UCSC registration - change from Local to Global Policies #
  8. # * Check status of FC/Uplink PO - bounce and wait #
  9. # * Disable unused FC uplinks
  10. # Global Profile
  11. # * Create Template ( create sp with below ) #
  12. # * Assign Scrub-Policy
  13. # * Host-Frimware Package
  14. # * ESXI bare metal
  15. #
  16. # Apply Scrub Policy - REboot - Unapply Scrub-Policy
  17. # zzScrubPolicy
  18. ###########################################################################################################################
  19.  
  20. Param (
  21. [Parameter(Mandatory=$True,Position=0,ValueFromPipelineByPropertyName=$True)][alias("ucsvip")][String]$UCS_Fabric_Interconnect_NAME,
  22. [Parameter(Mandatory=$True,Position=1,ValueFromPipelineByPropertyName=$True)][alias("ucscip")][String]$UCS_Central_IP,
  23. [Parameter(Mandatory=$True,Position=2,ValueFromPipelineByPropertyName=$True)][alias("fitype")][String]$hfi_hfi3_dfi_mfi,
  24. #[Parameter(Mandatory=$True,Position=3,ValueFromPipelineByPropertyName=$True)][alias("sertype")][String]$chassis_cseries_ignored,
  25. [Parameter(Mandatory=$True,Position=4,ValueFromPipelineByPropertyName=$True)][alias("notype")][Int]$no_chassis_or_cseries,
  26. [Parameter(Mandatory=$True,Position=5,ValueFromPipelineByPropertyName=$True)][alias("usr")][String]$ucsadmin,
  27. [Parameter(Mandatory=$True)][Security.SecureString]$ucspsswd,
  28. [Parameter(Mandatory=$True)][Security.SecureString]$UCS_Central_Shared_Secret
  29. )
  30.  
  31.  
  32. #######################
  33. # Input variables here#
  34. #######################
  35.  
  36. #Convert User Friendly Variables to Easy-To-Type
  37. $ucsvip = $UCS_Fabric_Interconnect_NAME
  38. $ucscip = $UCS_Central_IP
  39. $ucscpsswd = $UCS_Central_Shared_Secret
  40. $fitype = $hfi_hfi3_dfi_mfi
  41. $sertype = $chassis_cseries_ignored
  42. $notype = $no_chassis_or_cseries
  43.  
  44. #Convert Fi Type to Server Ports
  45. if($fitype -eq "mfi") {$noports = 1}
  46. elseif ($fitype -eq "hfi3") {$noports = 2}
  47. else {$noports = 4}
  48.  
  49. #DNS + NTP Values // Required for UCS Central
  50. $dns1 = "10.98.14.253"
  51. $dns2 = "10.98.14.254"
  52. $ntp1 = "45.42.35.183"
  53. $ntp2 = "ntp01.epichosted.com"
  54. $timezone = "America/Chicago"
  55.  
  56. #Total No of FC ports Configured per FI
  57. if ($fitype -eq "hfi3") {$maxfc = 10}
  58. else {$maxfc = 8}
  59.  
  60. #Total No of Uplink ports Configured per FI
  61. $maxup = 4
  62.  
  63. #Uplink PortChannel Settings
  64. $uplinkpo_a = 71
  65. $uplinkpo_b = 72
  66. $uplinkponm_a = ""
  67. $uplinkponm_b = ""
  68.  
  69. #SAN PortChannel Settings
  70. $fcpo_ah = 51
  71. $fcpo_ac = 53
  72. $fcpo_bh = 52
  73. $fcpo_bc = 54
  74. $fcpo_acname = "Clarity_fcpoA"
  75. $fcpo_ahname = "NonClarity_fcpoA"
  76. $fcpo_bcname = "Clarity_fcpoB"
  77. $fcpo_bhname = "NonClarity_fcpoB"
  78.  
  79.  
  80.  
  81. #######################################################
  82. # Function Configure Fabric Interconnect Server Ports #
  83. #######################################################
  84. function ConfigureServerPorts ($noports, $notype){
  85.  
  86. $portstart = 1
  87.  
  88. for($i=0; $i -lt $notype; $i++){
  89. Start-UcsTransaction
  90. for($j=0; $j -lt $noports; $j++){
  91. $goserv_a = Get-UcsFabricServerCloud -Id A | Add-UcsServerPort -AdminState enabled -PortId $portstart -SlotId 1
  92. $goserv_b = Get-UcsFabricServerCloud -Id B | Add-UcsServerPort -AdminState enabled -PortId $portstart -SlotId 1
  93. $portstart++
  94. }
  95. Complete-UcsTransaction
  96. }
  97. }
  98.  
  99. #######################################################
  100. # Function Configure Fabric Interconnect Eth Up #
  101. #######################################################
  102. function ConfigureUplinkPorts ($fitype, $maxup){
  103.  
  104. if($fitype -eq "hfi"){
  105. $slotvar = 1
  106. $portstart = 48
  107. }
  108. else{
  109. $slotvar = 2
  110. $portstart = 8
  111. }
  112.  
  113. Start-UcsTransaction
  114. for($j=0; $j -lt $maxup; $j++){
  115. $golan_a = Get-UcsFiLanCloud -Id A | Add-UcsUplinkPort -ModifyPresent -AdminState disabled -SlotId $slotvar -PortId $portstart -UsrLbl "Uplink Port"
  116. $golan_b = Get-UcsFiLanCloud -Id B | Add-UcsUplinkPort -ModifyPresent -AdminState disabled -SlotId $slotvar -PortId $portstart -UsrLbl "Uplink Port"
  117. $portstart--
  118. }
  119. Complete-UcsTransaction
  120. }
  121.  
  122. #######################################################
  123. # Function Configure Fabric Interconnect Up PO #
  124. #######################################################
  125. function ConfigureUplinkPortChannel ($fitype, $maxup){
  126.  
  127. if($fitype -eq "hfi"){
  128. $slotvar = 1
  129. $portstart = 48
  130. }
  131. else{
  132. $slotvar = 2
  133. $portstart = 8
  134. }
  135.  
  136. Start-UcsTransaction
  137. $gopo_a = Get-UcsFiLanCloud -Id A | Add-UcsUplinkPortChannel -AdminState disabled -Name $uplinkponm_a -PortId $uplinkpo_a
  138. $gopo_b = Get-UcsFiLanCloud -Id B | Add-UcsUplinkPortChannel -AdminState disabled -Name $uplinkponm_a -PortId $uplinkpo_b
  139.  
  140. for($j=0; $j -lt $maxup; $j++){
  141. $gopo_a | Add-UcsUplinkPortChannelMember -ModifyPresent -AdminState enabled -PortId $portstart -SlotId $slotvar
  142. $gopo_b | Add-UcsUplinkPortChannelMember -ModifyPresent -AdminState enabled -PortId $portstart -SlotId $slotvar
  143. $portstart--
  144. }
  145. Complete-UcsTransaction
  146. }
  147.  
  148. #######################################################
  149. # Function Configure Fabric Interconnect UP to FC #
  150. #######################################################
  151. function ConfigureUnifiedPorts ($fitype, $maxfc){
  152.  
  153. if($fitype -eq "hfi"){ $slotvar = 4 }
  154. else { $slotvar = 2 }
  155.  
  156. $portstart = 16
  157.  
  158. Start-UcsTransaction
  159. for($j=0; $j -lt $maxfc; $j++){
  160. $gosan_a = Get-UcsFiSanCloud -Id A | Add-UcsFcUplinkPort -ModifyPresent -AdminState enabled -SlotId $slotvar -PortId $portstart
  161. $gosan_b = Get-UcsFiSanCloud -Id B | Add-UcsFcUplinkPort -ModifyPresent -AdminState enabled -SlotId $slotvar -PortId $portstart
  162. $portstart--
  163. }
  164. Complete-UcsTransaction
  165. }
  166.  
  167. #######################################################
  168. # Function Configure Fabric Interconnect FC PO #
  169. #######################################################
  170. function ConfigureFCPortChannel ($fitype){
  171.  
  172. if($fitype -eq "hfi"){
  173. $slotvar = 4
  174. $maxfcpo = 2
  175. $portstart = 16
  176.  
  177. $portstart = ExecuteFCPortChannel $maxfcpo $portstart $slotvar $fcpo_ahname $fcpo_bhname $fcpo_ah $fcpo_bh
  178. #Function returns array of executed functions and then final value. This sets to that final value
  179. $portstart = $portstart[-1]
  180.  
  181. ExecuteFCPortChannel $maxfcpo $portstart $slotvar $fcpo_acname $fcpo_bcname $fcpo_ac $fcpo_bc
  182.  
  183. }
  184. elseif($fitype -eq "mfi"){
  185. $slotvar = 2
  186. $maxfcpo = 4
  187. $portstart = 16
  188.  
  189. ExecuteFCPortChannel $maxfcpo $portstart $slotvar $fcpo_ahname $fcpo_bhname $fcpo_ah $fcpo_bh
  190.  
  191. }
  192. elseif($fitype -eq "dfi"){
  193. $slotvar = 2
  194. $maxfcpo = 2
  195. $portstart = 16
  196.  
  197. ExecuteFCPortChannel $maxfcpo $portstart $slotvar $fcpo_ahname $fcpo_bhname $fcpo_ah $fcpo_bh
  198.  
  199. }
  200. else{}
  201.  
  202. }
  203.  
  204.  
  205. #######################################################
  206. # Function Execute Fabric Interconnect FC PO #
  207. #######################################################
  208. function ExecuteFCPortChannel ($maxfcpo, $portstart, $slotvar, $fcpo_aname, $fcpo_bname, $fcpo_a, $fcpo_b){
  209.  
  210. Start-UcsTransaction
  211. $gosanpo_a = Get-UcsFiSanCloud -Id A | Add-UcsFcUplinkPortChannel -AdminSpeed auto -AdminState disabled -Name $fcpo_aname -PortId $fcpo_a
  212. $gosanpo_b = Get-UcsFiSanCloud -Id B | Add-UcsFcUplinkPortChannel -AdminSpeed auto -AdminState disabled -Name $fcpo_bname -PortId $fcpo_b
  213.  
  214. for($j=0; $j -lt $maxfcpo; $j++){
  215. $gosanpo_a | Add-UcsFabricFcSanPcEp -ModifyPresent -AdminState enabled -SlotId $slotvar -PortId $portstart
  216. $gosanpo_b | Add-UcsFabricFcSanPcEp -ModifyPresent -AdminState enabled -SlotId $slotvar -PortId $portstart
  217. $portstart--
  218. }
  219. Complete-UcsTransaction
  220.  
  221. Start-UcsTransaction
  222. $gosanpo_a = Get-UcsFiSanCloud -Id A | Get-UcsFcUplinkPortChannel -Name $fcpo_aname | Set-UcsFcUplinkPortChannel -AdminState enabled -Force
  223. $gosanpo_b = Get-UcsFiSanCloud -Id B | Get-UcsFcUplinkPortChannel -Name $fcpo_bname | Set-UcsFcUplinkPortChannel -AdminState enabled -Force
  224. Complete-UcsTransaction
  225.  
  226. $portstart
  227.  
  228. }
  229.  
  230.  
  231. ######################################
  232. # Function Configure QoS Class #
  233. ######################################
  234. function ConfigureQOSClass {
  235.  
  236. Start-UcsTransaction
  237. Get-UcsQosClass -priority "platinum" | Set-UcsQosClass -mtu 9000 -AdminState disabled -Force
  238. Get-UcsQosClass -priority "gold" | Set-UcsQosClass -Weight 2 -mtu 9000 -AdminState enabled -Force
  239. Get-UcsQosClass -priority "silver" | Set-UcsQosClass -Weight "best-effort" -mtu 9000 -AdminState enabled -Force
  240. Get-UcsQosClass -priority "bronze" | Set-UcsQosClass -Weight "best-effort" -mtu 9000 -AdminState enabled -Force
  241. Set-UcsBestEffortQosClass -Weight 2 -mtu 9000 -Force
  242. Set-UcsFcQosClass -Weight 4 -Force
  243. Complete-UcsTransaction
  244.  
  245. }
  246.  
  247. ##########################################
  248. # Function Configure MISC Settings #
  249. ##########################################
  250. function ConfigureMISCSettings {
  251.  
  252. # Set Global System Policies for chassis discovery and power #
  253. Get-UcsChassisDiscoveryPolicy | Set-UcsChassisDiscoveryPolicy -Action 4-link -LinkAggregationPref port-channel -Rebalance user-acknowledged -Force
  254. Get-UcsPowerControlPolicy | Set-UcsPowerControlPolicy -Redundancy grid -Force
  255.  
  256. # Create maintenance policy #
  257. Get-UcsOrg -Level root | Add-UcsMaintenancePolicy -Descr "User acknowledge is required to reboot a server after a disruptive change" -Name user-acknowledge -UptimeDisr user-ack
  258.  
  259. # Set UCS Admin Settings #
  260. Get-UcsNativeAuth | Set-UcsNativeAuth -ConLogin local -DefLogin local -DefRolePolicy no-login -Force
  261. Add-UcsDnsServer -Name $dns1
  262. Add-UcsDnsServer -Name $dns2
  263. Set-UcsTimezone -Timezone $timezone -Force
  264. Add-UcsNtpServer -Name $ntp1
  265. Add-UcsNtpServer -Name $ntp2
  266.  
  267. }
  268.  
  269. #############################
  270. # (Y) Add to UCS Central #
  271. #############################
  272. function RegisterUCSC {
  273. #$password = $ucscpsswd | ConvertTo-SecureString -AsPlainText -Force
  274. Register-UcsCentral -Name $ucscip -SharedSecret $ucscpsswd
  275. }
  276.  
  277.  
  278. #########################################
  279. # Import the Cisco UCS PowerTool module #
  280. #########################################
  281. Import-Module CiscoUcsPS
  282.  
  283. ############################################
  284. # Authenticate to UCSM with the admin user #
  285. ############################################
  286. $user = $ucsadmin
  287. $password = $ucspsswd
  288. $cred = New-Object system.Management.automation.PSCredential($user, $password)
  289.  
  290. # Clear out Connected UCS Domains
  291. Disconnect-Ucs
  292.  
  293. $handle1 = Connect-Ucs -Name $ucsvip -Credential $cred
  294.  
  295. #Verify Connection to UCS Manager
  296. $connected = Get-UcsPSSession
  297. if ($connected -eq $null) {
  298. WriteLog "Error connecting to UCS Manager!"
  299. Return
  300. }
  301.  
  302. ConfigureServerPorts $noports $notype
  303.  
  304. ConfigureUplinkPorts $fitype $maxup
  305.  
  306. ConfigureUplinkPortChannel $fitype $maxup
  307.  
  308. ConfigureUnifiedPorts $fitype $maxfc
  309.  
  310. #EnableFCTrunking
  311.  
  312. ConfigureFCPortChannel $fitype
  313.  
  314. ConfigureQOSClass
  315.  
  316. ConfigureMISCSettings
  317.  
  318. RegisterUCSC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement