Class: AtlanticNet
- Inherits:
-
Object
- Object
- AtlanticNet
- Defined in:
- lib/atlantic_net.rb
Defined Under Namespace
Classes: HttpTransport
Constant Summary collapse
- VERSION =
"2010-12-30"- FORMAT =
"json"
Instance Method Summary collapse
-
#describe_images(options = {}) ⇒ Array<Hash>
Retrieve the description of all available cloud images or the description of a specific cloud image by providing the image id.
-
#describe_instance(instance_id) ⇒ Hash
Describe a specific cloud server.
-
#describe_plans(options = {}) ⇒ Array<Hash>
Retrieve a list of available cloud server plans, narrow the listing down optionally by server platform, or get information about just one specific plan.
-
#initialize(access_key, private_key, options = {}) ⇒ AtlanticNet
constructor
A new instance of AtlanticNet.
-
#list_instances ⇒ Array<Hash>
Retrieve the list of currently active cloud servers.
-
#list_ssh_keys ⇒ Array<Hash>
Retrieve the details of all SSH Keys associated with the account.
-
#reboot_instance(instance_id, options = {}) ⇒ Hash
Restart a specific cloud server.
-
#run_instance(server_name, plan_name, vm_location, options = {}) ⇒ Hash
Run a cloud server with the provided configuration options.
-
#signature(timestamp, request_id) ⇒ String
Generates a Base64 encoded Sha256 HMAC given a timestamp and a request_id.
-
#terminate_instance(instance_id) ⇒ Hash
Terminate a specific cloud server.
Constructor Details
#initialize(access_key, private_key, options = {}) ⇒ AtlanticNet
Returns a new instance of AtlanticNet.
53 54 55 56 57 |
# File 'lib/atlantic_net.rb', line 53 def initialize(access_key, private_key, = {}) @access_key = access_key @private_key = private_key @transport = () end |
Instance Method Details
#describe_images(options = {}) ⇒ Array<Hash>
Retrieve the description of all available cloud images or the description of a specific cloud image by providing the image id
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/atlantic_net.rb', line 173 def describe_images(={}) args = {} if .has_key? :image_id response = api_call('describe-image', {imageid: [:image_id]}) else response = api_call('describe-image') end response["describe-imageresponse"]["imagesset"].values end |
#describe_instance(instance_id) ⇒ Hash
Describe a specific cloud server.
108 109 110 111 |
# File 'lib/atlantic_net.rb', line 108 def describe_instance(instance_id) response = api_call('describe-instance', {instanceid: instance_id}) response["describe-instanceresponse"]["instanceSet"]["item"] end |
#describe_plans(options = {}) ⇒ Array<Hash>
Retrieve a list of available cloud server plans, narrow the listing down optionally by server platform, or get information about just one specific plan
194 195 196 197 198 199 200 201 202 |
# File 'lib/atlantic_net.rb', line 194 def describe_plans(={}) if .empty? response = api_call('describe-plan') else response = api_call('describe-plan',) end response["describe-planresponse"]["plans"].values end |
#list_instances ⇒ Array<Hash>
Retrieve the list of currently active cloud servers.
80 81 82 83 |
# File 'lib/atlantic_net.rb', line 80 def list_instances response = api_call('list-instances') response['list-instancesresponse']['instancesSet'].values end |
#list_ssh_keys ⇒ Array<Hash>
Retrieve the details of all SSH Keys associated with the account
208 209 210 211 |
# File 'lib/atlantic_net.rb', line 208 def list_ssh_keys response = api_call('list-sshkeys') response["list-sshkeysresponse"]["KeysSet"].values end |
#reboot_instance(instance_id, options = {}) ⇒ Hash
Restart a specific cloud server.
96 97 98 99 100 |
# File 'lib/atlantic_net.rb', line 96 def reboot_instance(instance_id, ={}) reboot_type = [:reboot_type] || "soft" response = api_call('reboot-instance', {instanceid: instance_id, reboottype: reboot_type}) response["reboot-instanceresponse"]["return"] end |
#run_instance(server_name, plan_name, vm_location, options = {}) ⇒ Hash
Run a cloud server with the provided configuration options.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/atlantic_net.rb', line 141 def run_instance(server_name, plan_name, vm_location, ={}) option_mapping = { image_id: :imageid, clone_image: :cloneimage, enable_backup: :enablebackup, server_quantity: :serverqty, key_id: :key_id } = {servername: server_name, planname: plan_name, vm_location: vm_location} unless .has_key? :image_id or .has_key? :clone_image fail ArgumentError.new("Missing argument: image_id or clone_image are required") end option_mapping.each do | key, value | if .has_key? key [value] = [key] end end response = api_call('run-instance', ) response["run-instanceresponse"]["instancesSet"]["item"] end |
#signature(timestamp, request_id) ⇒ String
Generates a Base64 encoded Sha256 HMAC given a timestamp and a request_id
69 70 71 72 73 74 |
# File 'lib/atlantic_net.rb', line 69 def signature(, request_id) string_to_sign = "#{timestamp}#{request_id}" digest = OpenSSL::Digest.new('sha256') Base64.encode64(OpenSSL::HMAC.digest(digest, @private_key, string_to_sign)).strip() end |
#terminate_instance(instance_id) ⇒ Hash
Terminate a specific cloud server.
119 120 121 122 |
# File 'lib/atlantic_net.rb', line 119 def terminate_instance(instance_id) response = api_call('terminate-instance', {instanceid: instance_id}) response["terminate-instanceresponse"]["instancesSet"]["item"] end |