Class: BrocadeAPIClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/BrocadeAPIClient/client.rb

Overview

Class for connecting to BNA

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_url, debug: false, secure: false, app_type: 'ruby_brocade', enable_logger: nil, log_file_path: nil) ⇒ Client

Returns a new instance of Client.



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
# File 'lib/BrocadeAPIClient/client.rb', line 25

def initialize(api_url, debug: false, secure: false, app_type: 'ruby_brocade', enable_logger: nil, log_file_path: nil)
  unless api_url.is_a?(String)
    raise BrocadeAPIClient::BrocadeException.new(nil,
                                                 "'api_url' parameter is mandatory and should be of type String")
  end
  @api_url = api_url
  @debug = debug
  @secure = secure
  @log_level = Logger::INFO
  @enable_logger = enable_logger
  @client_logger = nil
  @log_file_path = log_file_path
  init_log
  @http = JSONRestClient.new(
    @api_url, @secure, @debug,
    @client_logger
  )
  @fabrics = Fabrics.new(@http)
  @switches = Switches.new(@http)
  @ports = Ports.new(@http)
  @zones = Zones.new(@http)
  @events = Events.new(@http)
  @app_type = app_type
  @peer_zone_support = false
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



24
25
26
# File 'lib/BrocadeAPIClient/client.rb', line 24

def http
  @http
end

#loggerObject (readonly)

Returns the value of attribute logger.



24
25
26
# File 'lib/BrocadeAPIClient/client.rb', line 24

def logger
  @logger
end

Instance Method Details

#aliadd(fabrickey, aliname, *wwn) ⇒ Object

Add wwn to existing Alias Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond aliname - name for new alias wwn - to be added to aliname , it supports multiple wwns separated by comma

Returns

Status of request



421
422
423
424
# File 'lib/BrocadeAPIClient/client.rb', line 421

def aliadd(fabrickey, aliname, *wwn)
  result = @zones.alteralias(fabrickey, 'ADD', aliname, *wwn)
  result[1]
end

#alicreate(fabrickey, aliname, *wwn) ⇒ Object

Create Zone Aliases in a fabric Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond aliname - name for new alias wwn - to be added to aliname , it supports multiple wwns separated by comma

Returns

Status of request



408
409
410
411
# File 'lib/BrocadeAPIClient/client.rb', line 408

def alicreate(fabrickey, aliname, *wwn)
  result = @zones.alicreate(fabrickey, aliname, *wwn)
  result[1]
end

#alidelete(fabrickey, *alinames) ⇒ Object

Delete Aliases in defined Fabric Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond alinames - list of aliases to be delete

Returns

Status of request



446
447
448
449
# File 'lib/BrocadeAPIClient/client.rb', line 446

def alidelete(fabrickey, *alinames)
  result = @zones.alidelete(fabrickey, *alinames)
  result[1]
end

#aliremove(fabrickey, aliname, *wwn) ⇒ Object

Remove wwn to existing Alias Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond aliname - name for new alias wwn - to be added to aliname , it supports multiple wwns separated by comma

Returns

Status of request



434
435
436
437
# File 'lib/BrocadeAPIClient/client.rb', line 434

def aliremove(fabrickey, aliname, *wwn)
  result = @zones.alteralias(fabrickey, 'REMOVE', aliname, *wwn)
  result[1]
end

#alishow(fabrickey, zakey = 'none') ⇒ Object

Get Zone Aliases in a fabric Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond

Returns

Hash - Key zoneAliases , Value Array of Hashes with all aliases



345
346
347
348
# File 'lib/BrocadeAPIClient/client.rb', line 345

def alishow(fabrickey, zakey = 'none')
  result = @zones.alishow(fabrickey, zakey)
  result[1]
end

#allportsObject

Get ALL FC Ports in the Brocade Network Advisor

Returns

Hash - Key fcports , Value of all the ports in BNA



129
130
131
132
# File 'lib/BrocadeAPIClient/client.rb', line 129

def allports
  result = @ports.allports
  result[1]
end

#allswitchesObject

Get ALL FC Swiches in the Brocade Network Advisor

Returns

Hash - Key fcswitches and Value of all the switches in BNA



118
119
120
121
# File 'lib/BrocadeAPIClient/client.rb', line 118

def allswitches
  result = @switches.allswitches
  result[1]
end

#cfgadd(fabrickey, cfgname, *zonenames) ⇒ Object

Add zones to defined configuration Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond cfgname - Fabric configuration name to which to add the zones zonenames - list of zones to be added to the cfg

Returns

Status of request



370
371
372
373
# File 'lib/BrocadeAPIClient/client.rb', line 370

