Class: Cloudscale::Plugins::PluginMongodbPreop

Inherits:
Cloudscale::Preops::Preop show all
Includes:
Singleton
Defined in:
lib/cloudscale/plugins/preops/plugin_mongodb_preop.rb

Constant Summary collapse

@@options =
{
  :host => {
    :argument => "--host",
    :description => "Host for your MongoDB Instance (e.g. host.mongodb.com)",
    :required => true,
    :value => nil     
  },
  :port => {
    :argument => "--port",
    :description => "Port for your MongoDB Instance (Standard 27017)",
    :required => false,
    :value => 27017
  },        
  :db => {
    :argument => "--db",
    :description => "Database of your MongoDB instance",
    :required => true,
    :value => nil
  },
  :ssl => {
    :argument => "--ssl",
    :description => "Usage SSL of your MongoDB instance",
    :required => false,
    :value => false
  },     
  :username => {
    :argument => "--username",
    :description => "Username for your MongoDB instance",
    :required => false,
    :value => nil
  },
  :password => {
    :argument => "--password",
    :description => "Password for your MongoDB instance",
    :required => false,
    :value => nil
  },
  :connect_timeout => {
    :argument => "--connect_timeout",
    :description => "Connection Timeout for your MongoDB instance",
    :required => false,
    :value => 30
  },
  :op_timeout => {
    :argument => "--op_timeout",
    :description => "Operation TImeout for your MongoDB instance",
    :required => false,
    :value => 30
  }
}

Instance Attribute Summary collapse

Attributes inherited from Cloudscale::Preops::Preop

#log, #registry

Instance Method Summary collapse

Methods inherited from Cloudscale::Preops::Preop

#clear_options, #get_option, #get_option_value, #init, #init_charts, #init_menus, #init_options, #save_options, #set_option_value

Constructor Details

#initializePluginMongodbPreop

Returns a new instance of PluginMongodbPreop.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/cloudscale/plugins/preops/plugin_mongodb_preop.rb', line 72

def initialize
  self.init
  begin
    @connection = Mongo::Connection.new(options[:host][:value], options[:port][:value])    
  rescue Mongo::ConnectionFailure
    puts "Unable to connect to the MongoDB Daemon.",
    "Please ensure it is running on #{@host}:#{@port}\n\nException Message: #{$!.message}. Also confirm if SSL should be enabled or disabled."
  end
    
  # Try to connect to the database
  if (@connection != nil)
    @db = @connection.db(options[:db][:value])
  end
  
  begin
    if (@username != nil)
      @db.authenticate(options[:username][:value], options[:password][:value])
    end
  rescue Mongo::AuthenticationError
    puts "Unable to authenticate to MongoDB Database." << $!.message
  end
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



16
17
18
# File 'lib/cloudscale/plugins/preops/plugin_mongodb_preop.rb', line 16

def connection
  @connection
end

#dbObject

Returns the value of attribute db.



16
17
18
# File 'lib/cloudscale/plugins/preops/plugin_mongodb_preop.rb', line 16

def db
  @db
end

Instance Method Details

#optionsObject



68
69
70
# File 'lib/cloudscale/plugins/preops/plugin_mongodb_preop.rb', line 68

def options      
  @@options
end