Class: Nephophobia::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/nephophobia/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Required: host: A String with the host to connect. access_key: A String containing the AWS Access Key. secret_key: A String containing the AWS Secret Key. project: An optional String containing the “Project Name”

the Acccess Key is intended for.


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nephophobia/client.rb', line 11

def initialize options
  @port = options[:port] || 8773

  @connection = Hugs::Client.new(
    :host         => options[:host],
    :scheme       => options[:scheme] || "http",
    :port         => @port,
    :type         => options[:type] || :xml,
    :raise_errors => true
  )

  @aws = AWS.new(
    :host       => options[:host],
    :port       => @port,
    :access_key => options[:access_key],
    :secret_key => options[:secret_key],
    :project    => options[:project]
  )
end

Instance Method Details

#action(inflict, filter) ⇒ Object

Vanity wrapper around #raw.

inflict: A String with the EC2 API action to execute. filter: An optional Hash containing the EC2 API filters.



53
54
55
# File 'lib/nephophobia/client.rb', line 53

def action inflict, filter
  raw "get", { "Action" => inflict }.merge(filter)
end

#computeObject

Provide a simple interface to the EC2 Compute resources.



60
61
62
63
# File 'lib/nephophobia/client.rb', line 60

def compute
  @path      = "/services/Cloud"
  @compute ||= Nephophobia::Resource::Compute.new self
end

#credentialObject

Provide a simple interface to the EC2 Credential resources.



68
69
70
71
# File 'lib/nephophobia/client.rb', line 68

def credential
  @path         = "/services/Cloud"
  @credential ||= Nephophobia::Resource::Credential.new self
end

#imageObject

Provide a simple interface to the EC2 Image resources.



76
77
78
79
# File 'lib/nephophobia/client.rb', line 76

def image
  @path    = "/services/Cloud"
  @image ||= Nephophobia::Resource::Image.new self
end

#projectObject

Provide a simple interface to the OpenStack Project resources.



84
85
86
87
# File 'lib/nephophobia/client.rb', line 84

def project
  @path      = "/services/Admin"
  @project ||= Nephophobia::Resource::Project.new self
end

#raw(method, params) ⇒ Object

Worker method which constructs the properly signed URL, and performs the Net::HTTP call. Returns a typical Net::HTTP response with a Hash body.

method: The HTTP method used for the request. params: A Hash containing the



39
40
41
42
43
44
45
# File 'lib/nephophobia/client.rb', line 39

def raw method, params
  @aws.path     = @path
  response      = @connection.send method, @path, :query => @aws.signed_params(method, params)
  response.body = Hashify.convert response.body.root

  response
end

#roleObject

Provide a simple interface to the OpenStack Role resources.



100
101
102
103
# File 'lib/nephophobia/client.rb', line 100

def role
  @path   = "/services/Admin"
  @role ||= Nephophobia::Resource::Role.new self
end

#userObject

Provide a simple interface to the OpenStack User resources.



92
93
94
95
# File 'lib/nephophobia/client.rb', line 92

def user
  @path   = "/services/Admin"
  @user ||= Nephophobia::Resource::User.new self
end