def cfgadd(fabrickey, cfgname, *zonenames)
  result = @zones.altercfg(fabrickey, 'ADD', cfgname, *zonenames)
  result[1]
end

#cfgenable(fabrickey, cfgname) ⇒ Object

Enable defined zoning by configuration by name Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond cfgname - Fabric configuration name from which to remove the zones

Returns

Status of request



395
396
397
398
# File 'lib/BrocadeAPIClient/client.rb', line 395

def cfgenable(fabrickey, cfgname)
  result = @zones.cfgenable(fabrickey, cfgname)
  result[1]
end

#cfgremove(fabrickey, cfgname, *zonenames) ⇒ Object

Remove zones to defined configuration Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond cfgname - Fabric configuration name from which to remove the zones zonenames - list of zones to be removed to the cfg

Returns

Status of request



383
384
385
386
# File 'lib/BrocadeAPIClient/client.rb', line 383

def cfgremove(fabrickey, cfgname, *zonenames)
  result = @zones.altercfg(fabrickey, 'REMOVE', cfgname, *zonenames)
  result[1]
end

#cfgshow(fabrickey, type) ⇒ Object

Get Fabric configuration Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond

Returns

Hash - Key zoneAliases , Value Array of Hashes with all aliases



357
358
359
360
# File 'lib/BrocadeAPIClient/client.rb', line 357

def cfgshow(fabrickey, type)
  result = @zones.cfgshow(fabrickey, type)
  result[1]
end

#change_persistentportstates(switchwwn, state, *portwwns) ⇒ Object

Change port states for on FC switch(persistent) Input: switchWWN - switch WWN (it can be retrived using the Switches method) portWWNs - Multiple PortWWN in same switch that should be changed state - ‘disabled|enable’

Returns

Hash - Key fcPortStateChangeResponseEntry , Value Array of Hashes with all ports changed



157
158
159
160
# File 'lib/BrocadeAPIClient/client.rb', line 157

def change_persistentportstates(switchwwn, state, *portwwns)
  result = @ports.change_persistentportstates(switchwwn, state, *portwwns)
  result[1]
end

#change_portstates(switchwwn, state, *portwwns) ⇒ Object

Change port states for on FC switch(non-persistent) Input: switchWWN - switch WWN (it can be retrived using the Switches method) portWWNs - Multiple PortWWN in the same switch that should be changed state - ‘disabled|enable’

Returns

Hash - Key fcPortStateChangeResponseEntry , Value Array of Hashes with all ports changed



143
144
145
146
# File 'lib/BrocadeAPIClient/client.rb', line 143

def change_portstates(switchwwn, state, *portwwns)
  result = @ports.change_portstates(switchwwn, state, *portwwns)
  result[1]
end

#custom_events(startindex = '0', count = '10', origin = 'syslog', severity = 'INFO') ⇒ Object

Get custom events based on params Input: count - String value to retrive the number of last events

Returns

Status of request



512
513
514
515
# File 'lib/BrocadeAPIClient/client.rb', line 512

def custom_events(startindex = '0', count = '10', origin = 'syslog', severity = 'INFO')
  result = @events.custom_events(startindex, count, origin, severity)
  result[1]
end

#fabric(fabricid) ⇒ Object

Get FC Fabric Information based on Fabric ID

fabricID = string containing fabricID , ex ‘10:00:00:00:00:00’

Returns

Hash - Details of the specified fabric



96
97
98
99
# File 'lib/BrocadeAPIClient/client.rb', line 96

def fabric(fabricid)
  result = @fabrics.fabric(fabricid)
  result[1]
end

#fabricsObject

Get All FC Fabrics

Returns

Hash with value as Array of Fabrics - Details of the ALL fabrics



84
85
86
87
88
# File 'lib/BrocadeAPIClient/client.rb', line 84

def fabrics
  # API GET for fabrics
  result = @fabrics.fabrics
  result[1]
end

#fabricswitches(fabricid) ⇒ Object

Get FC switches members of a specific Fabric ID

fabricID = string containing fabricID , ex ‘10:00:00:00:00:00’

Returns

Hash - with Value Array with all the switches part of fabricID



107
108
109
110
# File 'lib/BrocadeAPIClient/client.rb', line 107

def fabricswitches(fabricid)
  result = @switches.fabricswitches(fabricid)
  result[1]
end

#login(username, password, options = nil) ⇒ Object

Raises:

  • (BrocadeAPIClient::UnsupportedVersion)


51
52
53
54
55
56
57
58
59
60
# File 'lib/BrocadeAPIClient/client.rb', line 51

