class Ropenstack::Nova

Public Instance Methods

action(id, act, *args) click to toggle source

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_volume(id, volume) click to toggle source

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
create_server(name, image, flavor, network = nil, metadata = nil) click to toggle source

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_image(id) click to toggle source

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
delete_server(id) click to toggle source

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
detach_volume(id, attachment) click to toggle source

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
flavors() click to toggle source

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
images() click to toggle source

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
quotas() click to toggle source

Get a tenants compute quotas

# File lib/ropenstack/nova.rb, line 123
def quotas()
  return get_request(address("/limits"), @token)
end
servers(id) → A single server with the id matching the parameter click to toggle source
servers() → All servers visible to the tenant making the request

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
servers_detailed() click to toggle source

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