brocade_api_client 0.1.1
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.
- checksums.yaml +7 -0
 - data/.rubocop.yml +13 -0
 - data/.travis.yml +9 -0
 - data/Gemfile +6 -0
 - data/Gemfile.lock +82 -0
 - data/LICENSE +234 -0
 - data/README.md +248 -0
 - data/Rakefile +38 -0
 - data/bin/console +14 -0
 - data/bin/setup +8 -0
 - data/brocade_api_client.gemspec +45 -0
 - data/lib/BrocadeAPIClient/apiversion.rb +47 -0
 - data/lib/BrocadeAPIClient/client.rb +533 -0
 - data/lib/BrocadeAPIClient/events.rb +35 -0
 - data/lib/BrocadeAPIClient/exceptions.rb +79 -0
 - data/lib/BrocadeAPIClient/fabrics.rb +28 -0
 - data/lib/BrocadeAPIClient/httpclient.rb +149 -0
 - data/lib/BrocadeAPIClient/ports.rb +52 -0
 - data/lib/BrocadeAPIClient/static.rb +16 -0
 - data/lib/BrocadeAPIClient/switches.rb +29 -0
 - data/lib/BrocadeAPIClient/version.rb +13 -0
 - data/lib/BrocadeAPIClient/zones.rb +183 -0
 - data/lib/brocade_api_client.rb +19 -0
 - metadata +176 -0
 
| 
         @@ -0,0 +1,35 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 2 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing,
         
     | 
| 
      
 6 
     | 
    
         
            +
            # software distributed
         
     | 
| 
      
 7 
     | 
    
         
            +
            # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
         
     | 
| 
      
 8 
     | 
    
         
            +
            # CONDITIONS OF ANY KIND, either express or implied. See the License for the
         
     | 
| 
      
 9 
     | 
    
         
            +
            # specific language governing permissions and limitations under the License.
         
     | 
| 
      
 10 
     | 
    
         
            +
            require_relative 'exceptions'
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            module BrocadeAPIClient
         
     | 
| 
      
 13 
     | 
    
         
            +
              # Evens REST API methods
         
     | 
| 
      
 14 
     | 
    
         
            +
              class Events
         
     | 
| 
      
 15 
     | 
    
         
            +
                def initialize(http_client)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @http_client = http_client
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @base_url = '/resourcegroups/All/events'
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def syslog_events(count = '10')
         
     | 
| 
      
 21 
     | 
    
         
            +
                  api_url = @base_url + '?startindex=0&count=' + count + '&specialEvent=true&origin=syslog'
         
     | 
| 
      
 22 
     | 
    
         
            +
                  _response, _body = @http_client.get(api_url)
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                def trap_events(count = '10')
         
     | 
| 
      
 26 
     | 
    
         
            +
                  api_url = @base_url + '?startindex=0&count=' + count + '&specialEvent=true&origin=trap'
         
     | 
| 
      
 27 
     | 
    
         
            +
                  _response, _body = @http_client.get(api_url)
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                def custom_events(startindex = '0', count = '10', origin = 'syslog', severity = 'INFO')
         
     | 
| 
      
 31 
     | 
    
         
            +
                  api_url = @base_url + '?startindex=' + startindex + '&count=' + count + '&specialEvent=true' + '&origin=' + origin + '&severity=' + severity
         
     | 
| 
      
 32 
     | 
    
         
            +
                  _response, _body = @http_client.get(api_url)
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,79 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 2 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing,
         
     | 
| 
      
 6 
     | 
    
         
            +
            # software distributed
         
     | 
| 
      
 7 
     | 
    
         
            +
            # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
         
     | 
| 
      
 8 
     | 
    
         
            +
            # CONDITIONS OF ANY KIND, either express or implied. See the License for the
         
     | 
| 
      
 9 
     | 
    
         
            +
            # specific language governing permissions and limitations under the License.
         
     | 
| 
      
 10 
     | 
    
         
            +
            require_relative 'static'
         
     | 
| 
      
 11 
     | 
    
         
            +
            module BrocadeAPIClient
         
     | 
| 
      
 12 
     | 
    
         
            +
              # Brocade Exception Classes
         
     | 
| 
      
 13 
     | 
    
         
            +
              class BrocadeException < StandardError
         
     | 
| 
      
 14 
     | 
    
         
            +
                attr_reader :message, :code, :ref, :http_status
         
     | 
| 
      
 15 
     | 
    
         
            +
                def initialize(code: nil, message: nil, ref: nil, http_status: nil)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @code = code
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @message = message
         
     | 
| 
      
 18 
     | 
    
         
            +
                  @ref = ref
         
     | 
| 
      
 19 
     | 
    
         
            +
                  @http_status = http_status
         
     | 
| 
      
 20 
     | 
    
         
            +
                  formatted_string = 'Error: '
         
     | 
| 
      
 21 
     | 
    
         
            +
                  formatted_string += format(' (HTTP %s)', @http_status) if @http_status
         
     | 
| 
      
 22 
     | 
    
         
            +
                  formatted_string += format(' API code: %s', @code) if @code
         
     | 
| 
      
 23 
     | 
    
         
            +
                  formatted_string += format(' - %s', @message) if @message
         
     | 
| 
      
 24 
     | 
    
         
            +
                  formatted_string += format(' - %s', @ref) if @ref
         
     | 
