Class: OpenstackBridge::Swift

Inherits:
Struct
  • Object
show all
Defined in:
lib/openstack_bridge/swift.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSwift

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

#authenticationObject

Returns the value of attribute authentication.



3
4
5
# File 'lib/openstack_bridge/swift.rb', line 3

def authentication
  @authentication
end

#hostObject

Returns the value of attribute host

Returns:

  • (Object)

    the current value of host



2
3
4
# File 'lib/openstack_bridge/swift.rb', line 2

def host
  @host
end

#passwordObject

Returns the value of attribute password

Returns:

  • (Object)

    the current value of password



2
3
4
# File 'lib/openstack_bridge/swift.rb', line 2

def password
  @password
end

#regionObject

Returns the value of attribute region

Returns:

  • (Object)

    the current value of region



2
3
4
# File 'lib/openstack_bridge/swift.rb', line 2

def region
  @region
end

#tenantObject

Returns the value of attribute tenant

Returns:

  • (Object)

    the current value of tenant



2
3
4
# File 'lib/openstack_bridge/swift.rb', line 2

def tenant
  @tenant
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



2
3
4
# File 'lib/openstack_bridge/swift.rb', line 2

def user
  @user
end

Instance Method Details

#container(name) ⇒ Object



31
32
33
34
# File 'lib/openstack_bridge/swift.rb', line 31

def container(name)
  create(name) unless containers.include?(name)
  OpenstackBridge::Container.new(self, name)
end

#containersObject



19
20
21
# File 'lib/openstack_bridge/swift.rb', line 19

def containers
  request(:get, "#{end_point}").raw_body.split("\n")
end

#create(name) ⇒ Object



23
24
25
# File 'lib/openstack_bridge/swift.rb', line 23

def create(name)
  request(:put, "#{end_point}/#{name}")
end

#delete(name) ⇒ Object



27
28
29
# File 'lib/openstack_bridge/swift.rb', line 27

def delete(name)
  request(:delete, "#{end_point}/#{name}")
end

#end_pointObject



15
16
17
# File 'lib/openstack_bridge/swift.rb', line 15

def end_point
  (region ? end_points.detect { |end_point| end_point['region'] == region } : end_points.first)['publicURL']
end

#end_pointsObject



11
12
13
# File 'lib/openstack_bridge/swift.rb', line 11

def end_points
  self.authentication.response['access']['serviceCatalog'].detect {|s| s['name'] == 'swift'}['endpoints']
end

#request(method, path, params = {}.to_json, httpclient = false) ⇒ Object

Raises:



36
37
38
39
40
41
42
43
44
45
# File 'lib/openstack_bridge/swift.rb', line 36

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))
  raise OpenstackBridge::Error.new(self), response.raw_body unless [200, 201, 202, 204].include?(response.code.to_i)
  response
end