PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/fog/rackspace/requests/compute_v2/rebuild_server.rb

https://gitlab.com/debian-ruby/ruby-fog-rackspace
Ruby | 71 lines | 29 code | 2 blank | 40 comment | 1 complexity | b8c07d0e09371fd8643d4e688d13bc63 MD5 | raw file
  1. module Fog
  2. module Compute
  3. class RackspaceV2
  4. class Real
  5. # The rebuild operation removes all data on the server and replaces it with the specified image.
  6. # The serverRef and all IP addresses remain the same. If you specify name, metadata, accessIPv4,
  7. # or accessIPv6 in the rebuild request, new values replace existing values. Otherwise, these values do not change.
  8. # @param [String] server_id id of the server to rebuild
  9. # @param [String] image_id id of image used to rebuild the server
  10. # @param [Hash] options
  11. # @option options [String] accessIPv4 The IP version 4 address.
  12. # @option options [String] accessIPv6 The IP version 6 address.
  13. # @option options [String] adminPass The administrator password.
  14. # @option options [Hash] metadata key value pairs of server metadata
  15. # @option options [String] OS-DCF:diskConfig The disk configuration value. (AUTO or MANUAL)
  16. # @option options [Hash] personality Hash containing data to inject into the file system of the cloud server instance during server creation.
  17. # @return [Excon::Response] response:
  18. # * body [Hash]:
  19. # * server [Hash]:
  20. # * name [String] - name of server
  21. # * imageRef [String] - id of image used to create server
  22. # * flavorRef [String] - id of flavor used to create server
  23. # * OS-DCF:diskConfig [String] - The disk configuration value.
  24. # * name [String] - name of server
  25. # * metadata [Hash] - Metadata key and value pairs.
  26. # * personality [Array]:
  27. # * [Hash]:
  28. # * path - path of the file created
  29. # * contents - Base 64 encoded file contents
  30. # * networks [Array]:
  31. # * [Hash]:
  32. # * uuid [String] - uuid of attached network
  33. # @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404
  34. # @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
  35. # @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
  36. # @raise [Fog::Compute::RackspaceV2::ServiceError]
  37. # @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Rebuild_Server-d1e3538.html
  38. # @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Metadata-d1e2529.html
  39. # @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Personality-d1e2543.html
  40. # @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#diskconfig_attribute
  41. #
  42. # * Status Transition:
  43. # * ACTIVE -> REBUILD -> ACTIVE
  44. # * ACTIVE -> REBUILD -> ERROR (on error)
  45. def rebuild_server(server_id, image_id, options={})
  46. data = {
  47. 'rebuild' => options || {}
  48. }
  49. data['rebuild']['imageRef'] = image_id
  50. request(
  51. :body => Fog::JSON.encode(data),
  52. :expects => [202],
  53. :method => 'POST',
  54. :path => "servers/#{server_id}/action"
  55. )
  56. end
  57. end
  58. class Mock
  59. def rebuild_server(server_id, image_id, options={})
  60. server = self.data[:servers][server_id]
  61. response(
  62. :body => {"server" => server},
  63. :status => 202
  64. )
  65. end
  66. end
  67. end
  68. end
  69. end