| 
      
 25 
     | 
    
         
            +
                  super(formatted_string)
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
              exceptions_map = [{ name: 'UnsupportedOption', message: 'Unsupported Zoning Option, supported ALL is without zonename' },
         
     | 
| 
      
 29 
     | 
    
         
            +
                                { name: 'UnsupportedAction', message: 'Unsupported Action, only ADD/Remove allowed' },
         
     | 
| 
      
 30 
     | 
    
         
            +
                                { name: 'UnsupportedVersion', message: "Unsupported Brocade Network Advisor version, min supported version is, #{BrocadeAPIClient::BNASupport::BNA_MIN_SUPPORTED}" },
         
     | 
| 
      
 31 
     | 
    
         
            +
                                { name: 'UnsupportedSeverityOption' },
         
     | 
| 
      
 32 
     | 
    
         
            +
                                { name: 'InvalidPeerzoneOptions', message: 'Use principal and members as hash keys' },
         
     | 
| 
      
 33 
     | 
    
         
            +
                                { name: 'InvalidVersion', message: 'Invalid API Version Detected' },
         
     | 
| 
      
 34 
     | 
    
         
            +
                                { name: 'RequestException' },
         
     | 
| 
      
 35 
     | 
    
         
            +
                                { name: 'ConnectionError', message: 'Connection Error to Brocade Network Advisor version' },
         
     | 
| 
      
 36 
     | 
    
         
            +
                                { name: 'HTTPError' },
         
     | 
| 
      
 37 
     | 
    
         
            +
                                { name: 'URLRequired' },
         
     | 
| 
      
 38 
     | 
    
         
            +
                                { name: 'TooManyRedirects' },
         
     | 
| 
      
 39 
     | 
    
         
            +
                                { name: 'Timeout' },
         
     | 
| 
      
 40 
     | 
    
         
            +
                                { name: 'SSLCertFailed' },
         
     | 
| 
      
 41 
     | 
    
         
            +
                                { name: 'HTTPBadRequest', http_status: 400, message: 'Bad request' },
         
     | 
| 
      
 42 
     | 
    
         
            +
                                { name: 'HTTPUnauthorized', http_status: 401, message: 'Unauthorized' },
         
     | 
| 
      
 43 
     | 
    
         
            +
                                { name: 'HTTPForbidden', http_status: 403, message: 'Forbidden' },
         
     | 
| 
      
 44 
     | 
    
         
            +
                                { name: 'HTTPNotFound', http_status: 404, message: 'Not found' },
         
     | 
| 
      
 45 
     | 
    
         
            +
                                { name: 'HTTPMethodNotAllowed', http_status: 405, message: 'Method Not Allowed' },
         
     | 
| 
      
 46 
     | 
    
         
            +
                                { name: 'HTTPNotAcceptable', http_status: 406, message: 'Method Not Acceptable' },
         
     | 
| 
      
 47 
     | 
    
         
            +
                                { name: 'HTTPProxyAuthRequired', http_status: 407, message: 'Proxy Authentication Required' },
         
     | 
| 
      
 48 
     | 
    
         
            +
                                { name: 'HTTPRequestTimeout', http_status: 408, message: 'Request Timeout' },
         
     | 
| 
      
 49 
     | 
    
         
            +
                                { name: 'HTTPConflict', http_status: 409, message: 'Conflict' },
         
     | 
| 
      
 50 
     | 
    
         
            +
                                { name: 'HTTPGone', http_status: 410, message: 'Gone' },
         
     | 
| 
      
 51 
     | 
    
         
            +
                                { name: 'HTTPLengthRequired', http_status: 411, message: 'Length Required' },
         
     | 
| 
      
 52 
     | 
    
         
            +
                                { name: 'HTTPPreconditionFailed', http_status: 412, message: 'Over limit' },
         
     | 
| 
      
 53 
     | 
    
         
            +
                                { name: 'HTTPRequestEntityTooLarge', http_status: 413, message: 'Request Entity Too Large' },
         
     | 
| 
      
 54 
     | 
    
         
            +
                                { name: 'HTTPRequestURITooLong', http_status: 414, message: 'Request URI Too Large' },
         
     | 
| 
      
 55 
     | 
    
         
            +
                                { name: 'HTTPUnsupportedMediaType', http_status: 415, message: 'Unsupported Media Type' },
         
     | 
| 
      
 56 
     | 
    
         
            +
                                { name: 'HTTPRequestedRangeNotSatisfiable', http_status: 416, message: 'Requested Range Not Satisfiable' },
         
     | 
| 
      
 57 
     | 
    
         
            +
                                { name: 'HTTPExpectationFailed', http_status: 417, message: 'Expectation Failed' },
         
     | 
| 
      
 58 
     | 
    
         
            +
                                { name: 'HTTPTeaPot', http_status: 418, message: 'I\'m A Teapot. (RFC 2324)' },
         
     | 
| 
      
 59 
     | 
    
         
            +
                                { name: 'HTTPInternalServerError', http_status: 500, message: 'Internal Server Error' },
         
     | 
| 
      
 60 
     | 
    
         
            +
                                { name: 'HTTPNotImplemented', http_status: 501, message: 'Not Implemented' },
         
     | 
| 
      
 61 
     | 
    
         
            +
                                { name: 'HTTPBadGateway', http_status: 502, message: 'Bad Gateway' },
         
     | 
| 
      
 62 
     | 
    
         
            +
                                { name: 'HTTPServiceUnavailable', http_status: 503, message: 'Service Unavailable' },
         
     | 
| 
      
 63 
     | 
    
         
            +
                                { name: 'HTTPGatewayTimeout', http_status: 504, message: 'Gateway Timeout' },
         
     | 
| 
      
 64 
     | 
    
         
            +
                                { name: 'HTTPVersionNotSupported', http_status: 505, message: 'Version Not Supported' }]
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
              exceptions_map.each { |x| BrocadeAPIClient.const_set(x[:name], BrocadeException.new(http_status: x[:http_status], message: x[:message])) }
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
              attr_accessor :code_map
         
     | 
