-
Notifications
You must be signed in to change notification settings - Fork 1
/
module_linux.py
721 lines (630 loc) · 30.1 KB
/
module_linux.py
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
import ast
import math
import sys, yaml, json
import paramiko
from pysnmp.entity.rfc3413.oneliner import cmdgen
class GetLinuxData:
def __init__(self, ip, ssh_port, timeout, usr, pwd, use_key_file, key_file,
get_serial_info, add_hdd_as_device_properties, add_hdd_as_parts,
get_hardware_info, get_os_details, get_cpu_info, get_memory_info,
ignore_domain, upload_ipv6, give_hostname_precedence, get_dv_install_info, debug):
self.machine_name = ip
self.port = int(ssh_port)
self.timeout = timeout
self.username = usr
self.password = pwd
self.use_key_file = use_key_file
self.key_file = key_file
self.get_serial_info = get_serial_info
self.get_hardware_info = get_hardware_info
self.get_os_details = get_os_details
self.get_cpu_info = get_cpu_info
self.get_memory_info = get_memory_info
self.ignore_domain = ignore_domain
self.upload_ipv6 = upload_ipv6
self.name_precedence = give_hostname_precedence
self.add_hdd_as_devp = add_hdd_as_device_properties
self.add_hdd_as_parts = add_hdd_as_parts
self.debug = debug
self.root = True
self.devicename = None
self.disk_sizes = {}
self.raids = {}
self.hdd_parts = {}
self.device_name = None
self.os = None
self.nics = []
self.alldata = []
self.interfacae_list = []
self.devargs = {}
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.raid_controlleroids = ['.1.3.6.1.4.1.674.10893.1.20.130.1.1.37.1','.1.3.6.1.4.1.674.10893.1.20.130.1.1.37.2']
def main(self):
self.connect()
self.are_u_root()
self.get_system()
if self.get_memory_info:
self.get_ram()
if self.get_cpu_info:
self.get_cpu()
if self.get_os_details:
self.get_os()
# self.get_hdd()
self.get_dv_install_info()
self.get_ip_ifconfig()
self.get_route_info()
#self.get_ip_ipaddr()
self.alldata.append(self.devargs)
return self.alldata
def connect(self):
try:
if not self.use_key_file:
self.ssh.connect(str(self.machine_name), port=self.port,
username=self.username, password=self.password, timeout=self.timeout)
else:
self.ssh.connect(str(self.machine_name), port=self.port,
username=self.username, key_filename=self.key_file, timeout=self.timeout)
except paramiko.AuthenticationException:
print str(self.machine_name) + ': authentication failed'
return None
except Exception as err:
print str(self.machine_name) + ': ' + str(err)
return None
def execute(self, cmd, needroot=False):
if needroot:
if self.root:
stdin, stdout, stderr = self.ssh.exec_command(cmd)
else:
cmd_sudo = "sudo -S -p '' %s" % cmd
stdin, stdout, stderr = self.ssh.exec_command(cmd_sudo)
stdin.write('%s\n' % self.password)
stdin.flush()
else:
stdin, stdout, stderr = self.ssh.exec_command(cmd)
data_err = stderr.readlines()
data_out = stdout.readlines()
if data_err and 'sudo: command not found' in str(data_err):
stdin, stdout, stderr = self.ssh.exec_command(cmd)
data_err = stderr.readlines()
data_out = stdout.readlines()
return data_out, data_err
def are_u_root(self):
cmd = 'id -u'
data, err = self.execute(cmd)
if data[0].strip() == '0':
self.root = True
else:
self.root = False
@staticmethod
def to_ascii(s):
try:
return s.encode('ascii', 'ignore')
except:
return None
@staticmethod
def closest_memory_assumption(v):
if v < 512:
v = 128 * math.ceil(v / 128.0)
elif v < 1024:
v = 256 * math.ceil(v / 256.0)
elif v < 4096:
v = 512 * math.ceil(v / 512.0)
elif v < 8192:
v = 1024 * math.ceil(v / 1024.0)
else:
v = 2048 * math.ceil(v / 2048.0)
return int(v)
def sizeof_fmt(self, num, suffix='B'):
num = num * 1024 * 1024
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
def get_name(self):
cmd = '/bin/hostname'
data_out, data_err = self.execute(cmd)
get_hostname_info = {}
device_name = None
if not data_err:
if self.ignore_domain:
device_name = self.to_ascii(data_out[0].rstrip()).split('.')[0]
else:
device_name = self.to_ascii(data_out[0].rstrip())
if device_name != '':
get_hostname_info['hostname'] = device_name
get_hostname_info['node_ipaddr'] = self.machine_name
get_hostname_info['public_ipaddr'] = self.get_public_ipaddr()
get_hostname_info['hdd_drive_count'] = len(self.get_hdd_names())
if self.name_precedence:
get_hostname_info['hostname'] = device_name
get_hostname_info['node_ip'] = self.machine_name
self.devargs.update({'hostname_info': get_hostname_info})
get_hostname_info['hdd_drive_count'] = len(self.get_hdd_names())
self.devargs.update({'hostname_info': get_hostname_info})
return device_name
return device_name
def get_system(self):
self.device_name = self.get_name()
if self.device_name not in ('', None):
cmd = '/usr/sbin/dmidecode -t system'
get_vendor_info = {}
get_physicaldevice_info = {}
data_out, data_err = self.execute(cmd, True)
if not data_err:
dev_type = None
for rec in data_out:
if rec.strip() not in ('\n', ' ', '', None):
rec = rec.strip()
if rec.startswith('Manufacturer:'):
manufacturer = str(rec.split(':')[1].strip())
get_vendor_info['manufacturer'] = manufacturer
if manufacturer in ['VMware, Inc.', 'Bochs', 'KVM', 'QEMU',
'Microsoft Corporation', 'Xen', 'innotek GmbH']:
dev_type = 'virtual'
get_vendor_info['type'] = dev_type
if 'Dell' in manufacturer:
raid_controller_info = {}
raid_controller_name = self.snmpget('1.3.6.1.4.1.674.10893.1.20.130.1.1.2.1', self.machine_name)
raid_controller_info['raid_controller_name'] = raid_controller_name
self.devargs.update({'raid_controller_info': raid_controller_info})
for ControllersOID in self.raid_controlleroids:
try:
controllerPhysicalDeviceCount = self.snmpget(ControllersOID, self.machine_name)
for PhysicalDevice in range(1, int(controllerPhysicalDeviceCount)):
get_physicaldevice_info['arrayDiskProductID'] = self.snmpget('iso.3.6.1.4.1.674.10893.1.20.130.4.1.6.'+str(PhysicalDevice), self.machine_name)
get_physicaldevice_info['arrayDiskSerialNo'] = self.snmpget('iso.3.6.1.4.1.674.10893.1.20.130.4.1.7.'+str(PhysicalDevice), self.machine_name)
get_physicaldevice_info['channelName'] = self.snmpget('iso.3.6.1.4.1.674.10893.1.20.130.2.1.2.'+str(PhysicalDevice), self.machine_name)
get_physicaldevice_info['arrayDiskEnclosureConnectionArrayDiskName'] = self.snmpget('iso.3.6.1.4.1.674.10893.1.20.130.5.1.6.'+str(PhysicalDevice), self.machine_name)
get_physicaldevice_info['arrayDiskEnclosureConnectionEnclosureName'] = self.snmpget('iso.3.6.1.4.1.674.10893.1.20.130.5.1.4.'+str(PhysicalDevice), self.machine_name)
get_physicaldevice_info['arrayDiskLengthInMB'] = self.snmpget('1.3.6.1.4.1.674.10893.1.20.130.4.1.11.'+str(PhysicalDevice), self.machine_name)
except Exception, e:
print "we got this exception %s" % e
#print "let's print hard_drive_info for dell Machine = %s" % get_physicaldevice_info
self.devargs.update({'hard_drive_info': get_physicaldevice_info})
if rec.startswith('UUID:'):
uuid = str(rec.split(':')[1].strip())
get_vendor_info['uuid'] = uuid
if rec.startswith('Serial Number:'):
serial = str(rec.split(':')[1].strip())
get_vendor_info['service_tag'] = serial
if rec.startswith('Product Name:') and dev_type != 'virtual':
hardware = str(rec.split(':')[1].strip())
get_vendor_info['hardware'] = hardware
self.devargs.update({'HW_vendor_info': get_vendor_info})
else:
if self.debug:
print '\t[-] Failed to get sysdata from host: %s using dmidecode. Message was: %s' % \
(self.machine_name, str(data_err))
self.get_system_2()
def get_system_2(self):
cmd = "grep '' /sys/devices/virtual/dmi/id/*"
data_out, data_err = self.execute(cmd, True)
if data_out:
dev_type = 'physical'
for rec in data_out:
if 'sys_vendor:' in rec:
manufacturer = rec.split(':')[1].strip()
self.devargs.update({'manufacturer': manufacturer})
if manufacturer in ['VMware, Inc.', 'Bochs', 'KVM', 'QEMU',
'Microsoft Corporation', 'Xen', 'innotek GmbH']:
dev_type = 'virtual'
self.devargs.update({'type': dev_type})
if 'product_uuid:' in rec:
uuid = rec.split(':')[1].strip()
self.devargs.update({'uuid': uuid})
if 'product_serial:' in rec:
serial = rec.split(':')[1].strip()
self.devargs.update({'serial_no': serial})
if 'product_name:' in rec and dev_type != 'virtual':
hardware = str(rec.split(':')[1].strip())
self.devargs.update({'hardware': hardware})
else:
if self.debug:
print '\t[-] Failed to get sysdata from host: %s using grep /sys.... Message was: %s' % \
(self.machine_name, str(data_err))
self.get_system_3()
def get_system_3(self):
cmd = "lshal -l -u computer"
data_out, data_err = self.execute(cmd)
if data_out:
dev_type = None
for rec in data_out:
if 'system.hardware.vendor' in rec:
manufacturer = rec.split('=')[1].split('(')[0].strip()
self.devargs.update({'manufacturer': manufacturer})
if manufacturer in ['VMware, Inc.', 'Bochs', 'KVM', 'QEMU',
'Microsoft Corporation', 'Xen', 'innotek GmbH']:
dev_type = 'virtual'
self.devargs.update({'type': dev_type})
if 'system.hardware.uuid' in rec:
uuid = rec.split('=')[1].split('(')[0].strip()
self.devargs.update({'uuid': uuid})
if 'system.hardware.serial' in rec:
serial = rec.split('=')[1].split('(')[0].strip()
self.devargs.update({'serial_no': serial})
if 'system.hardware.product' in rec and dev_type != 'virtual':
hardware = str(rec.split('=')[1].split('(')[0].strip())
self.devargs.update({'hardware': hardware})
else:
if self.debug:
print '\t[-] Failed to get sysdata from host: %s using lshal. Message was: %s' % \
(self.machine_name, str(data_err))
def get_ram(self):
cmd = 'grep MemTotal /proc/meminfo'
data_out, data_err = self.execute(cmd)
get_ram_info = {}
if not data_err:
memory_raw = ''.join(data_out).split()[1]
memory = self.closest_memory_assumption(int(memory_raw) / 1024)
get_ram_info['memory'] = self.sizeof_fmt(memory)
self.devargs.update({'ram_info': get_ram_info})
else:
if self.debug:
print '\t[-] Could not get RAM info from host %s. Message was: %s' % (self.machine_name, str(data_err))
def get_route_info(self):
cmd = '/sbin/route -n'
data_out, data_err = self.execute(cmd)
get_route_list = []
if not data_err:
for data in data_out:
get_route_list.append(data)
self.devargs.update({'route_info': {'default_route': ''.join(get_route_list)}})
else:
print "some issue getting route info host %s. Message was: %s" % (self.machine_name, str(data_err))
def get_os(self):
cmd = 'python -c "import platform; raw = list(platform.dist());raw.append(platform.release());print raw"'
data_out, data_err = self.execute(cmd)
get_os_info = {}
if not data_err:
if 'command not found' not in data_out[0]: # because some distros sport python3 by default!
self.os, ver, release, kernel_version = ast.literal_eval(data_out[0])
get_os_info['os'] = self.os
get_os_info['osver'] = ver
get_os_info['osverno'] = kernel_version
self.devargs.update({'os_info': get_os_info})
else:
cmd = 'python3 -c "import platform; raw = list(platform.dist());' \
'raw.append(platform.release());print (raw)"'
data_out, data_err = self.execute(cmd)
if not data_err:
self.os, ver, release, kernel_version = ast.literal_eval(data_out[0])
get_os_info['os'] = self.os
get_os_info['osver'] = ver
get_os_info['osverno'] = kernel_version
self.devargs.update({'os_info': get_os_info})
else:
if self.debug:
print '\t[-] Could not get OS info from host %s. Message was: %s' % (
self.machine_name, str(data_err))
else:
if self.debug:
print '\t[-] Could not get OS info from host %s. Message was: %s' % (self.machine_name, str(data_err))
def get_cpu(self):
cmd = 'cat /proc/cpuinfo'
data_out, data_err = self.execute(cmd)
get_cpu_info = {}
if not data_err:
cpus = 0
cores = 1
siblings = None
cpuspeed = 0
threads = None
for rec in data_out:
if rec.startswith('processor'):
cpus += 1
if rec.startswith('cpu MHz'):
cpuspeed = int((float(rec.split(':')[1].strip())))
if rec.startswith('model name'):
model_name = (str(rec.split(':')[1].strip()))
if rec.startswith('cpu cores'):
cores = int(rec.split(':')[1].strip())
if rec.startswith('siblings'):
threads = int(rec.split(':')[1].strip())
if siblings and threads:
cpu_count = cpus / threads
else:
cpu_count = cpus
get_cpu_info['model_name'] = model_name
get_cpu_info['no.cpus'] = cpu_count
get_cpu_info['cpuspeed-MHz'] = cpuspeed
self.devargs.update({'cpu_info': get_cpu_info})
else:
if self.debug:
print '\t[-] Could not get CPU info from host %s. Message was: %s' % (self.machine_name, str(data_err))
def get_ip_ifconfig(self):
cmd = '/sbin/ifconfig'
data_out, data_err = self.execute(cmd)
if not data_err:
new = True
nic = mac = ip = ''
for row in data_out:
if row not in ('', '\n', None):
if not row.startswith(' '):
if new:
nic = row.split()[0].strip(':').strip()
new = False
else:
if not nic.startswith('lo'):
self.ip_to_json(nic, mac, ip)
nic = row.split()[0].strip(':')
new = True
if 'HWaddr ' in row:
words = row.split()
macindex = words.index('HWaddr') + 1
mac = words[macindex].strip()
else:
new = False
if 'inet addr:' in row:
words = row.split()
ipindex = words.index('inet') + 1
ip = words[ipindex].strip('addr:').strip()
elif 'inet ' in row and 'addr:' not in row:
words = row.split()
ipindex = words.index('inet') + 1
ip = words[ipindex].strip()
if 'ether ' in row:
words = row.split()
macindex = words.index('ether') + 1
mac = words[macindex].strip()
if not nic.startswith('lo'):
self.ip_to_json(nic, mac, ip)
else:
if self.debug:
print '\t[-] Could not get IP info from host %s. Message was: %s' % (self.machine_name, str(data_err))
def ip_to_json(self, nic, mac, ip):
nicdata = {}
nicdata['port_name'] = str(nic)
nicdata['mac_address'] = str(mac)
nicdata['ip'] = str(ip)
self.interfacae_list.append(nicdata)
self.devargs.update({'interface_list': self.interfacae_list})
def get_public_ipaddr(self):
cmd = "wget http://ipinfo.io/ip -qO -"
data_out, data_err = self.execute(cmd)
if not data_err:
return str(data_out[0].strip())
else:
print "some issue getting public ipaddr info host %s. Message was: %s" % (self.machine_name, str(data_err))
def get_ip_ipaddr(self):
cmd = 'ip addr show'
interfaces_list = []
data_out, data_err = self.execute(cmd)
if not data_err and 'command not found' not in data_out[0]:
macmap = {}
ipmap = {}
ip6map = {}
nics = []
nicmap = {}
current_nic = None
for rec in data_out:
# macs
if not rec.startswith(' ') and rec not in ('', '\n'):
if ':' in rec:
mac = None
raw = rec.split(':')
try:
nic = raw[1].strip()
current_nic = nic
rec_index = data_out.index(rec)
mac_word = data_out[rec_index + 1]
if 'link/ether' in mac_word:
_, mac, _, _ = mac_word.split()
if nic != 'lo' and mac:
macmap.update({nic: mac})
except IndexError:
pass
# get nic names and ips
elif rec.strip().startswith('inet ') and 'scope global' in rec:
inetdata = rec.split()
ip = str(inetdata[1].split('/')[0])
interface = inetdata[-1]
if ':' in interface:
macmap.update({interface: macmap[interface.split(':')[0]]})
nics.append(interface)
ipmap.update({interface: ip})
# jsonize
for nic in nics:
nicdata = {}
macdata = {}
if nic in macmap:
mac = str(macmap[nic])
# macdata.update({'device': self.device_name})
macdata.update({'ipaddress': ip})
macdata.update({'port_name': nic})
macdata.update({'macaddress': mac})
if nic in ipmap:
ip = ipmap[nic]
nicdata.update({'device': self.device_name})
nicdata.update({'tag': nic})
nicdata.update({'ipaddress': ip})
if nic in macmap:
mac = macmap[nic]
nicdata.update({'macaddress': mac})
# if nicdata:
# self.alldata.append(nicdata)
if macdata:
interfaces_list.append(macdata)
self.devargs.update({'interface_list': interfaces_list})
#self.alldata.append(interfaces_list)
else:
if self.debug:
print '\t[-] Could not get NIC info from host %s. Switching to "ifconfig".' \
'\n\t\t Message was: %s' % (self.machine_name, str(data_err))
self.get_ip_ifconfig()
# def get_hdd(self):
# # get software raids. Hardware raids are way too complicated to fetch automatically.
# self.get_sw_raids()
# # ==================
# get_hdd_meta_data_info = []
#
# hdds = self.get_hdd_names()
# if hdds:
# if self.add_hdd_as_devp:
# self.devargs.update({'hddcount': len(hdds)})
# for hdd in hdds:
# self.get_hdd_info(hdd)
# # self.get_hdd_info_hdaparm(hdd)
# get_hdd_meta_data_info.append(self.get_hdd_info_hdaparm(hdd))
#
# #print get_hdd_meta_data_info
# # self.devargs.update({'hard_drive_info': get_hdd_meta_data_info})
def get_hdd_names(self):
hdd_names = []
cmd = '/sbin/fdisk -l | grep "Disk /dev"'
data_out, data_err = self.execute(cmd, True)
errhdds = []
if data_err:
for rec in data_err:
if "doesn't contain a valid partition table" in rec:
disk = rec.split()[1]
errhdds.append(disk)
for rec in data_out:
try:
mess = rec.strip().split()
disk = mess[1]
if disk.endswith(':'):
disk_name = disk.strip(':')
else:
disk_name = disk
sizeformat = mess[3].lower().strip(',')
size = float(mess[2])
if self.add_hdd_as_devp:
self.devargs.update({'hddsize': size})
if sizeformat in ('mib', 'mb'):
size = int(math.ceil(size / 1024))
if self.add_hdd_as_devp:
self.devargs.update({'hddsize': size})
hdd_names.append(disk_name)
self.disk_sizes.update({disk_name: size})
except Exception, e:
print e
pass
return hdd_names
def get_hdd_info(self, hdd):
pass
def get_hdd_info_hdaparm(self, hdd):
# if hdd not in self.raids:
cmd = 'sudo hdparm -I %s' % hdd
get_hdd_info_dict = {}
get_hdd_info_list = {}
device_name = hdd.split('/')[2]
data_out, data_err = self.execute(cmd, True)
if data_err:
print "get_hdd_info_hdaparm error ==> %s" %data_err
return
else:
for rec in data_out:
if 'model number' in rec.lower():
model = rec.split(':')[1].strip()
size = self.disk_sizes[hdd]
get_hdd_info_dict.update({'hdd_model': str(model)})
get_hdd_info_dict.update({'device_name': str(hdd)})
get_hdd_info_dict.update({'hddsize': str(size)})
if 'serial number' in rec.lower():
serial = rec.split(':')[1].strip()
get_hdd_info_dict.update({'serial_no': str(serial)})
if 'rotation rate' in rec.lower():
rpm = rec.split(':')[1].strip()
get_hdd_info_dict.update({'hddrpm': str(rpm)})
if 'transport:' in rec.lower():
if ',' in rec:
try:
transport = (rec.split(',')[-1]).split()[0]
get_hdd_info_dict.update({'transport': str(transport)})
except IndexError:
transport = (rec.split(',')[-1])
get_hdd_info_dict.update({'transport': str(transport)})
else:
transport = rec.lower()
get_hdd_info_dict.update({'transport': str(transport)})
#print get_hdd_info_dict
get_hdd_info_list.update({str(hdd): get_hdd_info_dict})
return get_hdd_info_list
def get_sw_raids(self):
cmd = 'cat /proc/mdstat'
# Note: we can get raid members here if needed!
data_out, data_err = self.execute(cmd, False)
if not data_err:
for rec in data_out:
if "active raid" in rec:
hddraid = 'software'
raw = rec.split()
for entry in raw:
if 'raid' in entry:
rtype = entry.strip()
hddraid_type = self.raid_type(rtype)
if self.add_hdd_as_devp:
self.devargs.update({'hddraid': hddraid})
self.devargs.update({'hddraid_type': hddraid_type})
if self.add_hdd_as_parts:
self.hdd_parts.update({'raid_type': hddraid_type})
def get_dv_install_info(self):
cmd = 'cat /usr/local/dv_info'
dv_info_dict = {}
data_out, data_err = self.execute(cmd, False)
# print data_out,data_err
for data_out_line in data_out:
key1 = str(data_out_line).strip().split('=', 1)[0]
value1 = str(data_out_line).strip().split('=', 1)[1]
dv_info_dict[key1] = value1
self.devargs.update({'dv_info': dv_info_dict})
def get_raid_controler_info(self, oid, machine_name):
print "entring snmpget function ip=%s and oid=%s" % (machine_name,oid)
cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.nextCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget((machine_name, 161)),
oid
)
# Check for errors and print out results
if errorIndication:
print(errorIndication)
else:
if errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1] or '?'
)
)
else:
for name, val in varBinds[0]:
#print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
return str(val)
def snmpget(self, oid, machine_name):
print "entring snmpget function ip=%s and oid=%s" % (machine_name,oid)
cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget((machine_name, 161)),
oid
)
# Check for errors and print out results
if errorIndication:
print(errorIndication)
else:
if errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1] or '?'
)
)
else:
for name, val in varBinds:
#print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
return str(val)
@staticmethod
def raid_type(rtype):
types = {'raido': 'raid 0',
'raid1': 'raid 1',
'raid3': 'raid 3',
'raid4': 'raid 4',
'raid5': 'raid 5',
'raid6': 'raid 6',
'raid10': 'raid 10',
'raid50': 'raid 50'}
if rtype in types:
return types[rtype]
else:
return rtype