Perform an action on a server on Openstack, by passing an id, and an action, some actions require more data.
E.g. action(id, “reboot”, “hard”)
# File lib/ropenstack/nova.rb, line 64 def action(id, act, *args) data = case act when "reboot" then {'reboot' =>{"type" => args[0]}} when "vnc" then {'os-getVNCConsole' => { "type" => "novnc" }} when "stop" then {'os-stop' => 'null'} when "start" then {'os-start' => 'null'} when "pause" then {'pause' => 'null'} when "unpause" then {'unpause' => 'null'} when "suspend" then {'suspend' => 'null'} when "resume" then {'resume' => 'null'} when "create_image" then {'createImage' => {'name' => args[0], 'metadata' => args[1]}} else raise "Invalid Action" end return post_request(address("/servers/" + id + "/action"), data, @token) end
Attach a cinder volume to a server, by passing the server id and the volume id.
# File lib/ropenstack/nova.rb, line 84 def attach_volume(id, volume) data = { 'volumeAttachment' => { 'volumeId' => volume, 'device' => "/dev/vdb" } } return post_request(address("/servers/" + id + "/os-volume_attachments"), data, @token) end
Creates a server on OpenStack.
# File lib/ropenstack/nova.rb, line 37 def create_server(name, image, flavor, network = nil, metadata = nil) data = { "server" => { "name" => name, "imageRef" => image, "flavorRef" => flavor, } } unless network.nil? data["server"]["networks"] = [{"uuid" => network}] end return post_request(address("/servers"), data, @token) end
Delete an image stored on Openstack through the nova endpoint
# File lib/ropenstack/nova.rb, line 108 def delete_image(id) uri = URI.parse("http://" + @location.host + ":" + @location.port.to_s + "/v2/images/" + id) return delete_request(uri, @token) end
Deletes a server from Openstack based on an id
# File lib/ropenstack/nova.rb, line 54 def delete_server(id) return delete_request(address("/servers/" + id), @token) end
Remove a cinder volume from a server, by passing the server id and the attachment id.
# File lib/ropenstack/nova.rb, line 93 def detach_volume(id, attachment) return delete_request(address("/servers/"+id+"/os-volume_attachments/"+volume), @token) end
Get a list of flavors that Servers can be
# File lib/ropenstack/nova.rb, line 116 def flavors() return get_request(address("/flavors/detail"), @token) end
Retrieve a list of images from Openstack through the nova endpoint
# File lib/ropenstack/nova.rb, line 100 def images() uri = URI.parse("http://" + @location.host + ":9292/v2/images") return get_request(uri, @token) end
Get a tenants compute quotas
# File lib/ropenstack/nova.rb, line 123 def quotas() return get_request(address("/limits"), @token) end
Gets a list of servers from OpenStack
# File lib/ropenstack/nova.rb, line 19 def servers(id) endpoint = "/servers" unless id.nil? endpoint = endpoint + "/" + id end return get_request(address(endpoint), @token) end
Gets a more detailed list of servers from openstack.
# File lib/ropenstack/nova.rb, line 30 def servers_detailed() return get_request(address("/servers/detail"), @token) end