| 
      
 69 
     | 
    
         
            +
              @@code_map = Hash.new('BrocadeException')
         
     | 
| 
      
 70 
     | 
    
         
            +
              exceptions_map.each do |c|
         
     | 
| 
      
 71 
     | 
    
         
            +
                inst = BrocadeAPIClient.const_get(c[:name])
         
     | 
| 
      
 72 
     | 
    
         
            +
                @@code_map[inst.http_status] = c
         
     | 
| 
      
 73 
     | 
    
         
            +
              end
         
     | 
| 
      
 74 
     | 
    
         
            +
              def self.exception_from_response(response, _body)
         
     | 
| 
      
 75 
     | 
    
         
            +
                # Return an instance of an ClientException
         
     | 
| 
      
 76 
     | 
    
         
            +
                cls = @@code_map[response.code]
         
     | 
| 
      
 77 
     | 
    
         
            +
                BrocadeAPIClient.const_get(cls[:name])
         
     | 
| 
      
 78 
     | 
    
         
            +
              end
         
     | 
| 
      
 79 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 2 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing,
         
     | 
| 
      
 6 
     | 
    
         
            +
            # software distributed
         
     | 
| 
      
 7 
     | 
    
         
            +
            # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
         
     | 
| 
      
 8 
     | 
    
         
            +
            # CONDITIONS OF ANY KIND, either express or implied. See the License for the
         
     | 
| 
      
 9 
     | 
    
         
            +
            # specific language governing permissions and limitations under the License.
         
     | 
| 
      
 10 
     | 
    
         
            +
            require_relative 'client'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require_relative 'httpclient'
         
     | 
| 
      
 12 
     | 
    
         
            +
            module BrocadeAPIClient
         
     | 
| 
      
 13 
     | 
    
         
            +
              # Fabrics REST API Methods
         
     | 
| 
      
 14 
     | 
    
         
            +
              class Fabrics
         
     | 
| 
      
 15 
     | 
    
         
            +
                def initialize(http_client)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @http_client = http_client
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @fabrics_url = '/resourcegroups/All/fcfabrics'
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def fabrics
         
     | 
| 
      
 21 
     | 
    
         
            +
                  _response, _body = @http_client.get(@fabrics_url)
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def fabric(fabricid)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  _response, _body = @http_client.get(@fabrics_url + '/' + fabricid.upcase)
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,149 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 2 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing,
         
     | 
| 
      
 6 
     | 
    
         
            +
            # software distributed
         
     | 
| 
      
 7 
     | 
    
         
            +
            # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
         
     | 
| 
      
 8 
     | 
    
         
            +
            # CONDITIONS OF ANY KIND, either express or implied. See the License for the
         
     | 
| 
      
 9 
     | 
    
         
            +
            # specific language governing permissions and limitations under the License.
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'httparty'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 12 
     | 
    
         
            +
            require 'logger'
         
     | 
| 
      
 13 
     | 
    
         
            +
            require_relative 'exceptions'
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            module BrocadeAPIClient
         
     | 
| 
      
 16 
     | 
    
         
            +
              # Class for talking to API
         
     | 
| 
      
 17 
     | 
    
         
            +
              class JSONRestClient
         
     | 
| 
      
 18 
     | 
    
         
            +
                USER_AGENT = 'ruby-brocadeclient'.freeze
         
     | 
| 
      
 19 
     | 
    
         
            +
                ACCEPT_TYPE = 'application/vnd.brocade.networkadvisor+json;version=v1'.freeze
         
     | 
| 
      
 20 
     | 
    
         
            +
                SESSION_COOKIE_NAME = 'WStoken'.freeze
         
     | 
| 
      
 21 
     | 
    
         
            +
                CONTENT_TYPE = 'application/vnd.brocade.networkadvisor+json;version=v1'.freeze
         
     | 
| 
      
 22 
     | 
    
         
            +
                attr_accessor :http_log_debug, :api_url, :session_key, :timeout, :secure,
         
     | 
| 
      
 23 
     | 
    
         
            +
                              :logger, :log_level
         
     | 
| 
      
 24 
     | 
    
         
            +
                @username = nil
         
     | 
| 
      
 25 
     | 
    
         
            +
                @password = nil
         
     | 
| 
      
 26 
     | 
    
         
            +
                def initialize(api_url, secure = false, http_log_debug = false,
         
     | 
| 
      
 27 
     | 
    
         
            +
                               client_logger = nil)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  @api_url = api_url
         
     | 
| 
      
 29 
     | 
    
         
            +
                  @secure = secure
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @http_log_debug = http_log_debug
         
     | 
| 
      
 31 
     | 
    
         
            +
                  @session_key = nil
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @client_logger = client_logger
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @httparty_log_level = :info
         
     | 
| 
      
 34 
     | 
    
         
            +
                  @httparty_log_format = :logstash
         
     | 
| 
      
 35 
     | 
    
         
            +
                  set_debug_flag
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                # This turns on/off http request/response debugging output to console
         
     | 
| 
      
 39 
     | 
    
         
            +
                def set_debug_flag
         
     | 
