Module: Fog::QingCloud

Extended by:
Provider
Defined in:
lib/fog/qingcloud/core.rb,
lib/fog/qingcloud/model.rb

Defined Under Namespace

Modules: Errors Classes: Mock, Model

Class Method Summary collapse

Class Method Details

.camelcase_string(str) ⇒ Object



34
35
36
# File 'lib/fog/qingcloud/core.rb', line 34

def self.camelcase_string(str)
  str.split('_').map{|x| x.capitalize}.join('')
end

.escape(string) ⇒ Object



71
72
73
74
75
# File 'lib/fog/qingcloud/core.rb', line 71

def self.escape(string)
  string.gsub(/([^a-zA-Z0-9_.\-~]+)/) {
    "%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
  }
end

.indexed_param(key, values) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/qingcloud/core.rb', line 16

def self.indexed_param(key, values)
  params = {}
  unless key.include?('%d')
    key << '.%d'
  end
  [*values].each_with_index do |value, index|
    if value.respond_to?('keys')
      k = format(key, index + 1)
      value.each do | vkey, vvalue |
        params["#{k}.#{vkey}"] = vvalue
      end
    else
      params[format(key, index + 1)] = value
    end
  end
  params
end

.indexed_request_param(name, values) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/fog/qingcloud/core.rb', line 63

def self.indexed_request_param(name, values)
  idx = -1
  Array(values).inject({}) do |params, value|
    params["#{name}.#{idx += 1}"] = value
    params
  end
end

.parse_security_group_options(group_name, options) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/fog/qingcloud/core.rb', line 186

def self.parse_security_group_options(group_name, options)
  options ||= Hash.new
  if group_name.is_a?(Hash)
    options = group_name
  elsif group_name
    if options.key?('GroupName')
      raise Fog::Compute::QingCloud::Error, 'Arguments specified both group_name and GroupName in options'
    end
    options = options.clone
    options['GroupName'] = group_name
  end
  name_specified = options.key?('GroupName') && !options['GroupName'].nil?
  group_id_specified = options.key?('GroupId') && !options['GroupId'].nil?
  unless name_specified || group_id_specified
    raise Fog::Compute::QingCloud::Error, 'Neither GroupName nor GroupId specified'
  end
  if name_specified && group_id_specified
    options.delete('GroupName')
  end
  options
end

.serialize_keys(key, value, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fog/qingcloud/core.rb', line 46

def self.serialize_keys(key, value, options = {})
  case value
  when Hash
    value.each do | k, v |
      options.merge!(serialize_keys("#{key}.#{k}", v))
    end
    return options
  when Array
    value.each_with_index do | it, idx |
      options.merge!(serialize_keys("#{key}.member.#{(idx + 1)}", it))
    end
    return options
  else
    return {key => value}
  end
end

.signed_params(params, options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fog/qingcloud/core.rb', line 78

def self.signed_params(params, options = {})
  params.merge!({
    'access_key_id'    => options[:qingcloud_access_key_id],
    'signature_method'   => options[:signature_method],
    'signature_version'  => options[:signature_version],
    'time_stamp'         => Time.now.utc.strftime("%FT%TZ"),
    'version'           => options[:version],
    'zone'  => options[:zone] || 'pek1'
  }).reject!{|k, v| v.nil?}

  query_string = ''
  for key in params.keys.sort
    query_string << "#{key}=#{escape(params[key].to_s)}&"
  end

  string_to_sign = "GET\n#{options[:path]}\n" << query_string.chop
  signed_string = Base64.encode64(options[:hmac].sign(string_to_sign))
  params['signature'] = signed_string.gsub(/\n/, '')
  params
end

.underscore_string(str) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/fog/qingcloud/core.rb', line 38

def self.underscore_string(str)
  if ('A'..'Z').include? str[0] 
    str.gsub(/([A-Z])/){|c| '_' + c.downcase}.sub(/^_/, '')
  else
    str.gsub(/([A-Z])/){|c| '_' + c.downcase}
  end
end

.wait_timeoutObject



8
9
10
# File 'lib/fog/qingcloud/core.rb', line 8

def self.wait_timeout
  @wait_timeout || Fog.timeout
end

.wait_timeout=(timeout) ⇒ Object



12
13
14
# File 'lib/fog/qingcloud/core.rb', line 12

def self.wait_timeout=(timeout)
  @wait_timeout = timeout
end