Module: Merb::Virtuozzo

Defined in:
lib/merb_virtuozzo/merb_virtuozzo.rb

Class Method Summary collapse

Class Method Details

.configObject

Parses the configuration file converting keys to symbols and stores values to Merb::Plugins.config.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/merb_virtuozzo/merb_virtuozzo.rb', line 26

def config
  @config ||= begin
    # Convert string keys to symbols
    full_config = Erubis.load_yaml_file(config_file)
    config = (Merb::Plugins.config[:virtuozzo] = {})
    (full_config[Merb.environment.to_sym] || full_config[Merb.environment] || full_config[:development]).each do |key, value|
      config[key.to_sym] = value
    end
    config
  end
end

.config_fileObject

Returns the expected location of a deployment configuration file.



6
# File 'lib/merb_virtuozzo/merb_virtuozzo.rb', line 6

def config_file() Merb.root / "config" / "virtuozzo.yml" end

.config_options(config = {}) ⇒ Object

Extract and merge default values from configuration options.



40
41
42
43
44
45
46
47
48
# File 'lib/merb_virtuozzo/merb_virtuozzo.rb', line 40

def config_options(config = {})
  options = {}

  options[:host] = (config[:host] || "https://localhost:4646")
  options[:username] = (config[:username] || config[:user] || "")
  options[:password] = config[:password] || ""

  options
end

.connectObject

Establishes connection or logs errors returning the connection on success.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/merb_virtuozzo/merb_virtuozzo.rb', line 59

def connect
  if File.exists?(config_file)
    Merb.logger.info!("Connecting to the Virtuozzo Agent at '#{config[:host]}' ...")
    
    o = config_options(config)
    
    connection_options = [
        o[:host],
        o[:username],
        o[:password],
        o.except(:host, :username, :password)
      ]
    
    @connection = ::Virtuozzo::SOAP::Connection.new(*connection_options)
    Merb.logger.error!("Connection Error: #{e}") unless @connection
    connection
  else
    copy_sample_config
    Merb.logger.set_log(STDERR)
    Merb.logger.error! "No virtuozzo.yml file found in #{Merb.root}/config."
    Merb.logger.error! "A sample file was created called config/virtuozzo.yml.sample for you to copy and edit."
    exit(1)
  end
end

.connectionObject

Singleton method for accessing an established connection session.



52
53
54
# File 'lib/merb_virtuozzo/merb_virtuozzo.rb', line 52

def connection
  @connection ||= connect
end

.copy_sample_configObject

Copies the template for the sample configuration file into the application’s config folder.



19
20
21
# File 'lib/merb_virtuozzo/merb_virtuozzo.rb', line 19

def copy_sample_config
  FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
end

.sample_destObject

Returnes the expected location of a sample configuration file.



10
# File 'lib/merb_virtuozzo/merb_virtuozzo.rb', line 10

def sample_dest() Merb.root / "config" / "virtuozzo.yml.sample" end

.sample_sourceObject

Returnes the location of the template for a sample configuration file.



14
# File 'lib/merb_virtuozzo/merb_virtuozzo.rb', line 14

def sample_source() File.dirname(__FILE__) / "virtuozzo.yml.sample" end