Class: OpenstackBridge::Swift
- Inherits:
-
Struct
- Object
- Struct
- OpenstackBridge::Swift
- Defined in:
- lib/openstack_bridge/swift.rb
Instance Attribute Summary collapse
-
#authentication ⇒ Object
Returns the value of attribute authentication.
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#tenant ⇒ Object
Returns the value of attribute tenant.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #container(name) ⇒ Object
- #containers ⇒ Object
- #create(name) ⇒ Object
- #delete(name) ⇒ Object
- #end_point ⇒ Object
-
#initialize ⇒ Swift
constructor
A new instance of Swift.
- #request(method, path, params = {}.to_json, httpclient = false) ⇒ Object
Constructor Details
#initialize ⇒ Swift
Returns a new instance of Swift.
5 6 7 8 9 |
# File 'lib/openstack_bridge/swift.rb', line 5 def initialize(*) super self.authentication = OpenstackBridge::Authentication.new(host, user, password, tenant) raise "Wrong authentication response" if !self.authentication.response || !self.authentication.response['access'] end |
Instance Attribute Details
#authentication ⇒ Object
Returns the value of attribute authentication.
3 4 5 |
# File 'lib/openstack_bridge/swift.rb', line 3 def authentication @authentication end |
#host ⇒ Object
Returns the value of attribute host
2 3 4 |
# File 'lib/openstack_bridge/swift.rb', line 2 def host @host end |
#password ⇒ Object
Returns the value of attribute password
2 3 4 |
# File 'lib/openstack_bridge/swift.rb', line 2 def password @password end |
#tenant ⇒ Object
Returns the value of attribute tenant
2 3 4 |
# File 'lib/openstack_bridge/swift.rb', line 2 def tenant @tenant end |
#user ⇒ Object
Returns the value of attribute user
2 3 4 |
# File 'lib/openstack_bridge/swift.rb', line 2 def user @user end |
Instance Method Details
#container(name) ⇒ Object
27 28 29 |
# File 'lib/openstack_bridge/swift.rb', line 27 def container(name) OpenstackBridge::Container.new(self, name) end |
#containers ⇒ Object
15 16 17 |
# File 'lib/openstack_bridge/swift.rb', line 15 def containers request(:get, "#{end_point}").raw_body.split("\n") end |
#create(name) ⇒ Object
19 20 21 |
# File 'lib/openstack_bridge/swift.rb', line 19 def create(name) request(:put, "#{end_point}/#{name}") end |
#delete(name) ⇒ Object
23 24 25 |
# File 'lib/openstack_bridge/swift.rb', line 23 def delete(name) request(:delete, "#{end_point}/#{name}") end |
#end_point ⇒ Object
11 12 13 |
# File 'lib/openstack_bridge/swift.rb', line 11 def end_point self.authentication.response['access']['serviceCatalog'].detect {|s| s['name'] == 'swift'}['endpoints'].first['publicURL'] end |
#request(method, path, params = {}.to_json, httpclient = false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/openstack_bridge/swift.rb', line 31 def request(method, path, params={}.to_json, httpclient = false) request = HTTPI::Request.new request.url = path request.body = params request.headers['Content-Type'] = 'application/json' request.headers['X-Auth-Token'] = authentication.token response = HTTPI.send(method, request, (httpclient ? :httpclient : :curb)) puts response.inspect raise OpenstackBridge::Error.new(self), response.raw_body unless [200, 201, 202, 204].include?(response.code.to_i) response end |