| 
      
 40 
     | 
    
         
            +
                  if @http_log_debug
         
     | 
| 
      
 41 
     | 
    
         
            +
                    @httparty_log_level = :debug
         
     | 
| 
      
 42 
     | 
    
         
            +
                    @httparty_log_format = :curl
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                def authenticate(user, password, _optional = nil)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @username = user
         
     | 
| 
      
 48 
     | 
    
         
            +
                  @pasword = password
         
     | 
| 
      
 49 
     | 
    
         
            +
                  @session_key = nil
         
     | 
| 
      
 50 
     | 
    
         
            +
                  auth_url = '/login'
         
     | 
| 
      
 51 
     | 
    
         
            +
                  headers, body = post(auth_url)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  @session_key = headers['WStoken']
         
     | 
| 
      
 53 
     | 
    
         
            +
                  JSON.parse(body)
         
     | 
| 
      
 54 
     | 
    
         
            +
                rescue StandardError
         
     | 
| 
      
 55 
     | 
    
         
            +
                  raise BrocadeAPIClient::ConnectionError
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                def url(api_url)
         
     | 
| 
      
 59 
     | 
    
         
            +
                  # should be http://<Server:Port>/rest
         
     | 
| 
      
 60 
     | 
    
         
            +
                  @api_url = api_url.chomp('/')
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                def get(url, **kwargs)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  headers, _payload = headers_payload(kwargs)
         
     | 
| 
      
 65 
     | 
    
         
            +
                  response = HTTParty.get(api_url + url,
         
     | 
| 
      
 66 
     | 
    
         
            +
                                          headers: headers,
         
     | 
| 
      
 67 
     | 
    
         
            +
                                          verify: false, logger: @client_logger,
         
     | 
| 
      
 68 
     | 
    
         
            +
                                          log_level: @httparty_log_level,
         
     | 
| 
      
 69 
     | 
    
         
            +
                                          log_format: @client_logger)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  validate_answer(response)
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                def post(url, **kwargs)
         
     | 
| 
      
 74 
     | 
    
         
            +
                  headers, payload = headers_payload(kwargs)
         
     | 
| 
      
 75 
     | 
    
         
            +
                  response = HTTParty.post(api_url + url,
         
     | 
| 
      
 76 
     | 
    
         
            +
                                           headers: headers,
         
     | 
| 
      
 77 
     | 
    
         
            +
                                           body: payload,
         
     | 
| 
      
 78 
     | 
    
         
            +
                                           verify: false,
         
     | 
| 
      
 79 
     | 
    
         
            +
                                           logger: @client_logger,
         
     | 
| 
      
 80 
     | 
    
         
            +
                                           log_level: @httparty_log_level,
         
     | 
| 
      
 81 
     | 
    
         
            +
                                           log_format: @httparty_log_format)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  validate_answer(response)
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                def put(url, **kwargs)
         
     | 
| 
      
 86 
     | 
    
         
            +
                  headers, payload = headers_payload(kwargs)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  response = HTTParty.put(api_url + url,
         
     | 
| 
      
 88 
     | 
    
         
            +
                                          headers: headers,
         
     | 
| 
      
 89 
     | 
    
         
            +
                                          body: payload,
         
     | 
| 
      
 90 
     | 
    
         
            +
                                          verify: false, logger: @client_logger,
         
     | 
| 
      
 91 
     | 
    
         
            +
                                          log_level: @httparty_log_level,
         
     | 
| 
      
 92 
     | 
    
         
            +
                                          log_format: @httparty_log_format)
         
     | 
| 
      
 93 
     | 
    
         
            +
                  validate_answer(response)
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                def delete(url, **kwargs)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  headers, _payload = headers_payload(kwargs)
         
     | 
| 
      
 98 
     | 
    
         
            +
                  response = HTTParty.delete(api_url + url,
         
     | 
| 
      
 99 
     | 
    
         
            +
                                             headers: headers,
         
     | 
| 
      
 100 
     | 
    
         
            +
                                             verify: false, logger: @client_logger,
         
     | 
| 
      
 101 
     | 
    
         
            +
                                             log_level: @httparty_log_level,
         
     | 
| 
      
 102 
     | 
    
         
            +
                                             log_format: @httparty_log_format)
         
     | 
| 
      
 103 
     | 
    
         
            +
                  validate_answer(response)
         
     | 
| 
      
 104 
     | 
    
         
            +
                end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                def validate_answer(response)
         
     | 
| 
      
 107 
     | 
    
         
            +
                  headers = response.headers
         
     | 
| 
      
 108 
     | 
    
         
            +
                  body = response.parsed_response
         
     | 
| 
      
 109 
     | 
    
         
            +
                  code_array = %w[200 204]
         
     | 
| 
      
 110 
     | 
    
         
            +
                  unless code_array.include?(response.code.to_s)
         
     | 
| 
      
 111 
     | 
    
         
            +
                    if body.nil?
         
     | 
| 
      
 112 
     | 
    
         
            +
                      exception = BrocadeAPIClient.exception_from_response(response, body)
         
     | 
| 
      
 113 
     | 
    
         
            +
                      @client_logger.error(exception)
         
     | 
| 
      
 114 
     | 
    
         
            +
                      raise exception
         
     | 
| 
      
 115 
     | 
    
         
            +
                    end
         
     | 
| 
      
 116 
     | 
    
         
            +
                  end
         
     | 
| 
      
 117 
     | 
    
         
            +
                  [headers, body]
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                def unauthenticate
         
     | 
