forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiq_ontap_client.rb
903 lines (756 loc) · 28.5 KB
/
miq_ontap_client.rb
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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
require 'wbem'
require 'net_app_manageability'
require 'miq_storage_defs'
require 'cim_association_defs'
require 'yaml'
require 'sync'
module MiqOntapClient
NAME_SPACE = "root/ontap"
MAX_CHUNK = 20
BLOCK_SIZE = 4192
LFS_BLOCK_SIZE = 4096
LUN_BLOCK_SIZE = 512
TYPE_SPECIFIC_MODEL_CLASSES = [
"ONTAP_ConcreteExtent", # < MiqCimInstance
"ONTAP_FileShare", # < SniaFileShare
"ONTAP_LogicalDisk", # < CimLogicalDisk
"ONTAP_FlexVolExtent", # < CimStorageExtent
"ONTAP_PlexExtent", # < MiqCimInstance
"ONTAP_RAIDGroupExtent", # < MiqCimInstance
"ONTAP_StorageVolume", # < CimStorageVolume
"ONTAP_StorageSystem" # < CimComputerSystem
]
CLASS_TO_PERF_OBJECT_NAMES = {
"ONTAP_ConcreteExtent" => ["aggregate"],
"ONTAP_DiskExtent" => ["disk"],
"ONTAP_StorageVolume" => ["LUN"],
"ONTAP_StorageSystem" => ["System"],
"ONTAP_LogicalDisk" => ["volume"]
# "ONTAP_FlexVolExtent" => [ "volume" ]
}
PERF_OBJECT_NAMES = CLASS_TO_PERF_OBJECT_NAMES.values.flatten.uniq
OBJECT_NAME_TO_INST_KEY = {
"aggregate" => ->(i) { i.name },
"disk" => ->(i) { i.disk_uid },
"LUN" => ->(i) { "#{i.path}-#{i.serial_number}" },
"processor" => ->(_i) { nil },
"System" => ->(_i) { nil },
"volume" => ->(i) { i.name }
}
OBJECT_NAME_TO_COUNTERS = {
"aggregate" => OntapAggregateDerivedMetric.counterNames,
"disk" => OntapDiskDerivedMetric.counterNames,
"LUN" => OntapLunDerivedMetric.counterNames,
"System" => OntapSystemDerivedMetric.counterNames,
"volume" => OntapVolumeDerivedMetric.counterNames
}
HOSTED_SHARE_ASSOCIATION = CimAssociations.CIM_ComputerSystem_TO_CIM_FileShare
SYSTEM_TO_LOGICAL_DISK_ASSOCIATION = CimAssociations.CIM_ComputerSystem_TO_CIM_LogicalDisk
SYSTEM_TO_STORAGE_VOLUME_ASSOCIATION = CimAssociations.CIM_ComputerSystem_TO_CIM_StorageVolume
SYSTEM_TO_FLEX_VOL_ASSOCIATION = CimAssociations.ONTAP_StorageSystem_TO_ONTAP_FlexVolExtent
SYSTEM_TO_IP_PROTOCOL_ENDPOINT = CimAssociations.CIM_ComputerSystem_TO_CIM_IPProtocolEndpoint
LFS_TO_LOGICAL_DISK_ASSOCIATION = CimAssociations.SNIA_LocalFileSystem_TO_CIM_StorageExtent
FILE_SHARE_TO_LFS_ASSOCIATION = CimAssociations.CIM_FileShare_TO_SNIA_LocalFileSystem
COMPOSIT_EXTENT_TO_COMPONENT_ASSOCIATION = CimAssociations.CIM_StorageExtent_TO_CIM_StorageExtent_down
ONTAP_FILE_SHARE_TO_FLEX_VOL_ASSOCIATION = CimAssociations.ONTAP_FileShare_TO_ONTAP_FlexVolExtent
class OntapClient
attr_reader :server, :conn, :version_string
attr_accessor :max_chunk
include MiqStorageDefs
@@counterInfoLock = Sync.new
@@counterInfo = nil
def initialize(server, username, password)
@currentTopElement = nil
@max_chunk = MAX_CHUNK
@server = server
@username = username
@password = password
@conn = NetAppManageability::Client.new do |c|
c.server = @server
c.auth_style = NetAppManageability::Client::NA_STYLE_LOGIN_PASSWORD
c.username = @username
c.password = @password
end
@version_string = @conn.system_get_version.version
end
def agent
@agent ||= NetappRemoteService.add(@server, @username, @password, NetappRemoteService::DEFAULT_AGENT_TYPE)
end
def updateOntap
@topMeNode, prior_status = storageSystem
@diskInfoHash = hashDiskInfo
logicalDiskNodeHash = {}
localFileSystemNodeHash = {}
flexVolExtentNodeHash = {}
volumeInfoHash = hashVolumeInfo
volumeInfoHash.values.uniq.each do |vi|
ldNode = logicalDiskNode(vi)
logicalDiskNodeHash[vi.name] = ldNode
@topMeNode.addAssociation(ldNode, SYSTEM_TO_LOGICAL_DISK_ASSOCIATION)
lfsNode = localFileSystemNode(vi)
localFileSystemNodeHash[vi.name] = lfsNode
lfsNode.addAssociation(ldNode, LFS_TO_LOGICAL_DISK_ASSOCIATION)
fveNode = flexVolExtentNode(vi)
flexVolExtentNodeHash[vi.name] = fveNode
ldNode.addAssociation(fveNode, COMPOSIT_EXTENT_TO_COMPONENT_ASSOCIATION)
@topMeNode.addAssociation(fveNode, SYSTEM_TO_FLEX_VOL_ASSOCIATION)
end
lunInfo.each do |li|
svNode = storageVolumeNode(li)
@topMeNode.addAssociation(svNode, SYSTEM_TO_STORAGE_VOLUME_ASSOCIATION)
if (fveNode = flexVolExtentNodeHash[volNameFromPath(li.path)])
svNode.addAssociation(fveNode, COMPOSIT_EXTENT_TO_COMPONENT_ASSOCIATION)
end
end
aggrInfo.each do |ai|
ceNode = concreteExtentNode(ai)
ai.volumes.contained_volume_info.to_ary.each do |cvi|
if (fveNode = flexVolExtentNodeHash[cvi.name])
fveNode.addAssociation(ceNode, COMPOSIT_EXTENT_TO_COMPONENT_ASSOCIATION)
end
end
end
fileShareNodeHash = {}
nfsExportHash = hashNfsExportRules
nfsExportHash.each do |k, v|
node = nfsFileShareNode(v)
fileShareNodeHash["nfs:#{k}"] = node
@topMeNode.addAssociation(node, HOSTED_SHARE_ASSOCIATION)
if (lfsNode = localFileSystemNodeHash[volNameFromPath(k)])
node.addAssociation(lfsNode, FILE_SHARE_TO_LFS_ASSOCIATION)
end
if (fveNode = flexVolExtentNodeHash[volNameFromPath(k)])
node.addAssociation(fveNode, ONTAP_FILE_SHARE_TO_FLEX_VOL_ASSOCIATION)
end
end
cifsShareHash = hashCifsShares
cifsShareHash.each do |k, v|
node = cifsFileShareNode(v)
fileShareNodeHash["cifs:#{k}"] = node
@topMeNode.addAssociation(node, HOSTED_SHARE_ASSOCIATION)
if (lfsNode = localFileSystemNodeHash[volNameFromPath(k)])
node.addAssociation(lfsNode, FILE_SHARE_TO_LFS_ASSOCIATION)
end
if (fveNode = flexVolExtentNodeHash[volNameFromPath(k)])
node.addAssociation(fveNode, ONTAP_FILE_SHARE_TO_FLEX_VOL_ASSOCIATION)
end
end
end
def storageSystem
cimClassName = "ONTAP_StorageSystem"
ontap_info = @conn.system_get_info.system_info
ipa = []
ip_info = getIpInfo
ip_info.each do |ai|
next unless ai.v4_primary_address
ipa << ai.v4_primary_address
end
keybindings = {
"CreationClassName" => cimClassName,
"Name" => "ONTAP:#{ontap_info.system_id}"
}
additionalProperties = {
"ElementName" => ontap_info.system_name,
"OtherIdentifyingInfo" => ipa
}
obj = WBEM::CIMInstance.new(cimClassName, ontap_info.merge(keybindings).merge(additionalProperties))
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
ssNode, ignore = newNode(obj, objName, ontap_info, true)
ip_info.each do |ai|
ipNode = ipProtocolEndpointNode(ai, ssNode)
ssNode.addAssociation(ipNode, SYSTEM_TO_IP_PROTOCOL_ENDPOINT)
end
ssNode
end
IpAdEntAddr = ".1.3.6.1.2.1.4.20.1.1"
IpAdEntIfIndex = ".1.3.6.1.2.1.4.20.1.2"
IpAdEntNetMask = ".1.3.6.1.2.1.4.20.1.3"
IfDescr = ".1.3.6.1.2.1.2.2.1.2"
def getIpInfo
ra = []
oid = IpAdEntAddr
loop do
rv = @conn.snmp_get_next { nma_object_id oid }
oid = rv.next_object_id
break if oid[IpAdEntAddr].nil?
ip = rv.value
netMask = @conn.snmp_get { nma_object_id "#{IpAdEntNetMask}.#{ip}" }.value
ifIdx = @conn.snmp_get { nma_object_id "#{IpAdEntIfIndex}.#{ip}" }.value
ifName = @conn.snmp_get { nma_object_id "#{IfDescr}.#{ifIdx}" }.value
ra << NetAppManageability::NAMHash.new do
v4_primary_address ip
v6_primary_address nil
subnet_mask netMask
end
end
ra
end
def ipProtocolEndpointNode(ipInfo, ssNode)
cimClassName = "ONTAP_IPProtocolEndPoint"
ip4 = ipInfo.v4_primary_address
snm = ipInfo.subnet_mask
ip6 = ipInfo.v6_primary_address
keybindings = {
"CreationClassName" => cimClassName,
"Name" => "IP:#{ipInfo.interface_name}:#{ip4}",
"SystemCreationClassName" => ssNode.class_name,
"SystemName" => ssNode.property('Name')
}
additionalProperties = {
"IPv4Address" => ip4,
"SubnetMask" => snm,
"IPv6Address" => ip6,
"NameFormat" => "IP:<Interface>:<IPV4|6 Address>",
"Caption" => cimClassName,
"Description" => cimClassName
}
obj = WBEM::CIMInstance.new(cimClassName, keybindings.merge(additionalProperties))
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
node, ignore = newNode(obj, objName, lunInfo, false)
node
end
def storageVolumeNode(lunInfo)
cimClassName = "ONTAP_StorageVolume"
keybindings = {
"CreationClassName" => cimClassName,
"DeviceID" => "#{lunInfo.path}:#{lunInfo.serial_number}",
"SystemCreationClassName" => @topMeNode.class_name,
"SystemName" => @topMeNode.property('Name')
}
additionalProperties = {
"ElementName" => lunInfo.path,
"Name" => "NETAPP LUN #{lunInfo.serial_number}",
"BlockSize" => LUN_BLOCK_SIZE.to_s, # XXX
"Caption" => cimClassName,
"Primordial" => 'false',
"ConsumableBlocks" => (lunInfo.size.to_i / LUN_BLOCK_SIZE).to_s,
"NumberOfBlocks" => (lunInfo.size.to_i / LUN_BLOCK_SIZE).to_s,
"DeltaReservation" => "???",
"Description" => cimClassName
}
obj = WBEM::CIMInstance.new(cimClassName, keybindings.merge(additionalProperties))
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
node, ignore = newNode(obj, objName, lunInfo, false)
node
end
def logicalDiskNode(volInfo)
cimClassName = "ONTAP_LogicalDisk"
keybindings = {
"CreationClassName" => cimClassName,
"DeviceID" => volInfo.uuid,
"SystemCreationClassName" => @topMeNode.class_name,
"SystemName" => @topMeNode.property('Name')
}
additionalProperties = {
"ElementName" => volInfo.name,
"Name" => volInfo.name,
"DeltaReservation" => volInfo.snapshot_percent_reserved.to_s,
"BlockSize" => BLOCK_SIZE.to_s, # XXX
"ConsumableBlocks" => (volInfo.size_total.to_i / BLOCK_SIZE).to_s,
"Caption" => cimClassName,
"NumberOfBlocks" => (volInfo.size_total.to_i / BLOCK_SIZE).to_s,
"Primordial" => 'false',
"Description" => cimClassName
}
obj = WBEM::CIMInstance.new(cimClassName, keybindings.merge(additionalProperties))
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
node, ignore = newNode(obj, objName, volInfo, false)
node
end
def flexVolExtentNode(volInfo)
cimClassName = "ONTAP_FlexVolExtent"
keybindings = {
"CreationClassName" => cimClassName,
"DeviceID" => volInfo.uuid,
"SystemCreationClassName" => @topMeNode.class_name,
"SystemName" => @topMeNode.property('Name')
}
additionalProperties = {
"ElementName" => volInfo.name,
"Name" => volInfo.name,
"DeltaReservation" => volInfo.snapshot_percent_reserved.to_s,
"BlockSize" => LUN_BLOCK_SIZE.to_s, # XXX
"ConsumableBlocks" => (volInfo.size_total.to_i / LUN_BLOCK_SIZE).to_s,
"Caption" => cimClassName,
"NumberOfBlocks" => (volInfo.size_total.to_i / LUN_BLOCK_SIZE).to_s,
"Primordial" => 'false',
"Description" => cimClassName
}
obj = WBEM::CIMInstance.new(cimClassName, keybindings.merge(additionalProperties))
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
node, ignore = newNode(obj, objName, volInfo, false)
node
end
def concreteExtentNode(aggrInfo)
cimClassName = "ONTAP_ConcreteExtent"
keybindings = {
"CreationClassName" => cimClassName,
"DeviceID" => aggrInfo.uuid,
"SystemCreationClassName" => @topMeNode.class_name,
"SystemName" => @topMeNode.property('Name')
}
additionalProperties = {
"Name" => aggrInfo.name,
"BlockSize" => LUN_BLOCK_SIZE.to_s, # XXX
"ConsumableBlocks" => (aggrInfo.size_total.to_i / LUN_BLOCK_SIZE).to_s, # XXX
"Caption" => cimClassName,
"NumberOfBlocks" => (aggrInfo.size_total.to_i / LUN_BLOCK_SIZE).to_s, # XXX
"Primordial" => 'false',
"Description" => cimClassName
}
obj = WBEM::CIMInstance.new(cimClassName, keybindings.merge(additionalProperties))
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
node, ignore = newNode(obj, objName, aggrInfo, false)
aggrInfo.plexes.plex_info.to_ary.each do |pi|
peNode = plexExtentNode(pi, aggrInfo)
node.addAssociation(peNode, COMPOSIT_EXTENT_TO_COMPONENT_ASSOCIATION)
end
node
end
def plexExtentNode(plexInfo, aggrInfo)
cimClassName = "ONTAP_PlexExtent"
keybindings = {
"CreationClassName" => cimClassName,
"DeviceID" => plexInfo.name,
"SystemCreationClassName" => @topMeNode.class_name,
"SystemName" => @topMeNode.property('Name')
}
additionalProperties = {
"Name" => plexInfo.name,
"BlockSize" => LUN_BLOCK_SIZE.to_s, # XXX
"ConsumableBlocks" => (aggrInfo.size_total.to_i / LUN_BLOCK_SIZE).to_s, # XXX
"Caption" => cimClassName,
"NumberOfBlocks" => (aggrInfo.size_total.to_i / LUN_BLOCK_SIZE).to_s, # XXX
"Primordial" => 'false',
"Description" => cimClassName
}
obj = WBEM::CIMInstance.new(cimClassName, keybindings.merge(additionalProperties))
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
node, ignore = newNode(obj, objName, plexInfo, false)
plexInfo.raid_groups.raid_group_info.to_ary.each do |ri|
rgeNode = raidGroupExtentNode(ri, aggrInfo)
node.addAssociation(rgeNode, COMPOSIT_EXTENT_TO_COMPONENT_ASSOCIATION)
end
node
end
def raidGroupExtentNode(rgInfo, aggrInfo)
cimClassName = "ONTAP_RAIDGroupExtent"
keybindings = {
"CreationClassName" => cimClassName,
"DeviceID" => rgInfo.name,
"SystemCreationClassName" => @topMeNode.class_name,
"SystemName" => @topMeNode.property('Name')
}
additionalProperties = {
"Name" => rgInfo.name,
"BlockSize" => LUN_BLOCK_SIZE.to_s, # XXX
"ConsumableBlocks" => (aggrInfo.size_total.to_i / LUN_BLOCK_SIZE).to_s, # XXX
"Caption" => cimClassName,
"NumberOfBlocks" => (aggrInfo.size_total.to_i / LUN_BLOCK_SIZE).to_s, # XXX
"Primordial" => 'false',
"Description" => cimClassName
}
obj = WBEM::CIMInstance.new(cimClassName, keybindings.merge(additionalProperties))
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
node, ignore = newNode(obj, objName, rgInfo, false)
rgInfo.disks.disk_info.to_ary.each do |di|
if (diskInfo = @diskInfoHash[di.name])
diskNode = diskNode(diskInfo)
node.addAssociation(diskNode, COMPOSIT_EXTENT_TO_COMPONENT_ASSOCIATION)
end
end
node
end
def diskNode(diskInfo)
cimClassName = "ONTAP_DiskExtent"
keybindings = {
"CreationClassName" => cimClassName,
"DeviceID" => diskInfo.name,
"SystemCreationClassName" => @topMeNode.class_name,
"SystemName" => @topMeNode.property('Name')
}
additionalProperties = {
"Name" => diskInfo.name,
"BlockSize" => LUN_BLOCK_SIZE.to_s, # XXX
"ConsumableBlocks" => diskInfo.physical_blocks,
"Caption" => cimClassName,
"NumberOfBlocks" => diskInfo.physical_blocks,
"Primordial" => 'true',
"Description" => cimClassName
}
obj = WBEM::CIMInstance.new(cimClassName, keybindings.merge(additionalProperties))
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
node, ignore = newNode(obj, objName, diskInfo, false)
node
end
def localFileSystemNode(volInfo)
cimClassName = "ONTAP_LocalFS"
keybindings = {
"CreationClassName" => cimClassName,
"CSCreationClassName" => @topMeNode.class_name,
"CSName" => @topMeNode.property('Name'),
"Name" => volInfo.uuid
}
additionalProperties = {
"FileSystemSize" => volInfo.size_total,
"Caption" => volInfo.name,
"BlockSize" => LFS_BLOCK_SIZE.to_s, # XXX
"Root" => "/vol/#{volInfo.name}",
"FileSystemType" => "WAFL"
}
obj = WBEM::CIMInstance.new(cimClassName, keybindings.merge(additionalProperties))
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
node, ignore = newNode(obj, objName, volInfo, false)
node
end
def nfsFileShareNode(nfsInfo)
cimClassName = "ONTAP_FileShare"
pn = nfsInfo.pathname
props = {
"ElementName" => pn,
"Name" => pn,
"Caption" => pn,
"InstanceID" => "#{@topMeNode.property('Name')}:nfs:#{pn}:(#{pn})"
}
keybindings = {
"InstanceID" => props["InstanceID"]
}
obj = WBEM::CIMInstance.new(cimClassName, props)
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
node, ignore = newNode(obj, objName, nfsInfo, false)
node
end
def cifsFileShareNode(cifsInfo)
cimClassName = "ONTAP_FileShare"
mp = cifsInfo.mount_point
sn = cifsInfo.share_name
props = {
"ElementName" => sn,
"Name" => mp,
"Caption" => sn,
"InstanceID" => "#{@topMeNode.property('Name')}:cifs:#{mp}:(#{sn})"
}
keybindings = {
"InstanceID" => props["InstanceID"]
}
obj = WBEM::CIMInstance.new(cimClassName, props)
objName = WBEM::CIMInstanceName.new(cimClassName, keybindings, nil, NAME_SPACE)
node, ignore = newNode(obj, objName, cifsInfo, false)
node
end
def newNode(obj, objName, typeSpecObj, topMe = false)
objNameStr = objName.to_s
node = MiqCimInstance.find_by_obj_name_str(objNameStr)
#
# This is the first time we've encountered this node. Add it to the database.
#
if node.nil?
node = MiqCimInstance.new
@topMeNode = node if topMe
className = obj.classname.to_s
node.class_name = className
node.class_hier = classHier(className)
node.namespace = objName.namespace
node.obj_name = objName
node.obj_name_str = objNameStr
node.obj = obj
node.type_spec_obj = typeSpecObj
node.source = agent.agent_type
node.is_top_managed_element = topMe
node.top_managed_element = @topMeNode unless topMe
node.agent = agent
node.zone_id = agent.zone_id
node.last_update_status = STORAGE_UPDATE_OK
node.type = typeForNode(node)
agent.top_managed_elements << node if topMe
@topMeNode.elements_with_metrics << node if CLASS_TO_PERF_OBJECT_NAMES[className]
node.save
return node, STORAGE_UPDATE_NEW
end
#
# This node has already been updated through another agent
# (or this agent through different storage device).
#
# XXX NOTE: if node.last_update_status == STORAGE_UPDATE_OK
# We may need to check if node.top_managed_element != @currentTopElement.
# This would indicate that more than one storage system is claiming ownership
# of the node. This may be the case for clusters.
#
return node, STORAGE_UPDATE_OK if node.last_update_status == STORAGE_UPDATE_OK
prior_status = node.last_update_status
node.obj = obj
node.type_spec_obj = typeSpecObj
node.agent = agent
node.zone_id = agent.zone_id
# add node to agent's top_managed_elements list
node.agent_top_id = agent.id if topMe
node.last_update_status = STORAGE_UPDATE_OK
node.save
node.mark_associations_stale
return node, prior_status
end
def typeForNode(node)
# If the node has a type-specific model, return the model's class name.
return node.typeFromClassName(node.class_name) if TYPE_SPECIFIC_MODEL_CLASSES.include?(node.class_name)
# Otherwise, return the name if the general class that applies to this node.
node.typeFromClassHier
end
def classHier(className)
CIM_CLASS_HIER[className] || (raise "OntapClient.classHier: unknown class #{className}")
end
def volNameFromPath(path)
pa = path.split("/")
return "vol0" unless pa[1] == "vol"
pa[2]
end
#
# Hash volume information by volume name and volume path.
#
def hashVolumeInfo
rh = {}
volumeInfo.each do |vi|
rh[vi.name] = vi
rh["/vol/#{vi.name}"] = vi
end
rh
end
def volumeInfo
rv = @conn.volume_list_info_iter_start
begin
tag = rv.tag
retArr = []
loop do
rv = @conn.volume_list_info_iter_next(:maximum, @max_chunk, :tag, tag)
return retArr if rv.records.to_i == 0
retArr.concat(rv.volumes.volume_info.to_ary)
end
ensure
@conn.volume_list_info_iter_end(:tag, tag)
end
end
def lunInfo
rv = @conn.lun_list_info
return [] if rv.luns.kind_of?(String)
rv.luns.lun_info.to_ary
end
def aggrInfo
rv = @conn.aggr_list_info(:verbose, true)
return [] if rv.aggregates.kind_of?(String)
rv.aggregates.aggr_info.to_ary
end
#
# Hash nfs export rules by path name.
#
def hashNfsExportRules
rh = {}
nfsExportRules.each do |ner|
rh[ner.pathname] = ner
end
rh
end
def nfsExportRules
@conn.nfs_exportfs_list_rules(:persistent, true).rules.exports_rule_info.to_ary
end
#
# Hash cifs shares by mount point.
#
def hashCifsShares
rh = {}
cifsShares.each do |cs|
rh[cs.mount_point] = cs
end
rh
end
def cifsShares
rv = @conn.cifs_share_list_iter_start
begin
tag = rv.tag
retArr = []
loop do
rv = @conn.cifs_share_list_iter_next(:maximum, @max_chunk, :tag, tag)
return retArr if rv.records.to_i == 0
retArr.concat(rv.cifs_shares.cifs_share_info.to_ary)
end
ensure
@conn.cifs_share_list_iter_end(:tag, tag)
end
end
def hashDiskInfo
rh = {}
diskInfo.each do |di|
rh[di.name] = di
end
rh
end
def diskInfo
@conn.disk_list_info.disk_details.disk_detail_info.to_ary
end
def updateMetrics(statistic_time)
@metricIdByKey = {}
perfHash = collectPerf(statistic_time)
topMe = agent.top_managed_elements.first
topMe.elements_with_metrics.each do |se|
updateMetricsForNode(se, perfHash)
end unless topMe.nil?
end
def updateMetricsForNode(node, perfHash)
className = node.class_name
perf_obj_names = CLASS_TO_PERF_OBJECT_NAMES[className]
ikeys = []
metricHash = NetAppManageability::NAMHash.new
metricHash.statistic_time = perfHash.statistic_time
perf_obj_names.each do |pon|
if (poh = perfHash[pon]).nil?
_log.warn "perf object type #{pon} not found for #{node.obj_name_str}"
next
end
ikey = OBJECT_NAME_TO_INST_KEY[pon].call(node.type_spec_obj)
if ikey.nil?
metricHash[pon] = poh
else
if (iv = poh[ikey]).nil?
_log.warn "perf instance #{ikey} not found for #{node.obj_name_str}"
return
end
ikeys << ikey
metricHash[pon] = NetAppManageability::NAMHash.new { |h| h[ikey] = iv }
end
end
fullKey = ikeys.sort.join(", ")
if (metricId = @metricIdByKey[fullKey]).nil?
metric = deriveMetrics(node, metricHash)
@metricIdByKey[fullKey] = metric.id
else
#
# Quick way to update node.metric_id without saving the serialized cols.
#
MiqCimInstance.where(:id => node.id).update_all(:metric_id => metricId) unless node.metric_id == metricId
end
end
def deriveMetrics(node, metricHash)
if (metric = node.metrics).nil?
metric = getMetricForNode(node, metricHash)
else
pon = CLASS_TO_PERF_OBJECT_NAMES[node.class_name].first
metric.derive_metrics(metricHash, counterInfo[pon])
end
metric
end
def getMetricForNode(node, metricHash = nil)
pon = CLASS_TO_PERF_OBJECT_NAMES[node.class_name].first
case pon
when "aggregate"
metric = OntapAggregateMetric.new
when "disk"
metric = OntapDiskMetric.new
when "LUN"
metric = OntapLunMetric.new
when "System"
metric = OntapSystemMetric.new
when "volume"
metric = OntapVolumeMetric.new
else
metric = MiqCimMetric.new
end
metric.metric_obj = metricHash
node.addNewMetric(metric)
metric
end
def getPerfData(objectname, counters = nil, instances = nil)
rv = @conn.perf_object_get_instances_iter_start do |ah|
ah.objectname = objectname
ah.counters = NetAppManageability::NAMHash.new { |h|
h.counter = counters
} unless counters.nil?
ah.instances = NetAppManageability::NAMHash.new { |h|
h.instance = instances
} unless instances.nil?
end
begin
tag = rv.tag
timestamp = rv.timestamp
retArr = []
loop do
rv = @conn.perf_object_get_instances_iter_next(:maximum, @max_chunk, :tag, tag)
return timestamp, retArr if rv.records.to_i == 0
retArr.concat(rv.instances.instance_data.to_ary)
end
ensure
@conn.perf_object_get_instances_iter_end(:tag, tag)
end
end
def collectPerf(statistic_time)
rh = NetAppManageability::NAMHash.new
rh.statistic_time = statistic_time
PERF_OBJECT_NAMES.each do |pon|
oh = rh[pon]
rh[pon] = oh = NetAppManageability::NAMHash.new unless oh
ts, rv = getPerfData(pon, OBJECT_NAME_TO_COUNTERS[pon])
rv.each do |inst|
oh[inst.name] = ih = NetAppManageability::NAMHash.new
ih.timestamp = ts
ih.name = inst.name
ih.counters = ch = NetAppManageability::NAMHash.new
inst.counters.counter_data.to_ary.each do |ce|
ch[ce.name] = ce.value
end
end
end
rh
end
def getCounterInfoForObj(objectname)
rv = @conn.perf_object_counter_list_info(:objectname, objectname)
rh = NetAppManageability::NAMHash.new
rv.counters.counter_info.to_ary.each do |ci|
rh[ci.name] = ci
end
rh
end
def getCounterInfo
rh = NetAppManageability::NAMHash.new
PERF_OBJECT_NAMES.each { |on| rh[on] = getCounterInfoForObj(on) }
rh
end
def counterInfo
@@counterInfoLock.synchronize(:EX) do
@@counterInfo = getCounterInfo if @@counterInfo.nil?
return @@counterInfo
end
end
end # class OntapClient
end # module MiqOntapClient
if $0 == "script/runner"
require "util/MiqDumpObj"
module NetAppManageability
class NAMHash
include MiqDumpObj
def __dump
dumpObj(self)
end
end
class NAMArray
include MiqDumpObj
def __dump
dumpObj(self)
end
end
end
begin
# SERVER = "192.168.252.30"
SERVER = "192.168.252.169"
USERNAME = "root"
PASSWORD = "smartvm"
include MiqOntapClient
puts "Connecting to #{SERVER}..."
oc = OntapClient.new(SERVER, USERNAME, PASSWORD)
puts "done."
puts "Version: #{oc.version_string}"
puts
# oc.counterInfo.__dump
oc.updateOntap
# oc.updateMetrics
rescue => err
puts err.to_s
puts err.backtrace.join("\n")
end
end