<commit_before>#!/usr/bin/env ruby

# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             #
#                                                                            #
# 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.                                             #
#--------------------------------------------------------------------------- #

ONE_LOCATION=ENV["ONE_LOCATION"]

if !ONE_LOCATION
    RUBY_LIB_LOCATION="/usr/lib/one/ruby"
    ETC_LOCATION="/etc/one/"
    REMOTES_LOCATION="/var/lib/one/remotes"
else
    RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
    ETC_LOCATION=ONE_LOCATION+"/etc/"
    REMOTES_LOCATION=ONE_LOCATION+"/var/remotes/"
end

$: << RUBY_LIB_LOCATION

require 'OpenNebulaDriver'
require 'getoptlong'

#-------------------------------------------------------------------------------
# The SSH Information Manager Driver
#-------------------------------------------------------------------------------
class InformationManagerDriverSSH < OpenNebulaDriver

    #---------------------------------------------------------------------------
    # Init the driver
    #---------------------------------------------------------------------------
    def initialize(hypervisor, threads, retries)
        super(threads, true, retries)

        @config = read_configuration

        @hypervisor = hypervisor
        @remote_dir = @config['SCRIPTS_REMOTE_DIR']

        # register actions
        register_action(:MONITOR, method("action_monitor"))
    end

    #---------------------------------------------------------------------------
    # Execute the run_probes in the remote host
    #---------------------------------------------------------------------------
    def action_monitor(number, host, do_update)
        if do_update == "1"
            # Use SCP to sync:
            sync_cmd = "scp -r #{REMOTES_LOCATION}/. #{host}:#{@remote_dir}"

            # Use rsync to sync:
            # sync_cmd = "rsync -Laz #{REMOTES_LOCATION} #{host}:#{@remote_dir}"
            LocalCommand.run(sync_cmd, log_method(number))
        end

        cmd_string = "#{@remote_dir}/im/run_probes #{@hypervisor} #{host}"      

        remotes_action(cmd_string, number, host, "MONITOR", @remote_dir)
    end
end

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Information Manager main program
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------

opts = GetoptLong.new(
    [ '--retries',    '-r', GetoptLong::OPTIONAL_ARGUMENT ],
    [ '--threads',    '-t', GetoptLong::OPTIONAL_ARGUMENT ]
)

hypervisor = ''
retries    = 0
threads    = 15

begin
    opts.each do |opt, arg|
        case opt
            when '--retries'
                retries = arg.to_i
            when '--threads'
                threads = arg.to_i
        end
    end
rescue Exception => e
    exit(-1)
end 

if ARGV.length >= 1 
    hypervisor = ARGV.shift
end

im = InformationManagerDriverSSH.new(hypervisor, threads, retries)
im.start_driver<commit_msg>feature #595: changed comments and formating<commit_after>#!/usr/bin/env ruby

# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             #
#                                                                            #
# 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.                                             #
#--------------------------------------------------------------------------- #

ONE_LOCATION=ENV["ONE_LOCATION"]

if !ONE_LOCATION
    RUBY_LIB_LOCATION="/usr/lib/one/ruby"
    ETC_LOCATION="/etc/one/"
    REMOTES_LOCATION="/var/lib/one/remotes"
else
    RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
    ETC_LOCATION=ONE_LOCATION+"/etc/"
    REMOTES_LOCATION=ONE_LOCATION+"/var/remotes/"
end

$: << RUBY_LIB_LOCATION

require 'OpenNebulaDriver'
require 'getoptlong'


# The SSH Information Manager Driver
class InformationManagerDriverSSH < OpenNebulaDriver

    # Init the driver
    def initialize(hypervisor, threads, retries)
        super(threads, true, retries)

        @config = read_configuration

        @hypervisor = hypervisor
        @remote_dir = @config['SCRIPTS_REMOTE_DIR']

        # register actions
        register_action(:MONITOR, method("action_monitor"))
    end

    # Execute the run_probes in the remote host
    def action_monitor(number, host, do_update)
        if do_update == "1"
            # Use SCP to sync:
            sync_cmd = "scp -r #{REMOTES_LOCATION}/. #{host}:#{@remote_dir}"

            # Use rsync to sync:
            # sync_cmd = "rsync -Laz #{REMOTES_LOCATION}
            #   #{host}:#{@remote_dir}"
            LocalCommand.run(sync_cmd, log_method(number))
        end

        cmd_string = "#{@remote_dir}/im/run_probes #{@hypervisor} #{host}"

        remotes_action(cmd_string, number, host, "MONITOR", @remote_dir)
    end
end


# Information Manager main program

opts = GetoptLong.new(
    [ '--retries',    '-r', GetoptLong::OPTIONAL_ARGUMENT ],
    [ '--threads',    '-t', GetoptLong::OPTIONAL_ARGUMENT ]
)

hypervisor = ''
retries    = 0
threads    = 15

begin
    opts.each do |opt, arg|
        case opt
            when '--retries'
                retries = arg.to_i
            when '--threads'
                threads = arg.to_i
        end
    end
rescue Exception => e
    exit(-1)
end

if ARGV.length >= 1
    hypervisor = ARGV.shift
end

im = InformationManagerDriverSSH.new(hypervisor, threads, retries)
im.start_driver
{'fraction_non_alphanumeric': 0.22967618527121192, 'fraction_numerical': 0.0053285968028419185, 'mean_word_length': 1.2502305564094682, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4417290', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1772, 'n_words': 458}