mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|compute] Added get_usage function, mocks, tests
This commit is contained in:
parent
a5826b4301
commit
a1ecf11e25
5 changed files with 62 additions and 9 deletions
|
@ -137,6 +137,7 @@ module Fog
|
|||
|
||||
# Usage
|
||||
request :list_usages
|
||||
request :get_usage
|
||||
|
||||
class Mock
|
||||
|
||||
|
|
|
@ -9,10 +9,15 @@ module Fog
|
|||
attribute :description
|
||||
attribute :enabled
|
||||
attribute :name
|
||||
|
||||
|
||||
def to_s
|
||||
self.name
|
||||
end
|
||||
|
||||
def usage(start_date, end_date)
|
||||
requires :id
|
||||
connection.get_usage(self.id, start_date, end_date).body['tenant_usage']
|
||||
end
|
||||
end # class Tenant
|
||||
end # class OpenStack
|
||||
end # module Compute
|
||||
|
|
|
@ -10,6 +10,10 @@ module Fog
|
|||
def all
|
||||
load(connection.list_tenants.body['tenants'])
|
||||
end
|
||||
|
||||
def usages(start_date = nil, end_date = nil, details = false)
|
||||
connection.list_usages(start_date, end_date, details).body['tenant_usages']
|
||||
end
|
||||
end # class Tenants
|
||||
end # class OpenStack
|
||||
end # module Compute
|
||||
|
|
|
@ -4,21 +4,50 @@ module Fog
|
|||
class Real
|
||||
|
||||
def get_usage(tenant_id, date_start, date_end)
|
||||
# TODO: Handle nasty date formats
|
||||
params = Hash.new
|
||||
params[:start] = date_start.iso8601.gsub(/\+.*/, '')
|
||||
params[:end] = date_end.iso8601.gsub(/\+.*/, '')
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => "os-simple-tenant-usage/#{tenant_id}?start=#{date_start.iso8601}&end=#{date_end.iso8601}"
|
||||
:path => "os-simple-tenant-usage/#{tenant_id}",
|
||||
:query => params
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
# TODO: Mocks to go here
|
||||
|
||||
def get_usage(tenant_id, date_start, date_end)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {"tenant_usage"=>
|
||||
{"total_memory_mb_usage" => 0.0,
|
||||
"total_vcpus_usage" => 0.0,
|
||||
"total_hours" => 0.0,
|
||||
"tenant_id" => tenant_id,
|
||||
"stop" => date_start,
|
||||
"start" => date_end,
|
||||
"total_local_gb_usage" => 0.0,
|
||||
"server_usages" =>[{
|
||||
"hours" => 0.0,
|
||||
"uptime" => 69180,
|
||||
"local_gb" => 0,
|
||||
"ended_at" => nil,
|
||||
"name" => "test server",
|
||||
"tenant_id" => tenant_id,
|
||||
"vcpus" => 1,
|
||||
"memory_mb" => 512,
|
||||
"state" => "active",
|
||||
"flavor" => "m1.tiny",
|
||||
"started_at" => "2012-03-05 09:11:44"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,9 +20,23 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock
|
||||
|
||||
# TODO: Mocks to go here
|
||||
|
||||
def list_usages(date_start = nil, date_end = nil, detailed=false)
|
||||
params = Hash.new
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {"tenant_usages"=>[{
|
||||
"total_memory_mb_usage" => 0.00036124444444444445,
|
||||
"total_vcpus_usage" => 7.055555555555556e-07,
|
||||
"start" => "2012-03-06 05:05:56.349001",
|
||||
"tenant_id" => "b97c8abba0c44a0987c63b858a4823e5",
|
||||
"stop" => "2012-03-06 05:05:56.349255",
|
||||
"total_hours" => 7.055555555555556e-07,
|
||||
"total_local_gb_usage" => 0.0
|
||||
}
|
||||
]
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue