Class: Rackspace::ServerApi

Inherits:
Api
  • Object
show all
Defined in:
lib/rackspace/server_api.rb

Instance Attribute Summary collapse

Attributes inherited from Api

#logger

Instance Method Summary collapse

Constructor Details

#initialize(rackspace_credentials) ⇒ ServerApi

Returns a new instance of ServerApi.



5
6
7
8
9
10
11
12
13
# File 'lib/rackspace/server_api.rb', line 5

def initialize(rackspace_credentials)
  super rackspace_credentials
  @api ||= Fog::Compute.new(
    rackspace_credentials.merge(
      version:   :v2,
      provider:  'Rackspace',
    )
  )
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



3
4
5
# File 'lib/rackspace/server_api.rb', line 3

def api
  @api
end

Instance Method Details

#create(params) ⇒ Object



19
20
21
22
# File 'lib/rackspace/server_api.rb', line 19

def create(params)
  servers.create(params)
  wait_for params.fetch(:name)
end

#find_by_name(name) ⇒ Object



15
16
17
# File 'lib/rackspace/server_api.rb', line 15

def find_by_name(name)
  servers.detect {|i| i.name == name && i.state != 'DELETED'}
end

#image_by_name(img_name) ⇒ Object



24
25
26
27
28
# File 'lib/rackspace/server_api.rb', line 24

def image_by_name(img_name)
  img = api.images.detect {|i| i.name == img_name}
  raise "No such server image #{img_name}" if img.nil?
  img
end

#serversObject



30
31
32
# File 'lib/rackspace/server_api.rb', line 30

def servers
  api.servers
end