class BrocadeAPIClient::Client

Class for connecting to BNA

Attributes

http[R]
logger[R]

Public Class Methods

new(api_url, debug: false, secure: false, app_type: 'ruby_brocade', enable_logger: nil, log_file_path: nil) click to toggle source
# 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

Public Instance Methods

aliadd(fabrickey, aliname, *wwn) click to toggle source

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

# 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) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 408
def alicreate(fabrickey, aliname, *wwn)
  result = @zones.alicreate(fabrickey, aliname, *wwn)
  result[1]
end
alidelete(fabrickey, *alinames) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 446
def alidelete(fabrickey, *alinames)
  result = @zones.alidelete(fabrickey, *alinames)
  result[1]
end
aliremove(fabrickey, aliname, *wwn) click to toggle source

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

# 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') click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 345
def alishow(fabrickey, zakey = 'none')
  result = @zones.alishow(fabrickey, zakey)
  result[1]
end
allports() click to toggle source

Get ALL FC Ports in the Brocade Network Advisor

Returns

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

# File lib/BrocadeAPIClient/client.rb, line 129
def allports
  result = @ports.allports
  result[1]
end
allswitches() click to toggle source

Get ALL FC Swiches in the Brocade Network Advisor

Returns

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

# File lib/BrocadeAPIClient/client.rb, line 118
def allswitches
  result = @switches.allswitches
  result[1]
end
cfgadd(fabrickey, cfgname, *zonenames) click to toggle source

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

# 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) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 395
def cfgenable(fabrickey, cfgname)
  result = @zones.cfgenable(fabrickey, cfgname)
  result[1]
end
cfgremove(fabrickey, cfgname, *zonenames) click to toggle source

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

# 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) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 357
def cfgshow(fabrickey, type)
  result = @zones.cfgshow(fabrickey, type)
  result[1]
end
change_persistentportstates(switchwwn, state, *portwwns) click to toggle source

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

# 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) click to toggle source

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

# 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') click to toggle source

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

Returns

Status of request

# 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) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 96
def fabric(fabricid)
  result = @fabrics.fabric(fabricid)
  result[1]
end
fabrics() click to toggle source

Get All FC Fabrics

Returns

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

# File lib/BrocadeAPIClient/client.rb, line 84
def fabrics
  # API GET for fabrics
  result = @fabrics.fabrics
  result[1]
end
fabricswitches(fabricid) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 107
def fabricswitches(fabricid)
  result = @switches.fabricswitches(fabricid)
  result[1]
end
login(username, password, options = nil) click to toggle source
# File lib/BrocadeAPIClient/client.rb, line 51
def login(username, password, options = nil)
  # Authenticate on the Brocade Network Advisor API
  login_info = @http.authenticate(username, password, options)
  api_v = APIVersion.parser(login_info['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
logout() click to toggle source
# File lib/BrocadeAPIClient/client.rb, line 62
def logout
  # Delete Session on REST API
  @http.unauthenticate
end
resourcegroups() click to toggle source

Get All networks

Returns

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

# File lib/BrocadeAPIClient/client.rb, line 73
def resourcegroups
  result = @http.get('/resourcegroups')
  result[1]
end
set_portname(switchwwn, portwwns, portname) click to toggle source

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

# 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) click to toggle source

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

Returns

Status of request

# File lib/BrocadeAPIClient/client.rb, line 490
def syslog_events(count)
  result = @events.syslog_events(count)
  result[1]
end
trans_abort(fabrickey) click to toggle source

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

Returns

Status of request

# File lib/BrocadeAPIClient/client.rb, line 479
def trans_abort(fabrickey)
  result = @zones.control_transaction(fabrickey, 'abort')
  result[1]
end
trans_commit(fabrickey) click to toggle source

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

Returns

Status of request

# File lib/BrocadeAPIClient/client.rb, line 468
def trans_commit(fabrickey)
  result = @zones.control_transaction(fabrickey, 'commit')
  result[1]
end
trans_start(fabrickey) click to toggle source

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

Returns

Status of request

# File lib/BrocadeAPIClient/client.rb, line 457
def trans_start(fabrickey)
  result = @zones.control_transaction(fabrickey, 'start')
  result[1]
end
trap_events(count) click to toggle source

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

Returns

Status of request

# File lib/BrocadeAPIClient/client.rb, line 501
def trap_events(count)
  result = @events.trap_events(count)
  result[1]
end
zoneadd_peerzone(fabrickey, zonename, **wwns) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 333
def zonedbs(fabrickey)
  result = @zones.zonedbs(fabrickey)
  result[1]
end
zonedelete(fabrickey, *zonenames) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 273
def zonedelete(fabrickey, *zonenames)
  result = @zones.zonedelete(fabrickey, *zonenames)
  result[1]
end
zoneremove_peerzone(fabrickey, zonename, **wwns) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 221
def zoneshow_active(fabrickey, zonename)
  result = @zones.zoneshow(fabrickey, 'active', zonename)
  result[1]
end
zoneshow_all(fabrickey) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 184
def zoneshow_all(fabrickey)
  result = @zones.zoneshow(fabrickey, 'all')
  result[1]
end
zoneshow_all_active(fabrickey) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 197
def zoneshow_all_active(fabrickey)
  result = @zones.zoneshow(fabrickey, 'active')
  result[1]
end
zoneshow_all_defined(fabrickey) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 209
def zoneshow_all_defined(fabrickey)
  result = @zones.zoneshow(fabrickey, 'defined')
  result[1]
end
zoneshow_defined(fabrickey, zonename) click to toggle source

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

# File lib/BrocadeAPIClient/client.rb, line 233
def zoneshow_defined(fabrickey, zonename)
  result = @zones.zoneshow(fabrickey, 'defined', zonename)
  result[1]
end

Private Instance Methods

init_log() click to toggle source
# File lib/BrocadeAPIClient/client.rb, line 519
def init_log
  # Create Logger
  @client_logger = if @enable_logger
                     if @log_file_path.nil?
                       Logger.new(STDOUT)
                     else
                       Logger.new(@log_file_path, 'daily')
                     end
                   else @enable_logger = false
                   end

  @log_level = Logger::DEBUG if @debug
end