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

https://github.com/angusscown/fog · Ruby · 68 lines · 29 code · 3 blank · 36 comment · 1 complexity · aee418510fdb38d87fb195267f69ea61 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. # @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Rebuild_Server-d1e3538.html
  34. # @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Metadata-d1e2529.html
  35. # @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Personality-d1e2543.html
  36. # @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#diskconfig_attribute
  37. #
  38. # * Status Transition:
  39. # * ACTIVE -> REBUILD -> ACTIVE
  40. # * ACTIVE -> REBUILD -> ERROR (on error)
  41. def rebuild_server(server_id, image_id, options={})
  42. data = {
  43. 'rebuild' => options || {}
  44. }
  45. data['rebuild']['imageRef'] = image_id
  46. request(
  47. :body => Fog::JSON.encode(data),
  48. :expects => [202],
  49. :method => 'POST',
  50. :path => "servers/#{server_id}/action"
  51. )
  52. end
  53. end
  54. class Mock
  55. def rebuild_server(server_id, image_id, options={})
  56. server = self.data[:servers][server_id]
  57. response(
  58. :body => {"server" => server},
  59. :status => 202
  60. )
  61. end
  62. end
  63. end
  64. end
  65. end