brocadesan 0.4.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 (79) hide show
  1. data/README +113 -0
  2. data/Rakefile +46 -0
  3. data/brocadesan.gemspec +14 -0
  4. data/lib/brocadesan.rb +8 -0
  5. data/lib/brocadesan/alias.rb +64 -0
  6. data/lib/brocadesan/config/brocade/san/switch_cmd_mapping.yml +116 -0
  7. data/lib/brocadesan/config/parser_mapping.yml +21 -0
  8. data/lib/brocadesan/device.rb +296 -0
  9. data/lib/brocadesan/monkey/string.rb +11 -0
  10. data/lib/brocadesan/provisioning.rb +894 -0
  11. data/lib/brocadesan/switch.rb +882 -0
  12. data/lib/brocadesan/wwn.rb +63 -0
  13. data/lib/brocadesan/zone.rb +60 -0
  14. data/lib/brocadesan/zone_configuration.rb +38 -0
  15. data/lib/meta_methods.rb +263 -0
  16. data/test/alias_test.rb +68 -0
  17. data/test/device_test.rb +203 -0
  18. data/test/output_helpers.rb +308 -0
  19. data/test/outputs/agshow_1.txt +7 -0
  20. data/test/outputs/agshow_1.yml +31 -0
  21. data/test/outputs/agshow_2.txt +4 -0
  22. data/test/outputs/agshow_2.yml +3 -0
  23. data/test/outputs/apt_policy_1.txt +6 -0
  24. data/test/outputs/apt_policy_1.yml +3 -0
  25. data/test/outputs/cfgshow_1.txt +5 -0
  26. data/test/outputs/cfgshow_1.yml +7 -0
  27. data/test/outputs/cfgshow_2.txt +31 -0
  28. data/test/outputs/cfgshow_2.yml +32 -0
  29. data/test/outputs/cfgshow_3.txt +9 -0
  30. data/test/outputs/cfgshow_3.yml +12 -0
  31. data/test/outputs/cfgtransshow_1.txt +2 -0
  32. data/test/outputs/cfgtransshow_1.yml +5 -0
  33. data/test/outputs/cfgtransshow_2.txt +3 -0
  34. data/test/outputs/cfgtransshow_2.yml +4 -0
  35. data/test/outputs/cfgtransshow_3.txt +3 -0
  36. data/test/outputs/cfgtransshow_3.yml +4 -0
  37. data/test/outputs/chassisname_1.txt +2 -0
  38. data/test/outputs/chassisname_1.yml +3 -0
  39. data/test/outputs/dlsshow_1.txt +4 -0
  40. data/test/outputs/dlsshow_1.yml +4 -0
  41. data/test/outputs/dlsshow_2.txt +4 -0
  42. data/test/outputs/dlsshow_2.yml +4 -0
  43. data/test/outputs/fabricshow_1.txt +10 -0
  44. data/test/outputs/fabricshow_1.yml +34 -0
  45. data/test/outputs/iodshow_1.txt +4 -0
  46. data/test/outputs/iodshow_1.yml +4 -0
  47. data/test/outputs/islshow_1.txt +6 -0
  48. data/test/outputs/islshow_1.yml +62 -0
  49. data/test/outputs/islshow_2.txt +2 -0
  50. data/test/outputs/islshow_2.yml +2 -0
  51. data/test/outputs/lscfg_show_1.txt +71 -0
  52. data/test/outputs/lscfg_show_1.yml +5 -0
  53. data/test/outputs/ns_1.txt +80 -0
  54. data/test/outputs/ns_1.yml +39 -0
  55. data/test/outputs/ns_2.txt +37 -0
  56. data/test/outputs/ns_2.yml +21 -0
  57. data/test/outputs/putty.log +1867 -0
  58. data/test/outputs/switch_1.txt +25 -0
  59. data/test/outputs/switch_1.yml +73 -0
  60. data/test/outputs/switch_2.txt +18 -0
  61. data/test/outputs/switch_2.yml +42 -0
  62. data/test/outputs/switch_3.txt +14 -0
  63. data/test/outputs/switch_3.yml +46 -0
  64. data/test/outputs/switchstatusshow_1.txt +21 -0
  65. data/test/outputs/switchstatusshow_1.yml +19 -0
  66. data/test/outputs/trunkshow_1.txt +8 -0
  67. data/test/outputs/trunkshow_1.yml +44 -0
  68. data/test/outputs/trunkshow_2.txt +2 -0
  69. data/test/outputs/trunkshow_2.yml +2 -0
  70. data/test/outputs/version_1.txt +6 -0
  71. data/test/outputs/version_1.yml +8 -0
  72. data/test/outputs/vf_switch_1.txt +25 -0
  73. data/test/outputs/vf_switch_1.yml +73 -0
  74. data/test/provisioning_test.rb +1043 -0
  75. data/test/switch_test.rb +476 -0
  76. data/test/wwn_test.rb +41 -0
  77. data/test/zone_configuration_test.rb +65 -0
  78. data/test/zone_test.rb +73 -0
  79. metadata +170 -0