def (username, password, options = nil)
  # Authenticate on the Brocade Network Advisor API
   = @http.authenticate(username, password, options)
  api_v = APIVersion.parser(['version'])
  min_api_version = APIVersion.parser(BrocadeAPIClient::BNASupport::BNA_MIN_SUPPORTED)
  min_peerzoning_version = APIVersion.parser(BrocadeAPIClient::BNASupport::BNA_PEER_ZONING_TDZ_MIN_SUPPORTED)
  raise BrocadeAPIClient::UnsupportedVersion if api_v < min_api_version

  @peer_zone_support = true if api_v >= min_peerzoning_version
end

#logoutObject



62
63
64
65
# File 'lib/BrocadeAPIClient/client.rb', line 62

def logout
  # Delete Session on REST API
  @http.unauthenticate
end

#resourcegroupsObject

Get All networks

Returns

Hash with value as Array of Networks (FC + IP)



73
74
75
76
# File 'lib/BrocadeAPIClient/client.rb', line 73

def resourcegroups
  result = @http.get('/resourcegroups')
  result[1]
end

#set_portname(switchwwn, portwwns, portname) ⇒ Object

Set Port Name for a specified port Input: the resource method(ussualy the of the Fabric) switchWWN - switch WWN (it can be retrived using the Switches method) portWWN - Port WWN portNames - the name for the PortName

Returns

Hash - Key fcPortStateChangeResponseEntry , Value Array of Hashes with all ports changed



172
173
174
175
# File 'lib/BrocadeAPIClient/client.rb', line 172

def set_portname(switchwwn, portwwns, portname)
  result = @ports.set_portname(switchwwn, portwwns, portname)
  result[1]
end

#syslog_events(count) ⇒ Object

Get syslog events Input: count - String value to retrive the number of last events

Returns

Status of request



490
491
492
493
# File 'lib/BrocadeAPIClient/client.rb', line 490

def syslog_events(count)
  result = @events.syslog_events(count)
  result[1]
end

#trans_abort(fabrickey) ⇒ Object

Abort Fabric transaction Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond

Returns

Status of request



479
480
481
482
# File 'lib/BrocadeAPIClient/client.rb', line 479

def trans_abort(fabrickey)
  result = @zones.control_transaction(fabrickey, 'abort')
  result[1]
end

#trans_commit(fabrickey) ⇒ Object

Commit Fabric transaction Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond

Returns

Status of request



468
469
470
471
# File 'lib/BrocadeAPIClient/client.rb', line 468

def trans_commit(fabrickey)
  result = @zones.control_transaction(fabrickey, 'commit')
  result[1]
end

#trans_start(fabrickey) ⇒ Object

Start Fabric transaction Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond

Returns

Status of request



457
458
459
460
# File 'lib/BrocadeAPIClient/client.rb', line 457

def trans_start(fabrickey)
  result = @zones.control_transaction(fabrickey, 'start')
  result[1]
end

#trap_events(count) ⇒ Object

Get trap events Input: count - String value to retrive the number of last events

Returns

Status of request



501
502
503
504
# File 'lib/BrocadeAPIClient/client.rb', line 501

def trap_events(count)
  result = @events.trap_events(count)
  result[1]
end

#zoneadd_peerzone(fabrickey, zonename, **wwns) ⇒ Object

Add aliases to standard zone Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond **wwns - hash with principal and members as keys and values as an array of wwns

Returns

status of request



309
310
311
312
# File 'lib/BrocadeAPIClient/client.rb', line 309

def zoneadd_peerzone(fabrickey, zonename, **wwns)
  result = @zones.alterzoning_peerzone(fabrickey, 'ADD', zonename, **wwns)
  result[1]
end

#zoneadd_standard(fabrickey, zonename, *aliases) ⇒ Object

Add aliases to standard zone Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond *aliasnames - a list of zones to be delete

Returns

status of request



285
286
287
288
# File 'lib/BrocadeAPIClient/client.rb', line 285

def zoneadd_standard(fabrickey, zonename, *aliases)
  result = @zones.alterzoning_standard(fabrickey, 'ADD', zonename, *aliases)
  result[1]
end

#zonecreate_peerzone(fabrickey, zonename, **members) ⇒ Object

Create Peerzone Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond zonename - string containing the zone name *aliases - list of aliases to be added in the zone

Returns

Hash - Key zones , Value Array of Hashes with all zones

Raises:

  • (BrocadeAPIClient::UnsupportedVersion)


259
260
261
262
263
264
# File 'lib/BrocadeAPIClient/client.rb', line 259

