Class: Oceanarium::Droplet
- Inherits:
-
Object
- Object
- Oceanarium::Droplet
- Defined in:
- lib/oceanarium/resources/droplet.rb
Instance Attribute Summary collapse
-
#backups_active ⇒ Object
Returns the value of attribute backups_active.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#image_id ⇒ Object
Returns the value of attribute image_id.
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
-
#locked ⇒ Object
Returns the value of attribute locked.
-
#name ⇒ Object
Returns the value of attribute name.
-
#region_id ⇒ Object
Returns the value of attribute region_id.
-
#size_id ⇒ Object
Returns the value of attribute size_id.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
- .action(id, action) ⇒ Object
-
.all ⇒ Object
Core API.
- .create(name, size_id, image_id, region_id, ssh_key_ids = nil) ⇒ Object
- .destroy(id) ⇒ Object
- .find(id) ⇒ Object
- .rebuild(id, image_id) ⇒ Object
- .rename(id, name) ⇒ Object
- .resize(id, size_id) ⇒ Object
- .restore(id, image_id) ⇒ Object
- .snapshot(id, name) ⇒ Object
Instance Method Summary collapse
- #destroy ⇒ Object
- #disable_backups ⇒ Object
- #enable_backups ⇒ Object
-
#initialize(option, api_key, config_id) ⇒ Droplet
constructor
A new instance of Droplet.
-
#new(name, size_id, image_id, region_id, ssh_key_ids = nil) ⇒ Object
User API.
- #password_reset ⇒ Object
- #power_cycle ⇒ Object
- #power_off ⇒ Object
- #power_on ⇒ Object
- #reboot ⇒ Object
- #rebuild(image_id) ⇒ Object
- #rename(new_name) ⇒ Object
- #resize(size_id) ⇒ Object
- #restore(image_id) ⇒ Object
- #shutdown ⇒ Object
- #snapshot(name) ⇒ Object
Constructor Details
#initialize(option, api_key, config_id) ⇒ Droplet
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/oceanarium/resources/droplet.rb', line 7 def initialize(option, api_key, config_id) if api_key.nil? || config_id.nil? raise 'No API key/client ID!' else if option.is_a?(Hash) @object = option else @object = Oceanarium::Droplet.find(option) end if @object.nil? self.id = nil else self.id = @object['id'] self.name = @object['name'] self.image_id = @object['image_id'] self.size_id = @object['size_id'] self.region_id = @object['region_id'] self.backups_active = @object['backups_active'] self.ip_address = @object['ip_address'] self.locked = @object['locked'] self.status = @object['status'] self.created_at = @object['created_at'] end end end |
Instance Attribute Details
#backups_active ⇒ Object
Returns the value of attribute backups_active.
5 6 7 |
# File 'lib/oceanarium/resources/droplet.rb', line 5 def backups_active @backups_active end |
#created_at ⇒ Object
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/oceanarium/resources/droplet.rb', line 5 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/oceanarium/resources/droplet.rb', line 5 def id @id end |
#image_id ⇒ Object
Returns the value of attribute image_id.
5 6 7 |
# File 'lib/oceanarium/resources/droplet.rb', line 5 def image_id @image_id end |
#ip_address ⇒ Object
Returns the value of attribute ip_address.
5 6 7 |
# File 'lib/oceanarium/resources/droplet.rb', line 5 def ip_address @ip_address end |
#locked ⇒ Object
Returns the value of attribute locked.
5 6 7 |
# File 'lib/oceanarium/resources/droplet.rb', line 5 def locked @locked end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/oceanarium/resources/droplet.rb', line 5 def name @name end |
#region_id ⇒ Object
Returns the value of attribute region_id.
5 6 7 |
# File 'lib/oceanarium/resources/droplet.rb', line 5 def region_id @region_id end |
#size_id ⇒ Object
Returns the value of attribute size_id.
5 6 7 |
# File 'lib/oceanarium/resources/droplet.rb', line 5 def size_id @size_id end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/oceanarium/resources/droplet.rb', line 5 def status @status end |
Class Method Details
.action(id, action) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/oceanarium/resources/droplet.rb', line 132 def self.action(id, action) # Performs single action to a Droplet. Returns status OK or Error @approved_actions = ['reboot', 'power_cycle', 'shutdown', 'power_off', 'power_on', 'password_reset', 'enable_backups', 'disable_backups', 'destroy'] if @approved_actions.include? action @request = Oceanarium::Request.new @get = @request.get("/droplets/#{id}/#{action}") return [@get.parsed_response['status'], @get.parsed_response['event_id']] else 'ERROR' end end |
.all ⇒ Object
Core API
100 101 102 103 104 105 106 107 |
# File 'lib/oceanarium/resources/droplet.rb', line 100 def self.all # Returns all Droplets in Array. Each Droplet is a Hash @request = Oceanarium::Request.new @get = @request.get('/droplets/') if @get.parsed_response['status'] == 'OK' @get.parsed_response['droplets'] end end |
.create(name, size_id, image_id, region_id, ssh_key_ids = nil) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/oceanarium/resources/droplet.rb', line 118 def self.create(name, size_id, image_id, region_id, ssh_key_ids=nil) @request = Oceanarium::Request.new if ssh_key_ids.nil? @get = @request.get(URI::encode("/droplets/new?name=#{name}&size_id=#{size_id}&image_id=#{image_id}®ion_id=#{region_id}")) else @get = @request.get(URI::encode("/droplets/new?name=#{name}&size_id=#{size_id}&image_id=#{image_id}®ion_id=#{region_id}&ssh_key_ids=#{ssh_key_ids}")) end if @get.parsed_response['status'] == 'OK' @get.parsed_response else @get.parsed_response end end |
.destroy(id) ⇒ Object
185 186 187 188 189 190 |
# File 'lib/oceanarium/resources/droplet.rb', line 185 def self.destroy(id) # Destroys Droplet @request = Oceanarium::Request.new @get = @request.get("/droplets/#{id}/destroy/") [@get.parsed_response['status'], @get.parsed_response['event_id']] end |
.find(id) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/oceanarium/resources/droplet.rb', line 109 def self.find(id) # Returns single Droplet Hash. Returns nil if error @request = Oceanarium::Request.new @get = @request.get("/droplets/#{id}") if @get.parsed_response['status'] == 'OK' @get.parsed_response['droplet'] end end |
.rebuild(id, image_id) ⇒ Object
178 179 180 181 182 183 |
# File 'lib/oceanarium/resources/droplet.rb', line 178 def self.rebuild(id, image_id) # Rebuild OS image on Droplet. Returns OK or Error @request = Oceanarium::Request.new @get = @request.get("/droplets/#{id}/rebuild/?image_id=#{image_id}") [@get.parsed_response['status'], @get.parsed_response['event_id']] end |
.rename(id, name) ⇒ Object
157 158 159 160 161 162 |
# File 'lib/oceanarium/resources/droplet.rb', line 157 def self.rename(id, name) # Renames Droplet. Name must be FQDN. Returns OK or Error @request = Oceanarium::Request.new @get = @request.get("/droplets/#{id}/rename/?name=#{name}") [@get.parsed_response['status'], @get.parsed_response['event_id']] end |
.resize(id, size_id) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/oceanarium/resources/droplet.rb', line 144 def self.resize(id, size_id) # Resizes Droplet. Returns OK or Error @request = Oceanarium::Request.new @sizes_request_get = @request.get("/sizes/") @sizes = @sizes_request_get.parsed_response['sizes'] if @sizes.select { |s| s['id'] == size_id }.empty? 'Error' else @get = @request.get("/droplets/#{id}/resize?size_id=#{size_id}") [@get.parsed_response['status'], @get.parsed_response['event_id']] end end |
.restore(id, image_id) ⇒ Object
171 172 173 174 175 176 |
# File 'lib/oceanarium/resources/droplet.rb', line 171 def self.restore(id, image_id) # Restores snapshot of Droplet. Returns OK or Error @request = Oceanarium::Request.new @get = @request.get("/droplets/#{id}/restore/?image_id=#{image_id}") [@get.parsed_response['status'], @get.parsed_response['event_id']] end |
.snapshot(id, name) ⇒ Object
164 165 166 167 168 169 |
# File 'lib/oceanarium/resources/droplet.rb', line 164 def self.snapshot(id, name) # Makes snapshot of Droplet. Returns OK or Error @request = Oceanarium::Request.new @get = @request.get("/droplets/#{id}/snapshot?name=#{name}") [@get.parsed_response['status'], @get.parsed_response['event_id']] end |
Instance Method Details
#destroy ⇒ Object
94 95 96 |
# File 'lib/oceanarium/resources/droplet.rb', line 94 def destroy Oceanarium::Droplet::action(self.id, 'destroy') end |
#disable_backups ⇒ Object
86 87 88 |
# File 'lib/oceanarium/resources/droplet.rb', line 86 def disable_backups Oceanarium::Droplet::action(self.id, 'disable_backups') end |
#enable_backups ⇒ Object
82 83 84 |
# File 'lib/oceanarium/resources/droplet.rb', line 82 def enable_backups Oceanarium::Droplet::action(self.id, 'enable_backups') end |
#new(name, size_id, image_id, region_id, ssh_key_ids = nil) ⇒ Object
User API
35 36 37 38 39 40 |
# File 'lib/oceanarium/resources/droplet.rb', line 35 def new(name, size_id, image_id, region_id, ssh_key_ids=nil) @new_id = Oceanarium::Droplet.create(name, size_id, image_id, region_id, ssh_key_ids=nil) unless @new_id['status'] == 'ERROR' [Oceanarium::droplet(@new_id['droplet']['id']), @new_id['droplet']['event_id']] end end |
#password_reset ⇒ Object
62 63 64 |
# File 'lib/oceanarium/resources/droplet.rb', line 62 def password_reset Oceanarium::Droplet::action(self.id, 'password_reset') end |
#power_cycle ⇒ Object
46 47 48 |
# File 'lib/oceanarium/resources/droplet.rb', line 46 def power_cycle Oceanarium::Droplet::action(self.id, 'power_cycle') end |
#power_off ⇒ Object
54 55 56 |
# File 'lib/oceanarium/resources/droplet.rb', line 54 def power_off Oceanarium::Droplet::action(self.id, 'power_off') end |
#power_on ⇒ Object
58 59 60 |
# File 'lib/oceanarium/resources/droplet.rb', line 58 def power_on Oceanarium::Droplet::action(self.id, 'power_on') end |
#reboot ⇒ Object
42 43 44 |
# File 'lib/oceanarium/resources/droplet.rb', line 42 def reboot Oceanarium::Droplet::action(self.id, 'reboot') end |
#rebuild(image_id) ⇒ Object
78 79 80 |
# File 'lib/oceanarium/resources/droplet.rb', line 78 def rebuild(image_id) Oceanarium::Droplet.rebuild(self.id, image_id) end |
#rename(new_name) ⇒ Object
90 91 92 |
# File 'lib/oceanarium/resources/droplet.rb', line 90 def rename(new_name) Oceanarium::Droplet.rename(self.id, new_name) end |
#resize(size_id) ⇒ Object
66 67 68 |
# File 'lib/oceanarium/resources/droplet.rb', line 66 def resize(size_id) Oceanarium::Droplet.resize(self.id, size_id) end |
#restore(image_id) ⇒ Object
74 75 76 |
# File 'lib/oceanarium/resources/droplet.rb', line 74 def restore(image_id) Oceanarium::Droplet.restore(self.id, image_id) end |
#shutdown ⇒ Object
50 51 52 |
# File 'lib/oceanarium/resources/droplet.rb', line 50 def shutdown Oceanarium::Droplet::action(self.id, 'shutdown') end |
#snapshot(name) ⇒ Object
70 71 72 |
# File 'lib/oceanarium/resources/droplet.rb', line 70 def snapshot(name) Oceanarium::Droplet.snapshot(self.id, name) end |