mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|compute] Fix Requests on Compute
Add list_usages, get_console_output, live_migrate_server, migrate_server
This commit is contained in:
parent
fd939faf6b
commit
3f08cbf399
7 changed files with 49 additions and 42 deletions
|
@ -46,7 +46,6 @@ module Fog
|
|||
request :list_servers
|
||||
request :list_servers_detail
|
||||
|
||||
|
||||
request :server_action
|
||||
request :change_password_server
|
||||
request :reboot_server
|
||||
|
@ -95,6 +94,11 @@ module Fog
|
|||
request :create_volume
|
||||
request :delete_volume
|
||||
|
||||
request :list_usages
|
||||
request :get_console_output
|
||||
request :live_migrate_server
|
||||
request :migrate_server
|
||||
|
||||
class Mock
|
||||
|
||||
def self.data
|
||||
|
@ -182,7 +186,7 @@ module Fog
|
|||
}.merge!(params[:headers] || {}),
|
||||
:host => @host,
|
||||
:path => "#{@path}/#{@tenant_id}/#{params[:path]}",
|
||||
:query => ('ignore_awful_caching' << Time.now.to_i.to_s)
|
||||
:query => params[:query] || ('ignore_awful_caching' << Time.now.to_i.to_s)
|
||||
}))
|
||||
rescue Excon::Errors::Unauthorized => error
|
||||
if error.response.body != 'Bad username or password' # token expiration
|
||||
|
|
|
@ -4,12 +4,12 @@ module Fog
|
|||
class Real
|
||||
|
||||
def get_console_output(server_id, log_length)
|
||||
|
||||
body = { 'os-getConsoleOutput' => {
|
||||
'length' => log_length
|
||||
}}
|
||||
body = {
|
||||
'os-getConsoleOutput' => {
|
||||
'length' => log_length
|
||||
}
|
||||
}
|
||||
server_action(server_id, body)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -18,7 +18,7 @@ module Fog
|
|||
|
||||
def get_console_output(server_id, log_length)
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.status = 200
|
||||
response
|
||||
end
|
||||
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class OpenStack
|
||||
class Real
|
||||
|
||||
def list_usage(date_start, date_end, detailed=false)
|
||||
# TODO: Handle nasty date formats
|
||||
detailed = (detailed ? "1" : "0")
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => "os-simple-tenant-usage?start=#{date_start.iso8601}&end=#{date_end.iso8601}&detailed=#{detailed}"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
# TODO: Mocks to go here
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
29
lib/fog/openstack/requests/compute/list_usages.rb
Normal file
29
lib/fog/openstack/requests/compute/list_usages.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class OpenStack
|
||||
class Real
|
||||
|
||||
def list_usages(date_start = nil, date_end = nil, detailed=false)
|
||||
params = Hash.new
|
||||
params[:start] = date_start.iso8601.gsub(/\+.*/, '') if date_start
|
||||
params[:end] = date_end.iso8601.gsub(/\+.*/, '') if date_end
|
||||
params[:detailed] = (detailed ? '1' : '0') if detailed
|
||||
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => 'os-simple-tenant-usage',
|
||||
:query => params
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
# TODO: Mocks to go here
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,12 +4,13 @@ module Fog
|
|||
class Real
|
||||
|
||||
def live_migrate_server(server_id, host, block_migration, disk_over_commit)
|
||||
|
||||
body = { 'os-migrateLive' => {
|
||||
'host' => host,
|
||||
'block_migration' => block_migration,
|
||||
'disk_over_commit' => disk_over_commit,
|
||||
}}
|
||||
body = {
|
||||
'os-migrateLive' => {
|
||||
'host' => host,
|
||||
'block_migration' => block_migration,
|
||||
'disk_over_commit' => disk_over_commit,
|
||||
}
|
||||
}
|
||||
server_action(server_id, body)
|
||||
|
||||
end
|
||||
|
|
|
@ -4,10 +4,8 @@ module Fog
|
|||
class Real
|
||||
|
||||
def migrate_server(server_id)
|
||||
|
||||
body = { 'migrate' => nil }
|
||||
server_action(server_id, body)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
class OpenStack
|
||||
class Real
|
||||
|
||||
def server_action(server_id, body, expects=202)
|
||||
def server_action(server_id, body, expects=[200,202])
|
||||
request(
|
||||
:body => Fog::JSON.encode(body),
|
||||
:expects => expects,
|
||||
|
|
Loading…
Add table
Reference in a new issue