-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathgetUcsProp.py
More file actions
executable file
·207 lines (171 loc) · 6.95 KB
/
Copy pathgetUcsProp.py
File metadata and controls
executable file
·207 lines (171 loc) · 6.95 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/python
# Copyright 2013 Cisco Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script retrieves UCS inventory
# Usage: getUcsProp.py [options]
#
# Options:
# -h, --help show this help message and exit
# -i IP, --ip=IP [Mandatory] UCSM IP Address
# -u USERNAME, --username=USERNAME
# [Mandatory] Account Username for UCSM Login
# -p PASSWORD, --password=PASSWORD
# [Mandatory] Account Password for UCSM Login
#
import getpass
import optparse
from UcsSdk import *
def getpassword(prompt):
if platform.system() == "Linux":
return getpass.unix_getpass(prompt=prompt)
elif platform.system() == "Windows" or platform.system() == "Microsoft":
return getpass.win_getpass(prompt=prompt)
else:
return getpass.getpass(prompt=prompt)
# Get Ethernet mode
def getEthernetMode(handle):
molist = handle.GetManagedObject(None, None, {OrgOrg.DN:"fabric/lan"})
if (molist != None):
for mo in molist:
for prop in UcsUtils.GetUcsPropertyMetaAttributeList(mo.propMoMeta.name):
if(str(prop) == "Mode"):
ethmode = mo.getattr(prop)
return ethmode
# Get software version
def getSwVersion(handle):
molist = handle.GetManagedObject(None, None, {OrgOrg.DN:"sys/mgmt/fw-system"})
if (molist != None):
for mo in molist:
for prop in UcsUtils.GetUcsPropertyMetaAttributeList(mo.propMoMeta.name):
if(str(prop) == "Version"):
version = mo.getattr(prop)
return version
# Get HA mode
def getHaMode(handle):
molist = handle.GetManagedObject(None, None, {OrgOrg.DN:"sys"})
if (molist != None):
for mo in molist:
for prop in UcsUtils.GetUcsPropertyMetaAttributeList(mo.propMoMeta.name):
if(str(prop) == "Mode"):
hamode = mo.getattr(prop)
return hamode
# Get FI model(for cluster 2 models will be returned)
def getFiModel(handle, hamode):
fi_model = []
molist = handle.GetManagedObject(None, None, {OrgOrg.DN:"sys/switch-A"})
if (molist != None):
for mo in molist:
for prop in UcsUtils.GetUcsPropertyMetaAttributeList(mo.propMoMeta.name):
if(str(prop) == "Model"):
fi_model.append(mo.getattr(prop))
# Get FI Model for B if its cluster
if (hamode == 'cluster'):
molist = handle.GetManagedObject(None, None, {OrgOrg.DN:"sys/switch-B"})
if (molist != None):
for mo in molist:
for prop in UcsUtils.GetUcsPropertyMetaAttributeList(mo.propMoMeta.name):
if(str(prop) == "Model"):
fi_model.append(mo.getattr(prop))
return fi_model
# Get Blade chassis model details
def getBladeDetail(handle):
chassis_model = []
server_model = []
molist = handle.GetManagedObject(None, EquipmentChassis.ClassId())
chassis_cnt = 0
if (molist != None):
for mo in molist:
chassis_cnt = chassis_cnt + 1
for prop in UcsUtils.GetUcsPropertyMetaAttributeList(mo.propMoMeta.name):
if(str(prop) == "Model"):
chassis_model.append(mo.getattr(prop))
molist1 = handle.GetManagedObject(None, ComputeBlade.ClassId())
server_cnt = 0
if (molist1 != None):
for mo1 in molist1:
server_cnt = server_cnt + 1
for prop in UcsUtils.GetUcsPropertyMetaAttributeList(mo1.propMoMeta.name):
if(str(prop) == "Model"):
server_model.append(mo1.getattr(prop))
return chassis_model, server_model
# Get Rack server model details
def getRackDetail(handle):
rack_model = []
molist = handle.GetManagedObject(None, ComputeRackUnit.ClassId())
rack_cnt = 0
if (molist != None):
for mo in molist:
rack_cnt = rack_cnt + 1
for prop in UcsUtils.GetUcsPropertyMetaAttributeList(mo.propMoMeta.name):
if(str(prop) == "Model"):
rack_model.append(mo.getattr(prop))
return rack_model
if __name__ == "__main__":
handle = UcsHandle()
try:
parser = optparse.OptionParser()
parser.add_option('-i', '--ip',dest="ip",
help="[Mandatory] UCSM IP Address")
parser.add_option('-u', '--username',dest="userName",
help="[Mandatory] Account Username for UCSM Login")
parser.add_option('-p', '--password',dest="password",
help="[Mandatory] Account Password for UCSM Login")
(options, args) = parser.parse_args()
if not options.ip:
parser.print_help()
parser.error("Provide UCSM IP Address")
if not options.userName:
parser.print_help()
parser.error("Provide UCSM UserName")
if not options.password:
options.password=getpassword("UCSM Password:")
handle.Login(options.ip,options.userName,options.password)
# Get Ethernet Mode
ethmode = getEthernetMode(handle)
# Get software version
version = getSwVersion(handle)
# Get cluster/standalone
hamode = getHaMode(handle)
# Get FI model for A
model = getFiModel(handle)
# Get chassis and servers
chassismodel, servermodel = getBladeDetail(handle)
# Get rack servers
rackmodel = getRackDetail(handle)
print 'hamode', hamode, 'ethmode', ethmode, 'version', version
print 'fia-model', model[0]
if (hamode == 'cluster'):
print 'fib-model', model[1]
print "Blade chassis:"
i = 0
while (i < len(chassismodel)):
print chassismodel[i]
i = i + 1
print "Blade servers:"
i = 0
while (i < len(servermodel)):
print servermodel[i]
i = i + 1
print "Rack servers:"
i = 0
while (i < len(rackmodel)):
print rackmodel[i]
i = i + 1
handle.Logout()
except Exception, err:
handle.Logout()
print "Exception:", str(err)
import traceback, sys
print '-'*60
traceback.print_exc(file=sys.stdout)
print '-'*60