examples/load-balance.rb in fog-google-0.1.3 vs examples/load-balance.rb in fog-google-0.2.0
- old
+ new
@@ -1,75 +1,74 @@
def test
# Config
name = "fog-lb-test-#{Time.now.to_i}"
- zone = 'us-central1-b'
- region = 'us-central1'
+ zone = "us-central1-b"
+ region = "us-central1"
# Setup
- gce = Fog::Compute.new provider: 'Google'
+ gce = Fog::Compute.new :provider => "Google"
servers = []
(1..3).each do |i|
begin
disk = gce.disks.create(
- name: "#{name}-#{i}",
- size_gb: 10,
- zone_name: zone,
- source_image: 'debian-7-wheezy-v20131120'
+ :name => "#{name}-#{i}",
+ :size_gb => 10,
+ :zone_name => zone,
+ :source_image => "debian-7-wheezy-v20131120"
)
disk.wait_for { disk.ready? }
rescue
puts "Failed to create disk #{name}-#{i}"
end
begin
server = gce.servers.create(
- name: "#{name}-#{i}",
- disks: [ disk.get_as_boot_disk(true, true) ],
- machine_type: 'f1-micro',
- zone_name: zone
+ :name => "#{name}-#{i}",
+ :disks => [disk.get_as_boot_disk(true, true)],
+ :machine_type => "f1-micro",
+ :zone_name => zone
)
servers << server
rescue
puts "Failed to create instance #{name}-#{i}"
end
end
begin
- health = gce.http_health_checks.new(name: name)
+ health = gce.http_health_checks.new(:name => name)
health.save
rescue
puts "Failed to create health check #{name}"
end
begin
pool = gce.target_pools.new(
- name: name,
- region: region,
- health_checks: health.self_link,
- instances: servers.map(&:self_link)
+ :name => name,
+ :region => region,
+ :health_checks => health.self_link,
+ :instances => servers.map(&:self_link)
)
pool.save
rescue
puts "Failed to create target pool #{name}"
end
begin
rule = gce.forwarding_rules.new(
- name: name,
- region: region,
- port_range: '1-65535',
- ip_protocol: 'TCP',
- target: pool.self_link
+ :name => name,
+ :region => region,
+ :port_range => "1-65535",
+ :ip_protocol => "TCP",
+ :target => pool.self_link
)
rule.save
rescue
puts "Failed to create forwarding rule #{name}"
end
-
# TODO(bensonk): Install apache, create individualized htdocs, and run some
# actual requests through the load balancer.
# Cleanup
begin
@@ -89,10 +88,10 @@
rescue
puts "Failed to clean up health check."
end
begin
- servers.each &:destroy
+ servers.each(&:destroy)
rescue
puts "Failed to clean up instances."
end
end