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.
-
#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
Returns a new instance of 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 |
# 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.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 |
#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
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/oceanarium/resources/droplet.rb', line 131 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}") @get.parsed_response['status'] else 'ERROR' end end |
.all ⇒ Object
Core API
99 100 101 102 103 104 105 106 |
# File 'lib/oceanarium/resources/droplet.rb', line 99 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
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/oceanarium/resources/droplet.rb', line 117 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['droplet']['id'] else @get.parsed_response['status'] end end |
.destroy(id) ⇒ Object
184 185 186 187 188 189 |
# File 'lib/oceanarium/resources/droplet.rb', line 184 def self.destroy(id) # Destroys Droplet @request = Oceanarium::Request.new @get = @request.get("/droplets/#{id}/destroy/") @get.parsed_response['status'] end |
.find(id) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/oceanarium/resources/droplet.rb', line 108 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
177 178 179 180 181 182 |
# File 'lib/oceanarium/resources/droplet.rb', line 177 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'] end |
.rename(id, name) ⇒ Object
156 157 158 159 160 161 |
# File 'lib/oceanarium/resources/droplet.rb', line 156 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'] end |
.resize(id, size_id) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/oceanarium/resources/droplet.rb', line 143 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'] end end |
.restore(id, image_id) ⇒ Object
170 171 172 173 174 175 |
# File 'lib/oceanarium/resources/droplet.rb', line 170 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'] end |
.snapshot(id, name) ⇒ Object
163 164 165 166 167 168 |
# File 'lib/oceanarium/resources/droplet.rb', line 163 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'] end |
Instance Method Details
#destroy ⇒ Object
93 94 95 |
# File 'lib/oceanarium/resources/droplet.rb', line 93 def destroy Oceanarium::Droplet::action(self.id, 'destroy') end |
#disable_backups ⇒ Object
85 86 87 |
# File 'lib/oceanarium/resources/droplet.rb', line 85 def disable_backups Oceanarium::Droplet::action(self.id, 'disable_backups') end |
#enable_backups ⇒ Object
81 82 83 |
# File 'lib/oceanarium/resources/droplet.rb', line 81 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
34 35 36 37 38 39 |
# File 'lib/oceanarium/resources/droplet.rb', line 34 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 == 'ERROR' Oceanarium::droplet(@new_id) end end |
#password_reset ⇒ Object
61 62 63 |
# File 'lib/oceanarium/resources/droplet.rb', line 61 def password_reset Oceanarium::Droplet::action(self.id, 'password_reset') end |
#power_cycle ⇒ Object
45 46 47 |
# File 'lib/oceanarium/resources/droplet.rb', line 45 def power_cycle Oceanarium::Droplet::action(self.id, 'power_cycle') end |
#power_off ⇒ Object
53 54 55 |
# File 'lib/oceanarium/resources/droplet.rb', line 53 def power_off Oceanarium::Droplet::action(self.id, 'power_off') end |
#power_on ⇒ Object
57 58 59 |
# File 'lib/oceanarium/resources/droplet.rb', line 57 def power_on Oceanarium::Droplet::action(self.id, 'power_on') end |
#reboot ⇒ Object
41 42 43 |
# File 'lib/oceanarium/resources/droplet.rb', line 41 def reboot Oceanarium::Droplet::action(self.id, 'reboot') end |
#rebuild(image_id) ⇒ Object
77 78 79 |
# File 'lib/oceanarium/resources/droplet.rb', line 77 def rebuild(image_id) Oceanarium::Droplet.rebuild(self.id, image_id) end |
#rename(new_name) ⇒ Object
89 90 91 |
# File 'lib/oceanarium/resources/droplet.rb', line 89 def rename(new_name) Oceanarium::Droplet.rename(self.id, new_name) end |
#resize(size_id) ⇒ Object
65 66 67 |
# File 'lib/oceanarium/resources/droplet.rb', line 65 def resize(size_id) Oceanarium::Droplet.resize(self.id, size_id) end |
#restore(image_id) ⇒ Object
73 74 75 |
# File 'lib/oceanarium/resources/droplet.rb', line 73 def restore(image_id) Oceanarium::Droplet.restore(self.id, image_id) end |
#shutdown ⇒ Object
49 50 51 |
# File 'lib/oceanarium/resources/droplet.rb', line 49 def shutdown Oceanarium::Droplet::action(self.id, 'shutdown') end |
#snapshot(name) ⇒ Object
69 70 71 |
# File 'lib/oceanarium/resources/droplet.rb', line 69 def snapshot(name) Oceanarium::Droplet.snapshot(self.id, name) end |