Skip to content

Instantly share code, notes, and snippets.

@seanhandley

seanhandley/lb.rb

Created Aug 26, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.