@@ -0,0 +1,63 @@
1
+ module Brocade module SAN
2
+
3
+ # Wwn model
4
+ class Wwn
5
+ # returns value of the WWN
6
+ attr_reader :value
7
+
8
+ # description of WWN is provided by device itself
9
+
10
+ attr_reader :symbol
11
+
12
+ # device type - usualy target or initiator
13
+
14
+ attr_reader :dev_type
15
+
16
+ # port index where wwn is located
17
+
18
+ attr_reader :port_index
19
+
20
+ # domain of switch where wwn is online
21
+ #
22
+ # domain of 0 means the switch does not have any domain id
23
+
24
+ attr_reader :domain_id
25
+
26
+ # value naming rule
27
+ # value ca be only WWN
28
+ #
29
+ # 50:00:10:20:30:40:50:60
30
+
31
+ VALUE_RULE='([\da-f]{2}:){7}[\da-f]{2}'
32
+
33
+ # verifies if +str+ matches convetion defined in Wwn::VALUE_RULE
34
+ # raises Switch::Error: Incorrect value format if not
35
+ # this method is used internally mostly
36
+
37
+ def self.verify_value(str)
38
+ raise Switch::Error.new("Incorrect value format \"#{str}\"") if !str.match(/#{VALUE_RULE}/i)
39
+ end
40
+
41
+ # shadows value
42
+ def name
43
+ @value
44
+ end
45
+
46
+ # init method
47
+ #
48
+ # opts => :symbol => "text" - device description
49
+ def initialize(value,dev_type,domain_id,port_index,opts={}) # :nodoc:
50
+ Wwn::verify_value(value)
51
+ @value=value
52
+ @dev_type=dev_type
53
+ @domain_id=domain_id.to_i
54
+ @port_index=port_index.to_i
55
+ @symbol= !opts[:symbol].nil? ? opts[:symbol] : ""
56
+ end
57
+
58
+ def to_s
59
+ @value
60
+ end
61
+ end
62
+
63
+ end; end
@@ -0,0 +1,60 @@
1
+ module Brocade module SAN
2
+
3
+ # Zone model
4
+ class Zone
5
+ # returns name of the zone
6
+ attr_reader :name
7
+
8
+ # true if zone is active / member of effective ZoneConfiguration
9
+ attr_reader :active
10
+
11
+ # member naming rule
12
+ # member can be anything that match Switch::NAME_RULE
13
+ # or WWN or Domain,Index port notation
14
+ # allowed examples:
15
+ #
16
+ # 50:00:10:20:30:40:50:60
17
+ #
18
+ # 2,61
19
+ #
20
+ # alias_test_3
21
+
22
+ MEMBER_RULE='([\da-f]{2}:){7}[\da-f]{2}|\d{1,3},\d{1,3}|' << Switch::NAME_RULE
23
+
24
+ # verifies if +str+ matches convetion defined in Zone::MEMBER_RULE
25
+ # raises Switch::Error: Incorrect name format if not
26
+ # this method is used internally mostly
27
+
28
+ def self.verify_member_name(str)
29
+ raise Switch::Error.incorrect("#{str}") if !str.match(/#{MEMBER_RULE}/i)
30
+ end
31
+
32
+ # init method
33
+ def initialize(name,opts={}) # :nodoc:
34
+ Switch::verify_name(name)
35
+ @name=name
36
+ @active=opts[:active].nil? ? false : opts[:active]
37
+ @members=[]
38
+ end
39
+
40
+ # returns array of members
41
+
42
+ def members
43
+ @members
44
+ end
45
+
46
+ # add member to the object
47
+ # members of zones are aliases, wwns or D,I notation
48
+ # +member+ is name of the member
49
+ def add_member(member)
50
+ Zone::verify_member_name(member)
51
+ @members<<member
52
+ end
53
+
54
+ def to_s
55
+ @name
56
+ end
57
+
58
+ end
59
+
60
+ end; end
@@ -0,0 +1,38 @@
1
+ module Brocade module SAN
2
+
3
+ # Zone Configuration model
4
+ class ZoneConfiguration
5
+ # returns name of the zone configuration
6
+ attr_reader :name
7
+
8
+ # true if configuration is effective, false if defined
9
+ attr_reader :effective
10
+
11
+ # init method
12
+ def initialize(name,opts={}) # :nodoc:
13
+ Switch::verify_name(name)
14
+ @name=name
15
+ @effective=opts[:effective].nil? ? false : true
16
+ @members=[]
17
+ end
18
+
19
+ # returns array of members
20
+
21
+ def members
22
+ @members
23
+ end
24
+
25
+ # add member to the object
26
+ # members of zone configurations are zones
27
+ # +member+ is name of the zone
28
+ def add_member(member)
29
+ Switch::verify_name(member)
30
+ @members<<member
31
+ end
32
+
33
+ def to_s
34
+ @name
35
+ end
36
+ end
37
+
38
+ end; end
@@ -0,0 +1,263 @@
1
+ class Brocade::SAN::Switch
2
+ ##
3
+ # :method: name
4
+ # :call-seq:
5
+ # name(forced=true)
6
+ #
7
+ # If called with +true+ argument it will get the switch_name from the switch instead of cache
8
+ #
9
+ # Returns value in (string) format
10
+
11
+ ##
12
+ # :method: state
13
+ # :call-seq:
14
+ # state(forced=true)
15
+ #
16
+ # If called with +true+ argument it will get the switch_state from the switch instead of cache
17
+ #
18
+ # Returns value in (string) format
19
+
20
+ ##
21
+ # :method: mode
22
+ # :call-seq:
23
+ # mode(forced=true)
24
+ #
25
+ # If called with +true+ argument it will get the switch_mode from the switch instead of cache
26
+ #
27
+ # Returns value in (string) format
28
+
29
+ ##
30
+ # :method: role
31
+ # :call-seq:
32
+ # role(forced=true)
33
+ #
34
+ # If called with +true+ argument it will get the switch_role from the switch instead of cache
35
+ #
36
+ # Returns value in (string) format
37
+
38
+ ##
39
+ # :method: domain
40
+ # :call-seq:
41
+ # domain(forced=true)
42
+ #
43
+ # If called with +true+ argument it will get the switch_domain from the switch instead of cache
44
+ #
45
+ # Returns value in (integer) format
46
+
47
+ ##
48
+ # :method: id
49
+ # :call-seq:
50
+ # id(forced=true)
51
+ #
52
+ # If called with +true+ argument it will get the switch_id from the switch instead of cache
53
+ #
54
+ # Returns value in (string) format
55
+
56
+ ##
57
+ # :method: wwn
58
+ # :call-seq:
59
+ # wwn(forced=true)
60
+ #
61
+ # If called with +true+ argument it will get the switch_wwn from the switch instead of cache
62
+ #
63
+ # Returns value in (string) format
64
+
65
+ ##
66
+ # :method: zoning_enabled
67
+ # :call-seq:
68
+ # zoning_enabled(forced=true)
69
+ #
70
+ # If called with +true+ argument it will get the zoning_enabled from the switch instead of cache
71
+ #
72
+ # Returns value in (boolean) format
73
+
74
+ ##
75
+ # :method: active_config
76
+ # :call-seq:
77
+ # active_config(forced=true)
78
+ #
79
+ # If called with +true+ argument it will get the active_config from the switch instead of cache
80
+ #
81
+ # Returns value in (string) format
82
+
83
+ ##
84
+ # :method: switch_beacon
85
+ # :call-seq:
86
+ # switch_beacon(forced=true)
87
+ #
88
+ # If called with +true+ argument it will get the switch_beacon from the switch instead of cache
89
+ #
90
+ # Returns value in (string) format
91
+
92
+ ##
93
+ # :method: fc_router
94
+ # :call-seq:
95
+ # fc_router(forced=true)
96
+ #
97
+ # If called with +true+ argument it will get the fc_router from the switch instead of cache
98
+ #
99
+ # Returns value in (string) format
100
+
101
+ ##
102
+ # :method: allow_xisl_use
103
+ # :call-seq:
104
+ # allow_xisl_use(forced=true)
105
+ #
106
+ # If called with +true+ argument it will get the allow_xisl_use from the switch instead of cache
107
+ #
108
+ # Returns value in (string) format
109
+
110
+ ##
111
+ # :method: ls_attributes
112
+ # :call-seq:
113
+ # ls_attributes(forced=true)
114
+ #
115
+ # If called with +true+ argument it will get the ls_attributes from the switch instead of cache
116
+ #
117
+ # Returns value in (string) format
118
+
119
+ ##
120
+ # :method: kernel
121
+ # :call-seq:
122
+ # kernel(forced=true)
123
+ #
124
+ # If called with +true+ argument it will get the kernel from the switch instead of cache
125
+ #
126
+ # Returns value in (string) format
127
+
128
+ ##
129
+ # :method: firmware
130
+ # :call-seq:
131
+ # firmware(forced=true)
132
+ #
133
+ # If called with +true+ argument it will get the fabric_os from the switch instead of cache
134
+ #
135
+ # Returns value in (string) format
136
+
137
+ ##
138
+ # :method: logical_switches
139
+ # :call-seq:
140
+ # logical_switches(forced=true)
141
+ #
142
+ # If called with +true+ argument it will get the created_switches from the switch instead of cache
143
+ #
144
+ # Returns value in (array) format
145
+
146
+ ##
147
+ # :method: ports
148
+ # :call-seq:
149
+ # ports(forced=true)
150
+ #
151
+ # If called with +true+ argument it will get the ports from the switch instead of cache
152
+ #
153
+ # Returns value in (array) format
154
+
155
+ ##
156
+ # :method: aptpolicy
157
+ # :call-seq:
158
+ # aptpolicy(forced=true)
159
+ #
160
+ # If called with +true+ argument it will get the current_policy from the switch instead of cache
161
+ #
162
+ # Returns value in (integer) format
163
+
164
+ ##
165
+ # :method: chassisname
166
+ # :call-seq:
167
+ # chassisname(forced=true)
168
+ #
169
+ # If called with +true+ argument it will get the chassisname from the switch instead of cache
170
+ #
171
+ # Returns value in (string) format
172
+
173
+ ##
174
+ # :method: dls
175
+ # :call-seq:
176
+ # dls(forced=true)
177
+ #
178
+ # If called with +true+ argument it will get the dlsshow from the switch instead of cache
179
+ #
180
+ # Returns value in (string) format
181
+
182
+ ##
183
+ # :method: iod
184
+ # :call-seq:
185
+ # iod(forced=true)
186
+ #
187
+ # If called with +true+ argument it will get the iodshow from the switch instead of cache
188
+ #
189
+ # Returns value in (string) format
190
+
191
+ ##
192
+ # :method: status
193
+ # :call-seq:
194
+ # status(forced=true)
195
+ #
196
+ # If called with +true+ argument it will get the switch_state from the switch instead of cache
197
+ #
198
+ # Returns value in (string) format
199
+
200
+ ##
201
+ # :method: status_details
202
+ # :call-seq:
203
+ # status_details(forced=true)
204
+ #
205
+ # If called with +true+ argument it will get the switchstatusshow from the switch instead of cache
206
+ #
207
+ # Returns value in (string) format
208
+
209
+ ##
210
+ # :method: ip
211
+ # :call-seq:
212
+ # ip(forced=true)
213
+ #
214
+ # If called with +true+ argument it will get the ip_address from the switch instead of cache
215
+ #
216
+ # Returns value in (string) format
217
+
218
+ ##
219
+ # :method: supportshow
220
+ # :call-seq:
221
+ # supportshow(forced=true)
222
+ #
223
+ # If called with +true+ argument it will get the supportshow from the switch instead of cache
224
+ #
225
+ # Returns value in (string) format
226
+
227
+ ##
228
+ # :method: isls
229
+ # :call-seq:
230
+ # isls(forced=true)
231
+ #
232
+ # If called with +true+ argument it will get the isl_links from the switch instead of cache
233
+ #
234
+ # Returns value in (array) format
235
+
236
+ ##
237
+ # :method: trunks
238
+ # :call-seq:
239
+ # trunks(forced=true)
240
+ #
241
+ # If called with +true+ argument it will get the trunk_links from the switch instead of cache
242
+ #
243
+ # Returns value in (array) format
244
+
245
+ ##
246
+ # :method: access_gateways
247
+ # :call-seq:
248
+ # access_gateways(forced=true)
249
+ #
250
+ # If called with +true+ argument it will get the ag from the switch instead of cache
251
+ #
252
+ # Returns value in (array) format
253
+
254
+ ##
255
+ # :method: cfg_transaction
256
+ # :call-seq:
257
+ # cfg_transaction(forced=true)
258
+ #
259
+ # If called with +true+ argument it will get the cfg_transaction from the switch instead of cache
260
+ #
261
+ # Returns value in (hash) format
262
+
263
+ end
@@ -0,0 +1,68 @@
1
+ require 'brocadesan'
2
+ require 'minitest/autorun'
3
+ require 'output_helpers'
4
+
5
+ module Brocade module SAN
6
+
7
+ class AliasTest < MiniTest::Test
8
+ include OutputReader
9
+ include Mock::Net::SSH
10
+ patch_set
11
+
12
+ def setup
13
+ init_dev
14
+ end
15
+
16
+ def init_dev
17
+ @switch = Switch.new("test","test","test")
18
+ end
19
+
20
+ def test_new_alias
21
+ al=Alias.new("test")
22
+ assert_equal "test", al.name
23
+ assert_raises Switch::Error do
24
+ zone=Alias.new("test-d")
25
+ end
26
+ end
27
+
28
+ def test_members
29
+ @output_dir=File.join(Dir.pwd,"test","outputs")
30
+ read_all_starting_with "cfgshow_" do |file,output|
31
+ response=new_mock_response
32
+ response.data=output
33
+ init_dev
34
+ yaml=read_yaml_for(file)
35
+ @switch.stub :query, response do
36
+ @switch.aliases.each_with_index do |al,i|
37
+ assert_equal yaml[:defined_configuration][:alias].values[i], al.members
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def test_add_member
44
+ a=Alias.new("test")
45
+ a.add_member "50:00:10:20:30:40:50:60"
46
+ assert_equal ["50:00:10:20:30:40:50:60"], a.members
47
+ a.add_member "2,61"
48
+ assert_equal ["50:00:10:20:30:40:50:60","2,61"], a.members
49
+
50
+ assert_raises(Switch::Error) do
51
+ a.add_member "invalid_name_for_alias_member"
52
+ end
53
+ end
54
+
55
+ def test_validity_verification
56
+ name = "invalid_name_for_alias_member"
57
+ exp = assert_raises(Switch::Error) do
58
+ Alias::verify_member_name name
59
+ end
60
+ assert_equal Switch::Error.incorrect(name).message, exp.message
61
+ assert_silent do
62
+ Alias::verify_member_name "50:00:10:20:30:40:50:60"
63
+ Alias::verify_member_name "2,61"
64
+ end
65
+ end
66
+ end
67
+
68
+ end; end