Class: Profitbricks::Server
Class Method Summary collapse
-
.create(options = {}) ⇒ Server
Creates a Virtual Server within an existing data center.
-
.find(options = {}) ⇒ Object
Finds a virtual server.
Instance Method Summary collapse
-
#delete ⇒ Boolean
Deletes the virtual Server.
-
#reboot ⇒ Boolean
Reboots the virtual Server (POWER CYCLE).
-
#update(options = {}) ⇒ Boolean
Updates parameters of an existing virtual Server device.
Methods inherited from Model
#attributes, belongs_to, get_xml_and_update_attributes, #get_xml_and_update_attributes, has_many, #initialize, #reload
Constructor Details
This class inherits a constructor from Profitbricks::Model
Class Method Details
.create(options = {}) ⇒ Server
Creates a Virtual Server within an existing data center. Parameters can be specified to set up a boot device and connect the server to an existing LAN or the Internet.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/profitbricks/server.rb', line 55 def create( = {}) raise ArgumentError.new("You must provide :cores and :ram") if [:ram].nil? and [:cores].nil? raise ArgumentError.new(":ram has to be at least 256MiB and a multiple of it") if [:ram] < 256 or ([:ram] % 256) > 0 raise ArgumentError.new(":os_type has to be either 'WINDOWS' or 'OTHER'") if [:os_type] and !['WINDOWS', 'OTHER'].include? [:os_type] xml = "<arg0>" xml += get_xml_and_update_attributes , [:cores, :ram, :name, :boot_from_storage_id, :boot_from_image_id, :os_type, :internet_access, :lan_id] xml += "</arg0>" response = Profitbricks.request :create_server, xml self.find(:id => response.to_hash[:create_server_return][:return][:server_id]) end |
.find(options = {}) ⇒ Object
Finds a virtual server
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/profitbricks/server.rb', line 71 def find( = {}) # FIXME #if options[:name] # dc = PB::Server.all().select { |d| d.name == options[:name] }.first # options[:id] = dc.id if dc #end raise "Unable to locate the server named '#{[:name]}'" unless [:id] response = Profitbricks.request :get_server, "<serverId>#{[:id]}</serverId>" PB::Server.new(response.to_hash[:get_server_response][:return]) end |
Instance Method Details
#delete ⇒ Boolean
Deletes the virtual Server.
7 8 9 10 |
# File 'lib/profitbricks/server.rb', line 7 def delete response = Profitbricks.request :delete_server, "<serverId>#{self.id}</serverId>" return true if response.to_hash[:delete_server_response][:return] end |
#reboot ⇒ Boolean
Reboots the virtual Server (POWER CYCLE).
14 15 16 17 |
# File 'lib/profitbricks/server.rb', line 14 def reboot response = Profitbricks.request :reboot_server, "<serverId>#{self.id}</serverId>" return true if response.to_hash[:reboot_server_response][:return] end |
#update(options = {}) ⇒ Boolean
Updates parameters of an existing virtual Server device.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/profitbricks/server.rb', line 28 def update( = {}) return false if .empty? raise ArgumentError.new(":ram and :cores are mandatory options.") unless [:ram] or [:core] raise ArgumentError.new(":ram has to be at least 256MiB and a multiple of it") if [:ram] < 256 or ([:ram] % 256) > 0 raise ArgumentError.new(":os_type has to be either 'WINDOWS' or 'OTHER'") if [:os_type] and !['WINDOWS', 'OTHER'].include? [:os_type] xml = "<arg0><serverId>#{self.id}</serverId>" xml += get_xml_and_update_attributes , [:cores, :ram, :name, :boot_from_storage_id, :boot_from_image_id, :os_type] xml += "</arg0>" response = Profitbricks.request :update_server, xml return true if response.to_hash[:update_server_response][:return] end |