spectools 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. data/CHANGELOG.txt +1 -0
  2. data/Manifest.txt +80 -0
  3. data/README.txt +33 -0
  4. data/README.vnmsh.txt +39 -0
  5. data/Rakefile +42 -0
  6. data/TODO +5 -0
  7. data/lib/spectools.rb +588 -0
  8. data/lib/spectools/version.rb +9 -0
  9. data/lib/vnmsh.rb +1930 -0
  10. data/test/data/connect.success +8 -0
  11. data/test/data/create.alarm +2 -0
  12. data/test/data/create.association +1 -0
  13. data/test/data/create.model +1 -0
  14. data/test/data/create.model.ip +1 -0
  15. data/test/data/destroy.alarm +1 -0
  16. data/test/data/destroy.association +1 -0
  17. data/test/data/destroy.model +9 -0
  18. data/test/data/seek +2 -0
  19. data/test/data/seek.-s +17 -0
  20. data/test/data/show.alarms +10 -0
  21. data/test/data/show.alarms-a +11 -0
  22. data/test/data/show.alarms-a-x +22 -0
  23. data/test/data/show.alarms-x +20 -0
  24. data/test/data/show.alarms.mh +1 -0
  25. data/test/data/show.associations +160 -0
  26. data/test/data/show.attributes +909 -0
  27. data/test/data/show.attributes.attr +2 -0
  28. data/test/data/show.attributes.attriid +2 -0
  29. data/test/data/show.attributes.attrname +6 -0
  30. data/test/data/show.attributes.attrr +14 -0
  31. data/test/data/show.attributes.enum +2 -0
  32. data/test/data/show.attributes.flags +16 -0
  33. data/test/data/show.attributes.mth +242 -0
  34. data/test/data/show.attributes.mth.attrr +12 -0
  35. data/test/data/show.children +47 -0
  36. data/test/data/show.children.rel +14 -0
  37. data/test/data/show.devices +21 -0
  38. data/test/data/show.enumerations +142383 -0
  39. data/test/data/show.enumerations.attr +4 -0
  40. data/test/data/show.enumerations.mth +149 -0
  41. data/test/data/show.events +2001 -0
  42. data/test/data/show.events-a +10001 -0
  43. data/test/data/show.events-n5 +6 -0
  44. data/test/data/show.events-x-n5 +21 -0
  45. data/test/data/show.inheritance +12 -0
  46. data/test/data/show.landscapes +3 -0
  47. data/test/data/show.models +2252 -0
  48. data/test/data/show.models.mhr +18 -0
  49. data/test/data/show.models.mname +4 -0
  50. data/test/data/show.models.mth +4 -0
  51. data/test/data/show.parents +6 -0
  52. data/test/data/show.relations +151 -0
  53. data/test/data/show.rules +5838 -0
  54. data/test/data/show.types +4210 -0
  55. data/test/data/show.types.flags +3137 -0
  56. data/test/data/show.types.mthr +55 -0
  57. data/test/data/show.types.mtname +2 -0
  58. data/test/data/show.watch +9 -0
  59. data/test/data/test.reconnect +1 -0
  60. data/test/data/update.alarm +1 -0
  61. data/test/data/update.model +3 -0
  62. data/test/test_helper.rb +2 -0
  63. data/test/test_spectools.rb +403 -0
  64. data/test/test_vnmsh.rb +1537 -0
  65. data/test/testcmds/ack +1 -0
  66. data/test/testcmds/connect +32 -0
  67. data/test/testcmds/create +34 -0
  68. data/test/testcmds/destroy +36 -0
  69. data/test/testcmds/disconnect +7 -0
  70. data/test/testcmds/seek +18 -0
  71. data/test/testcmds/show +243 -0
  72. data/test/testcmds/update +12 -0
  73. data/test/vnmsh/ack +1 -0
  74. data/test/vnmsh/connect +5 -0
  75. data/test/vnmsh/create +1 -0
  76. data/test/vnmsh/destroy +1 -0
  77. data/test/vnmsh/disconnect +1 -0
  78. data/test/vnmsh/seek +3 -0
  79. data/test/vnmsh/show +1 -0
  80. data/test/vnmsh/update +1 -0
  81. metadata +134 -0