| 
      
 121 
     | 
    
         
            +
                  # delete the session on the brocade network advisor
         
     | 
| 
      
 122 
     | 
    
         
            +
                  unless @session_key.nil?
         
     | 
| 
      
 123 
     | 
    
         
            +
                    post('/logout')
         
     | 
| 
      
 124 
     | 
    
         
            +
                    @session_key = nil
         
     | 
| 
      
 125 
     | 
    
         
            +
                  end
         
     | 
| 
      
 126 
     | 
    
         
            +
                end
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
                def headers_payload(**kwargs)
         
     | 
| 
      
 129 
     | 
    
         
            +
                  kwargs['headers'] = kwargs.fetch('headers', {})
         
     | 
| 
      
 130 
     | 
    
         
            +
                  if session_key
         
     | 
| 
      
 131 
     | 
    
         
            +
                    kwargs['headers'] = kwargs.fetch('headers', {})
         
     | 
| 
      
 132 
     | 
    
         
            +
                    kwargs['headers'][SESSION_COOKIE_NAME] = session_key
         
     | 
| 
      
 133 
     | 
    
         
            +
                  else
         
     | 
| 
      
 134 
     | 
    
         
            +
                    kwargs['headers']['WSUsername'] = @username
         
     | 
| 
      
 135 
     | 
    
         
            +
                    kwargs['headers']['WSPassword'] = @username
         
     | 
| 
      
 136 
     | 
    
         
            +
                  end
         
     | 
| 
      
 137 
     | 
    
         
            +
                  kwargs['headers']['User-Agent'] = USER_AGENT
         
     | 
| 
      
 138 
     | 
    
         
            +
                  kwargs['headers']['Accept'] = ACCEPT_TYPE
         
     | 
| 
      
 139 
     | 
    
         
            +
                  if kwargs.key?(:body)
         
     | 
| 
      
 140 
     | 
    
         
            +
                    kwargs['headers']['Content-Type'] = CONTENT_TYPE
         
     | 
| 
      
 141 
     | 
    
         
            +
                    kwargs[:body] = kwargs[:body].to_json
         
     | 
| 
      
 142 
     | 
    
         
            +
                    payload = kwargs[:body]
         
     | 
| 
      
 143 
     | 
    
         
            +
                  else
         
     | 
| 
      
 144 
     | 
    
         
            +
                    payload = nil
         
     | 
| 
      
 145 
     | 
    
         
            +
                  end
         
     | 
| 
      
 146 
     | 
    
         
            +
                  [kwargs['headers'], payload]
         
     | 
| 
      
 147 
     | 
    
         
            +
                end
         
     | 
| 
      
 148 
     | 
    
         
            +
              end
         
     | 
| 
      
 149 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,52 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 2 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing,
         
     | 
| 
      
 6 
     | 
    
         
            +
            # software distributed
         
     | 
| 
      
 7 
     | 
    
         
            +
            # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
         
     | 
| 
      
 8 
     | 
    
         
            +
            # CONDITIONS OF ANY KIND, either express or implied. See the License for the
         
     | 
| 
      
 9 
     | 
    
         
            +
            # specific language governing permissions and limitations under the License.
         
     | 
| 
      
 10 
     | 
    
         
            +
            module BrocadeAPIClient
         
     | 
| 
      
 11 
     | 
    
         
            +
              # Ports REST API Methods
         
     | 
| 
      
 12 
     | 
    
         
            +
              class Ports
         
     | 
| 
      
 13 
     | 
    
         
            +
                def initialize(http_client)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  @http_client = http_client
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @base_url = '/resourcegroups/All'
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def allports
         
     | 
| 
      
 19 
     | 
    
         
            +
                  api_url = @base_url + '/fcports'
         
     | 
| 
      
 20 
     | 
    
         
            +
                  _response, _body = @http_client.get(api_url)
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                def change_portstates(switchwwn, state, *portwwns)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  payload = {}
         
     | 
| 
      
 25 
     | 
    
         
            +
                  portwwns.map!(&:upcase)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  api_url = @base_url + '/fcswitches/' + switchwwn.upcase + '/fcports/fcportstate'
         
     | 
| 
      
 27 
     | 
    
         
            +
                  payload['fcPortState'] = state
         
     | 
| 
      
 28 
     | 
    
         
            +
                  payload['fcPortWWNs'] = portwwns
         
     | 
| 
      
 29 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                def change_persistentportstates(switchwwn, state, *portwwns)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  payload = {}
         
     | 
| 
      
 34 
     | 
    
         
            +
                  api_url = @base_url + '/fcswitches/' + switchwwn.upcase + '/fcports/fcportpersistentstate'
         
     | 
| 
      
 35 
     | 
    
         
            +
                  portwwns.map!(&:upcase)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  payload['fcPortState'] = state
         
     | 
| 
      
 37 
     | 
    
         
            +
                  payload['fcPortWWNs'] = portwwns
         
     | 
| 
      
 38 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                def set_portname(switchwwn, portwwn, portname)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  porthash = {}
         
     | 
| 
      
 43 
     | 
    
         
            +
                  portarray = []
         
     | 
| 
      
 44 
     | 
    
         
            +
                  api_url = @base_url + '/fcswitches/' + switchwwn.upcase + '/fcports/fcportnames'
         
     | 
| 
      
 45 
     | 
    
         
            +
                  porthash['fcPortWWN'] = portwwn.upcase
         
     | 
| 
      
 46 
     | 
    
         
            +
                  porthash['fcPortName'] = portname
         
     | 
