code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'AWS/EC2'
require 'basic_configuration'
require 'aws_context'
require 'pp'
# Attach a volume to a running instance.
if ARGV[0] == '-?' || ARGV.size != 3 then
puts "usage: attach-volume volume-id instance-id device"
exit 1
end
volume_id = ARGV[0]
i... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "app"))
require 'test/unit'
require 'MockAWS/clock'
require 'logger_factory'
require 'configuration'
require 'pool_configuration'
require 'aws_context'
require 'pp'
# Test that the standard policy classes can be created, and have the
# right class names. This tests the dynamic lo... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "app"))
require 'test/unit'
require 'MockAWS/clock'
require 'logger_factory'
require 'configuration'
require 'pool_configuration'
require 'policy_limit'
require 'aws_context'
require 'pp'
# Test the ManualPolicy class.
# Make sure it adjusts the number of instances appropriately i... | Ruby |
#!/usr/bin/ruby
require 'test/unit/testsuite'
require 'configuration-test'
require 'instance-test'
require 'instance-pool-test'
require 'enumerator-test'
require 'named-queue-test'
require 'job-policy-test'
require 'resource-policy-tests'
require 'fixed-policy-tests'
require 'daytime-policy-tests'
require 'manual-poli... | Ruby |
#!/usr/bin/ruby
require 'test/unit/testsuite'
require 'configuration-test'
require 'instance-test'
require 'instance-pool-test'
require 'enumerator-test'
require 'named-queue-test'
require 'job-policy-test'
require 'resource-policy-tests'
require 'fixed-policy-tests'
require 'daytime-policy-tests'
require 'manual-poli... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "app"))
require 'test/unit'
require 'MockAWS/clock'
require 'logger_factory'
require 'aws_context'
require 'named_queue'
require 'pp'
# test the NamedQueue implementation.
class NamedQueueTests < Test::Unit::TestCase
def setup
LoggerFactory.setup("/tmp/test.out")
logf = ... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "app"))
require 'pp'
require 'test/unit'
require 'MockAWS/clock'
require 'logger_factory'
require 'configuration'
require 'pool_configuration'
require 'aws_context'
require 'reporter'
# Test the ConfigInfo class.
# This also test InifileConfig
class ConfigInfoTests < Test::Unit:... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "app"))
require 'test/unit'
require 'logger_factory'
require 'MockAWS/clock'
require 'configuration'
require 'pool_configuration'
require 'aws_context'
require 'pp'
# Test the DaytimePolicy class.
# This class is an example of adding an additional policy to the system.
class Dayti... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "app"))
require 'test/unit'
require 'MockAWS/clock'
require 'logger_factory'
require 'configuration'
require 'pool_configuration'
require 'policy_limit'
require 'aws_context'
require 'pp'
# Test the JobPolicy class.
# Make sure it adjusts the number of instances appropriately in a... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "app"))
require 'test/unit'
require 'MockAWS/clock'
require 'logger_factory'
require 'configuration'
require 'pool_configuration'
require 'pp'
# Test the Instance class.
class InstanceTests < Test::Unit::TestCase
def setup
Clock.set(0)
config_files = ['aws-config.ini', '... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "app"))
require 'test/unit'
require 'MockAWS/clock'
require 'logger_factory'
require 'configuration'
require 'pool_configuration'
require 'policy_limit'
require 'aws_context'
require 'pp'
# test the PolicyResource class.
class ResourcePolicyTests < Test::Unit::TestCase
def setup... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "app"))
require 'test/unit'
require 'MockAWS/clock'
require 'logger_factory'
require 'configuration'
require 'pool_configuration'
require 'aws_context'
require 'pp'
# Test the InstancePool class.
class InstancePoolTests < Test::Unit::TestCase
def setup
LoggerFactory.setup("/... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "app"))
require 'test/unit'
require 'MockAWS/clock'
require 'logger_factory'
require 'aws_context'
require 'ec2_instance_enumerator'
require 'ec2_image_enumerator'
require 'pp'
# tests the EC2ImageEnumerator and the C2InstanceEnumerators.
class EnumeratorTests < Test::Unit::TestCa... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "app"))
require 'test/unit'
require 'stringio'
require 'rexml/document'
require 'time'
require 'MockAWS/clock'
require 'logger_factory'
require 'configuration'
require 'pool_configuration'
require 'pool_runner'
require 'aws_context'
require 'pp'
# Test the Cloudmaster class.
class... | Ruby |
require 'pp'
# Compute primes.
class Primes
# Start with a couple primes.
def initialize
@shutdown = false
@primes = []
add(2)
add(3)
end
# Test if a number is prime
# by dividing by previous primes.
def prime?(p)
limit = Math::sqrt(p).ceil
(1..@primes.size-1).each do |i|
if... | Ruby |
$:.unshift File.join(File.dirname(__FILE__))
$:.unshift File.join(ENV['HOME'], 'lib')
require 'aws_context'
require 'user_data'
require 'pp'
require 'open-uri'
require 'yaml'
require 'primes'
# TODO use the log factory
# Manages generation of primes.
# Pulls jobs from a SQS primes-work queue one at a time.
# Compu... | Ruby |
require 'pp'
require 'gserver'
# Computes successive fibonacci numbers.
# Each instance is independent -- it produces one stream of numbers.
class Fibonacci
# Start the sequence.
def initialize
@f1, @f2 = 1, 1
end
# Return the next member of the sequence.
def next
@f1, @f2 = @f2, @f1+@f2
@f1
... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
$:.unshift File.join(ENV['HOME'], 'lib')
require 'aws_context'
require 'user_data'
require 'clock'
require 'periodic'
require 'pp'
require 'open-uri'
require 'yaml'
require 'gserver'
# Compute successive fibonacci numbers
class Fibonacci
def initialize
... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
$:.unshift File.join(ENV['HOME'], 'lib')
require 'aws_context'
require 'user_data'
require 'clock'
require 'periodic'
require 'pp'
require 'open-uri'
require 'yaml'
require 'gserver'
# Compute successive fibonacci numbers
class Fibonacci
def initialize
... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'monitor'
require 'open-uri'
aws_env = ENV['AWS_ENV']
puts "Environment: #{aws_env}"
begin
iid = open('http://169.254.169.254/latest/meta-data/instance-id').read(200)
rescue
# when running locally, use fake iid
iid="iid-fake"
end
begin
moni... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'monitor'
require 'open-uri'
aws_env = ENV['AWS_ENV']
puts "Environment: #{aws_env}"
begin
iid = open('http://169.254.169.254/latest/meta-data/instance-id').read(200)
rescue
# when running locally, use fake iid
iid="iid-fake"
end
begin
moni... | Ruby |
require 'basic_configuration'
require 'aws_context'
require 'user_data'
require 'yaml'
require 'open-uri'
require 'pp'
# Sample, meant to run on an Amazon EC2 instance.
#
# It monitors another subsystem (in this case a Darwin Streaming Server)
# and provides periodic load estimates.
class MonitorDarwin
def initiali... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'basic_configuration'
require 'aws_context'
require 'pp'
max_count = 10000 # up to 3 seconds
n = 1
args = ARGV
while args.size > 0
a = args.shift
case
when a == '-?':
puts "usage: feed-primes-queue [-m max-cont] [n]"
exit 1
wh... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'basic_configuration'
require 'aws_context'
require 'pp'
max_count = 10000 # up to 3 seconds
n = 1
args = ARGV
while args.size > 0
a = args.shift
case
when a == '-?':
puts "usage: feed-primes-queue [-m max-cont] [n]"
exit 1
wh... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'AWS/S3'
require 'configuration'
require 'aws_context'
require 'yaml'
require 'pp'
config = Cloudmaster::Configuration.new
s3 = AwsContext.instance.s3(*config.keys)
bucket = config.pools[0][:active_set_bucket]
key = config.pools[0][:active_set_key]
... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'AWS/SQS'
require 'configuration'
require 'aws_context'
require 'yaml'
require 'pp'
# Reads from a queue and dumps the instances messages into a file.
# Each message replaces the file.
# File contans instance id and the reported load.
# Continues rea... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'AWS/S3'
require 'configuration'
require 'aws_context'
require 'yaml'
require 'pp'
config = Cloudmaster::Configuration.new
s3 = AwsContext.instance.s3(*config.keys)
bucket = config.pools[0][:active_set_bucket]
key = config.pools[0][:active_set_key]
... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'AWS/SQS'
require 'configuration'
require 'aws_context'
require 'yaml'
require 'pp'
# Reads from a queue and dumps the instances messages into a file.
# Each message replaces the file.
# File contans instance id and the reported load.
# Continues rea... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'net/telnet'
#
# Connects to fib client on the given host:port.
# Requests a new fib valie once a second.
class FibClient
# Create a new FibClient on the given host and port.
def initialize(host, port)
@client = Net::Telnet::new('Host' => ... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'basic_configuration'
require 'aws_context'
require 'fib-client'
require 'allocator'
# Allocates a server, connects a fib client to it,
# and fetches a stream of fibonacci numbers.
port = 20808
config = BasicConfiguration.new
aws_bucket = conf... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'fib-client'
# usage: test-client [host [port]]
#
# connects to fib client on host:port and gets a new
# value once a second
#
# Used to test generate-fib running locally.
# 1) in one window: ruby generate-fig.rb
# 2) in another: test-client
case A... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'basic_configuration'
require 'aws_context'
require 'allocator'
require 'pp'
config = BasicConfiguration.new
aws_bucket = config.aws[:aws_bucket]
if aws_bucket.nil?
puts "Bucket must be set: define AWS_BUCKET in environment or config file."
exit... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'net/telnet'
#
# Connects to fib client on the given host:port.
# Requests a new fib valie once a second.
class FibClient
# Create a new FibClient on the given host and port.
def initialize(host, port)
@client = Net::Telnet::new('Host' => ... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'basic_configuration'
require 'aws_context'
require 'pp'
require 'yaml'
# Allocates work to servers in the active-set.
# This is a sample of how a resource pool can be managed.
#
# Reads the active-set from S3, finds the lowest load, and
# alloc... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'basic_configuration'
require 'aws_context'
require 'fib-client'
require 'allocator'
# Allocates a server, connects a fib client to it,
# and fetches a stream of fibonacci numbers.
port = 20808
config = BasicConfiguration.new
aws_bucket = conf... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'basic_configuration'
require 'aws_context'
require 'pp'
require 'yaml'
# Allocates work to servers in the active-set.
# This is a sample of how a resource pool can be managed.
#
# Reads the active-set from S3, finds the lowest load, and
# alloc... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'basic_configuration'
require 'aws_context'
require 'allocator'
require 'pp'
config = BasicConfiguration.new
aws_bucket = config.aws[:aws_bucket]
if aws_bucket.nil?
puts "Bucket must be set: define AWS_BUCKET in environment or config file."
exit... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'fib-client'
# usage: test-client [host [port]]
#
# connects to fib client on host:port and gets a new
# value once a second
#
# Used to test generate-fib running locally.
# 1) in one window: ruby generate-fig.rb
# 2) in another: test-client
case A... | Ruby |
require 'aws_context'
module Cloudmaster
# Implements a queue specified by name.
# The queue name is used to look up the actual SQS queue.
# The queue name is used in a substring match, so possibly more than one
# string may match.
# If no queue is found for given name, or if there are
# multiple, the Nam... | Ruby |
require 'periodic'
require 'pp'
require 'logger'
require 'reporter'
require 'instance_pool'
require 'aws_context'
require 'policy_factory'
require 'active_set_factory'
require 'status_parser_factory'
require 'logger_factory'
require 'policy'
module Cloudmaster
# PoolManager
#
# Manages one InstancePool, which is co... | Ruby |
require 'policy'
module Cloudmaster
# Provide manual policy.
# This policy only changes the instances when requested to do so.
# This implementation uses a queue to convey manual requests
# to the policy module.
class PolicyManual < Policy
def initialize(reporter, config, instances)
super(reporter... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(ENV['AWS_HOME'], "app")
require 'configuration'
require 'aws_context'
require 'configuration'
require 'pool_runner'
require 'pp'
# Get optional args specifying what server to manage.
verbose = false
config_files = []
opts = []
args = ARGV
while args.size > 0
a = args.shift
cas... | Ruby |
require 'inifile'
require 'basic_configuration'
require 'pp'
# Configuration
# Read an ini file and create a configuration.
# The configuration contains the aws configuration, the defaults, and all the pool sections.
module Cloudmaster
class Configuration < BasicConfiguration
attr_reader :default, :pools
... | Ruby |
require 'aws_context'
# This implementation of ActiveSet writes the active set to a queue
module Cloudmaster
class ActiveSetQueue
def initialize(config)
@sqs = AwsContext.instance.sqs
active_set_queue_name = config.append_env(config[:active_set_queue])
@active_set_queue = NamedQueue.new(active... | Ruby |
require 'named_queue'
require 'ec2_image_enumerator'
module Cloudmaster
# All configuration parameters passed in through the constructor.
# Items with * must be defined
#
# ==aws_config==
# aws_env -- used to form queue, instance, and s3 key names --
# typically development|test|production
# *aws_acces... | Ruby |
#!/usr/bin/ruby
$:.unshift File.join(ENV['AWS_HOME'], "app")
require 'configuration'
require 'aws_context'
require 'configuration'
require 'pool_runner'
require 'pp'
# Get optional args specifying what server to manage.
verbose = false
config_files = []
opts = []
args = ARGV
while args.size > 0
a = args.shift
cas... | Ruby |
require 'aws_context'
# This implementation of ActiveSet writes the active set to S3.
module Cloudmaster
class ActiveSetS3
def initialize(config)
@s3 = AwsContext.instance.s3
@config = config
end
private
public
def valid?
@config[:active_set_bucket] && @config[:active_set_ke... | Ruby |
# The standard implementation of status parser
require 'rexml/document'
require 'time'
# Process a message as sent from Linfguard.
# Convert it into a form usable with pob pools.
# If we want to make an accurate load estimate, we need to take
# the last interval into account, and average over some time period.
module ... | Ruby |
# This implementation of ActiveSet does nothing
# It is appropriate when you don't want the active set.
module Cloudmaster
class ActiveSetNone
def initialize(config)
end
def valid?
true
end
def update(active_set)
end
end
end
| Ruby |
# This is a factory for Policy implementations.
require 'factory'
module Cloudmaster
class PolicyFactory
include Factory
def PolicyFactory.create(policy_name, *params)
name = policy_name.nil? ? 'default' : policy_name.to_s
require 'policy_' + name.downcase
class_name = 'Policy' +name.capit... | Ruby |
require 'pool_configuration'
require 'pool_manager'
module Cloudmaster
# oolRunner
#
# Manages separate PoolManagers, each in a separate thread.
#
# Knows how to start (run) and stop (shutdown) the pools.
#
# Creates a thread for each pool in config, and runs a PoolManager in it.
# This needs to ... | Ruby |
require 'policy_limit'
module Cloudmaster
# Provides the common data and behaviors for policies.
# This includes storing the configuration and instance collection.
# It also includes implementing essential methods such as ensure_limite and
# stop_hung_instances.
# Finally, this implements helpers that proce... | Ruby |
# This is a factory for ActiveSet implementations.
require 'factory'
module Cloudmaster
class ActiveSetFactory
include Factory
def ActiveSetFactory.create(type, *params)
name = type.nil? ? 'none' : type.to_s
require 'active_set_' + name.downcase
class_name = 'ActiveSet' + name.capitalize
... | Ruby |
# This is a factory for StatusParser implementations.
require 'factory'
module Cloudmaster
class StatusParserFactory
include Factory
def StatusParserFactory.create(type, *params)
name = type.nil? ? 'none' : type.to_s
require 'status_parser_' + name.downcase
class_name = 'StatusParser' + na... | Ruby |
require 'aws_context'
module Cloudmaster
# Provides enumerators for EC2 images.
# The information is read once from EC2 and stored.
# It is then enumearted one image at a time.
# The stored list of images can also be searched
# Get the EC2 images and store them.
# Allow lookup by matching on the name.
... | Ruby |
require 'policy'
module Cloudmaster
# Provides resource policy implementation.
# Instances managed under a resource policy are expected to issue
# periodic status messages, giving their estimated load (generally
# between 0 and 1).
class PolicyResource < Policy
# Each policy object gets the configurati... | Ruby |
require 'policy'
module Cloudmaster
# Provides job policy
# Instances managed by the job policy take work from a queue and report
# status thrugh another queue.
class PolicyJob < Policy
# Initialize the policy by giving it access to the configuration and
# the collection of instances.
def initia... | Ruby |
require 'policy'
module Cloudmaster
# Provide fixed policy.
# This never adjusts the size of the pool.
# PolicyFixed is still useful, because it still ensures that the number
# of instances stay beteen the maximum and minimum (because this is
# enforced in the base class apply).
class PolicyFixed < Policy... | Ruby |
require 'aws_context'
require 'ec2_instance_enumerator'
require 'instance'
require 'yaml'
module Cloudmaster
# Stores and operates on a collection of instances
#
# Internally, instances are stored as an array of Instance objects.
class InstancePool
include Enumerable
# Create an instance pool.
... | Ruby |
require 'aws_context'
module Cloudmaster
# Provides an enumerator for EC2 instances.
# Query for instances when object created.
# Handles all instances we own, or just ones maching a list of ids.
class EC2InstanceEnumerator
include Enumerable
# Get the list of instances from EC2
def initialize(*i... | Ruby |
module Cloudmaster
# This enforces the limits on starting and stopping instances.
# It can be used by other policies to make sure thrie own adjust method
# does not increase or decrease by more than the configurable start limit or stop limit.
# This also provides an exaplanation for its actions.
class Policy... | Ruby |
# The standard implementation of status parser
require 'yaml'
module Cloudmaster
class StatusParserStd
def parse_message(body)
YAML.load(body)
end
end
end
| Ruby |
module Cloudmaster
# Holds information about a specific instance.
# When we create an instance in EC2, we create one of these classes to hold
# information about the instance. Instances are members of the InstancePool.
#
# Each instance holds the following information:
# * id -- instance id
# * public... | Ruby |
require 'policy'
module Cloudmaster
# Provide example daytime policy
# This increases the pool size during the day.
# This is provided as part of an example on how to create custom policies.
class PolicyDaytime < Policy
# Define the adjust function increase the pool in the
# daytime if it is below da... | Ruby |
require 'instance_logger'
module Cloudmaster
# Creates and outputs log messages
# These are formatted with a timestamp and an instance name.
# This remembers the log device, which is anything with puts.
# This is treated as a global. It is initialized by calling "Reporter.setup"
# and then anyone can get a... | Ruby |
# The default logger writes to a file descriptor.
# This could be an actual file, or a stream such as STDOUT.
class FileLogger
def initialize(file = nil, *args)
case
when file.nil?
@fd = STDOUT
@needs_close = false
when file.is_a?(String)
@fd = File.new(file, "a")
@needs_close = tr... | Ruby |
# Used to execute tasks periodically.
# Execute at most once each interval (seconds).
# If interval is < 0, never execute.
# If interval is 0, execute every time.
class Periodic
# Create a periodic execution at this interval.
def initialize(interval)
@last_time = Clock.at(0)
@interval ... | Ruby |
# Used to wrap Time so it can be mocked
class Clock < Time
def Clock.sleep(numeric = 0)
Kernel.sleep numeric
end
end
| Ruby |
require 'AWS/SQS'
require 'AWS/EC2'
require 'AWS/S3'
require 'AWS/SimpleDB'
require 'SafeAWS/SQS'
require 'SafeAWS/EC2'
require 'SafeAWS/S3'
require 'SafeAWS/SimpleDB'
require 'RetryAWS/SQS'
require 'RetryAWS/EC2'
require 'RetryAWS/S3'
require 'RetryAWS/SimpleDB'
require 'MockAWS/EC2'
require 'MockAWS/S3'
require 'Moc... | Ruby |
# Sample Ruby code for the O'Reilly book "Programming Amazon Web
# Services" by James Murty.
#
# This code was written for Ruby version 1.8.6 or greater.
#
# The SQS module implements the Query API of the Amazon Simple Queue
# Service.
require 'AWS'
class SQS
include AWS # Include the AWS module as a mixin
ENDPOI... | Ruby |
# Sample Ruby code for the O'Reilly book "Programming Amazon Web
# Services" by James Murty.
#
# This code was written for Ruby version 1.8.6 or greater.
#
# The EC2 module implements the Query API of the Amazon Elastic Compute Cloud
# service.
#
# Extended by Charles Hayden to cover EBS interface extensions.
require '... | Ruby |
# Sample Ruby code for the O'Reilly book "Using AWS Infrastructure
# Services" by James Murty.
#
# This code was written for Ruby version 1.8.6 or greater.
#
# The SimpleDB module implements the Query API of the Amazon SimpleDB
# Service.
require 'AWS'
require 'bigdecimal'
class SimpleDB
include AWS # Include the A... | Ruby |
# Sample Ruby code for the O'Reilly book "Programming Amazon Web
# Services" by James Murty.
#
# This code was written for Ruby version 1.8.6 or greater.
#
# The AWS module includes HTTP messaging and utility methods that handle
# communication with Amazon Web Services' REST or Query APIs. Service
# client implementati... | Ruby |
# Sample Ruby code for the O'Reilly book "Programming Amazon Web
# Services" by James Murty.
#
# This code was written for Ruby version 1.8.6 or greater.
#
# The S3 module implements the REST API of the Amazon Simple Storage Service.
require 'AWS'
require 'digest/md5'
class S3
include AWS # Include the AWS module a... | Ruby |
# The instance logger writes to a file in a given directory.
# The file is determined by the instance_id in the message.
# The file is opened and closed each time something is written.
class InstanceLogger
def initialize(dir)
@directory = dir
end
def puts(instance, msg)
File.open(File.join(@directory, in... | Ruby |
# Logs to a string.
# This is useful in testing so that we can read back what
# was put into the log, to see if it was what was expected.
class StringLogger
def initialize(*params)
@log = StringIO.new("", "w")
end
def close
end
def puts(msg)
@log.puts(msg)
end
def string
@log.string
end
... | Ruby |
require 'factory'
require 'sys_logger'
require 'string_logger'
require 'file_logger'
class LoggerFactory
include Factory
@@filename = 'logfile'
@@program = 'unknown'
def LoggerFactory.setup(filename, program = 'unknown')
@@filename = filename
@@program = program
end
def LoggerFactory.create(type... | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "lib", "OriginalAWS"))
require 'OriginalAWS/SQS'
module AWS
class SQS
def initialize(*args)
@sqs = ::SQS.new(*args)
end
def method_missing(key, *args)
@sqs.send(key, *args)
end
end
end | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "lib", "OriginalAWS"))
require 'OriginalAWS/EC2'
module AWS
class EC2
def initialize(*args)
@ec2 = ::EC2.new(*args)
end
def method_missing(key, *args)
@ec2.send(key, *args)
end
end
end | Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "lib", "OriginalAWS"))
require 'OriginalAWS/SimpleDB'
module AWS
class SimpleDB
def initialize(*args)
@ec2 = ::SimpleDB.new(*args)
end
def method_missing(key, *args)
@ec2.send(key, *args)
end
end
end
| Ruby |
require '../OriginalAWS/AWS'
| Ruby |
$:.unshift(File.join(ENV['AWS_HOME'], "lib", "OriginalAWS"))
require 'OriginalAWS/S3'
module AWS
class S3
def initialize(*args)
@s3 = ::S3.new(*args)
end
def method_missing(key, *args, &block)
@s3.send(key, *args, &block)
end
end
end | Ruby |
# Used to mock Time
class Clock
attr_accessor :time
include Comparable
@@current_time = 0
def initialize(time)
@time = time
end
def Clock.at(time)
Clock.new(time)
end
def Clock.now
Clock.new(@@current_time)
end
def Clock.hour
(@@current_time/3600).floor
end
def to_s
... | Ruby |
module MockAWS
# Mock SQS
class SQS
@@log = STDOUT
@@queues = ["http://queue.amazonaws.com/A13T024T56MRDD/manual-manual-test",
"http://queue.amazonaws.com/A13T024T56MRDC/fib-status-test",
"http://queue.amazonaws.com/A13T024T56MRDC/fib-work-test",
"http://queue.amazonaws.com/A13T024T56MRDC/pri... | Ruby |
# Mock SQS
# Provide just enough for cloudmaster.
module MockAWS
# Mock EC2
class EC2
@@log = STDOUT
@@images = [
{:owner_id=>"452272755447",
:state=>"available",
:id=>"ami-08856161",
:is_public=>false,
:location=>"chayden/chayden-ami-primes-test.img.manifest.xml"},
... | Ruby |
require 'AWS/SimpleDB'
module MockAWS
class SimpleDB
def initialize(*params)
end
def list_domains(max_domains = 100)
[]
end
def create_domain(domain_name)
true
end
def delete_domain(domain_name)
true
end
def put_attributes(domain_name, item_name, attribut... | Ruby |
module MockAWS
# Mock S3
class S3
@@contents = {}
def initialize(*params)
end
# Create an S3 object.
def create_object(bucket_name, object_key, opts={})
key = "#{bucket_name}/#{object_key}"
value = opts[:data]
@@contents[key] = value
end
# Return an object stored pre... | Ruby |
# This contains common factory methods.
module Factory
# Given a class name as a string, create an instance of that class
# and initialize it with the given arguments.
def Factory.create_object_from_string(class_name, *args)
ObjectSpace.each_object(Class) do |x|
if x.name == class_name || x.name == "Cl... | Ruby |
require 'AWS/SQS'
module RetryAWS
# Wrap SQS routines that we use.
# Catch exceptions and return something reasonable.
class SQS
def initialize(*params)
@sqs = AWS::SQS.new(*params)
@@log = STDOUT
@retry_limit = 16
end
def logger=(logger)
@@log = logger
end
private
... | Ruby |
require 'AWS/EC2'
# RetryAWS wraps the AWS module in exception catcher blocks, so that any
# exceptions that are thrown do not affect the caller.
#
# The RetryEC2, RetrySQS, and RetryS3 log any errors that they encounter, so
# that they can be examined later.
module RetryAWS
# Wrap EC2 functions that we use.
# Cat... | Ruby |
require 'AWS/SimpleDB'
# RetryAWS wraps the AWS module in code that retries it if it fails.
#
module RetryAWS
class SimpleDB
def initialize(access_key, secret_key)
@simple_db = AWS::SimpleDB.new(access_key, secret_key)
@@log = STDOUT
end
def logger=(logger)
@@log = logger
end
... | Ruby |
require 'AWS/S3'
module RetryAWS
class S3
def initialize(access_key, secret_key)
@s3 = AWS::S3.new(access_key, secret_key)
@@log = STDOUT
@retry_limit = 16
end
def logger=(logger)
@@log = logger
end
private
def report_error(res)
@@log.puts "error #{$!}"
... | Ruby |
#
# This class represents the INI file and can be used to parse INI files.
# Derived from IniFile gem, found on http://rubyforge.org/projects/inifile/
#
class IniFile
#
# call-seq:
# IniFile.load( filename )
# IniFile.load( filename, options )
#
# Open the given _filename_ and load the contents of th... | Ruby |
require 'AWS/SQS'
module SafeAWS
# Wrap SQS routines that we use.
# Catch exceptions and return something reasonable.
class SQS
def initialize(*params)
@sqs = AWS::SQS.new(*params)
@@log = STDOUT
end
def logger=(logger)
@@log = logger
end
private
# report error and r... | Ruby |
require 'AWS/EC2'
# SafeAWS wraps the AWS module in exception catcher blocks, so that any
# exceptions that are thrown do not affect the caller.
#
# The SafeEC2, SafeSQS, SafeSimpleDB and SafeS3 log any errors that they encounter, so
# that they can be examined later.
module SafeAWS
# Wrap EC2 functions that we use.... | Ruby |
require 'AWS/SimpleDB'
# SafeAWS wraps the AWS module in exception catcher blocks, so that any
# exceptions that are thrown do not affect the caller.
#
# The SafeEC2, SafeSQS, SafeSimpleDB, and SafeS3 log any errors that they encounter, so
# that they can be examined later.
module SafeAWS
# Wrap SimpleDB functions t... | Ruby |
require 'AWS/S3'
module SafeAWS
class S3
def initialize(access_key, secret_key)
@s3 = AWS::S3.new(access_key, secret_key)
@@log = STDOUT
end
def logger=(logger)
@@log = logger
end
private
def report_error(res)
@@log.puts "error #{$!}"
$@.each {|line| @@log.pu... | Ruby |
require 'inifile'
require 'pp'
# BasicConfiguration
# Read an ini file and create a configuration.
# The configuration contains the aws configuration only.
class BasicConfiguration
attr_reader :aws
# Default list of config files to search for
DEFAULT_CONFIG_FILES = ['aws-config.ini', 'default-config.ini', 'con... | Ruby |
require 'syslog'
# Logs using the syslog facility.
class SysLogger
def initialize(dummy, program_name)
@log = Syslog.open(program_name)
end
def close
end
def puts(msg)
@log.info(msg)
end
def debug(msg)
@log.debug(msg)
end
def info(msg)
@log.info(msg)
end
def notice(msg)
@log.... | Ruby |
# This class loads user data.
require 'open-uri'
require 'yaml'
class UserData
# Load user data
def self.load
begin
iid = open('http://169.254.169.254/latest/meta-data/instance-id').read(200)
user_data = open('http://169.254.169.254/latest/user-data').read(2000)
data = YAML.load(user_data)
... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.