Class: Fog::Compute::Rackspace::Server

Inherits:
Server
  • Object
show all
Defined in:
lib/fog/rackspace/models/compute/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Server

Returns a new instance of Server.



21
22
23
24
25
# File 'lib/fog/rackspace/models/compute/server.rb', line 21

def initialize(attributes={})
  self.flavor_id  ||= 1  # 256 server
  self.image_id   ||= 49 # Ubuntu 10.04 LTS 64bit
  super
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



19
20
21
# File 'lib/fog/rackspace/models/compute/server.rb', line 19

def password
  @password
end

Instance Method Details

#destroyObject



27
28
29
30
31
# File 'lib/fog/rackspace/models/compute/server.rb', line 27

def destroy
  requires :id
  service.delete_server(id)
  true
end

#flavorObject



33
34
35
36
# File 'lib/fog/rackspace/models/compute/server.rb', line 33

def flavor
  requires :flavor_id
  service.flavors.get(flavor_id)
end

#imageObject



38
39
40
41
# File 'lib/fog/rackspace/models/compute/server.rb', line 38

def image
  requires :image_id
  service.images.get(image_id)
end

#imagesObject



43
44
45
46
# File 'lib/fog/rackspace/models/compute/server.rb', line 43

def images
  requires :id
  service.images(:server => self)
end

#private_ip_addressObject



48
49
50
# File 'lib/fog/rackspace/models/compute/server.rb', line 48

def private_ip_address
  addresses['private'].first
end

#public_ip_addressObject



52
53
54
# File 'lib/fog/rackspace/models/compute/server.rb', line 52

def public_ip_address
  addresses['public'].first
end

#ready?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/fog/rackspace/models/compute/server.rb', line 56

def ready?
  self.state == 'ACTIVE'
end

#reboot(type = 'SOFT') ⇒ Object



60
61
62
63
64
# File 'lib/fog/rackspace/models/compute/server.rb', line 60

def reboot(type = 'SOFT')
  requires :id
  service.reboot_server(id, type)
  true
end

#save(options = {}) ⇒ Object

Raises:

  • (Fog::Errors::Error)


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/fog/rackspace/models/compute/server.rb', line 66

def save(options = {})
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  requires :flavor_id, :image_id
  options = {
    'metadata'    => ,
    'name'        => name,
    'personality' => personality
  }
  options = options.reject {|key, value| value.nil?}
  data = service.create_server(flavor_id, image_id, options)
  merge_attributes(data.body['server'])
  true
end

#setup(credentials = {}) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fog/rackspace/models/compute/server.rb', line 80

def setup(credentials = {})
  requires :ssh_ip_address, :identity, :public_key, :username
  Fog::SSH.new(ssh_ip_address, username, credentials).run([
    %{mkdir .ssh},
    %{echo "#{public_key}" >> ~/.ssh/authorized_keys},
    %{passwd -l #{username}},
    %{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
    %{echo "#{Fog::JSON.encode()}" >> ~/metadata.json}
  ])
rescue Errno::ECONNREFUSED
  sleep(1)
  retry
end