| 
      
 47 
     | 
    
         
            +
                  portarray.push(porthash)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  payload = { 'fcPortNameChangeReqEntry' => portarray }
         
     | 
| 
      
 49 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 2 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing,
         
     | 
| 
      
 6 
     | 
    
         
            +
            # software distributed
         
     | 
| 
      
 7 
     | 
    
         
            +
            # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
         
     | 
| 
      
 8 
     | 
    
         
            +
            # CONDITIONS OF ANY KIND, either express or implied. See the License for the
         
     | 
| 
      
 9 
     | 
    
         
            +
            # specific language governing permissions and limitations under the License.
         
     | 
| 
      
 10 
     | 
    
         
            +
            module BrocadeAPIClient
         
     | 
| 
      
 11 
     | 
    
         
            +
              # Class to support versions checks for Brocade Network Advisor
         
     | 
| 
      
 12 
     | 
    
         
            +
              class BNASupport
         
     | 
| 
      
 13 
     | 
    
         
            +
                BNA_MIN_SUPPORTED = '14.2.0'.freeze
         
     | 
| 
      
 14 
     | 
    
         
            +
                BNA_PEER_ZONING_TDZ_MIN_SUPPORTED = '14.4.0'.freeze
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 2 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing,
         
     | 
| 
      
 6 
     | 
    
         
            +
            # software distributed
         
     | 
| 
      
 7 
     | 
    
         
            +
            # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
         
     | 
| 
      
 8 
     | 
    
         
            +
            # CONDITIONS OF ANY KIND, either express or implied. See the License for the
         
     | 
| 
      
 9 
     | 
    
         
            +
            # specific language governing permissions and limitations under the License.
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            module BrocadeAPIClient
         
     | 
| 
      
 12 
     | 
    
         
            +
              # Switches REST API Methods
         
     | 
| 
      
 13 
     | 
    
         
            +
              class Switches
         
     | 
| 
      
 14 
     | 
    
         
            +
                def initialize(http_client)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @http_client = http_client
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @base_url = '/resourcegroups/All'
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                def fabricswitches(fabricid)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  api_url = @base_url + '/fcfabrics/' + fabricid.upcase + '/fcswitches'
         
     | 
| 
      
 21 
     | 
    
         
            +
                  _response, _body = @http_client.get(api_url)
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def allswitches
         
     | 
| 
      
 25 
     | 
    
         
            +
                  api_url =  @base_url + '/fcswitches'
         
     | 
| 
      
 26 
     | 
    
         
            +
                  _response, _body = @http_client.get(api_url)
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 2 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing,
         
     | 
| 
      
 6 
     | 
    
         
            +
            # software distributed
         
     | 
| 
      
 7 
     | 
    
         
            +
            # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
         
     | 
| 
      
 8 
     | 
    
         
            +
            # CONDITIONS OF ANY KIND, either express or implied. See the License for the
         
     | 
| 
      
 9 
     | 
    
         
            +
            # specific language governing permissions and limitations under the License.
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            module BrocadeAPIClient
         
     | 
| 
      
 12 
     | 
    
         
            +
              VERSION = '0.1.1'.freeze
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,183 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 2 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing,
         
     | 
| 
      
 6 
     | 
    
         
            +
            # software distributed
         
     | 
| 
      
 7 
     | 
    
         
            +
            # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
         
     | 
| 
      
 8 
     | 
    
         
            +
            # CONDITIONS OF ANY KIND, either express or implied. See the License for the
         
     | 
| 
      
 9 
     | 
    
         
            +
            # specific language governing permissions and limitations under the License.
         
     | 
| 
      
 10 
     | 
    
         
            +
            require_relative 'exceptions'
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            module BrocadeAPIClient
         
     | 
| 
      
 13 
     | 
    
         
            +
              # Zones REST API Methods
         
     | 
| 
      
 14 
     | 
    
         
            +
              class Zones
         
     | 
| 
      
 15 
     | 
    
         
            +
                def initialize(http_client)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @http_client = http_client
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @base_url = '/resourcegroups/All/fcfabrics/'
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def zoneshow(fabrickey, zones = 'all', zkey = 'none')
         
     | 
| 
      
 21 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/zones'
         
     | 
| 
      
 22 
     | 
    
         
            +
                  if zones == 'all'
         
     | 
| 
      
 23 
     | 
    
         
            +
                  elsif zones == 'active'
         
     | 
| 
      
 24 
     | 
    
         
            +
                    api_url += if zkey == 'none'
         
     | 
| 
      
 25 
     | 
    
         
            +
                                 '?active=true'
         
     | 
| 
      
 26 
     | 
    
         
            +
                               else '/' + zkey + '-true'
         
     | 
| 
      
 27 
     | 
    
         
            +
                               end
         
     | 
| 
      
 28 
     | 
    
         
            +
                  elsif zones == 'defined'
         
     | 
| 
      
 29 
     | 
    
         
            +
                    api_url += if zkey == 'none'
         
     | 
| 
      
 30 
     | 
    
         
            +
                                 '?active=false'
         
     | 
| 
      
 31 
     | 
    
         
            +
                               else '/' + zkey + '-false'
         
     | 
| 
      
 32 
     | 
    
         
            +
                               end
         
     | 
| 
      
 33 
     | 
    
         
            +
                  else
         
     | 
| 
      
 34 
     | 
    
         
            +
                    err_msg = 'Unsupported Zoning Option, supported ALL is without zonename'
         
     | 
