Module: Fog::Compute::CloudSigma::CommonMockAndReal

Included in:
Mock, Real
Defined in:
lib/fog/cloudsigma/compute.rb

Instance Method Summary collapse

Instance Method Details

#balanceObject



91
92
93
94
95
# File 'lib/fog/cloudsigma/compute.rb', line 91

def balance
  response = get_balance

  Balance.new(response.body)
end

#currencyObject



103
104
105
106
107
# File 'lib/fog/cloudsigma/compute.rb', line 103

def currency
  # Cache since currency does not change
  @currency ||= profile.currency

end

#current_pricingObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/fog/cloudsigma/compute.rb', line 145

def current_pricing
  resp = get_pricing(currency)

  current_levels = resp.body['current']
  current_prices = resp.body['objects']

  current_pricing_pairs = current_levels.map do |resource, level|
    price_for_resource_and_level = current_prices.detect do |price|
      price['level'] == level && price['resource'] == resource
    end
    price_for_resource_and_level ||= {}

    [resource, price_for_resource_and_level]
  end

  Pricing.new(Hash[current_pricing_pairs])
end

#current_pricing_levelsObject



115
116
117
118
119
# File 'lib/fog/cloudsigma/compute.rb', line 115

def current_pricing_levels
  resp = get_pricing(currency)

  resp.body['current']
end

#current_usageObject



97
98
99
100
101
# File 'lib/fog/cloudsigma/compute.rb', line 97

def current_usage
  response = get_current_usage

  CurrentUsage.new(response.body['usage'])
end

#initialize(options = {}) ⇒ Object



80
81
82
83
84
# File 'lib/fog/cloudsigma/compute.rb', line 80

def initialize(options={})
  @init_options = options

  setup_connection(options)
end

#next_pricingObject



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/fog/cloudsigma/compute.rb', line 163

def next_pricing
  resp = get_pricing(currency)

  current_levels = resp.body['next']
  current_prices = resp.body['objects']

  current_pricing_pairs = current_levels.map do |resource, level|
    price_for_resource_and_level = current_prices.detect do |price|
      price['level'] == level && price['resource'] == resource
    end
    price_for_resource_and_level ||= {}

    [resource, price_for_resource_and_level]
  end

  Pricing.new(Hash[current_pricing_pairs])
end

#next_pricing_levelsObject



121
122
123
124
125
# File 'lib/fog/cloudsigma/compute.rb', line 121

def next_pricing_levels
  resp = get_pricing(currency)

  resp.body['next']
end

#pricingObject



109
110
111
112
113
# File 'lib/fog/cloudsigma/compute.rb', line 109

def pricing
  resp = get_princing(currency)

  resp.body['objects']
end

#profileObject



86
87
88
89
# File 'lib/fog/cloudsigma/compute.rb', line 86

def profile
  response = get_profile
  Profile.new(response.body)
end

#subscription_pricingObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/fog/cloudsigma/compute.rb', line 127

def subscription_pricing
  resp = get_pricing(currency, true)

  current_levels = resp.body['current']
  current_prices = resp.body['objects']

  current_pricing_pairs = current_levels.map do |resource, level|
    price_for_resource_and_level = current_prices.detect do |price|
      price['resource'] == resource
    end
    price_for_resource_and_level ||= {}

    [resource, price_for_resource_and_level]
  end

  Pricing.new(Hash[current_pricing_pairs])
end