Class: Rackspace::Scaling::ServerOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/rackspace-scaling/server_operation.rb

Instance Method Summary collapse

Constructor Details

#initialize(auth, region = 'DFW') ⇒ ServerOperation

Returns a new instance of ServerOperation.



4
5
6
7
8
9
# File 'lib/rackspace-scaling/server_operation.rb', line 4

def initialize(auth, region = 'DFW')
  @auth = auth
  @server_endpoint = @auth.endpoints['cloudServersOpenStack']['endpoints'][region]['publicURL']+"/servers"
  @flavor_endpoint = @auth.endpoints['cloudServersOpenStack']['endpoints'][region]['publicURL']+"/flavors"
  @image_endpoint = @auth.endpoints['cloudServersOpenStack']['endpoints'][region]['publicURL']+"/images"
end

Instance Method Details

#create(options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rackspace-scaling/server_operation.rb', line 36

def create(options = {})
  create_options = {
    :server => {
      'name' => options[:name],
      'imageRef' => options[:image_id],
      'flavorRef' => options[:flavor_id] 
    }
  }
  resp = Typhoeus::Request.post(@server_endpoint, :headers => { 'X-Auth-Token' => @auth.token, 'Accept' => 'application/json', 'Content-Type' => 'application/json'}, :body => create_options.to_json)
  parsed_response = JSON.parse(resp.body)['server']
end

#destroy(guid) ⇒ Object



48
49
50
51
52
# File 'lib/rackspace-scaling/server_operation.rb', line 48

def destroy(guid)
  server_url = "#{@server_endpoint}/#{guid}"
  resp = Typhoeus::Request.delete(server_url, :headers => { 'X-Auth-Token' => @auth.token, 'Accept' => 'application/json'})
  return resp.success?
end

#list_flavorsObject



23
24
25
26
27
28
# File 'lib/rackspace-scaling/server_operation.rb', line 23

def list_flavors
  @flavor_list ||= begin
    resp = Typhoeus::Request.get(@flavor_endpoint, :headers => { 'X-Auth-Token' => @auth.token, 'Accept' => 'application/json'})
    parsed_response = JSON.parse(resp.body)['flavors']
  end
end

#list_images(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rackspace-scaling/server_operation.rb', line 11

def list_images(options = {})
  url = "#{@image_endpoint}"
  if(options[:detail])
    url = "#{url}/detail"
  end
  
  @image_list ||= begin
    resp = Typhoeus::Request.get(url, :headers => { 'X-Auth-Token' => @auth.token, 'Accept' => 'application/json'})
    parsed_response = JSON.parse(resp.body)['images']
  end
end

#list_servers(options = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rackspace-scaling/server_operation.rb', line 54

def list_servers(options = {})
  url = "#{@server_endpoint}"
  
  if(options[:detail])
    url += '/detail'
  end
  
  @server_list ||= begin
    resp = Typhoeus::Request.get(url, :headers => { 'X-Auth-Token' => @auth.token, 'Accept' => 'application/json'})
    parsed_response = JSON.parse(resp.body)['servers']
  end
end

#status(server_id) ⇒ Object



30
31
32
33
34
# File 'lib/rackspace-scaling/server_operation.rb', line 30

def status(server_id)
  url = "#{@server_endpoint}/#{server_id}"
  resp = Typhoeus::Request.get(url, :headers => { 'X-Auth-Token' => @auth.token, 'Accept' => 'application/json'})
  JSON.parse(resp.body)['server']
end