| 
      
 35 
     | 
    
         
            +
                    raise BrocadeAPIClient::UnsupportedOption
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
                  _response, _body = @http_client.get(api_url)
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                def zonedbs(fabrickey)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/zonedbs'
         
     | 
| 
      
 42 
     | 
    
         
            +
                  _response, _body = @http_client.get(api_url)
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                def alishow(fabrickey, zakey = 'none')
         
     | 
| 
      
 46 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/zonealiases'
         
     | 
| 
      
 47 
     | 
    
         
            +
                  api_url += '/' + zakey unless zakey == 'none'
         
     | 
| 
      
 48 
     | 
    
         
            +
                  _response, _body = @http_client.get(api_url)
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                def cfgshow(fabrickey, type)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  api_url =  @base_url + fabrickey.upcase + '/zonesets'
         
     | 
| 
      
 53 
     | 
    
         
            +
                  if type == 'all'
         
     | 
| 
      
 54 
     | 
    
         
            +
                  elsif type == 'active'
         
     | 
| 
      
 55 
     | 
    
         
            +
                    api_url += '?active=true'
         
     | 
| 
      
 56 
     | 
    
         
            +
                  elsif type == 'defined'
         
     | 
| 
      
 57 
     | 
    
         
            +
                    api_url +=  '?active=false'
         
     | 
| 
      
 58 
     | 
    
         
            +
                  else raise BrocadeAPIClient::UnsupportedOption
         
     | 
| 
      
 59 
     | 
    
         
            +
                  end
         
     | 
| 
      
 60 
     | 
    
         
            +
                  _response, _body = @http_client.get(api_url)
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                def alicreate(fabrickey, aliname, *wwn)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  wwn.map!(&:upcase)
         
     | 
| 
      
 65 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/createzoningobject'
         
     | 
| 
      
 66 
     | 
    
         
            +
                  alihash ||= { name: aliname, memberNames: wwn }
         
     | 
| 
      
 67 
     | 
    
         
            +
                  (aliarray ||= []) << alihash
         
     | 
| 
      
 68 
     | 
    
         
            +
                  payload ||= { zoneAliases: aliarray }
         
     | 
| 
      
 69 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                def control_transaction(fabrickey, action)
         
     | 
| 
      
 73 
     | 
    
         
            +
                  payload ||= { lsanZoning: 'false', action: action.upcase }
         
     | 
| 
      
 74 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/controlzonetransaction'
         
     | 
| 
      
 75 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 76 
     | 
    
         
            +
                end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                def zonecreate_standard(fabrickey, zonename, *aliases)
         
     | 
| 
      
 79 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/createzoningobject'
         
     | 
| 
      
 80 
     | 
    
         
            +
                  zonearray = []
         
     | 
| 
      
 81 
     | 
    
         
            +
                  zonehash ||= { name: zonename, aliasNames: aliases, type: 'STANDARD' }
         
     | 
| 
      
 82 
     | 
    
         
            +
                  (zonearray ||= []) << zonehash
         
     | 
| 
      
 83 
     | 
    
         
            +
                  payload ||= { zones: zonearray }
         
     | 
| 
      
 84 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 85 
     | 
    
         
            +
                end
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                def zonecreate_peerzone(fabrickey, zonename, **members)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  raise BrocadeAPIClient::InvalidPeerzoneOptions unless members.key?(:principal) && members.key?(:members)
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/createzoningobject'
         
     | 
| 
      
 91 
     | 
    
         
            +
                  peermembers ||= { peerMemberName: members[:members] }
         
     | 
| 
      
 92 
     | 
    
         
            +
                  peerdetails ||= { principalMemberName: members[:principal], peerMembers: peermembers }
         
     | 
| 
      
 93 
     | 
    
         
            +
                  zonedetails ||= { name: zonename, type: 'STANDARD', peerZone: 'True', peerZoneDetails: peerdetails }
         
     | 
| 
      
 94 
     | 
    
         
            +
                  (zonearray ||= []) << zonedetails
         
     | 
| 
      
 95 
     | 
    
         
            +
                  payload ||= { zones: zonearray }
         
     | 
| 
      
 96 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 97 
     | 
    
         
            +
                end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                def zonedelete(fabrickey, *zonenames)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/deletezoningobject'
         
     | 
| 
      
 101 
     | 
    
         
            +
                  payload ||= { zoneNames: zonenames }
         
     | 
| 
      
 102 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 103 
     | 
    
         
            +
                end
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                def alidelete(fabrickey, *alinames)
         
     | 
| 
      
 106 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/deletezoningobject'
         
     | 
| 
      
 107 
     | 
    
         
            +
                  payload ||= { zoneAliasNames: alinames }
         
     | 
| 
      
 108 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 109 
     | 
    
         
            +
                end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                def altercfg(fabrickey, action, cfgname, *zonenames)
         
     | 
| 
      
 112 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/updatezoningobject'
         
     | 
| 
      
 113 
     | 
    
         
            +
                  payload ||= { action: validate_answer(action) }
         
     | 
| 
      
 114 
     | 
    
         
            +
                  cfghash ||= { name: cfgname, zoneNames: zonenames }
         
     | 
| 
      
 115 
     | 
    
         
            +
                  (cfgarray ||= []) << cfghash
         
     | 
| 
      
 116 
     | 
    
         
            +
                  payload.store(:zoneSets, cfgarray)
         
     | 
| 
      
 117 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                def alteralias(fabrickey, action, aliname, *wwn)
         
     | 
| 
      
 121 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/updatezoningobject'
         
     | 
