<commit_before>module OneviewSDK
  # Resource for logical interconnect groups
  # Common Data Attributes:
  #   category
  #   created
  #   description
  #   enclosureType (Required)
  #   eTag
  #   interconnectMapTemplate (Required)
  #   modified
  #   name (Required)
  #   state
  #   status
  #   uplinkSets (Required) (default = [])
  #   uri
  class LogicalInterconnect < Resource
    BASE_URI = '/rest/logical-interconnects'.freeze
    LOCATION_URI = '/rest/logical-interconnects/locations/interconnects'.freeze

    # Creates an Interconnect in the desired Bay in a specified enclosure
    # WARN: It does not creates the LOGICAL INTERCONNECT itself.
    # It will fail if no interconnect is already present on the specified position
    # @param [Fixnum] Number of the bay to put the interconnect
    # @param [OneviewSDK::Resource] Enclosure to insert the interconnect
    def create(bay_number, enclosure)
      entry = {
        'locationEntries' => [
          { 'value' => bay_number, 'type' => 'Bay' },
          { 'value' => enclosure['uri'], 'type' => 'Enclosure' }
        ]
      }
      response = @client.rest_post(self.class::LOCATION_URI, { 'body' => entry }, @api_version)
      @client.response_handler(response)
      # CREATE ONE INTERCONNECT RESOURCE HERE
    end

    # Deletes an INTERCONNECT
    # WARN: This won't delete the LOGICAL INTERCONNECT itself, and may cause inconsistency between the enclosure and LIG
    # @param [Fixnum] Number of the bay to locate the logical interconnect
    # @param [OneviewSDK::Resource] Enclosure to remove the logical interconnect
    def delete(bay_number, enclosure)
      delete_uri = self.class::LOCATION_URI + "?location=Enclosure:#{enclosure['uri']},Bay:#{bay_number}"
      response = @client.rest_delete(delete_uri, {}, @api_version)
      @client.response_handler(response)
      self
    end

    # Updates internal networks on the logical interconnect
    # @param [OneviewSDK::EthernetNetworks] List of networks to update the Logical Interconnect
    def update_internal_networks(*networks)
      uris = []
      return @client.response_handler(@client.rest_put(@data['uri'] + '/internalNetworks', 'body' => [])) unless networks
      networks.each do |net|
        net.retrieve! unless net['uri']
        uris.push(net['uri'])
      end
      response = @client.rest_put(@data['uri'] + '/internalNetworks', 'body' => uris)
      body = @client.response_handler(response)
      set_all(body)
      self
    end

    # Lists internal networks on the logical interconnect
    # @return [OneviewSDK::Resource] List of networks
    def list_vlan_networks
      results = OneviewSDK::Resource.find_by(@client, {}, @data['uri'] + '/internalVlans')
      internal_networks = []
      results.each do |vlan|
        net = if vlan['generalNetworkUri'].include? 'ethernet-network'
                OneviewSDK::EthernetNetwork.new(@client, uri: vlan['generalNetworkUri'])
              elsif vlan['generalNetworkUri'].include? 'fc-network'
                OneviewSDK::FCNetwork.new(@client, uri: vlan['generalNetworkUri'])
              else
                OneviewSDK::FCoENetwork.new(@client, uri: vlan['generalNetworkUri'])
              end
        net.retrieve!
        internal_networks.push(net)
      end
      internal_networks
    end

    # Updates ethernet settings of the Logical Interconnect
    # @note The attribute is defined inside the instance of the Logical Interconnect
    # @return Updated instance of the Logical Interconnect
    def update_ethernet_settings
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['ethernetSettings']
      update_options = {
        'If-Match' =>  @data['ethernetSettings'].delete('eTag'),
        'Body' => @data['ethernetSettings']
      }
      response = @client.rest_put(@data['uri'] + '/ethernetSettings', update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
      self
    end

    # Updates settings of the Logical Interconnect
    # @param Options to update the Logical Interconnect
    # @return Updated instance of the Logical Interconnect
    def update_settings(options = {})
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['uri']
      options['type'] ||= 'InterconnectSettingsV3'
      options['ethernetSettings'] ||= {}
      options['ethernetSettings']['type'] ||= 'EthernetInterconnectSettingsV3'
      update_options = {
        'If-Match' =>  @data['eTag'],
        'Body' => options
      }
      response = @client.rest_put(@data['uri'] + '/settings', update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
      self
    end

    # Returns logical interconnects to a consistent state.
    # The current logical interconnect state is compared to the associated logical interconnect group.
    # @return returns the updated object
    def compliance
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['uri']
      response = @client.rest_put(@data['uri'] + '/compliance', {}, @api_version)
      body = client.response_handler(response)
      set_all(body)
      self
    end

    # Asynchronously applies or re-applies the logical interconnect configuration to all managed interconnects
    # @return returns the updated object
    def configuration
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['uri']
      response = @client.rest_put(@data['uri'] + '/configuration', {}, @api_version)
      body = client.response_handler(response)
      set_all(body)
      self
    end

    # Updates port monitor settings of the Logical Interconnect
    # @note The attribute is defined inside the instance of the Logical Interconnect
    # @return Updated instance of the Logical Interconnect
    def update_port_monitor
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['portMonitor']
      update_options = {
        'If-Match' =>  @data['portMonitor'].delete('eTag'),
        'Body' => @data['portMonitor']
      }
      response = @client.rest_put(@data['portMonitor']['uri'], update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
      self
    end

    # Updates QoS aggregated configuration of the Logical Interconnect
    # @note The attribute is defined inside the instance of the Logical Interconnect
    # @return Updated instance of the Logical Interconnect
    def update_qos_configuration
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['qosConfiguration']
      update_options = {
        'If-Match' =>  @data['qosConfiguration'].delete('eTag'),
        'Body' => @data['qosConfiguration']
      }
      response = @client.rest_put(@data['uri'] + '/qos-aggregated-configuration', update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
      self
    end

    # Updates telemetry configuration of the Logical Interconnect
    # @note The attribute is defined inside the instance of the Logical Interconnect
    # @return Updated instance of the Logical Interconnect
    def update_telemetry_configuration
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['telemetryConfiguration']
      update_options = {
        'If-Match' =>  @data['telemetryConfiguration'].delete('eTag'),
        'Body' => @data['telemetryConfiguration']
      }
      response = @client.rest_put(@data['telemetryConfiguration']['uri'], update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
      self
    end

    # Updates snmp configuration of the Logical Interconnect
    # @note The attribute is defined inside the instance of the Logical Interconnect.
    #   Use helper methods to add the trap destination values: #add_snmp_trap_destination and #generate_trap_options
    # @return Updated instance of the Logical Interconnect
    def update_snmp_configuration
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['snmpConfiguration']
      update_options = {
        'If-Match' =>  @data['snmpConfiguration'].delete('eTag'),
        'Body' => @data['snmpConfiguration']
      }
      response = @client.rest_put(@data['uri'] + '/snmp-configuration', update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
      self
    end

    # It will add one trap destination to the Logical Interconnect SNMP configuration
    # @param trap_format [String] SNMP version for this trap destination, `'SNMPv1'` or `'SNMPv2'` or `'SNMPv3'`
    # @param trap_destination [String] The trap destination IP address or host name
    # @param community_string [String] Authentication string for the trap destination
    # @param trap_options [Hash] Hash with the options of the trap. Create it using generate_trap_options method
    def add_snmp_trap_destination(trap_destination, trap_format = 'SNMPv1', community_string = 'public', trap_options = {})
      validate_trap_format(trap_format)
      trap_options['communityString'] = community_string
      trap_options['trapDestination'] = trap_destination<commit_msg>Fixing mininum unit test coverage<commit_after>module OneviewSDK
  # Resource for logical interconnect groups
  # Common Data Attributes:
  #   category
  #   created
  #   description
  #   enclosureType (Required)
  #   eTag
  #   interconnectMapTemplate (Required)
  #   modified
  #   name (Required)
  #   state
  #   status
  #   uplinkSets (Required) (default = [])
  #   uri
  class LogicalInterconnect < Resource
    BASE_URI = '/rest/logical-interconnects'.freeze
    LOCATION_URI = '/rest/logical-interconnects/locations/interconnects'.freeze

    # Creates an Interconnect in the desired Bay in a specified enclosure
    # WARN: It does not creates the LOGICAL INTERCONNECT itself.
    # It will fail if no interconnect is already present on the specified position
    # @param [Fixnum] Number of the bay to put the interconnect
    # @param [OneviewSDK::Resource] Enclosure to insert the interconnect
    def create(bay_number, enclosure)
      entry = {
        'locationEntries' => [
          { 'value' => bay_number, 'type' => 'Bay' },
          { 'value' => enclosure['uri'], 'type' => 'Enclosure' }
        ]
      }
      response = @client.rest_post(self.class::LOCATION_URI, { 'body' => entry }, @api_version)
      @client.response_handler(response)
    end

    # Deletes an INTERCONNECT
    # WARN: This won't delete the LOGICAL INTERCONNECT itself, and may cause inconsistency between the enclosure and LIG
    # @param [Fixnum] Number of the bay to locate the logical interconnect
    # @param [OneviewSDK::Resource] Enclosure to remove the logical interconnect
    def delete(bay_number, enclosure)
      delete_uri = self.class::LOCATION_URI + "?location=Enclosure:#{enclosure['uri']},Bay:#{bay_number}"
      response = @client.rest_delete(delete_uri, {}, @api_version)
      @client.response_handler(response)
      self
    end

    # Updates internal networks on the logical interconnect
    # @param [OneviewSDK::EthernetNetworks] List of networks to update the Logical Interconnect
    def update_internal_networks(*networks)
      uris = []
      return @client.response_handler(@client.rest_put(@data['uri'] + '/internalNetworks', 'body' => [])) unless networks
      networks.each do |net|
        net.retrieve! unless net['uri']
        uris.push(net['uri'])
      end
      response = @client.rest_put(@data['uri'] + '/internalNetworks', 'body' => uris)
      body = @client.response_handler(response)
      set_all(body)
    end

    # Lists internal networks on the logical interconnect
    # @return [OneviewSDK::Resource] List of networks
    def list_vlan_networks
      results = OneviewSDK::Resource.find_by(@client, {}, @data['uri'] + '/internalVlans')
      internal_networks = []
      results.each do |vlan|
        net = if vlan['generalNetworkUri'].include? 'ethernet-network'
                OneviewSDK::EthernetNetwork.new(@client, uri: vlan['generalNetworkUri'])
              elsif vlan['generalNetworkUri'].include? 'fc-network'
                OneviewSDK::FCNetwork.new(@client, uri: vlan['generalNetworkUri'])
              else
                OneviewSDK::FCoENetwork.new(@client, uri: vlan['generalNetworkUri'])
              end
        net.retrieve!
        internal_networks.push(net)
      end
      internal_networks
    end

    # Updates ethernet settings of the Logical Interconnect
    # @note The attribute is defined inside the instance of the Logical Interconnect
    # @return Updated instance of the Logical Interconnect
    def update_ethernet_settings
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['ethernetSettings']
      update_options = {
        'If-Match' =>  @data['ethernetSettings'].delete('eTag'),
        'Body' => @data['ethernetSettings']
      }
      response = @client.rest_put(@data['uri'] + '/ethernetSettings', update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
    end

    # Updates settings of the Logical Interconnect
    # @param Options to update the Logical Interconnect
    # @return Updated instance of the Logical Interconnect
    def update_settings(options = {})
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['uri']
      options['type'] ||= 'InterconnectSettingsV3'
      options['ethernetSettings'] ||= {}
      options['ethernetSettings']['type'] ||= 'EthernetInterconnectSettingsV3'
      update_options = {
        'If-Match' =>  @data['eTag'],
        'Body' => options
      }
      response = @client.rest_put(@data['uri'] + '/settings', update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
    end

    # Returns logical interconnects to a consistent state.
    # The current logical interconnect state is compared to the associated logical interconnect group.
    # @return returns the updated object
    def compliance
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['uri']
      response = @client.rest_put(@data['uri'] + '/compliance', {}, @api_version)
      body = client.response_handler(response)
      set_all(body)
    end

    # Asynchronously applies or re-applies the logical interconnect configuration to all managed interconnects
    # @return returns the updated object
    def configuration
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['uri']
      response = @client.rest_put(@data['uri'] + '/configuration', {}, @api_version)
      body = client.response_handler(response)
      set_all(body)
    end

    # Updates port monitor settings of the Logical Interconnect
    # @note The attribute is defined inside the instance of the Logical Interconnect
    # @return Updated instance of the Logical Interconnect
    def update_port_monitor
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['portMonitor']
      update_options = {
        'If-Match' =>  @data['portMonitor'].delete('eTag'),
        'Body' => @data['portMonitor']
      }
      response = @client.rest_put(@data['portMonitor']['uri'], update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
    end

    # Updates QoS aggregated configuration of the Logical Interconnect
    # @note The attribute is defined inside the instance of the Logical Interconnect
    # @return Updated instance of the Logical Interconnect
    def update_qos_configuration
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['qosConfiguration']
      update_options = {
        'If-Match' =>  @data['qosConfiguration'].delete('eTag'),
        'Body' => @data['qosConfiguration']
      }
      response = @client.rest_put(@data['uri'] + '/qos-aggregated-configuration', update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
    end

    # Updates telemetry configuration of the Logical Interconnect
    # @note The attribute is defined inside the instance of the Logical Interconnect
    # @return Updated instance of the Logical Interconnect
    def update_telemetry_configuration
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['telemetryConfiguration']
      update_options = {
        'If-Match' =>  @data['telemetryConfiguration'].delete('eTag'),
        'Body' => @data['telemetryConfiguration']
      }
      response = @client.rest_put(@data['telemetryConfiguration']['uri'], update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
    end

    # Updates snmp configuration of the Logical Interconnect
    # @note The attribute is defined inside the instance of the Logical Interconnect.
    #   Use helper methods to add the trap destination values: #add_snmp_trap_destination and #generate_trap_options
    # @return Updated instance of the Logical Interconnect
    def update_snmp_configuration
      fail 'Please retrieve the Logical Interconnect before trying to update' unless @data['snmpConfiguration']
      update_options = {
        'If-Match' =>  @data['snmpConfiguration'].delete('eTag'),
        'Body' => @data['snmpConfiguration']
      }
      response = @client.rest_put(@data['uri'] + '/snmp-configuration', update_options, @api_version)
      body = @client.response_handler(response)
      set_all(body)
    end

    # It will add one trap destination to the Logical Interconnect SNMP configuration
    # @param trap_format [String] SNMP version for this trap destination, `'SNMPv1'` or `'SNMPv2'` or `'SNMPv3'`
    # @param trap_destination [String] The trap destination IP address or host name
    # @param community_string [String] Authentication string for the trap destination
    # @param trap_options [Hash] Hash with the options of the trap. Create it using generate_trap_options method
    def add_snmp_trap_destination(trap_destination, trap_format = 'SNMPv1', community_string = 'public', trap_options = {})
      validate_trap_format(trap_format)
      trap_options['communityString'] = community_string
      trap_options['trapDestination'] = trap_destination
{'fraction_non_alphanumeric': 0.09747799319544202, 'fraction_numerical': 0.0006480531403575094, 'mean_word_length': 3.5121832358674463, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6609486', 'n_tokens_mistral': 5104, 'n_tokens_neox': 4988, 'n_words': 1491}