Class: RackspaceCloud::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/rackspace_cloud/server.rb

Constant Summary collapse

STATUS_VALUES =
%w{ACTIVE BUILD REBUILD SUSPENDED QUEUE_RESIZE PREP_RESIZE VERIFY_RESIZE PASSWORD RESCUE REBOOT HARD_REBOOT SHARE_IP SHARE_IP_NO_CONFIG DELETE_IP UNKNOWN}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, server_json) ⇒ Server

Returns a new instance of Server.



9
10
11
12
# File 'lib/rackspace_cloud/server.rb', line 9

def initialize(base, server_json)
  @base = base
  populate(server_json)
end

Instance Attribute Details

#adminPassObject (readonly)

Returns the value of attribute adminPass.



5
6
7
# File 'lib/rackspace_cloud/server.rb', line 5

def adminPass
  @adminPass
end

#baseObject (readonly)

Returns the value of attribute base.



3
4
5
# File 'lib/rackspace_cloud/server.rb', line 3

def base
  @base
end

#flavorObject (readonly)

Returns the value of attribute flavor.



3
4
5
# File 'lib/rackspace_cloud/server.rb', line 3

def flavor
  @flavor
end

#host_idObject (readonly)

Returns the value of attribute host_id.



4
5
6
# File 'lib/rackspace_cloud/server.rb', line 4

def host_id
  @host_id
end

#imageObject (readonly)

Returns the value of attribute image.



3
4
5
# File 'lib/rackspace_cloud/server.rb', line 3

def image
  @image
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rackspace_cloud/server.rb', line 3

def name
  @name
end

#private_ipsObject (readonly)

Returns the value of attribute private_ips.



5
6
7
# File 'lib/rackspace_cloud/server.rb', line 5

def private_ips
  @private_ips
end

#progressObject (readonly)

Returns the value of attribute progress.



4
5
6
# File 'lib/rackspace_cloud/server.rb', line 4

def progress
  @progress
end

#public_ipsObject (readonly)

Returns the value of attribute public_ips.



5
6
7
# File 'lib/rackspace_cloud/server.rb', line 5

def public_ips
  @public_ips
end

#rackspace_idObject (readonly)

Returns the value of attribute rackspace_id.



4
5
6
# File 'lib/rackspace_cloud/server.rb', line 4

def rackspace_id
  @rackspace_id
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/rackspace_cloud/server.rb', line 3

def status
  @status
end

Instance Method Details

#confirm_resizeObject



34
35
36
# File 'lib/rackspace_cloud/server.rb', line 34

def confirm_resize
  action_request('confirmResize' => nil)
end

#deleteObject



51
52
53
# File 'lib/rackspace_cloud/server.rb', line 51

def delete
  @base.request("/servers/#{@rackspace_id}", :method => :delete)
end

#hard_rebootObject



22
23
24
# File 'lib/rackspace_cloud/server.rb', line 22

def hard_reboot
  action_request('reboot' => {'type' => 'HARD'})      
end

#ready?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rackspace_cloud/server.rb', line 14

def ready?
  self.refresh.status == 'ACTIVE'
end

#rebootObject



18
19
20
# File 'lib/rackspace_cloud/server.rb', line 18

def reboot
  action_request('reboot' => {'type' => 'SOFT'})
end

#rebuild(new_image = nil) ⇒ Object



26
27
28
# File 'lib/rackspace_cloud/server.rb', line 26

def rebuild(new_image=nil)
  action_request('rebuild' => {'imageId' => new_image ? new_image.to_i : image.to_i})      
end

#refreshObject

update this server’s status and progress by calling /servers/<id>



64
65
66
67
# File 'lib/rackspace_cloud/server.rb', line 64

def refresh
  populate(@base.request("/servers/#{@rackspace_id}")['server'])
  self
end

#resize(new_flavor) ⇒ Object



30
31
32
# File 'lib/rackspace_cloud/server.rb', line 30

def resize(new_flavor)
  action_request('resize' => {'flavorId' => new_flavor.to_i})
end

#revert_resizeObject



38
39
40
# File 'lib/rackspace_cloud/server.rb', line 38

def revert_resize
  action_request('revertResize' => nil)
end

#share_ip_address(ip_address, shared_ip_address_group, configure_server = true) ⇒ Object



42
43
44
45
# File 'lib/rackspace_cloud/server.rb', line 42

def share_ip_address(ip_address, shared_ip_address_group, configure_server = true)
  @base.request("/servers/#{@rackspace_id}/ips/public/#{ip_address}", 
  :method => :put, :data => {'shareIp' => {'sharedIpGroupId' => shared_ip_address_group.to_i, 'configureServer' => configure_server}})
end

#unshare_ip_address(ip_address) ⇒ Object



47
48
49
# File 'lib/rackspace_cloud/server.rb', line 47

def unshare_ip_address(ip_address)
  @base.request("/servers/#{@rackspace_id}/ips/public/#{ip_address}", :method => :delete)
end

#update_admin_password(new_password) ⇒ Object



59
60
61
# File 'lib/rackspace_cloud/server.rb', line 59

def update_admin_password(new_password)
  @base.request("/servers/#{@rackspace_id}", :method => :put, :data => {"server" => {"adminPass" => new_password}})
end

#update_server_name(new_name) ⇒ Object



55
56
57
# File 'lib/rackspace_cloud/server.rb', line 55

def update_server_name(new_name)
  @base.request("/servers/#{@rackspace_id}", :method => :put, :data => {"server" => {"name" => new_name}})
end