Sha256: 4d8e32e7c64bd409fd8a58cf85fc8ed9560d227c77463617c974b7ea5cc9c95e

Contents?: true

Size: 1.71 KB

Versions: 6

Compression:

Stored size: 1.71 KB

Contents

require 'cloud66_agent/utils/vital_signs'
require 'cloud66_agent/utils/version'
require 'cloud66_agent/utils/server'

module Cloud66
  module Commands
    class Configure
      def self.perform(server_uid, cloud)
        begin
          if cloud.nil? || cloud.empty?
            # try figure it out
            $config.is_aws = Utils::VitalSigns.is_aws?

            if $config.is_aws
              $config.is_gc = false
            else
              # try figure it out
              $config.is_gc = Utils::VitalSigns.is_gc?
            end
          else
            # use the passed in value
            $config.is_aws = (cloud == 'aws')

            # use the passed in value
            $config.is_gc = (cloud == 'googlecloud')
          end
          data = {
              :timezone => Time.new.zone,
              :server_uid => server_uid,
              :version => Utils::Version.current,
              :system => Utils::VitalSigns.system_info}

          address_info = Utils::VitalSigns.address_info
          data = data.merge(address_info)
        rescue => exc
          data = {error: exc.message}
        end
        result = Utils::Server.send_configure data
        $config.agent_uid = result['agent_uid']

        disk_warning_percent = result['disk_warning_percent']
        $config.disk_warning_percent = disk_warning_percent.to_i unless disk_warning_percent.nil?
        disk_critical_percent = result['disk_critical_percent']
        $config.disk_critical_percent = disk_critical_percent.to_i unless disk_critical_percent.nil?

        $config.disabled = false
        $config.save
        exit 0
      rescue => exc
        $logger.error "Command \"configure\" failed: #{exc.message}"
        exit -1
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cloud66_agent-1.4.5 lib/cloud66_agent/commands/configure.rb
cloud66_agent-1.4.4 lib/cloud66_agent/commands/configure.rb
cloud66_agent-1.4.3 lib/cloud66_agent/commands/configure.rb
cloud66_agent-1.4.2 lib/cloud66_agent/commands/configure.rb
cloud66_agent-1.4.1 lib/cloud66_agent/commands/configure.rb
cloud66_agent-1.4.0 lib/cloud66_agent/commands/configure.rb