<commit_before># frozen_string_literal: true

module ServiceLayer
  module NetworkingServices
    # Implements Openstack Router
    module Router
      def router_map
        @router_map ||= class_map_proc(Networking::Router)
      end

      def routers(filter = {})
        elektron_networking.get('routers', filter).map_to(
          'body.routers', &router_map
        )
      end

      def find_router!(id)
        return nil unless id
        elektron_networking.get("routers/#{id}").map_to(
          'body.router', &router_map
        )
      end

      def find_router(id)
        find_router!(id)
      rescue Elektron::Errors::ApiResponse
        nil
      end

      def new_router(attributes = {})
        router_map.call(attributes)
      end

      def add_router_interfaces(router_id, interface_ids)
        interface_ids.each do |interface_id|
          elektron_networking.put(
            "routers/#{router_id}/add_router_interface"
          ) do
            { subnet_id: interface_id }
          end
        end
      end

      def remove_router_interfaces(router_id, interface_ids)
        interface_ids.each do |interface_id|
          elektron_networking.put(
            "routers/#{router_id}/remove_router_interface"
          ) do
            { subnet_id: interface_id }
          end
        end
      end

      ################### Model Interface ###################
      def create_router(attributes)
        elektron_networking.post('routers') do
          { 'router' => attributes }
        end.body['router']
      end

      def update_router(id, attributes)
        elektron_networking.put("routers/#{id}") do
          { 'router' => attributes }
        end.body['router']
      end

      def delete_router(id)
        elektron_networking.delete("routers/#{id}")
      end
    end
  end
end<commit_msg>fixes #237, before a router is deleted, all linked interfaces are removed. The error was that the subnet_id of such a interface contained an undefined character. That is now fixed<commit_after># frozen_string_literal: true

module ServiceLayer
  module NetworkingServices
    # Implements Openstack Router
    module Router
      def router_map
        @router_map ||= class_map_proc(Networking::Router)
      end

      def routers(filter = {})
        elektron_networking.get('routers', filter).map_to(
          'body.routers', &router_map
        )
      end

      def find_router!(id)
        return nil unless id
        elektron_networking.get("routers/#{id}").map_to(
          'body.router', &router_map
        )
      end

      def find_router(id)
        find_router!(id)
      rescue Elektron::Errors::ApiResponse
        nil
      end

      def new_router(attributes = {})
        router_map.call(attributes)
      end

      def add_router_interfaces(router_id, interface_ids)
        interface_ids.each do |interface_id|
          elektron_networking.put(
            "routers/#{router_id}/add_router_interface"
          ) do
            { subnet_id: interface_id }
          end
        end
      end

      def remove_router_interfaces(router_id, interface_ids)
        interface_ids.each do |interface_id|
          elektron_networking.put(
            "routers/#{router_id}/remove_router_interface"
          ) do
            { subnet_id: interface_id }
          end
        end
      end

      ################### Model Interface ###################
      def create_router(attributes)
        elektron_networking.post('routers') do
          { 'router' => attributes }
        end.body['router']
      end

      def update_router(id, attributes)
        elektron_networking.put("routers/#{id}") do
          { 'router' => attributes }
        end.body['router']
      end

      def delete_router(id)
        elektron_networking.delete("routers/#{id}")
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1041017653167186, 'fraction_numerical': 0.000778816199376947, 'mean_word_length': 2.1633825944170773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5565677', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1117, 'n_words': 226}