diff --git a/lib/fog/compute/requests/hp/confirm_resized_server.rb b/lib/fog/compute/requests/hp/confirm_resized_server.rb new file mode 100644 index 000000000..deac579ae --- /dev/null +++ b/lib/fog/compute/requests/hp/confirm_resized_server.rb @@ -0,0 +1,34 @@ +module Fog + module HP + class Compute + class Real + + # Confirm resizing + # + # ==== Parameters + # * server_id<~Integer> - Id of server to confirm + # + def confirm_resized_server(server_id) + body = { 'confirmResize' => nil } + server_action(server_id, body, 204) + end + + end + + class Mock + + def confirm_resized_server(server_id) + response = Excon::Response.new + response.status = 204 + + self.data[:servers][server_id].delete('old_flavorId') + self.data[:last_modified][:servers][server_id] = Time.now + self.data[:servers][server_id]['status'] = 'ACTIVE' + + response + end + + end + end + end +end diff --git a/lib/fog/compute/requests/hp/reboot_server.rb b/lib/fog/compute/requests/hp/reboot_server.rb new file mode 100644 index 000000000..ffbd17c22 --- /dev/null +++ b/lib/fog/compute/requests/hp/reboot_server.rb @@ -0,0 +1,30 @@ +module Fog + module HP + class Compute + class Real + + # Reboot an existing server + # + # ==== Parameters + # * server_id<~Integer> - Id of server to reboot + # * type<~String> - Type of reboot, must be in ['HARD', 'SOFT'] + # + def reboot_server(server_id, type = 'SOFT') + body = { 'reboot' => { 'type' => type }} + server_action(server_id, body) + end + + end + + class Mock + + def reboot_server(server_id, type = 'SOFT') + response = Excon::Response.new + response.status = 202 + response + end + + end + end + end +end diff --git a/lib/fog/compute/requests/hp/resize_server.rb b/lib/fog/compute/requests/hp/resize_server.rb new file mode 100644 index 000000000..b356f80de --- /dev/null +++ b/lib/fog/compute/requests/hp/resize_server.rb @@ -0,0 +1,39 @@ +module Fog + module HP + class Compute + class Real + + # Reboot an existing server + # + # ==== Parameters + # * server_id<~Integer> - Id of server to resize + # * size<~String> - new size. call list_flavors to get available flavors + # + def resize_server(server_id, flavor_id) + body = { 'resize' => { 'flavorRef' => flavor_id }} + server_action(server_id, body) + end + + end + + class Mock + + # FIXME: should probably transition instead of skipping to VERIFY_RESIZE + def resize_server(server_id, flavor_id) + response = Excon::Response.new + response.status = 202 + + # keep track of this for reverts + self.data[:servers][server_id]['old_flavorId'] = self.data[:servers][server_id]['flavorId'] + + self.data[:servers][server_id]['flavorId'] = flavor_id + self.data[:last_modified][:servers][server_id] = Time.now + self.data[:servers][server_id]['status'] = 'VERIFY_RESIZE' + + response + end + + end + end + end +end diff --git a/lib/fog/compute/requests/hp/revert_resized_server.rb b/lib/fog/compute/requests/hp/revert_resized_server.rb new file mode 100644 index 000000000..2f912fff4 --- /dev/null +++ b/lib/fog/compute/requests/hp/revert_resized_server.rb @@ -0,0 +1,35 @@ +module Fog + module HP + class Compute + class Real + + # Revert resizing + # + # ==== Parameters + # * server_id<~Integer> - Id of server to revert + # + def revert_resized_server(server_id) + body = { 'revertResize' => nil } + server_action(server_id, body) + end + + end + + class Mock + + def revert_resized_server(server_id) + response = Excon::Response.new + response.status = 202 + + self.data[:servers][server_id]['flavorId'] = self.data[:servers][server_id]['old_flavorId'] + self.data[:servers][server_id].delete('old_flavorId') + self.data[:last_modified][:servers][server_id] = Time.now + self.data[:servers][server_id]['status'] = 'ACTIVE' + + response + end + + end + end + end +end diff --git a/lib/fog/compute/requests/hp/server_action.rb b/lib/fog/compute/requests/hp/server_action.rb new file mode 100644 index 000000000..0c297612c --- /dev/null +++ b/lib/fog/compute/requests/hp/server_action.rb @@ -0,0 +1,25 @@ +module Fog + module HP + class Compute + class Real + + # Reboot an existing server + # + # ==== Parameters + # * server_id<~Integer> - Id of server to reboot + # * body<~.to_json object> - Body of the request, describes the action (see reboot_server as an example) + # * expect<~Integer> - expected return, 202 except for confirm resize (204) + # + def server_action(server_id, body, expects=202) + request( + :body => body.to_json, + :expects => expects, + :method => 'POST', + :path => "servers/#{server_id}/action.json" + ) + end + + end + end + end +end