Created
August 26, 2017 13:35
-
-
Save seanhandley/6df74162e13b588856e831b27f4e9257 to your computer and use it in GitHub Desktop.
Build a load balancer with Fog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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