@@ -0,0 +1 @@
1
+ 1.0.0 - Initial release.
@@ -0,0 +1,80 @@
1
+ TODO
2
+ CHANGELOG.txt
3
+ Manifest.txt
4
+ README.txt
5
+ README.vnmsh.txt
6
+ Rakefile
7
+ lib/spectools.rb
8
+ lib/spectools/version.rb
9
+ lib/vnmsh.rb
10
+ test/data/connect.success
11
+ test/data/create.alarm
12
+ test/data/create.association
13
+ test/data/create.model
14
+ test/data/create.model.ip
15
+ test/data/destroy.alarm
16
+ test/data/destroy.association
17
+ test/data/destroy.model
18
+ test/data/seek
19
+ test/data/seek.-s
20
+ test/data/show.alarms
21
+ test/data/show.alarms-a
22
+ test/data/show.alarms-a-x
23
+ test/data/show.alarms-x
24
+ test/data/show.alarms.mh
25
+ test/data/show.associations
26
+ test/data/show.attributes
27
+ test/data/show.attributes.attr
28
+ test/data/show.attributes.attriid
29
+ test/data/show.attributes.attrname
30
+ test/data/show.attributes.attrr
31
+ test/data/show.attributes.enum
32
+ test/data/show.attributes.flags
33
+ test/data/show.attributes.mth
34
+ test/data/show.attributes.mth.attrr
35
+ test/data/show.children
36
+ test/data/show.children.rel
37
+ test/data/show.devices
38
+ test/data/show.enumerations
39
+ test/data/show.enumerations.attr
40
+ test/data/show.enumerations.mth
41
+ test/data/show.events
42
+ test/data/show.events-a
43
+ test/data/show.events-n5
44
+ test/data/show.events-x-n5
45
+ test/data/show.inheritance
46
+ test/data/show.landscapes
47
+ test/data/show.models
48
+ test/data/show.models.mhr
49
+ test/data/show.models.mname
50
+ test/data/show.models.mth
51
+ test/data/show.parents
52
+ test/data/show.relations
53
+ test/data/show.rules
54
+ test/data/show.types
55
+ test/data/show.types.flags
56
+ test/data/show.types.mthr
57
+ test/data/show.types.mtname
58
+ test/data/show.watch
59
+ test/data/test.reconnect
60
+ test/data/update.alarm
61
+ test/data/update.model
62
+ test/test_helper.rb
63
+ test/test_spectools.rb
64
+ test/test_vnmsh.rb
65
+ test/testcmds/ack
66
+ test/testcmds/connect
67
+ test/testcmds/create
68
+ test/testcmds/destroy
69
+ test/testcmds/disconnect
70
+ test/testcmds/seek
71
+ test/testcmds/show
72
+ test/testcmds/update
73
+ test/vnmsh/ack
74
+ test/vnmsh/connect
75
+ test/vnmsh/create
76
+ test/vnmsh/destroy
77
+ test/vnmsh/disconnect
78
+ test/vnmsh/seek
79
+ test/vnmsh/show
80
+ test/vnmsh/update
@@ -0,0 +1,33 @@
1
+ SpecTools is a toolset designed to make working with CA's SPECTRUM product (now Network Fault Manager) much easier. The base library represents the SPECTRUM data model: Models, Events, Alarms, Model Types, etc. All extra functionality is provided by extensions.
2
+
3
+ Using the base SpecTools classes is very simple. Just require it!
4
+
5
+ require 'rubygems'
6
+ require 'spcetools'
7
+
8
+ model = SpecTools::Model.new
9
+ model.handle = 'test handle'
10
+
11
+ All of the classes have good RDoc, so reference it to see what the structure looks like.
12
+
13
+ Using Extensions.
14
+
15
+ SpecTools has a very easy way of adding extra functionality to the library, called extensions.
16
+
17
+ Using extensions.
18
+
19
+ Using an extension is usually just a matter of requiring the object. For example, to use
20
+ the CLI extenson, VNMSH, you would just:
21
+
22
+ require 'rubygems'
23
+ require 'spectools'
24
+ require 'vnmsh'
25
+
26
+ Extensions extend the SpecTools by adding methods to the SpecTools classes. The methods all share
27
+ a common prefix, which identifies the extension.`SpecTools has a config option,
28
+ SpecTools::Config.default_access_method , that allows a user to determine what extension methods
29
+ to use by default. For example, if SpecTools::Config.default_access_method = :cli , any method with
30
+ a cli_ prefix will be available without needing to use the prefix. To continue the example, calling
31
+ Model.find will automatically call Model.cli_find for you.
32
+
33
+ Currently, the only available extension is VNMSH. You can read more about it in README.vnmsh.
@@ -0,0 +1,39 @@
1
+ What is VNMSH?
2
+
3
+ The VNMSH extension allows you to use SpecTools with the SPECTRUM
4
+ CLI interface. With few exceptions, anything you can do with CLI,
5
+ you can do with VNMSH. Also, the extension provides everything in
6
+ SpecTools objects, not a flat strings or lines, so the data looks much
7
+ more structures.
8
+
9
+ Using the VNMSH Extension for SpecTools
10
+
11
+ First, require both SpecTools and VNMSH:
12
+
13
+ require 'rubygems'
14
+ require 'spectools'
15
+ require 'vnmsh'
16
+
17
+ Now, we'll establish a new VNMSH connection. If you have SPECROOT
18
+ defined on the system, it is used, otherwise you'll need to pass
19
+ it in:
20
+
21
+ session = VNMSH.new
22
+ session.connect
23
+
24
+ You can now use any SpecTools method with a cli_ prefix. If you want
25
+ to use VNMSH as you're default access method with SpecTools, set
26
+ SpecTools::Config.default_access_method = :cli . This way, you won't
27
+ have to use the cli_ prefix when using VNMSH methods.
28
+
29
+ All cli methods take a session as the last parameter. The session is
30
+ VNMSH session that you connected with. If you want to use a session
31
+ and don't want to explictly pass it, you can simply assign your
32
+ connected session to VNMSH.default session:
33
+
34
+ VNMSH.default_session = session
35
+
36
+ Then you won't need to explictly pass a session over, however you can
37
+ still override the default session by explictly passing it.
38
+
39
+ Have fun using VNMSH!
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'fileutils'
3
+ require 'hoe'
4
+ include FileUtils
5
+ require File.join(File.dirname(__FILE__), 'lib', 'spectools', 'version')
6
+
7
+ AUTHOR = "Donavan Pantke" # can also be an array of Authors
8
+ EMAIL = "spectools-general@rubyforge.org"
9
+ DESCRIPTION = "A utility suite for CA's SPECTRUM Network Fault Manager"
10
+ GEM_NAME = "spectools" # what ppl will type to install your gem
11
+ RUBYFORGE_PROJECT = "spectools" # The unix name for your project
12
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
13
+
14
+
15
+ NAME = "spectools"
16
+ REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
17
+ VERS = ENV['VERSION'] || (Spectools::VERSION::STRING + (REV ? ".#{REV}" : ""))
18
+
19
+ class Hoe
20
+ def extra_deps
21
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
22
+ end
23
+ end
24
+ ENV['NODOT'] = '1'
25
+ # Generate all the Rake tasks
26
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
27
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
28
+ p.author = AUTHOR
29
+ p.description = DESCRIPTION
30
+ p.email = EMAIL
31
+ p.summary = DESCRIPTION
32
+ p.url = HOMEPATH
33
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
34
+ p.rdoc_pattern = /^(lib|bin)|txt|TODO$/
35
+
36
+ # p.clean_globs = CLEAN #An array of file patterns to delete on clean.
37
+
38
+ # == Optional
39
+ #p.changes - A description of the release's latest changes.
40
+ #p.extra_deps - An array of rubygem dependencies.
41
+ #p.spec_extras - A hash of extra values to set in the gemspec.
42
+ end
data/TODO ADDED
@@ -0,0 +1,5 @@
1
+ TODO for version 1.1.0:
2
+ - Create dispacther for use by AlarmNotifier.
3
+ Future versions:
4
+ - Create hooks to Southbound Gateway.
5
+ - Create hooks to Modeling Gateway.
@@ -0,0 +1,588 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'stringio'
4
+
5
+ # Copyright 2007 Donavan Pantke
6
+
7
+ #SpecTools is a set of classes designed to help admins of CA's Spectrum perform common functions
8
+
9
+ #We define here an extension to the String class to test if the string contains a valid Hex Code
10
+ class String #:nodoc:
11
+ def hex?
12
+ !((self =~ /^0x[a-fA-F0-9]+$/).nil?)
13
+ end
14
+ end
15
+
16
+ # == Utility Module for SpecTools
17
+ # The module defines some useful extensions that SpecTools utilizes.
18
+ module SpecToolsExtensions
19
+
20
+ # This method allows extension developers to extend SpecTools without having to redefine stock methods.
21
+ # call_extension is usually invoked through method_missing or call_default_extension. It takes a method (in symbol form)
22
+ # and appends the prefix defined in SpecTools::Config.default_access_method .
23
+ # Example:
24
+ #
25
+ # <tt>call_extension(:get_attr,*args)</tt>
26
+ #
27
+ # if SpecTools::Config.default_access_method is set to <tt>:access</tt>, call_extension will attempt call
28
+ # <tt>access_call_extension(*args)</tt>
29
+ # on itself, if the method is available. If the method does not exist, +NoMethodError+ is raised.
30
+ def call_extension(method,*args)
31
+ newmethod = SpecTools::Config.default_access_method.to_s + '_' + method.to_s
32
+ if self.respond_to?(newmethod.to_sym)
33
+ self.send(newmethod.to_sym, *args)
34
+ else
35
+ raise NoMethodError, "undefined method `#{newmethod}' for #{self}"
36
+ end
37
+ end
38
+
39
+ def method_missing(method, *args) #:nodoc:
40
+ if SpecTools::Config.default_access_method != nil
41
+ call_extension(method,*args)
42
+ else
43
+ super.method_missing
44
+ end
45
+ end
46
+
47
+ def self.method_missing(method, *args) #:nodoc:
48
+ if SpecTools::Config.default_access_method != nil
49
+ call_extension(method,*args)
50
+ else
51
+ super.method_missing
52
+ end
53
+ end
54
+
55
+
56
+ # This method is explicitly called by the standard SpecTools object methods.
57
+ #
58
+ # Calls call_extension with the method sent.
59
+ #
60
+ # If <tt>SpecTools::Config.default_access_method</tt> is not set, <tt>SpecTools::NoAccessMethodError</tt> is raised.
61
+ def call_default_extension(method,*args)
62
+ if SpecTools::Config.default_access_method != nil
63
+ call_extension(method,*args)
64
+ else
65
+ raise SpecTools::NoAccessMethodError, 'In order to use this method, you must define Config::default_access_method'
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ module SpecTools
72
+
73
+
74
+ #Raised when SpecTools::Config.default_access_method is not set, and so the default accessor cannot be used.
75
+ class NoAccessMethodError < StandardError
76
+ end
77
+
78
+ #Raised when an attribute is assigned an incorrect value for its type. E.g. a list attribute is
79
+ #assigned a non-list value, or a non-list attribute is assigned a value_table.
80
+ class InvalidValueTypeError < StandardError
81
+ end
82
+
83
+
84
+
85
+
86
+
87
+ # == SpecTools::Config
88
+ # Contains module configuration.
89
+ class Config
90
+
91
+ class << self
92
+ #The default extension the data classes use when performing lookups.
93
+ #The VNMSH extension defines the :cli access method.
94
+ attr_accessor :default_access_method
95
+ end
96
+
97
+ end
98
+
99
+ # == SpecTools::Attr
100
+ # Represents a Spectrum Attribute
101
+ class Attr
102
+
103
+ extend SpecToolsExtensions
104
+ include SpecToolsExtensions
105
+
106
+ #The attribute ID
107
+ attr_accessor :id
108
+ #The attribute name
109
+ attr_accessor :name
110
+ #The value of the attribute.
111
+ #Cannot be written to if the attribute is a list.
112
+ #If read from a list attribute, returns the first
113
+ #value from the list.
114
+ attr_accessor :value
115
+ #For list attributes, a hash of instance-value pairs.
116
+ #Can only be set if the attribute is a list attribute.
117
+ attr_accessor :value_table
118
+ #A hash of the attribute's available enumerations
119
+ attr_accessor :enums
120
+ #The primitive type of the attribute
121
+ attr_accessor :type
122
+ #Set to true if the attribute is external
123
+ attr_accessor :external
124
+ #Set to true if the attribute is readable
125
+ attr_accessor :readable
126
+ #Set to true if the attribute is writeable
127
+ attr_accessor :writeable
128
+ #Set to true if the attribute is shared
129
+ attr_accessor :shared
130
+ #Set to true if the attribute is a list attribute
131
+ attr_accessor :list
132
+ #Set to true if the attribute is guaranteed
133
+ attr_accessor :guaranteed
134
+ #Set to true of the attribute is global
135
+ attr_accessor :global
136
+ #Set to true if the attribute is in memory
137
+ attr_accessor :memory
138
+ #Set to true if the attribute is a database attribute
139
+ attr_accessor :database
140
+ #Set to true if the attribute is polled
141
+ attr_accessor :polled
142
+ #Set to true if the attribute is logged
143
+ attr_accessor :logged
144
+ #Set to true if the attribute is preserved
145
+ attr_accessor :preserve
146
+
147
+ def initialize(id = nil, name = nil, value = nil, value_table = nil, enums = nil, list = false, type = nil, external = false, readable = false, writeable = false, shared = false, guaranteed = false, global = false, memory = false, database = false, polled = false, logged = false, preserve = false)
148
+ if id.nil? || id.hex?
149
+ @id = id
150
+ else
151
+ raise ArgumentError, "Id is not a hex code"
152
+ end
153
+ @name = name
154
+ @enums = enums
155
+ @type = type
156
+ @external = external
157
+ @readable = readable
158
+ @writeable = writeable
159
+ @shared = shared
160
+ @list = list
161
+ @guaranteed = guaranteed
162
+ @global = global
163
+ @memory = memory
164
+ @database = database
165
+ @polled = polled
166
+ @logged = logged
167
+ @preserve = preserve
168
+ if list
169
+ if value_table
170
+ @value_table = value_table
171
+ else
172
+ value_table = Hash.new
173
+ end
174
+ @value = nil
175
+ else
176
+ @value_table = nil
177
+ @value = value
178
+ end
179
+ end
180
+
181
+ #Override the default writer for value. If the attr is a list , raise an error.
182
+ def value=(value) #:nodoc:
183
+ if list
184
+ raise InvalidValueTypeError, 'Attempt to set a list attribute to a non-list value'
185
+ else
186
+ @value = value
187
+ end
188
+ end
189
+
190
+ #Override the default writer for value_table. If the attr is a not a list, raise an error
191
+ def value_table=(value) #:nodoc:
192
+ unless list
193
+ raise InvalidValueTypeError, 'Attempt to set a regular attribute to a list value.'
194
+ else
195
+ @value_table = value
196
+ end
197
+ end
198
+
199
+ #Override the default value accessor. If we're a list attribute, return the first value in the list.
200
+ def value #:nodoc:
201
+ if list && value_table
202
+ @value_table[value_table.keys.sort.first]
203
+ elsif list
204
+ nil
205
+ else
206
+ @value
207
+ end
208
+ end
209
+
210
+ #Override the default list writer. Populate the appropriate value attribute.
211
+ def list=(list) #:nodoc:
212
+ if list
213
+ @value_table = Hash.new unless @value_table
214
+ end
215
+ @list = list
216
+ end
217
+
218
+
219
+
220
+ #Look up the value of the given attribute and return its enumerated counterpart.
221
+ #If the Attr does not have a populated enums hash, will
222
+ #attempt to use SpecToolsExtensions#call_default_extension to obtain the enumerations
223
+ #via the <tt>get_enums</tt> method. If enumeration fails, the original value
224
+ #is returned. All <tt>args</tt> are used for the call to <tt>get_enums</tt>, if
225
+ #necessary.
226
+ #<b>Note:</b> Errors raised by a call to get_enums will not be caught.
227
+ def enumerate(*args)
228
+ if enums.kind_of?(Hash)
229
+ avail_enums = enums
230
+ else
231
+ begin
232
+ avail_enums = call_default_extension(:get_enums, *args)
233
+ rescue NoAccessMethodError, NoMethodError
234
+ avail_enums = {}
235
+ end
236
+ end
237
+ if avail_enums[value]
238
+ return avail_enums[value]
239
+ else
240
+ return value
241
+ end
242
+
243
+ end
244
+
245
+ #Change the value of the attribute to its enumerated string.
246
+ #If enumeration fails, the value is left unchanged.
247
+ #All arguments are passed through to enumerate.
248
+ def enumerate!(*args)
249
+ enum = enumerate(*args)
250
+ self.value = enum unless enum == value
251
+ end
252
+
253
+
254
+
255
+ end
256
+
257
+ # == SpecTools::MType
258
+ # Represents a Spectrum model type
259
+ class MType
260
+
261
+ extend SpecToolsExtensions
262
+ include SpecToolsExtensions
263
+
264
+ #The model type handle (mth)
265
+ attr_accessor :handle
266
+ #The model type's name
267
+ attr_accessor :name
268
+ #Set to true if the model type is visible
269
+ attr_accessor :visible
270
+ #Set to true if the model type can be instantiated
271
+ attr_accessor :instantiable
272
+ #Set to true if new model types can be derived from this one
273
+ attr_accessor :derivable
274
+ #Set to true if only one model of this type can exist
275
+ attr_accessor :unique
276
+ #Set to true if a model of the type must exist in the database
277
+ attr_accessor :required
278
+ #Set to true if models of this type can be destroyed
279
+ attr_accessor :destroyable
280
+ #An hash of Attr objects for this model type.
281
+ #When setting this attribute, you may either pass in a valid Hash
282
+ #or an Array of Attr objects
283
+ attr_accessor :attrs
284
+ #The type of inheritance
285
+ attr_accessor :inheritance
286
+
287
+ def initialize(handle = nil, name = nil, attrs=Hash.new, visible = false, instantiable = false, derivable = false, destroyable = true, unique = false, required = false,inheritance = nil)
288
+ if handle.nil? || handle.hex?
289
+ @handle = handle
290
+ else
291
+ raise ArgumentError, "Handle is not a hex code"
292
+ end
293
+ @name = name
294
+ @visible = visible
295
+ @instantiable = instantiable
296
+ @derivable = derivable
297
+ @destroyable = destroyable
298
+ @unique = unique
299
+ @required = required
300
+ @inheritance = inheritance
301
+ @attrs = populate(attrs)
302
+ end
303
+
304
+ #define a custom setter for attrs that will automatically convert
305
+ #an Array into a properly formatted hash.
306
+ def attrs=(new_attrs) #:nodoc:
307
+ if new_attrs.kind_of?(Hash)
308
+ @attrs = new_attrs
309
+ elsif new_attrs.kind_of?(Array)
310
+ @attrs = populate(new_attrs)
311
+ else
312
+ raise ArgumentError, 'attrs can only be assigned an Array or a Hash of Attr objects'
313
+ end
314
+ end
315
+
316
+ private
317
+ #Generate an attribute hash from an array
318
+ def populate(attrs)
319
+ attrs_hash = Hash.new
320
+ attrs.each do |specattr|
321
+ raise ArgumentError,
322
+ 'The array can only contain SpecTools::Attr objects' unless specattr.kind_of?(Attr)
323
+ attrs_hash[specattr.id] = specattr
324
+ end
325
+ attrs_hash
326
+ end
327
+
328
+
329
+
330
+ end
331
+
332
+ # == SpecTools::Model
333
+ # Represents a Spectrum model
334
+ class Model
335
+
336
+ extend SpecToolsExtensions
337
+ include SpecToolsExtensions
338
+
339
+ #The model's handle
340
+ attr_accessor :handle
341
+ #The model's name
342
+ attr_accessor :name
343
+ #The model's MType
344
+ attr_accessor :type
345
+ #A hash of Attr objects for the model
346
+ attr_accessor :attrs
347
+
348
+ def initialize(handle = nil, name = nil, type = MType.new, *attrs)
349
+ if handle.nil? || handle.hex?
350
+ @handle = handle
351
+ else
352
+ raise ArgumentError, "Handle is not a hex code"
353
+ end
354
+ @name = name
355
+ @type = type
356
+ @attrs = Hash.new
357
+ attrs.each do |specattr|
358
+ if specattr.nil? || specattr.instance_of?(Attr)
359
+ @attrs[specattr.id] = specattr
360
+ else
361
+ raise ArgumentError
362
+ end
363
+ end
364
+
365
+ end
366
+
367
+ end
368
+
369
+ # == SpecTools::Relation
370
+ # Represents a Spectrum relation
371
+ class Relation
372
+
373
+ extend SpecToolsExtensions
374
+ include SpecToolsExtensions
375
+
376
+ #The relation's name
377
+ attr_accessor :name
378
+ #This relation's type
379
+ attr_accessor :type
380
+
381
+ def initialize(name = nil, type = nil)
382
+ @name = name
383
+ @type = type
384
+ end
385
+
386
+ end
387
+
388
+ # == SpecTools::Association
389
+ # Represents a Spectrum Association
390
+ class Association
391
+
392
+ extend SpecToolsExtensions
393
+ include SpecToolsExtensions
394
+
395
+ #The Model on the left hand side of the association
396
+ attr_accessor :left_model
397
+ #The Model on the right hand side of the association
398
+ attr_accessor :right_model
399
+ #The Relation used for this association
400
+ attr_accessor :relation
401
+
402
+ def initialize(left_model = Model.new, right_model = Model.new, relation = Relation.new)
403
+ @left_model = left_model
404
+ @right_model = right_model
405
+ @relation = relation
406
+ end
407
+
408
+ end
409
+
410
+ # == SpecTools::Alarm
411
+ # Represents a Spectrum alarm
412
+ class Alarm
413
+
414
+ extend SpecToolsExtensions
415
+ include SpecToolsExtensions
416
+
417
+ #The alarm's ID
418
+ attr_accessor :id
419
+ #The time the alarm was generated.
420
+ #This time is local!
421
+ attr_accessor :time
422
+ #The alarm's Probable Cause ID
423
+ attr_accessor :causeid
424
+ #The Model the alarm was asserted against
425
+ attr_accessor :model
426
+ #The alarm's severity
427
+ attr_accessor :severity
428
+ #Who the alarm is assigned to
429
+ attr_accessor :assignment
430
+ #The alarm's status
431
+ attr_accessor :status
432
+ #Set to true if the alarm has been acknowledged
433
+ attr_accessor :ack
434
+ #Set to true if the alarm is stale
435
+ attr_accessor :stale
436
+ #The Probable Cause text for the alarm
437
+ attr_accessor :message
438
+ #The URL for extra information about this alarm
439
+ attr_accessor :url
440
+ #The ticket number associated with this alarm
441
+ attr_accessor :ticket
442
+
443
+ def initialize(id = nil, time = nil, causeid = nil, model = Model.new, severity = nil, ack = false, stale = false, assignment = nil, status = nil, message = nil, url = nil, ticket = nil)
444
+ @id = id
445
+ @time = time
446
+ if causeid.nil? || causeid.hex?
447
+ @causeid = causeid
448
+ else
449
+ raise ArgumentError, "causeid is not a hex code."
450
+ end
451
+ if model.nil? || model.kind_of?(Model)
452
+ @model = model
453
+ else
454
+ raise ArgumentError, "model is not a Model object"
455
+ end
456
+ @severity = severity
457
+ @ack = ack
458
+ @stale = stale
459
+ @assignment = assignment
460
+ @status = status
461
+ @message = message
462
+ @url = url
463
+ @ticket = ticket
464
+ end
465
+
466
+ #Returns true if the alarm has been acknowledged
467
+ def ack?
468
+ @ack
469
+ end
470
+
471
+ #Returns true if the alarm is stale
472
+ def stale?
473
+ @stale
474
+ end
475
+
476
+
477
+ end
478
+
479
+ # == SpecTools::Landscape
480
+ # Represents a Spectrum Landscape
481
+ class Landscape
482
+
483
+ extend SpecToolsExtensions
484
+ include SpecToolsExtensions
485
+
486
+ #This landscape's SpectroSERVER
487
+ attr_accessor :ss
488
+ #The landscape's precedence
489
+ attr_accessor :precedence
490
+ #The SS port that the landscape is using
491
+ attr_accessor :port
492
+ #The landscape's service
493
+ attr_accessor :service
494
+ #The landscape's handle
495
+ attr_accessor :handle
496
+
497
+ def initialize(handle = nil, ssname = nil, precedence = nil, port = nil, service = nil )
498
+ @ss = ssname
499
+ @precedence = precedence
500
+ @port = port
501
+ @service = service
502
+ if handle.nil? || handle.hex?
503
+ @handle = handle
504
+ else
505
+ raise ArgumentError, "Handle is not a hex code"
506
+ end
507
+ end
508
+
509
+ end
510
+
511
+ # == SpecTools::Event
512
+ # Represents a Spectrum event
513
+ class Event
514
+
515
+ extend SpecToolsExtensions
516
+
517
+ #The time of the event
518
+ #This time is local!
519
+ attr_accessor :time
520
+ #The event's type (or Event ID)
521
+ attr_accessor :type
522
+ #The Model the event was asserted against
523
+ attr_accessor :model
524
+ #The event message
525
+ attr_accessor :message
526
+
527
+ def initialize(time = nil, type = nil, model = Model.new, message = '')
528
+ @time = time
529
+ if type.nil? || type.hex?
530
+ @type = type
531
+ else
532
+ raise ArgumentError, "Type is not a hex code."
533
+ end
534
+ @model = model
535
+ @message = message
536
+ end
537
+
538
+ end
539
+
540
+ # == SpecTools::Rule
541
+ # Represents a Spectrum Rule
542
+ class Rule
543
+
544
+ extend SpecToolsExtensions
545
+ include SpecToolsExtensions
546
+
547
+ #The MType on the left hand side of the rule
548
+ attr_accessor :left_mtype
549
+ #The MType on the right hand side of the rule
550
+ attr_accessor :right_mtype
551
+
552
+ def initialize(left_mtype = MType.new, right_mtype = MType.new)
553
+ @left_mtype = left_mtype
554
+ @right_mtype = right_mtype
555
+ end
556
+
557
+ end
558
+
559
+ # == SpecTools::Watch
560
+ # Represents a SpectroWATCH
561
+ class Watch
562
+
563
+ extend SpecToolsExtensions
564
+ include SpecToolsExtensions
565
+
566
+ #The watch's ID (analogous to an Attr ID)
567
+ attr_accessor :id
568
+ #The watch's name
569
+ attr_accessor :name
570
+ #The watch's type
571
+ attr_accessor :type
572
+ #The watch's status
573
+ attr_accessor :status
574
+
575
+ def initialize(id = nil, name = nil, type = nil, status = nil)
576
+ @id = id
577
+ @name = name
578
+ @type = type
579
+ @status = status
580
+ end
581
+
582
+
583
+ end
584
+
585
+ end
586
+
587
+
588
+