def zonecreate_peerzone(fabrickey, zonename, **members)
  raise BrocadeAPIClient::UnsupportedVersion unless @peer_zone_support

  result = @zones.zonecreate_peerzone(fabrickey, zonename, **members)
  result[1]
end

#zonecreate_standard(fabrickey, zonename, *aliases) ⇒ Object

Create standard zone Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond zonename - string containing the zone name *aliases - list of aliases to be added in the zone

Returns

Hash - Key zones , Value Array of Hashes with all zones



246
247
248
249
# File 'lib/BrocadeAPIClient/client.rb', line 246

def zonecreate_standard(fabrickey, zonename, *aliases)
  result = @zones.zonecreate_standard(fabrickey, zonename, *aliases)
  result[1]
end

#zonedbs(fabrickey) ⇒ Object

Get Zone DB in a fabric(active and defined) Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond

Returns

Hash - Key zones , Value Array of Hashes with all zones



333
334
335
336
# File 'lib/BrocadeAPIClient/client.rb', line 333

def zonedbs(fabrickey)
  result = @zones.zonedbs(fabrickey)
  result[1]
end

#zonedelete(fabrickey, *zonenames) ⇒ Object

Delete Zones from defined configuration Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond *zonenames - a list of zones to be delete

Returns

status of request



273
274
275
276
# File 'lib/BrocadeAPIClient/client.rb', line 273

def zonedelete(fabrickey, *zonenames)
  result = @zones.zonedelete(fabrickey, *zonenames)
  result[1]
end

#zoneremove_peerzone(fabrickey, zonename, **wwns) ⇒ Object

Remove members/principal from peerzone Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond **wwns - hash with principal and members as keys and values as an array of wwns

Returns

status of request



321
322
323
324
# File 'lib/BrocadeAPIClient/client.rb', line 321

def zoneremove_peerzone(fabrickey, zonename, **wwns)
  result = @zones.alterzoning_peerzone(fabrickey, 'REMOVE', zonename, **wwns)
  result[1]
end

#zoneremove_standard(fabrickey, zonename, *aliases) ⇒ Object

Add aliases to standard zone Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond *aliasnames - a list of zones to be delete

Returns

status of request



297
298
299
300
# File 'lib/BrocadeAPIClient/client.rb', line 297

def zoneremove_standard(fabrickey, zonename, *aliases)
  result = @zones.alterzoning_standard(fabrickey, 'REMOVE', zonename, *aliases)
  result[1]
end

#zoneshow_active(fabrickey, zonename) ⇒ Object

Get INFO about active zone in a Fabric( defined) Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond zonename - string containing the zone name

Returns

Hash - Key zones , Value Array of Hashes with all zones



221
222
223
224
# File 'lib/BrocadeAPIClient/client.rb', line 221

def zoneshow_active(fabrickey, zonename)
  result = @zones.zoneshow(fabrickey, 'active', zonename)
  result[1]
end

#zoneshow_all(fabrickey) ⇒ Object

Get all Zones in a Fabric(both active and defined) Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond

Returns

Hash - Key zones , Value Array of Hashes with all zones



184
185
186
187
# File 'lib/BrocadeAPIClient/client.rb', line 184

def zoneshow_all(fabrickey)
  result = @zones.zoneshow(fabrickey, 'all')
  result[1]
end

#zoneshow_all_active(fabrickey) ⇒ Object

Get all Zones in a Fabric(active) Input: fabrickey - fabric key WWN(it can be retrived

using the fabrics methond

Returns

Hash - Key zones , Value Array of Hashes with all zones



197
198
199
200
# File 'lib/BrocadeAPIClient/client.rb', line 197

def zoneshow_all_active(fabrickey)
  result = @zones.zoneshow(fabrickey, 'active')
  result[1]
end

#zoneshow_all_defined(fabrickey) ⇒ Object

Get all Zones in a Fabric( defined) Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond

Returns

Hash - Key zones , Value Array of Hashes with all zones



209
210
211
212
# File 'lib/BrocadeAPIClient/client.rb', line 209

def zoneshow_all_defined(fabrickey)
  result = @zones.zoneshow(fabrickey, 'defined')
  result[1]
end

#zoneshow_defined(fabrickey, zonename) ⇒ Object

Get INFO about a defined zone in a Fabric( defined) Input: fabrickey - fabric key WWN(it can be retrived using the fabrics methond zonename - string containing the zone name

Returns

Hash - Key zones , Value Array of Hashes with all zones



233
234
235
236
# File 'lib/BrocadeAPIClient/client.rb', line 233

def zoneshow_defined(fabrickey, zonename)
  result = @zones.zoneshow(fabrickey, 'defined', zonename)
  result[1]
end