Class: Fog::Compute::Joyent::Real
- Inherits:
-
Object
- Object
- Fog::Compute::Joyent::Real
- Defined in:
- lib/fog/joyent/compute.rb,
lib/fog/joyent/requests/compute/get_key.rb,
lib/fog/joyent/requests/compute/list_keys.rb,
lib/fog/joyent/requests/compute/create_key.rb,
lib/fog/joyent/requests/compute/delete_key.rb,
lib/fog/joyent/requests/compute/get_dataset.rb,
lib/fog/joyent/requests/compute/get_machine.rb,
lib/fog/joyent/requests/compute/get_package.rb,
lib/fog/joyent/requests/compute/stop_machine.rb,
lib/fog/joyent/requests/compute/list_datasets.rb,
lib/fog/joyent/requests/compute/list_machines.rb,
lib/fog/joyent/requests/compute/list_packages.rb,
lib/fog/joyent/requests/compute/start_machine.rb,
lib/fog/joyent/requests/compute/create_machine.rb,
lib/fog/joyent/requests/compute/delete_machine.rb,
lib/fog/joyent/requests/compute/reboot_machine.rb,
lib/fog/joyent/requests/compute/get_machine_tag.rb,
lib/fog/joyent/requests/compute/add_machine_tags.rb,
lib/fog/joyent/requests/compute/list_machine_tags.rb,
lib/fog/joyent/requests/compute/delete_machine_tag.rb,
lib/fog/joyent/requests/compute/get_machine_metadata.rb,
lib/fog/joyent/requests/compute/get_machine_snapshot.rb,
lib/fog/joyent/requests/compute/list_machine_snapshots.rb,
lib/fog/joyent/requests/compute/create_machine_snapshot.rb,
lib/fog/joyent/requests/compute/delete_all_machine_tags.rb,
lib/fog/joyent/requests/compute/delete_machine_metadata.rb,
lib/fog/joyent/requests/compute/delete_machine_snapshot.rb,
lib/fog/joyent/requests/compute/update_machine_metadata.rb,
lib/fog/joyent/requests/compute/delete_all_machine_metadata.rb,
lib/fog/joyent/requests/compute/start_machine_from_snapshot.rb
Overview
Mock
Instance Method Summary collapse
- #add_machine_tags(machine_id, tags = {}) ⇒ Object
-
#create_key(params = {}) ⇒ Object
Creates a new SSH Key ==== Parameters * name<~String> - Name to assign to this key * key<~String> - OpenSSH formatted public key.
- #create_machine(params = {}) ⇒ Object
- #create_machine_snapshot(machine_id, snapshot_name) ⇒ Object
- #delete_all_machine_metadata(machine_id) ⇒ Object
- #delete_all_machine_tags(machine_id) ⇒ Object
- #delete_key(name) ⇒ Object
- #delete_machine(machine_id) ⇒ Object
- #delete_machine_metadata(machine_id, key) ⇒ Object
- #delete_machine_snapshot(machine_id, snapshot) ⇒ Object
- #delete_machine_tag(machine_id, tagname) ⇒ Object
- #get_dataset ⇒ Object
- #get_key(keyid) ⇒ Object
- #get_machine(uuid) ⇒ Object
- #get_machine_metadata(machine_id, options = {}) ⇒ Object
- #get_machine_snapshot(machine_id, snapshot_name) ⇒ Object
- #get_machine_tag(machine_id, tagname) ⇒ Object
- #get_package(name) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_datasets ⇒ Object
- #list_keys ⇒ Object
- #list_machine_snapshots(machine_id) ⇒ Object
- #list_machine_tags(machine_id) ⇒ Object
- #list_machines(options = {}) ⇒ Object
-
#list_packages ⇒ Object
Lists all the packages available to the authenticated user ==== Returns Exon::Response<Array> * name<~String> The “friendly name for this package * memory<~Number> How much memory will by available (in Mb) * disk<~Number> How much disk space will be available (in Gb) * swap<~Number> How much swap memory will be available (in Mb) * default<~Boolean> Whether this is the default package in this datacenter”.
- #reboot_machine(id) ⇒ Object
- #request(request = {}) ⇒ Object
- #start_machine(id) ⇒ Object
- #start_machine_from_snapshot(machine_id, snapshot_name) ⇒ Object
- #stop_machine(uuid) ⇒ Object
- #update_machine_metadata(machine_id, metadata) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/fog/joyent/compute.rb', line 99 def initialize( = {}) @connection_options = [:connection_options] || {} @persistent = [:persistent] || false @joyent_url = [:joyent_url] || 'https://us-sw-1.api.joyentcloud.com' @joyent_version = [:joyent_version] || '~6.5' @joyent_username = [:joyent_username] unless @joyent_username raise ArgumentError, "options[:joyent_username] required" end if [:joyent_keyname] && [:joyent_keyfile] if File.exists?([:joyent_keyfile]) @joyent_keyname = [:joyent_keyname] @joyent_key = File.read([:joyent_keyfile]) @rsa = OpenSSL::PKey::RSA.new(@joyent_key) @header_method = method(:header_for_signature_auth) else raise ArgumentError, "options[:joyent_keyfile] provided does not exist." end elsif [:joyent_password] @joyent_password = [:joyent_password] @header_method = method(:header_for_basic_auth) else raise ArgumentError, "Must provide either a joyent_password or joyent_keyname and joyent_keyfile pair" end @connection = Fog::Connection.new( @joyent_url, @persistent, @connection_options ) end |
Instance Method Details
#add_machine_tags(machine_id, tags = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/joyent/requests/compute/add_machine_tags.rb', line 7 def (machine_id, ={}) raise ArgumentError, "tags must be a Hash of tags" unless .is_a?(Hash) request( :path => "/my/machines/#{machine_id}/tags", :method => "POST", :body => , :expects => 200 ) end |
#create_key(params = {}) ⇒ Object
Creates a new SSH Key
Parameters
-
name<~String> - Name to assign to this key
-
key<~String> - OpenSSH formatted public key
Returns
-
response<~Excon::Response>:
-
body<~Hash>:
-
‘name’<~String> - Name for this key
-
‘key’<~String> - OpenSSH formatted public key
-
-
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/joyent/requests/compute/create_key.rb', line 41 def create_key(params={}) raise ArgumentError, "error creating key: [name] is required" unless params[:name] raise ArgumentError, "error creating key: [key] is required" unless params[:key] request( :method => "POST", :path => "/my/keys", :body => { "name" => params[:name], "key" => params[:key] }, :expects => 201 ) end |
#create_machine(params = {}) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/joyent/requests/compute/create_machine.rb', line 5 def create_machine(params = {}) request( :method => "POST", :path => "/my/machines", :body => params, :expects => [200, 201, 202] ) end |
#create_machine_snapshot(machine_id, snapshot_name) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/fog/joyent/requests/compute/create_machine_snapshot.rb', line 6 def create_machine_snapshot(machine_id, snapshot_name) request( :method => "POST", :path => "/my/machines/#{machine_id}/snapshots", :body => {"name" => snapshot_name }, :expects => [201] ) end |
#delete_all_machine_metadata(machine_id) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/joyent/requests/compute/delete_all_machine_metadata.rb', line 6 def (machine_id) request( :method => "DELETE", :path => "/my/machines/#{machine_id}/metadata", :expects => 204 ) end |
#delete_all_machine_tags(machine_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/joyent/requests/compute/delete_all_machine_tags.rb', line 5 def (machine_id) request( :path => "/my/machines/#{machine_id}/tags", :method => "DELETE", :expects => 204 ) end |
#delete_key(name) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/fog/joyent/requests/compute/delete_key.rb', line 18 def delete_key(name) request( :method => "DELETE", :path => "/my/keys/#{name}", :expects => 204 ) end |
#delete_machine(machine_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/joyent/requests/compute/delete_machine.rb', line 5 def delete_machine(machine_id) request( :path => "/my/machines/#{machine_id}", :method => "DELETE", :expects => [200, 204] ) end |
#delete_machine_metadata(machine_id, key) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/fog/joyent/requests/compute/delete_machine_metadata.rb', line 8 def (machine_id, key) request( :method => "DELETE", :path => "/my/machines/#{machine_id}/metadata/#{key}", :expects => [200, 204] ) end |
#delete_machine_snapshot(machine_id, snapshot) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/joyent/requests/compute/delete_machine_snapshot.rb', line 6 def delete_machine_snapshot(machine_id, snapshot) request( :method => "DELETE", :path => "/my/machines/#{machine_id}/snapshots/#{snapshot}", :expects => [200, 204] ) end |
#delete_machine_tag(machine_id, tagname) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/joyent/requests/compute/delete_machine_tag.rb', line 5 def delete_machine_tag(machine_id, tagname) request( :path => "/my/machines/#{machine_id}/tags/#{tagname}", :method => "DELETE", :expects => 204 ) end |
#get_dataset ⇒ Object
18 19 20 21 22 23 |
# File 'lib/fog/joyent/requests/compute/get_dataset.rb', line 18 def get_dataset request( :method => "GET", :path => "/my/datasets" ) end |
#get_key(keyid) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/fog/joyent/requests/compute/get_key.rb', line 19 def get_key(keyid) request( :method => "GET", :path => "/my/keys/#{keyid}", :expects => 200 ) end |
#get_machine(uuid) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/fog/joyent/requests/compute/get_machine.rb', line 19 def get_machine(uuid) request( :method => "GET", :path => "/my/machines/#{uuid}", :expects => 200 ) end |
#get_machine_metadata(machine_id, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fog/joyent/requests/compute/get_machine_metadata.rb', line 6 def (machine_id, = {}) query = {} if [:credentials] if [:credentials].is_a?(Boolean) query[:credentials] = [:credentials] else raise ArgumentError, "options[:credentials] must be a Boolean or nil" end end request( :path => "/my/machines/#{machine_id}/metadata", :query => query ) end |
#get_machine_snapshot(machine_id, snapshot_name) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/fog/joyent/requests/compute/get_machine_snapshot.rb', line 5 def get_machine_snapshot(machine_id, snapshot_name) request( :path => "/my/machines/#{machine_id}/snapshots/#{snapshot_name}", :method => "GET" ) end |
#get_machine_tag(machine_id, tagname) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/fog/joyent/requests/compute/get_machine_tag.rb', line 7 def get_machine_tag(machine_id, tagname) request( :path => "/my/machines/#{machine_id}/tags/#{tagname}", :method => "GET", :headers => {"Accept" => "text/plain"}, :expects => 200 ) end |
#get_package(name) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/fog/joyent/requests/compute/get_package.rb', line 21 def get_package(name) name = URI.escape(name) request( :method => "GET", :path => "/my/packages/#{name}", :expects => 200 ) end |
#list_datasets ⇒ Object
15 16 17 18 19 20 |
# File 'lib/fog/joyent/requests/compute/list_datasets.rb', line 15 def list_datasets request( :method => "GET", :path => "/my/datasets" ) end |
#list_keys ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/fog/joyent/requests/compute/list_keys.rb', line 14 def list_keys request( :expects => 200, :method => :'GET', :path => '/my/keys' ) end |
#list_machine_snapshots(machine_id) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/fog/joyent/requests/compute/list_machine_snapshots.rb', line 5 def list_machine_snapshots(machine_id) request( :method => "GET", :path => "/my/machines/#{machine_id}/snapshots" ) end |
#list_machine_tags(machine_id) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/joyent/requests/compute/list_machine_tags.rb', line 6 def (machine_id) request( :path => "/my/machines/#{machine_id}/tags", :method => "GET", :expects => 200 ) end |
#list_machines(options = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/fog/joyent/requests/compute/list_machines.rb', line 15 def list_machines(={}) request( :path => "/my/machines", :method => "GET", :query => ) end |
#list_packages ⇒ Object
Lists all the packages available to the authenticated user
Returns
Exon::Response<Array>
-
name<~String> The “friendly name for this package
-
memory<~Number> How much memory will by available (in Mb)
-
disk<~Number> How much disk space will be available (in Gb)
-
swap<~Number> How much swap memory will be available (in Mb)
-
default<~Boolean> Whether this is the default package in this datacenter“
24 25 26 27 28 29 30 |
# File 'lib/fog/joyent/requests/compute/list_packages.rb', line 24 def list_packages request( :path => "/my/packages", :method => "GET", :expects => 200 ) end |
#reboot_machine(id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/joyent/requests/compute/reboot_machine.rb', line 5 def reboot_machine(id) request( :method => "POST", :query => {"action" => "reboot"}, :path => "/my/machines/#{id}" ) end |
#request(request = {}) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/fog/joyent/compute.rb', line 139 def request(request = {}) request[:headers] = { "X-Api-Version" => @joyent_version, "Content-Type" => "application/json", "Accept" => "application/json" }.merge(request[:headers] || {}).merge(@header_method.call) if request[:body] request[:body] = MultiJson.encode(request[:body]) end response = @connection.request(request) if response.headers["Content-Type"] == "application/json" response.body = json_decode(response.body) end raise_if_error!(request, response) response end |
#start_machine(id) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/joyent/requests/compute/start_machine.rb', line 5 def start_machine(id) request( :method => "POST", :path => "/my/machines/#{id}", :query => {"action" => "start"}, :expects => 202 ) end |
#start_machine_from_snapshot(machine_id, snapshot_name) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/joyent/requests/compute/start_machine_from_snapshot.rb', line 5 def start_machine_from_snapshot(machine_id, snapshot_name) request( :method => "POST", :path => "/my/machines/#{machine_id}/snapshots/#{snapshot_name}", :expects => 202 ) end |
#stop_machine(uuid) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/joyent/requests/compute/stop_machine.rb', line 5 def stop_machine(uuid) request( :method => "POST", :path => "/my/machines/#{uuid}", :query => {"action" => "stop"}, :expects => 202 ) end |
#update_machine_metadata(machine_id, metadata) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/joyent/requests/compute/update_machine_metadata.rb', line 5 def (machine_id, ) request( :method => "POST", :path => "/my/machines/#{machine_id}/metadata", :body => ) end |