| 
      
 122 
     | 
    
         
            +
                  payload ||= { action: validate_answer(action) }
         
     | 
| 
      
 123 
     | 
    
         
            +
                  wwn.map!(&:upcase)
         
     | 
| 
      
 124 
     | 
    
         
            +
                  alihash ||= { name: aliname, memberNames: wwn }
         
     | 
| 
      
 125 
     | 
    
         
            +
                  (aliarray ||= []) << alihash
         
     | 
| 
      
 126 
     | 
    
         
            +
                  payload.store(:zoneAliases, aliarray)
         
     | 
| 
      
 127 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 128 
     | 
    
         
            +
                end
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                def alterzoning_standard(fabrickey, action, zonename, *aliases)
         
     | 
| 
      
 131 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/updatezoningobject'
         
     | 
| 
      
 132 
     | 
    
         
            +
                  payload ||= { action: validate_answer(action) }
         
     | 
| 
      
 133 
     | 
    
         
            +
                  zonehash ||= { name: zonename, aliasNames: aliases }
         
     | 
| 
      
 134 
     | 
    
         
            +
                  (zonearray ||= []) << zonehash
         
     | 
| 
      
 135 
     | 
    
         
            +
                  payload.store(:zones, zonearray)
         
     | 
| 
      
 136 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 137 
     | 
    
         
            +
                end
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
                def alterzoning_peerzone(fabrickey, action, zonename, **wwn)
         
     | 
| 
      
 140 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/updatezoningobject'
         
     | 
| 
      
 141 
     | 
    
         
            +
                  peerdetails = {}
         
     | 
| 
      
 142 
     | 
    
         
            +
                  peermembers = {}
         
     | 
| 
      
 143 
     | 
    
         
            +
                  payload ||= { action: validate_answer(action) }
         
     | 
| 
      
 144 
     | 
    
         
            +
                  case (wwn.keys & %i[principal members]).sort
         
     | 
| 
      
 145 
     | 
    
         
            +
                  when %i[members principal]
         
     | 
| 
      
 146 
     | 
    
         
            +
                    wwn[:members].map!(&:upcase)
         
     | 
| 
      
 147 
     | 
    
         
            +
                    wwn[:principal].map!(&:upcase)
         
     | 
| 
      
 148 
     | 
    
         
            +
                    peermembers = { peerMemberName: wwn[:members] }
         
     | 
| 
      
 149 
     | 
    
         
            +
                    peerdetails = { principalMemberName: wwn[:principal] }
         
     | 
| 
      
 150 
     | 
    
         
            +
                  when [:principal]
         
     | 
| 
      
 151 
     | 
    
         
            +
                    wwn[:principal].map!(&:upcase)
         
     | 
| 
      
 152 
     | 
    
         
            +
                    peerdetails = { principalMemberName: wwn[:principal] }
         
     | 
| 
      
 153 
     | 
    
         
            +
                  when [:members]
         
     | 
| 
      
 154 
     | 
    
         
            +
                    wwn[:members].map!(&:upcase)
         
     | 
| 
      
 155 
     | 
    
         
            +
                    peermembers = { peerMemberName: wwn[:members] }
         
     | 
| 
      
 156 
     | 
    
         
            +
                  else
         
     | 
| 
      
 157 
     | 
    
         
            +
                    raise BrocadeAPIClient::InvalidPeerzoneOptions
         
     | 
| 
      
 158 
     | 
    
         
            +
                  end
         
     | 
| 
      
 159 
     | 
    
         
            +
                  peerdetails.store(:peerMembers, peermembers)
         
     | 
| 
      
 160 
     | 
    
         
            +
                  zonedetails ||= { name: zonename, type: 'STANDARD', peerZone: 'True', peerZoneDetails: peerdetails }
         
     | 
| 
      
 161 
     | 
    
         
            +
                  (zonearray ||= []) << zonedetails
         
     | 
| 
      
 162 
     | 
    
         
            +
                  payload.store(:zones, zonearray)
         
     | 
| 
      
 163 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 164 
     | 
    
         
            +
                end
         
     | 
| 
      
 165 
     | 
    
         
            +
             
     | 
| 
      
 166 
     | 
    
         
            +
                def cfgenable(fabrickey, cfgname)
         
     | 
| 
      
 167 
     | 
    
         
            +
                  api_url = @base_url + fabrickey.upcase + '/zonesets/' + cfgname + '-false/activate'
         
     | 
| 
      
 168 
     | 
    
         
            +
                  payload = {}
         
     | 
| 
      
 169 
     | 
    
         
            +
                  _response, _body = @http_client.post(api_url, body: payload)
         
     | 
| 
      
 170 
     | 
    
         
            +
                end
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
                private
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
                def validate_answer(action)
         
     | 
| 
      
 175 
     | 
    
         
            +
                  case action.upcase
         
     | 
| 
      
 176 
     | 
    
         
            +
                  when 'ADD', 'REMOVE'
         
     | 
| 
      
 177 
     | 
    
         
            +
                    action.upcase
         
     | 
| 
      
 178 
     | 
    
         
            +
                  else
         
     | 
| 
      
 179 
     | 
    
         
            +
                    raise BrocadeAPIClient::UnsupportedAction
         
     | 
| 
      
 180 
     | 
    
         
            +
                  end
         
     | 
| 
      
 181 
     | 
    
         
            +
                end
         
     | 
| 
      
 182 
     | 
    
         
            +
              end
         
     | 
| 
      
 183 
     | 
    
         
            +
            end
         
     |