#--
# Copyright 2013 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#++

module Vagrant
  module Openshift
    module Action
      class CleanNetworkSetup
        include CommandHelper

        def initialize(app, env)
          @app = app
          @env = env
        end

        def call(env)
          is_fedora = env[:machine].communicate.test("test -e /etc/fedora-release")

          if !is_fedora
            if env[:machine].communicate.test("test -e /etc/udev/rules.d/70-persistent-net.rules")
              remote_write(env[:machine], "/etc/udev/rules.d/70-persistent-net.rules") do
%{# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

}
              end
            end
          end

          sudo env[:machine], "yum clean all"
          sudo env[:machine], "rm -f /var/lib/mlocate/mlocate.db"
          @app.call(env)
        end
      end
    end
  end
end