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

- (Server) initialize(attributes = {})

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

- (Object) password (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

- (Object) destroy



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

- (Object) flavor



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

- (Object) image



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

- (Object) images



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

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

- (Object) private_ip_address



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

def private_ip_address
  addresses['private'].first
end

- (Object) public_ip_address



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

def public_ip_address
  addresses['public'].first
end

- (Boolean) ready?

Returns:

  • (Boolean)


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

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

- (Object) reboot(type = 'SOFT')



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

- (Object) save(options = {})

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

- (Object) setup(credentials = {})



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