Skip to content

Instantly share code, notes, and snippets.

@krames
Created June 18, 2013 21:14
Show Gist options
  • Select an option

  • Save krames/5809428 to your computer and use it in GitHub Desktop.

Select an option

Save krames/5809428 to your computer and use it in GitHub Desktop.
This gist explains how to use access rules with Cloud Load Balancers

#Cloud Load Balancers Access Rules

This document describes the access rules for cloud load balancers.

Create Service

Using a US-based account:

service = Fog::Rackspace::LoadBalancers.new({ :rackspace_username => RACKSPACE_USER_NAME, # Your Rackspace Username :rackspace_api_key => RACKSPACE_API, # Your Rackspace API key :rackspace_region => :ord, # Defaults to :dfw :connection_options => {} # Optional })

Using a UK-based account:

service = Fog::Rackspace::LoadBalancers.new({
	:rackspace_username  => RACKSPACE_USER_NAME,        # Your Rackspace Username
	:rackspace_api_key   => RACKSPACE_API,              # Your Rackspace API key
	:rackspace_auth_url  => Fog::Rackspace::UK_AUTH_ENDPOINT,
	:rackspace_region    => :lon,
	:connection_options  => {}                          # Optional
})

To learn more about obtaining cloud credentials refer to the Getting Started with Fog and the Rackspace Open Cloud document.

List Access Rules

To list access rules for a load balancer lb execute the following:

lb.access_rules

This returns a collection of Fog::Rackspace::LoadBalancers::AccessRule models:

 <Fog::Rackspace::LoadBalancers::AccessRules
[
  <Fog::Rackspace::LoadBalancers::AccessRule
    id=39011,
    address="10.10.0.15",
    type="ALLOW"
  >,
  <Fog::Rackspace::LoadBalancers::AccessRule
    id=39013,
    address="10.10.1.0/24",
    type="ALLOW"
  >
]>

Creating Access Rule

Cloud Load balancers will allow to you to create ALLOW or DENY rules by IP Address or by CIDR.

To allow 10.10.1.1 you would execute the following:

lb.access_rules.create :address => 10.10.1.1, :type => "ALLOW"

To deny IP range 172.156.1.0 - 172.156.1.255 you would execute the following:

lb.access_rules.create :address => '172.156.1.0/24', :type => "DENY"

Note: ALLOW and DENY must be in all capitals or the service will raise a Fog::Rackspace::LoadBalancers::BadRequest exception.

Deleting Rules

To delete a specific role you can execute the following:

rule.destroy

To remove all rules from the load balancer execute the following:

service.delete_all_access_rules(lb.id)
@PaulReiber
Copy link
Copy Markdown

Markdown confuses me.

Why, for example, isn't the example for the U.S. wrapped in a nice grey border?
Under "Using a US-based account:" you have a regular old paragraph.
Under "Using a UK-based account:" you have a nice "code block".

I took a stare at the markdown, and it looks the SAME. Arrgh!

EDIT: there IS a difference - the first para isn't indented a full tabstop. Hope this helps!
-pbr.

@krames
Copy link
Copy Markdown
Author

krames commented Jun 23, 2013

Sounds like you figured it out, the Gray code block shows up when the line is indented.

You should checkout http://mouapp.com/. I use it to create my markdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment