Class: Fog::Compute::UKCloud::Real
- Inherits:
-
Object
- Object
- Fog::Compute::UKCloud::Real
- Defined in:
- lib/fog/ukcloud/compute.rb,
lib/fog/ukcloud/requests/compute/get_ping.rb,
lib/fog/ukcloud/requests/compute/get_my_vm.rb,
lib/fog/ukcloud/requests/compute/post_login_session.rb
Constant Summary collapse
- UKCLOUD_DEFAULT_ENDPOINT =
'portal.skyscapecloud.com'
Instance Attribute Summary collapse
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#ukcloud_endpoint ⇒ Object
readonly
Returns the value of attribute ukcloud_endpoint.
-
#ukcloud_username ⇒ Object
readonly
Returns the value of attribute ukcloud_username.
Instance Method Summary collapse
- #get_cookies ⇒ Object
- #get_my_vm ⇒ Object
- #get_ping ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #login ⇒ Object
- #post_login_session ⇒ Object
- #request(params) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/ukcloud/compute.rb', line 29 def initialize(={}) @ukcloud_username = [:ukcloud_username] @ukcloud_password = [:ukcloud_password] @ukcloud_endpoint = [:ukcloud_endpoint] || UKCLOUD_DEFAULT_ENDPOINT @path = 'api' = [:connection_options] || {} [:omit_default_port] = true unless [:omit_default_port] = '' scheme = 'https' port = '443' url = sprintf('%s://%s:%s', scheme, @ukcloud_endpoint, port) @connection = Fog::XML::Connection.new(url, false, ) end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
27 28 29 |
# File 'lib/fog/ukcloud/compute.rb', line 27 def end |
#ukcloud_endpoint ⇒ Object (readonly)
Returns the value of attribute ukcloud_endpoint.
27 28 29 |
# File 'lib/fog/ukcloud/compute.rb', line 27 def ukcloud_endpoint @ukcloud_endpoint end |
#ukcloud_username ⇒ Object (readonly)
Returns the value of attribute ukcloud_username.
27 28 29 |
# File 'lib/fog/ukcloud/compute.rb', line 27 def ukcloud_username @ukcloud_username end |
Instance Method Details
#get_cookies ⇒ Object
46 47 48 49 |
# File 'lib/fog/ukcloud/compute.rb', line 46 def login if .empty? end |
#get_my_vm ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/ukcloud/requests/compute/get_my_vm.rb', line 5 def get_my_vm request( :expects => 200, :method => 'GET', :parser => Fog::ToHashDocument.new, :path => "#{@path}/my_vm" ) end |
#get_ping ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/ukcloud/requests/compute/get_ping.rb', line 5 def get_ping request( :expects => 200, :method => 'GET', #:parser => Fog::ToHashDocument.new, :path => "#{@path}/ping" ) end |
#login ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/fog/ukcloud/compute.rb', line 87 def login response = post_login_session = response.headers['Set-Cookie'] if response[:cookies].empty? && response.status == 201 then err = RuntimeError.new("No Cookie In Response") raise Fog::UKCloud::Errors::ServiceError.slurp(err) end end |
#post_login_session ⇒ Object
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 32 33 34 35 |
# File 'lib/fog/ukcloud/requests/compute/post_login_session.rb', line 7 def post_login_session body = { :email => @ukcloud_username, :password => @ukcloud_password } begin @connection.request( :headers => {'Accept' => 'application/json'}, :expects => 201, :method => 'POST', :body => Fog::JSON.encode(body), :path => "#{@path}/authenticate" ) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::BadRequest then Fog::UKCloud::Errors::BadRequest.slurp(error); when Excon::Errors:: then Fog::UKCloud::Errors::.slurp(error); when Excon::Errors::Forbidden then Fog::UKCloud::Errors::Forbidden.slurp(error); when Excon::Errors::Conflict then Fog::UKCloud::Errors::Conflict.slurp(error); else Fog::UKCloud::Errors::ServiceError.slurp(error) end end end |
#request(params) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fog/ukcloud/compute.rb', line 52 def request(params) path = params[:path] params[:body] = Fog::JSON.encode(params[:body]) if params[:body] begin headers = { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Cookie' => } @connection.request({ :body => params[:body], :expects => params[:expects], :headers => headers.merge!(params[:headers] || {}), :idempotent => params[:idempotent], :method => params[:method], :parser => params[:parser], :path => path, :query => params[:query] }) rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::BadRequest then Fog::UKCloud::Errors::BadRequest.slurp(error); when Excon::Errors:: then Fog::UKCloud::Errors::.slurp(error); when Excon::Errors::Forbidden then Fog::UKCloud::Errors::Forbidden.slurp(error); when Excon::Errors::Conflict then Fog::UKCloud::Errors::Conflict.slurp(error); else Fog::UKCloud::Errors::ServiceError.slurp(error) end end end |