Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade aws-sdk to v2 #20

Merged
merged 7 commits into from
Sep 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: ruby
sudo: false
rvm:
- 2.0.0
script:
Expand All @@ -15,3 +16,8 @@ env:
- TEST_VPC1=vpc-18f5097d
- TEST_VPC2=vpc-e5f50980
- TEST_INTERVAL=3
- AWS_REGION=ap-northeast-1
addons:
apt:
packages:
- libpcap-dev
6 changes: 3 additions & 3 deletions bin/roadwork
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ ARGV.options do |opt|
credentials_opts = {}
credentials_opts[:profile_name] = profile_name if profile_name
credentials_opts[:path] = credentials_path if credentials_path
provider = AWS::Core::CredentialProviders::SharedCredentialFileProvider.new(credentials_opts)
provider = Aws::SharedCredentials.new(credentials_opts)
aws_opts[:credential_provider] = provider
elsif (access_key and !secret_key) or (!access_key and secret_key) or mode.nil?
puts opt.help
exit 1
end
AWS.config(aws_opts)
Aws.config.update(aws_opts)
rescue => e
$stderr.puts e
exit 1
end
end

if options[:debug]
AWS.config(
Aws.config.update(
:http_wire_trace => true,
:logger => options[:logger]
)
Expand Down
10 changes: 4 additions & 6 deletions lib/roadworker/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(options = {})
@options = OpenStruct.new(options)
@options.logger ||= Logger.new($stdout)
String.colorize = @options.color
@options.route53 = AWS::Route53.new
@options.route53 = Aws::Route53::Client.new
@health_checks = HealthCheck.health_checks(@options.route53, :extended => true)
@options.health_checks = @health_checks
@route53 = Route53Wrapper.new(@options)
Expand All @@ -20,10 +20,8 @@ def apply(file)
if dsl.hosted_zones.empty? and not @options.force
log(:warn, "Nothing is defined (pass `--force` if you want to remove)", :yellow)
else
AWS.memoize {
walk_hosted_zones(dsl)
updated = @options.updated
}
walk_hosted_zones(dsl)
updated = @options.updated
end

if updated and not @options.no_health_check_gc
Expand All @@ -34,7 +32,7 @@ def apply(file)
end

def export
exported = AWS.memoize { @route53.export }
exported = @route53.export

if block_given?
yield(exported, DSL.method(:convert))
Expand Down
12 changes: 3 additions & 9 deletions lib/roadworker/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ module Roadworker
class Collection

class << self
def batch(collection)
if collection.respond_to?(:each_batch)
collection.each_batch do |batch|
batch.each do |item|
yield(item)
end
end
else
collection.each do |item|
def batch(pageable_response, collection_name)
pageable_response.each do |response|
response.public_send(collection_name).each do |item|
yield(item)
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/roadworker/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def vpc(vpc_region, vpc_id)
raise "Invalid VPC ID: #{vpc_id}"
end

vpc_h = {:vpc_region => vpc_region.to_s, :vpc_id => vpc_id.to_s}
vpc_h = Aws::Route53::Types::VPC.new(:vpc_region => vpc_region.to_s, :vpc_id => vpc_id.to_s)

if @result.vpcs.include?(vpc_h)
raise "VPC is already defined: #{vpc_h.inspect}"
Expand Down Expand Up @@ -120,7 +120,7 @@ def region(value)
end

def dns_name(value, options = {})
options = AWS::Route53.normalize_dns_name_options(options)
options = Aws::Route53.normalize_dns_name_options(options)
@result.dns_name = [value, options]
end

Expand Down Expand Up @@ -159,12 +159,12 @@ def health_check(url, *options)
end
end

if config[:search_string]
config[:type] += '_STR_MATCH'
if config.search_string
config.type += '_STR_MATCH'
end

config[:request_interval] ||= 30
config[:failure_threshold] ||= 3
config.request_interval ||= 30
config.failure_threshold ||= 3

@result.health_check = config
end
Expand All @@ -174,7 +174,7 @@ def resource_records(*values)
raise "Duplicate ResourceRecords: #{values.join(', ')}"
end

@result.resource_records = [values].flatten.map {|i| {:value => i} }
@result.resource_records = [values].flatten.map {|i| Aws::Route53::Types::ResourceRecord.new(:value => i) }
end

end # ResourceRecordSet
Expand Down
9 changes: 5 additions & 4 deletions lib/roadworker/route53-exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ def export
private

def export_hosted_zones(hosted_zones)
Collection.batch(@options.route53.hosted_zones) do |zone|
zone_h = item_to_hash(zone, :name, :vpcs)
Collection.batch(@options.route53.list_hosted_zones, :hosted_zones) do |zone|
next unless matched_zone?(zone.name)
resp = @options.route53.get_hosted_zone(id: zone.id)
zone_h = { name: zone.name, vpcs: resp.vp_cs }
hosted_zones << zone_h

rrsets = []
zone_h[:rrsets] = rrsets

Collection.batch(zone.rrsets) do |record|
Collection.batch(@options.route53.list_resource_record_sets(hosted_zone_id: zone.id), :resource_record_sets) do |record|
if record.name == zone.name and %w(SOA NS).include?(record.type) and not @options.with_soa_ns
next
end
Expand Down Expand Up @@ -78,7 +79,7 @@ def item_to_hash(item, *attrs)
h = {}

attrs.each do |attribute|
value = item.send(attribute)
value = item.public_send(attribute)
h[attribute] = value if value
end

Expand Down
20 changes: 13 additions & 7 deletions lib/roadworker/route53-ext.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'aws-sdk-v1'
require 'aws-sdk'

module AWS
class Route53
module Aws
module Route53

# http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
S3_WEBSITE_ENDPOINTS = {
Expand Down Expand Up @@ -59,10 +59,16 @@ def dns_name_to_alias_target(name, options, hosted_zone_id, hosted_zone_name)
private

def elb_dns_name_to_alias_target(name, region)
elb = AWS::ELB.new(:region => region)

load_balancer = elb.load_balancers.find do |lb|
lb.dns_name == name
elb = Aws::ElasticLoadBalancing::Client.new(:region => region)

load_balancer = nil
elb.describe_load_balancers.each do |page|
page.load_balancer_descriptions.each do |lb|
if lb.dns_name == name
load_balancer = lb
end
end
break if load_balancer
end

unless load_balancer
Expand Down
36 changes: 17 additions & 19 deletions lib/roadworker/route53-health-check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def parse_url(url)
path = nil
end

config = {}
config = Aws::Route53::Types::HealthCheckConfig.new

{
:port => url.port,
Expand All @@ -60,9 +60,9 @@ def parse_url(url)
}

if url.host =~ /\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\Z/
config[:ip_address] = url.host
config.ip_address = url.host
else
config[:fully_qualified_domain_name] = url.host
config.fully_qualified_domain_name = url.host
end

return config
Expand All @@ -81,7 +81,7 @@ def health_checks(options = {})

while is_truncated
opts = next_marker ? {:marker => next_marker} : {}
response = @route53.client.list_health_checks(opts)
response = @route53.list_health_checks(opts)

response[:health_checks].each do |check|
check_list[check[:id]] = check[:health_check_config]
Expand All @@ -98,7 +98,7 @@ def check_list.find_or_create(attrs)
health_check_id, config = self.find {|hcid, elems| elems == attrs }

unless health_check_id
response = @route53.client.create_health_check({
response = @route53.create_health_check({
:caller_reference => UUID.new.generate,
:health_check_config => attrs,
})
Expand All @@ -116,24 +116,22 @@ def check_list.find_or_create(attrs)
end

def gc(options = {})
AWS.memoize {
check_list = health_checks
return if check_list.empty?
check_list = health_checks
return if check_list.empty?

if (logger = options[:logger])
logger.info('Clean HealthChecks (pass `--no-health-check-gc` if you do not want to clean)')
end
if (logger = options[:logger])
logger.info('Clean HealthChecks (pass `--no-health-check-gc` if you do not want to clean)')
end

@route53.hosted_zones.each do |zone|
zone.rrsets.each do |record|
check_list.delete(record.health_check_id)
end
Collection.batch(@route53.list_hosted_zones, :hosted_zones) do |zone|
Collection.batch(@route53.list_resource_record_sets(hosted_zone_id: zone.id), :resource_record_sets) do |record|
check_list.delete(record.health_check_id)
end
end

check_list.each do |health_check_id, config|
@route53.client.delete_health_check(:health_check_id => health_check_id)
end
}
check_list.each do |health_check_id, config|
@route53.delete_health_check(:health_check_id => health_check_id)
end
end

end # HealthCheck
Expand Down
Loading