Skip to content

Instantly share code, notes, and snippets.

@seanhandley
Created August 26, 2017 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanhandley/6df74162e13b588856e831b27f4e9257 to your computer and use it in GitHub Desktop.
Save seanhandley/6df74162e13b588856e831b27f4e9257 to your computer and use it in GitHub Desktop.
Build a load balancer with Fog
require 'fog/openstack'
conn = {
openstack_auth_url: ENV["OS_AUTH_URL"],
openstack_username: ENV["OS_USERNAME"],
openstack_api_key: ENV["OS_PASSWORD"],
openstack_project_name: ENV["OS_PROJECT_NAME"],
openstack_domain_id: ENV["OS_USER_DOMAIN_NAME"]
}
fog = Fog::Network::OpenStack.new(conn)
subnet = fog.subnets.first
unless subnet
default_cidr = '192.168.0.0/24'
default_dns = ['8.8.8.8', '8.8.4.4']
default_name = 'default'
ext_net = fog.networks.all.find{|n| n.router_external}
network = fog.networks.create name: default_name
subnet = fog.subnets.create name: default_name,
cidr: default_cidr,
network_id: network.id,
ip_version: 4,
dns_nameservers: default_dns,
tenant_id: project_uuid
router = fog.routers.create name: default_name,
external_gateway_info: external_network.id
fog.add_router_interface router.id, subnet.id
end
lb_pool = fog.lb_pools.create subnet_id: subnet.id,
protocol: 'HTTP',
lb_method: 'ROUND_ROBIN'
lb_member = fog.lb_members.create pool_id: lb_pool.id,
address: '1.2.3.4',
protocol_port: 80,
weight: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment