Sha256: 1d59ca751ec04623dabdd8491b45a7b17754c713abcb25b540b2b578048f2481

Contents?: true

Size: 1.89 KB

Versions: 34

Compression:

Stored size: 1.89 KB

Contents

def test
  # Config
  name = "fog-lb-test-#{Time.now.to_i}"
  zone = 'us-central1-b'
  region = 'us-central1'

  # Setup
  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'
      )
      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
      )
      servers << server
    rescue
      puts "Failed to create instance #{name}-#{i}"
    end
  end

  begin
    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)
    )
    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
    )
    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
    rule.destroy
  rescue
    puts "Failed to clean up forwarding rule."
  end

  begin
    pool.destroy
  rescue
    puts "Failed to clean up target pool."
  end

  begin
    health.destroy
  rescue
    puts "Failed to clean up health check."
  end

  begin
    servers.each &:destroy
  rescue
    puts "Failed to clean up instances."
  end
end

Version data entries

34 entries across 32 versions & 6 rubygems

Version Path
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-google-0.1.0/examples/load-balance.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-google-0.1.0/examples/load-balance.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-google-0.1.0/examples/load-balance.rb
fog-google-0.1.3 examples/load-balance.rb
fog-google-0.1.2 examples/load-balance.rb
fog-google-0.1.1 examples/load-balance.rb
fog-google-0.1.0 examples/load-balance.rb
fog-google-0.0.9 examples/load-balance.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-google-0.0.7/examples/load-balance.rb
fog-google-0.0.7 examples/load-balance.rb
fog-google-0.0.6 examples/load-balance.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/google/examples/load-balance.rb
fog-google-0.0.5 examples/load-balance.rb
fog-google-0.0.4 examples/load-balance.rb
fog-google-0.0.3 examples/load-balance.rb
fog-google-0.0.2 examples/load-balance.rb
fog-1.29.0 lib/fog/google/examples/load-balance.rb
fog-1.28.0 lib/fog/google/examples/load-balance.rb
fog-1.27.0 lib/fog/google/examples/load-balance.rb
fog-1.26.0 lib/fog/google/examples/load-balance.rb