Module: OpenStack

Defined in:
lib/openstack.rb,
lib/openstack/connection.rb,
lib/openstack/compute/image.rb,
lib/openstack/volume/volume.rb,
lib/openstack/compute/flavor.rb,
lib/openstack/compute/server.rb,
lib/openstack/compute/address.rb,
lib/openstack/swift/container.rb,
lib/openstack/volume/snapshot.rb,
lib/openstack/compute/metadata.rb,
lib/openstack/image/connection.rb,
lib/openstack/swift/connection.rb,
lib/openstack/volume/connection.rb,
lib/openstack/compute/connection.rb,
lib/openstack/swift/storage_object.rb,
lib/openstack/compute/personalities.rb

Overview

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

Defined Under Namespace

Modules: Compute, Image, Swift, Volume Classes: AuthV10, AuthV20, Authentication, Connection, Exception

Constant Summary collapse

VERSION =
IO.read(File.dirname(__FILE__) + '/../VERSION')
MAX_PERSONALITY_ITEMS =

Constants that set limits on server creation

5
MAX_PERSONALITY_FILE_SIZE =
10240
MAX_SERVER_PATH_LENGTH =
255

Class Method Summary collapse

Class Method Details

.get_query_params(params, keys, url = "") ⇒ Object

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



101
102
103
104
105
106
107
108
109
110
# 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 = {}) ⇒ Object



91
92
93
94
95
96
# 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) ⇒ Object

Helper method to recursively symbolize hash keys.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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