June 10, 2013 in Systems4 minutes
I had a few scripts that were written WAY before PowerTool was out of beta, and the only way I knew how to generate a Service Profile Template was to use manual XML calls. For instance:
1
2$cmd = "<configConfMos inHierarchical='true'>
3 <inConfigs>
4 <pair key='org-root/org-" + $orgName + "/ls-" + $serviceProfileName + "' >
5 <lsServer
6 agentPolicyName=''
7 biosProfileName=''
8 bootPolicyName='" + $bootPolicyName + "'
9 descr=''
10 dn='org-root/org-" + $orgName + "/ls-" + $serviceProfileName + "'
11 dynamicConPolicyName=''
12 extIPState='none'
13 hostFwPolicyName=''
14 identPoolName='" + $UUID_POOL_NAME + "'
15 localDiskPolicyName='default'
16 maintPolicyName='default'
17 mgmtAccessPolicyName=''
18 mgmtFwPolicyName=''
19 name='" + $serviceProfileName + "'
20 powerPolicyName='default'
21 scrubPolicyName=''
22 srcTemplName=''
23 statsPolicyName='default'
24 status='created'
25 type='initial-template'
26 usrLbl=''
27 uuid='0'
28 vconProfileName=''>
29 <vnicEther
30 adaptorProfileName='VMWare'
31 addr='derived'
32 adminVcon='any'
33 identPoolName=''
34 mtu='1500'
35 name='" + $VNIC_A_NAME + "'
36 nwCtrlPolicyName=''
37 nwTemplName='" + $VNIC_TEMPLATE_A_NAME + "'
38 order='3'
39 pinToGroupName=''
40 qosPolicyName=''
41 rn='ether-" + $VNIC_A_NAME + "'
42 statsPolicyName='default'
43 status='created'
44 switchId='" + $switchId + "'>
45 </vnicEther>
46 <vnicEther
47 adaptorProfileName='VMWare'
48 addr='derived'
49 adminVcon='any'
50 identPoolName=''
51 mtu='1500'
52 name='" + $VNIC_B_NAME + "'
53 nwCtrlPolicyName=''
54 nwTemplName='" + $VNIC_TEMPLATE_B_NAME + "'
55 order='4'
56 pinToGroupName=''
57 qosPolicyName=''
58 rn='ether-" + $VNIC_B_NAME + "'
59 statsPolicyName='default'
60 status='created'
61 switchId='" + $switchId + "'>
62 </vnicEther>
63 <vnicFcNode
64 addr='pool-derived'
65 identPoolName='" + $WWNN_POOL_NAME + "'
66 rn='fc-node' >
67 </vnicFcNode>
68 <vnicFc
69 adaptorProfileName='VMWare'
70 addr='derived'
71 adminVcon='any'
72 identPoolName=''
73 maxDataFieldSize='2048'
74 name='" + $VHBA_A_NAME + "'
75 nwTemplName='" + $VHBA_TEMPLATE_A_NAME + "'
76 order='1'
77 persBind='disabled'
78 persBindClear='no'
79 pinToGroupName=''
80 qosPolicyName=''
81 rn='fc-" + $VHBA_A_NAME + "'
82 statsPolicyName='default'
83 status='created'
84 switchId='" + $switchId + "'>
85 </vnicFc>
86 <vnicFc
87 adaptorProfileName='VMWare'
88 addr='derived'
89 adminVcon='any'
90 identPoolName=''
91 maxDataFieldSize='2048'
92 name='" + $VHBA_B_NAME + "'
93 nwTemplName='" + $VHBA_TEMPLATE_B_NAME + "'
94 order='2'
95 persBind='disabled'
96 persBindClear='no'
97 pinToGroupName=''
98 qosPolicyName=''
99 rn='fc-" + $VHBA_B_NAME+ "'
100 statsPolicyName='default'
101 status='created'
102 switchId='" + $switchId + "'>
103 </vnicFc>
104 <lsRequirement
105 name='" + $SERVER_POOL_NAME + "'
106 qualifier=''
107 restrictMigration='no'
108 rn='pn-req' >
109 </lsRequirement>
110 <lsPower
111 rn='power'
112 state='down' >
113 </lsPower>
114 </lsServer>
115 </pair>
116 </inConfigs>
117 </configConfMos>"
118
119Invoke-UcsXml -XmlQuery $cmd
If most of your script is composed of normal cmdlets, this looks pretty absurd - so if you can avoid calling direct XML, you should. Same thing if you’re trying to create your own PowerTool-esque library (say, with Python instead of bleh PowerShell), you would take these XML calls and hide them away in modular functions so that you can call them with a single command and a few arguments.
Most other templates (like vNIC and vHBA) have a dedicated cmdlet for creating those constructs. For instance:
1 Add-UcsVhbaTemplate -Org $organization -Name "BARE-NONP-B" -Descr "Non-Prod Baremetal Fabric B" -IdentPoolName "WWPN-BARE-NONP-B" -SwitchId A -TemplType "updating-template"
As I tab through the cmdlets that start with “Add-UcsServiceProfile” I noticed there was no “Add-UcsServiceProfileTemplate” as one would expect.
Poking around in the release notes for v1.0 of the PowerTool library, I noticed that one of the new features was the ability to filter Service Profiles based on type (aimed at being able to get all the Service Profiles in the system:
1 # Get all Service Profile Templates.
2
3 Get-UcsServiceProfile -Filter 'Type -clike *-template' | select Ucs,Dn,Name
So I ran a Get-Help for this cmdlet:
1 -Type <string>
2 Specifies if service profile or service profile template needs to be created. Valid values are: initial-template, instance, updating-template
3
4 Required? true
5 Position? named
6 Default value
7 Accept pipeline input?
8 Accept wildcard characters?
So….at least in this version of PowerTool, the same cmdlet is used to create SPs and SPTs, just need to set this “flag” to one of those three options.