Method: OpenStack::Compute::Server#populate
- Defined in:
- lib/openstack/compute/server.rb
#populate(data = nil) ⇒ Object Also known as: refresh
Makes the actual API call to get information about the given server object. If you are attempting to track the status or project of a server object (for example, when rebuilding, creating, or resizing a server), you will likely call this method within a loop until the status becomes “ACTIVE” or other conditions are met.
Returns true if the API call succeeds.
>> server.refresh
=> true
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/openstack/compute/server.rb', line 51 def populate(data=nil) path = "/servers/#{URI.encode(@id.to_s)}" if data.nil? then response = @compute.connection.req("GET", path) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) data = JSON.parse(response.body)["server"] end @id = data["id"] || data["uuid"] @name = data["name"] @status = data["status"] @progress = data["progress"] @addresses = get_addresses(data["addresses"]) @metadata = OpenStack::Compute::Metadata.new(@compute, path, data["metadata"]) @hostId = data["hostId"] @image = data["image"] || data["imageId"] @flavor = data["flavor"] || data["flavorId"] @key_name = data["key_name"] # if provider uses the keys API extension for accessing servers @created = data["created"] @security_groups = (data["security_groups"] || []).inject([]){|res, c| res << c["id"] ; res} true end |