module OpenStack

Ruby OpenStack API

See COPYING for license information.


Documentation & Examples

To begin reviewing the available methods and examples, view the README.rdoc file

Example: os = OpenStack::Connection.create({:username => “herp@derp.com”, :api_key=>“password”,

:auth_url => "https://region-a.geo-1.identity.cloudsvc.com:35357/v2.0/",
:authtenant=>"herp@derp.com-default-tenant", :service_type=>"object-store")

will return a handle to the object-storage service swift. Alternatively, passing :service_type=>“compute” will return a handle to the compute service nova.

Initial version of this code is based on and refactored from the rackspace/ruby-cloudfiles repo @ github.com/rackspace/ruby-cloudfiles - Copyright © 2011, Rackspace US, Inc.

See COPYING for license information

Initial version of this code is based on and refactored from the rackspace/ruby-cloudfiles repo @ github.com/rackspace/ruby-cloudfiles - Copyright © 2011, Rackspace US, Inc.

See COPYING for license information

Initial version of this code is based on and refactored from the rackspace/ruby-cloudfiles repo @ github.com/rackspace/ruby-cloudfiles - Copyright © 2011, Rackspace US, Inc.

See COPYING for license information

Constants

MAX_PERSONALITY_FILE_SIZE
MAX_PERSONALITY_ITEMS

Constants that set limits on server creation

MAX_SERVER_PATH_LENGTH
VERSION

Public Class Methods

get_query_params(params, keys, url="") click to toggle source

e.g. keys = [:limit, :marker] params = {:limit=>2, :marker=“marios”, :prefix=>“/”} you want url = /container_name?limit=2&marker=marios

# File lib/openstack.rb, line 101
def self.get_query_params(params, keys, url="")
  set_keys = params.inject([]){|res, (k,v)| res << k if keys.include?(k) and not v.nil?; res }
  return url if set_keys.empty?
  url = "#{url}?#{set_keys[0]}=#{params[set_keys[0]]}"
  set_keys.slice!(0)
  set_keys.each do |k|
    url = "#{url}&#{k}=#{params[set_keys[0]]}"
  end
  url
end
paginate(options = {}) click to toggle source
# File lib/openstack.rb, line 91
def self.paginate(options = {})
  path_args = []
  path_args.push(URI.encode("limit=#{options[:limit]}")) if options[:limit]
  path_args.push(URI.encode("offset=#{options[:offset]}")) if options[:offset]
  path_args.join("&")
end
symbolize_keys(obj) click to toggle source

Helper method to recursively symbolize hash keys.

# File lib/openstack.rb, line 57
def self.symbolize_keys(obj)
  case obj
  when Array
    obj.inject([]){|res, val|
      res << case val
      when Hash, Array
        symbolize_keys(val)
      else
        val
      end
      res
    }
  when Hash
    obj.inject({}){|res, (key, val)|
      nkey = case key
      when String
        key.to_sym
      else
        key
      end
      nval = case val
      when Hash, Array
        symbolize_keys(val)
      else
        val
      end
      res[nkey] = nval
      res
    }
  else
    obj
  end
end