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

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

Instance Attribute Summary collapse

Attributes inherited from Server

#private_key, #private_key_path, #public_key, #public_key_path, #username

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Server

#scp, #scp_download, #ssh, #ssh_port, #sshable?

Methods inherited from Model

#inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

#initialize(attributes = {}) ⇒ Server

Returns a new instance of Server.



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

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.



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

def password
  @password
end

Instance Method Details

#destroyObject



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

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

#flavorObject



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

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

#imageObject



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

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

#imagesObject



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

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

#private_ip_addressObject



50
51
52
# File 'lib/fog/rackspace/models/compute/server.rb', line 50

def private_ip_address
  addresses['private'].first
end

#public_ip_addressObject



54
55
56
# File 'lib/fog/rackspace/models/compute/server.rb', line 54

def public_ip_address
  addresses['public'].first
end

#ready?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/fog/rackspace/models/compute/server.rb', line 58

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

#reboot(type = 'SOFT') ⇒ Object



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

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

#saveObject

Raises:



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

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

#setup(credentials = {}) ⇒ Object



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

def setup(credentials = {})
  requires :public_ip_address, :identity, :public_key, :username
  Fog::SSH.new(public_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