fog 0.0.29 → 0.0.30
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/fog +18 -11
- data/fog.gemspec +43 -14
- data/lib/fog.rb +7 -1
- data/lib/fog/aws/ec2.rb +0 -7
- data/lib/fog/aws/models/ec2/address.rb +22 -26
- data/lib/fog/aws/models/ec2/addresses.rb +7 -22
- data/lib/fog/aws/models/ec2/instance.rb +2 -15
- data/lib/fog/aws/models/ec2/instances.rb +6 -23
- data/lib/fog/aws/models/ec2/key_pair.rb +2 -17
- data/lib/fog/aws/models/ec2/key_pairs.rb +6 -23
- data/lib/fog/aws/models/ec2/security_group.rb +18 -22
- data/lib/fog/aws/models/ec2/security_groups.rb +6 -23
- data/lib/fog/aws/models/ec2/snapshot.rb +2 -15
- data/lib/fog/aws/models/ec2/snapshots.rb +7 -20
- data/lib/fog/aws/models/ec2/volume.rb +23 -22
- data/lib/fog/aws/models/ec2/volumes.rb +8 -22
- data/lib/fog/aws/models/s3/bucket.rb +1 -1
- data/lib/fog/aws/models/s3/buckets.rb +3 -20
- data/lib/fog/aws/models/s3/objects.rb +11 -22
- data/lib/fog/aws/requests/ec2/allocate_address.rb +1 -1
- data/lib/fog/aws/requests/ec2/associate_address.rb +2 -2
- data/lib/fog/aws/requests/ec2/attach_volume.rb +2 -2
- data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +1 -1
- data/lib/fog/aws/requests/ec2/create_key_pair.rb +2 -2
- data/lib/fog/aws/requests/ec2/create_security_group.rb +2 -2
- data/lib/fog/aws/requests/ec2/create_snapshot.rb +2 -2
- data/lib/fog/aws/requests/ec2/create_volume.rb +3 -3
- data/lib/fog/aws/requests/ec2/delete_key_pair.rb +1 -1
- data/lib/fog/aws/requests/ec2/delete_security_group.rb +2 -2
- data/lib/fog/aws/requests/ec2/delete_snapshot.rb +2 -2
- data/lib/fog/aws/requests/ec2/delete_volume.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_addresses.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_availability_zones.rb +1 -1
- data/lib/fog/aws/requests/ec2/describe_images.rb +1 -1
- data/lib/fog/aws/requests/ec2/describe_instances.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_key_pairs.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_regions.rb +1 -1
- data/lib/fog/aws/requests/ec2/describe_security_groups.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_snapshots.rb +2 -2
- data/lib/fog/aws/requests/ec2/describe_volumes.rb +2 -2
- data/lib/fog/aws/requests/ec2/detach_volume.rb +2 -2
- data/lib/fog/aws/requests/ec2/disassociate_address.rb +2 -2
- data/lib/fog/aws/requests/ec2/get_console_output.rb +2 -2
- data/lib/fog/aws/requests/ec2/reboot_instances.rb +2 -2
- data/lib/fog/aws/requests/ec2/release_address.rb +2 -2
- data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +1 -1
- data/lib/fog/aws/requests/ec2/run_instances.rb +2 -2
- data/lib/fog/aws/requests/ec2/terminate_instances.rb +2 -2
- data/lib/fog/aws/requests/s3/copy_object.rb +2 -2
- data/lib/fog/aws/requests/s3/delete_bucket.rb +3 -3
- data/lib/fog/aws/requests/s3/delete_object.rb +2 -2
- data/lib/fog/aws/requests/s3/get_bucket.rb +2 -2
- data/lib/fog/aws/requests/s3/get_bucket_location.rb +2 -2
- data/lib/fog/aws/requests/s3/get_object.rb +2 -2
- data/lib/fog/aws/requests/s3/get_request_payment.rb +2 -2
- data/lib/fog/aws/requests/s3/get_service.rb +1 -1
- data/lib/fog/aws/requests/s3/head_object.rb +1 -1
- data/lib/fog/aws/requests/s3/put_bucket.rb +1 -1
- data/lib/fog/aws/requests/s3/put_object.rb +2 -2
- data/lib/fog/aws/requests/s3/put_request_payment.rb +1 -1
- data/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +2 -2
- data/lib/fog/aws/requests/simpledb/create_domain.rb +1 -1
- data/lib/fog/aws/requests/simpledb/delete_attributes.rb +2 -2
- data/lib/fog/aws/requests/simpledb/delete_domain.rb +1 -1
- data/lib/fog/aws/requests/simpledb/domain_metadata.rb +2 -2
- data/lib/fog/aws/requests/simpledb/get_attributes.rb +2 -2
- data/lib/fog/aws/requests/simpledb/list_domains.rb +1 -1
- data/lib/fog/aws/requests/simpledb/put_attributes.rb +1 -1
- data/lib/fog/aws/requests/simpledb/select.rb +1 -1
- data/lib/fog/aws/s3.rb +0 -7
- data/lib/fog/aws/simpledb.rb +0 -4
- data/lib/fog/collection.rb +35 -7
- data/lib/fog/connection.rb +10 -130
- data/lib/fog/model.rb +18 -13
- data/lib/fog/parser.rb +0 -5
- data/lib/fog/rackspace.rb +35 -15
- data/lib/fog/rackspace/files.rb +36 -6
- data/lib/fog/rackspace/models/servers/server.rb +2 -16
- data/lib/fog/rackspace/models/servers/servers.rb +6 -21
- data/lib/fog/rackspace/requests/files/delete_container.rb +38 -0
- data/lib/fog/rackspace/requests/files/delete_object.rb +39 -0
- data/lib/fog/rackspace/requests/files/get_container.rb +61 -0
- data/lib/fog/rackspace/requests/files/get_containers.rb +5 -7
- data/lib/fog/rackspace/requests/files/head_container.rb +44 -0
- data/lib/fog/rackspace/requests/files/head_containers.rb +1 -1
- data/lib/fog/rackspace/requests/files/put_container.rb +38 -0
- data/lib/fog/rackspace/requests/files/put_object.rb +41 -0
- data/lib/fog/rackspace/requests/servers/create_image.rb +6 -0
- data/lib/fog/rackspace/requests/servers/create_server.rb +21 -2
- data/lib/fog/rackspace/requests/servers/delete_server.rb +18 -3
- data/lib/fog/rackspace/requests/servers/get_server_details.rb +17 -5
- data/lib/fog/rackspace/requests/servers/list_addresses.rb +52 -0
- data/lib/fog/rackspace/requests/servers/list_flavors.rb +2 -4
- data/lib/fog/rackspace/requests/servers/list_flavors_detail.rb +41 -0
- data/lib/fog/rackspace/requests/servers/list_images.rb +1 -1
- data/lib/fog/rackspace/requests/servers/list_images_detail.rb +1 -1
- data/lib/fog/rackspace/requests/servers/list_private_addresses.rb +50 -0
- data/lib/fog/rackspace/requests/servers/list_public_addresses.rb +50 -0
- data/lib/fog/rackspace/requests/servers/list_servers.rb +11 -2
- data/lib/fog/rackspace/requests/servers/list_servers_detail.rb +17 -2
- data/lib/fog/rackspace/requests/servers/reboot_server.rb +3 -6
- data/lib/fog/rackspace/requests/servers/update_server.rb +18 -5
- data/lib/fog/rackspace/servers.rb +20 -0
- data/spec/aws/models/ec2/address_spec.rb +4 -4
- data/spec/aws/models/ec2/instance_spec.rb +6 -6
- data/spec/aws/models/ec2/key_pair_spec.rb +5 -5
- data/spec/aws/models/ec2/security_group_spec.rb +5 -5
- data/spec/aws/models/ec2/snapshot_spec.rb +8 -8
- data/spec/aws/models/ec2/snapshots_spec.rb +6 -6
- data/spec/aws/models/ec2/volume_spec.rb +6 -5
- data/spec/aws/models/ec2/volumes_spec.rb +4 -4
- data/spec/aws/requests/ec2/associate_address_spec.rb +2 -2
- data/spec/aws/requests/ec2/attach_volume_spec.rb +2 -2
- data/spec/aws/requests/ec2/create_key_pair_spec.rb +1 -1
- data/spec/aws/requests/ec2/create_security_group_spec.rb +1 -1
- data/spec/aws/requests/ec2/create_snapshot_spec.rb +1 -1
- data/spec/aws/requests/ec2/delete_security_group_spec.rb +1 -1
- data/spec/aws/requests/ec2/delete_snapshot_spec.rb +1 -1
- data/spec/aws/requests/ec2/delete_volume_spec.rb +2 -2
- data/spec/aws/requests/ec2/describe_addresses_spec.rb +1 -1
- data/spec/aws/requests/ec2/describe_instances_spec.rb +1 -1
- data/spec/aws/requests/ec2/describe_key_pairs_spec.rb +1 -1
- data/spec/aws/requests/ec2/describe_security_groups_spec.rb +1 -1
- data/spec/aws/requests/ec2/describe_snapshots_spec.rb +1 -1
- data/spec/aws/requests/ec2/describe_volumes_spec.rb +1 -1
- data/spec/aws/requests/ec2/detach_volume_spec.rb +1 -1
- data/spec/aws/requests/ec2/disassociate_address_spec.rb +1 -1
- data/spec/aws/requests/ec2/get_console_output_spec.rb +1 -1
- data/spec/aws/requests/ec2/reboot_instances_spec.rb +1 -1
- data/spec/aws/requests/ec2/release_address_spec.rb +1 -1
- data/spec/aws/requests/ec2/terminate_instances_spec.rb +1 -1
- data/spec/aws/requests/s3/copy_object_spec.rb +4 -5
- data/spec/aws/requests/s3/delete_bucket_spec.rb +3 -4
- data/spec/aws/requests/s3/delete_object_spec.rb +2 -3
- data/spec/aws/requests/s3/get_bucket_location_spec.rb +1 -1
- data/spec/aws/requests/s3/get_bucket_spec.rb +4 -6
- data/spec/aws/requests/s3/get_object_spec.rb +6 -10
- data/spec/aws/requests/s3/get_request_payment_spec.rb +1 -1
- data/spec/aws/requests/s3/head_object_spec.rb +2 -4
- data/spec/aws/requests/s3/put_object_spec.rb +4 -7
- data/spec/aws/requests/s3/put_request_payment_spec.rb +1 -1
- data/spec/aws/requests/simpledb/batch_put_attributes_spec.rb +1 -1
- data/spec/aws/requests/simpledb/delete_attributes_spec.rb +1 -1
- data/spec/aws/requests/simpledb/domain_metadata_spec.rb +1 -1
- data/spec/aws/requests/simpledb/get_attributes_spec.rb +1 -1
- data/spec/aws/requests/simpledb/put_attributes_spec.rb +1 -1
- data/spec/rackspace/requests/files/delete_container_spec.rb +24 -0
- data/spec/rackspace/requests/files/delete_object_spec.rb +37 -0
- data/spec/rackspace/requests/files/get_container_spec.rb +33 -0
- data/spec/rackspace/requests/files/get_containers_spec.rb +12 -1
- data/spec/rackspace/requests/files/head_container_spec.rb +30 -0
- data/spec/rackspace/requests/files/head_containers_spec.rb +9 -1
- data/spec/rackspace/requests/files/put_container_spec.rb +15 -0
- data/spec/rackspace/requests/files/put_object_spec.rb +20 -0
- data/spec/rackspace/requests/servers/create_image_spec.rb +16 -2
- data/spec/rackspace/requests/servers/create_server_spec.rb +1 -1
- data/spec/rackspace/requests/servers/delete_image_spec.rb +32 -0
- data/spec/rackspace/requests/servers/delete_server_spec.rb +1 -1
- data/spec/rackspace/requests/servers/get_server_details_spec.rb +1 -1
- data/spec/rackspace/requests/servers/list_addresses_spec.rb +34 -0
- data/spec/rackspace/requests/servers/list_flavors_detail_spec.rb +17 -0
- data/spec/rackspace/requests/servers/list_flavors_spec.rb +6 -3
- data/spec/rackspace/requests/servers/list_images_detail_spec.rb +18 -0
- data/spec/rackspace/requests/servers/list_images_spec.rb +5 -2
- data/spec/rackspace/requests/servers/list_private_addresses_spec.rb +32 -0
- data/spec/rackspace/requests/servers/list_public_addresses_spec.rb +32 -0
- data/spec/rackspace/requests/servers/list_servers_detail_spec.rb +1 -1
- data/spec/rackspace/requests/servers/reboot_server_spec.rb +31 -0
- data/spec/rackspace/requests/servers/update_server_spec.rb +33 -0
- data/spec/spec_helper.rb +5 -1
- metadata +50 -14
- data/benchs/headers_split_vs_match.rb +0 -18
- data/benchs/stripping.rb +0 -26
- data/lib/fog/errors.rb +0 -145
- data/lib/fog/response.rb +0 -12
- data/spec/rackspace/requests/servers/delete_image.rb +0 -12
- data/spec/rackspace/requests/servers/list_images_detail.rb +0 -12
- data/spec/rackspace/requests/servers/reboot_server.rb +0 -12
- data/spec/rackspace/requests/servers/update_server.rb +0 -12
data/lib/fog/aws/s3.rb
CHANGED
@@ -12,12 +12,6 @@ module Fog
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.reload
|
15
|
-
load "fog/collection.rb"
|
16
|
-
load "fog/connection.rb"
|
17
|
-
load "fog/model.rb"
|
18
|
-
load "fog/parser.rb"
|
19
|
-
load "fog/response.rb"
|
20
|
-
|
21
15
|
load "fog/aws/models/s3/bucket.rb"
|
22
16
|
load "fog/aws/models/s3/buckets.rb"
|
23
17
|
load "fog/aws/models/s3/object.rb"
|
@@ -105,7 +99,6 @@ module Fog
|
|
105
99
|
response = @connection.request({
|
106
100
|
:block => params[:block],
|
107
101
|
:body => params[:body],
|
108
|
-
:error_parser => Fog::Errors::Parser.new,
|
109
102
|
:expects => params[:expects],
|
110
103
|
:headers => params[:headers],
|
111
104
|
:host => params[:host],
|
data/lib/fog/aws/simpledb.rb
CHANGED
@@ -12,10 +12,6 @@ module Fog
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.reload
|
15
|
-
load "fog/connection.rb"
|
16
|
-
load "fog/parser.rb"
|
17
|
-
load "fog/response.rb"
|
18
|
-
|
19
15
|
load "fog/aws/parsers/simpledb/basic.rb"
|
20
16
|
load "fog/aws/parsers/simpledb/domain_metadata.rb"
|
21
17
|
load "fog/aws/parsers/simpledb/get_attributes.rb"
|
data/lib/fog/collection.rb
CHANGED
@@ -5,12 +5,17 @@ module Fog
|
|
5
5
|
class_eval <<-EOS, __FILE__, __LINE__
|
6
6
|
attr_accessor :#{name}
|
7
7
|
EOS
|
8
|
-
attributes
|
8
|
+
@attributes ||= []
|
9
|
+
@attributes |= [name]
|
9
10
|
for other_name in [*other_names]
|
10
11
|
aliases[other_name] = name
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
15
|
+
def self.model(new_model)
|
16
|
+
@model = new_model
|
17
|
+
end
|
18
|
+
|
14
19
|
def self.aliases
|
15
20
|
@aliases ||= {}
|
16
21
|
end
|
@@ -19,6 +24,20 @@ module Fog
|
|
19
24
|
@attributes ||= []
|
20
25
|
end
|
21
26
|
|
27
|
+
def attributes
|
28
|
+
attributes = {}
|
29
|
+
for attribute in self.class.attributes
|
30
|
+
attributes[attribute] = send("#{attribute}")
|
31
|
+
end
|
32
|
+
attributes
|
33
|
+
end
|
34
|
+
|
35
|
+
def create(attributes = {})
|
36
|
+
object = new(attributes)
|
37
|
+
object.save
|
38
|
+
object
|
39
|
+
end
|
40
|
+
|
22
41
|
def initialize(attributes = {})
|
23
42
|
merge_attributes(attributes)
|
24
43
|
end
|
@@ -36,12 +55,8 @@ module Fog
|
|
36
55
|
data << "]>"
|
37
56
|
end
|
38
57
|
|
39
|
-
def
|
40
|
-
|
41
|
-
for attribute in self.class.attributes
|
42
|
-
attributes[attribute] = send("#{attribute}")
|
43
|
-
end
|
44
|
-
attributes
|
58
|
+
def model
|
59
|
+
self.class.instance_variable_get('@model')
|
45
60
|
end
|
46
61
|
|
47
62
|
def merge_attributes(new_attributes = {})
|
@@ -55,6 +70,19 @@ module Fog
|
|
55
70
|
self
|
56
71
|
end
|
57
72
|
|
73
|
+
def new(attributes = {})
|
74
|
+
model.new(
|
75
|
+
attributes.merge!(
|
76
|
+
:collection => self,
|
77
|
+
:connection => connection
|
78
|
+
)
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def reload
|
83
|
+
self.clear.concat(all)
|
84
|
+
end
|
85
|
+
|
58
86
|
private
|
59
87
|
|
60
88
|
def connection=(new_connection)
|
data/lib/fog/connection.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
3
|
-
require 'socket'
|
4
|
-
require 'uri'
|
2
|
+
require 'excon'
|
5
3
|
|
6
4
|
require "fog/errors"
|
7
5
|
require "fog/response"
|
@@ -11,142 +9,24 @@ unless Fog.mocking?
|
|
11
9
|
module Fog
|
12
10
|
class Connection
|
13
11
|
|
14
|
-
unless const_defined?(:CHUNK_SIZE)
|
15
|
-
CHUNK_SIZE = 1048576 # 1 megabyte
|
16
|
-
end
|
17
|
-
|
18
12
|
def initialize(url)
|
19
|
-
@
|
20
|
-
end
|
21
|
-
|
22
|
-
def connection
|
23
|
-
if @connection && !@connection.closed?
|
24
|
-
@connection
|
25
|
-
else
|
26
|
-
@connection = TCPSocket.open(@uri.host, @uri.port)
|
27
|
-
if @uri.scheme == 'https'
|
28
|
-
@ssl_context = OpenSSL::SSL::SSLContext.new
|
29
|
-
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
30
|
-
@connection = OpenSSL::SSL::SSLSocket.new(@connection, @ssl_context)
|
31
|
-
@connection.sync_close = true
|
32
|
-
@connection.connect
|
33
|
-
end
|
34
|
-
end
|
13
|
+
@excon = Excon.new(url)
|
35
14
|
end
|
36
15
|
|
37
16
|
def request(params)
|
38
|
-
params
|
39
|
-
|
40
|
-
params[:
|
17
|
+
if parser = params.delete(:parser)
|
18
|
+
body = Nokogiri::XML::SAX::PushParser.new(parser)
|
19
|
+
params[:block] = lambda { |chunk| body << chunk }
|
41
20
|
end
|
42
|
-
if params[:query] && !params[:query].empty?
|
43
|
-
params[:path] << "?#{params[:query]}"
|
44
|
-
end
|
45
|
-
request = "#{params[:method]} #{params[:path]} HTTP/1.1\r\n"
|
46
|
-
params[:headers] ||= {}
|
47
|
-
params[:headers]['Host'] = params[:host]
|
48
|
-
if params[:body] && !params[:headers]['Content-Length']
|
49
|
-
params[:headers]['Content-Length'] = params[:body].length
|
50
|
-
end
|
51
|
-
for key, value in params[:headers]
|
52
|
-
request << "#{key}: #{value}\r\n"
|
53
|
-
end
|
54
|
-
request << "\r\n"
|
55
|
-
connection.write(request)
|
56
21
|
|
57
|
-
|
58
|
-
if params[:body].is_a?(String)
|
59
|
-
connection.write(params[:body])
|
60
|
-
else
|
61
|
-
while chunk = params[:body].read(CHUNK_SIZE)
|
62
|
-
connection.write(chunk)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
22
|
+
response = @excon.request(params)
|
66
23
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
if params[:expects] && ![*params[:expects]].include?(response.status)
|
71
|
-
error = true
|
72
|
-
end
|
73
|
-
while true
|
74
|
-
data = connection.readline.chomp!
|
75
|
-
if data == ""
|
76
|
-
break
|
77
|
-
end
|
78
|
-
header = data.split(': ')
|
79
|
-
response.headers[capitalize(header[0])] = header[1]
|
24
|
+
if parser
|
25
|
+
body.finish
|
26
|
+
response.body = parser.response
|
80
27
|
end
|
81
28
|
|
82
|
-
|
83
|
-
if (error && params[:error_parser]) || params[:parser]
|
84
|
-
if error
|
85
|
-
parser = params[:error_parser]
|
86
|
-
elsif params[:parser]
|
87
|
-
parser = params[:parser]
|
88
|
-
end
|
89
|
-
body = Nokogiri::XML::SAX::PushParser.new(parser)
|
90
|
-
elsif params[:block]
|
91
|
-
body = nil
|
92
|
-
else
|
93
|
-
body = ''
|
94
|
-
end
|
95
|
-
|
96
|
-
if response.headers['Content-Length']
|
97
|
-
if error || !params[:block]
|
98
|
-
body << connection.read(response.headers['Content-Length'].to_i)
|
99
|
-
else
|
100
|
-
remaining = response.headers['Content-Length'].to_i
|
101
|
-
while remaining > 0
|
102
|
-
params[:block].call(connection.read([CHUNK_SIZE, remaining].min))
|
103
|
-
remaining -= CHUNK_SIZE;
|
104
|
-
end
|
105
|
-
end
|
106
|
-
elsif response.headers['Transfer-Encoding'] == 'chunked'
|
107
|
-
while true
|
108
|
-
chunk_size = connection.readline.chomp!.to_i(16)
|
109
|
-
# 2 == "/r/n".length
|
110
|
-
chunk = connection.read(chunk_size + 2)[0...-2]
|
111
|
-
if chunk_size == 0
|
112
|
-
break
|
113
|
-
else
|
114
|
-
if error || !params[:block]
|
115
|
-
body << chunk
|
116
|
-
else
|
117
|
-
params[:block].call(chunk)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
elsif response.headers['Connection'] == 'close'
|
122
|
-
body << connection.read
|
123
|
-
@connection = nil
|
124
|
-
end
|
125
|
-
|
126
|
-
if parser
|
127
|
-
body.finish
|
128
|
-
response.body = parser.response
|
129
|
-
else
|
130
|
-
response.body = body
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
if error
|
135
|
-
raise(Fog::Errors.status_error(params[:expects], response.status, response))
|
136
|
-
else
|
137
|
-
response
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
private
|
142
|
-
|
143
|
-
def capitalize(header)
|
144
|
-
words = header.split('-')
|
145
|
-
header = ''
|
146
|
-
for word in words
|
147
|
-
header << word[0..0].upcase << word[1..-1] << '-'
|
148
|
-
end
|
149
|
-
header.chop!
|
29
|
+
response
|
150
30
|
end
|
151
31
|
|
152
32
|
end
|
data/lib/fog/model.rb
CHANGED
@@ -5,7 +5,8 @@ module Fog
|
|
5
5
|
class_eval <<-EOS, __FILE__, __LINE__
|
6
6
|
attr_accessor :#{name}
|
7
7
|
EOS
|
8
|
-
attributes
|
8
|
+
@attributes ||= []
|
9
|
+
@attributes |= [name]
|
9
10
|
for other_name in [*other_names]
|
10
11
|
aliases[other_name] = name
|
11
12
|
end
|
@@ -24,6 +25,18 @@ module Fog
|
|
24
25
|
@attributes ||= []
|
25
26
|
end
|
26
27
|
|
28
|
+
def attributes
|
29
|
+
attributes = {}
|
30
|
+
for attribute in self.class.attributes
|
31
|
+
attributes[attribute] = send("#{attribute}")
|
32
|
+
end
|
33
|
+
attributes
|
34
|
+
end
|
35
|
+
|
36
|
+
def collection
|
37
|
+
@collection
|
38
|
+
end
|
39
|
+
|
27
40
|
def identity
|
28
41
|
send(self.class.instance_variable_get('@identity'))
|
29
42
|
end
|
@@ -40,18 +53,6 @@ module Fog
|
|
40
53
|
data << ">"
|
41
54
|
end
|
42
55
|
|
43
|
-
def attributes
|
44
|
-
attributes = {}
|
45
|
-
for attribute in self.class.attributes
|
46
|
-
attributes[attribute] = send("#{attribute}")
|
47
|
-
end
|
48
|
-
attributes
|
49
|
-
end
|
50
|
-
|
51
|
-
def collection
|
52
|
-
@collection
|
53
|
-
end
|
54
|
-
|
55
56
|
def merge_attributes(new_attributes = {})
|
56
57
|
for key, value in new_attributes
|
57
58
|
if aliased_key = self.class.aliases[key]
|
@@ -63,6 +64,10 @@ module Fog
|
|
63
64
|
self
|
64
65
|
end
|
65
66
|
|
67
|
+
def new_record?
|
68
|
+
!identity
|
69
|
+
end
|
70
|
+
|
66
71
|
def reload
|
67
72
|
new_attributes = collection.get(identity).attributes
|
68
73
|
merge_attributes(new_attributes)
|
data/lib/fog/parser.rb
CHANGED
data/lib/fog/rackspace.rb
CHANGED
@@ -6,23 +6,43 @@ module Fog
|
|
6
6
|
load 'fog/rackspace/servers.rb'
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
9
|
+
unless Fog.mocking?
|
10
|
+
|
11
|
+
def self.authenticate(options)
|
12
|
+
connection = Fog::Connection.new("https://auth.api.rackspacecloud.com")
|
13
|
+
response = connection.request({
|
14
|
+
:expects => 204,
|
15
|
+
:headers => {
|
16
|
+
'X-Auth-Key' => options[:rackspace_api_key],
|
17
|
+
'X-Auth-User' => options[:rackspace_username]
|
18
|
+
},
|
19
|
+
:host => 'auth.api.rackspacecloud.com',
|
20
|
+
:method => 'GET',
|
21
|
+
:path => 'v1.0'
|
22
|
+
})
|
23
|
+
response.headers.reject do |key, value|
|
24
|
+
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
else
|
29
|
+
|
30
|
+
def self.authenticate(options)
|
31
|
+
{
|
32
|
+
'X-Auth_Token' => '01234567-0123-0123-0123-01234',
|
33
|
+
'X-CDN-Management-Url' => 'https://cdn.cloaddrive.com/v1/CloudFS_01234-0123',
|
34
|
+
'X-Server-Management-Url' => 'https://servers.api.rackspacecloud.com/v1.0/01234',
|
35
|
+
'X-Storage-Url' => 'https://storage.clouddrive.com/v1/CloudFS_01234-0123'
|
36
|
+
}
|
23
37
|
end
|
38
|
+
|
39
|
+
srand(Time.now.to_i)
|
40
|
+
|
41
|
+
class Mock
|
42
|
+
end
|
43
|
+
|
24
44
|
end
|
25
45
|
|
26
46
|
end
|
27
47
|
end
|
28
|
-
Fog::Rackspace.reload
|
48
|
+
Fog::Rackspace.reload
|
data/lib/fog/rackspace/files.rb
CHANGED
@@ -3,7 +3,14 @@ module Fog
|
|
3
3
|
class Files
|
4
4
|
|
5
5
|
def self.reload
|
6
|
+
load "fog/rackspace/requests/files/delete_container.rb"
|
7
|
+
load "fog/rackspace/requests/files/delete_object.rb"
|
8
|
+
load "fog/rackspace/requests/files/get_container.rb"
|
6
9
|
load "fog/rackspace/requests/files/get_containers.rb"
|
10
|
+
load "fog/rackspace/requests/files/head_container.rb"
|
11
|
+
load "fog/rackspace/requests/files/head_containers.rb"
|
12
|
+
load "fog/rackspace/requests/files/put_container.rb"
|
13
|
+
load "fog/rackspace/requests/files/put_object.rb"
|
7
14
|
end
|
8
15
|
|
9
16
|
def initialize(options={})
|
@@ -22,18 +29,40 @@ module Fog
|
|
22
29
|
@connection = Fog::Connection.new("#{@storage_scheme}://#{@storage_host}:#{@storage_port}")
|
23
30
|
end
|
24
31
|
|
32
|
+
def parse_data(data)
|
33
|
+
metadata = {
|
34
|
+
:body => nil,
|
35
|
+
:headers => {}
|
36
|
+
}
|
37
|
+
|
38
|
+
if data.is_a?(String)
|
39
|
+
metadata[:body] = data
|
40
|
+
metadata[:headers]['Content-Length'] = metadata[:body].size.to_s
|
41
|
+
else
|
42
|
+
filename = File.basename(data.path)
|
43
|
+
unless (mime_types = MIME::Types.of(filename)).empty?
|
44
|
+
metadata[:headers]['Content-Type'] = mime_types.first.content_type
|
45
|
+
end
|
46
|
+
metadata[:body] = data.read
|
47
|
+
metadata[:headers]['Content-Length'] = File.size(data.path).to_s
|
48
|
+
end
|
49
|
+
# metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
|
50
|
+
metadata
|
51
|
+
end
|
52
|
+
|
25
53
|
def cdn_request(params)
|
26
54
|
response = @connection.request({
|
27
55
|
:body => params[:body],
|
28
56
|
:expects => params[:expects],
|
29
57
|
:headers => {
|
30
58
|
'X-Auth-Token' => @auth_token
|
31
|
-
},
|
59
|
+
}.merge!(params[:headers] || {}),
|
32
60
|
:host => @cdn_host,
|
33
61
|
:method => params[:method],
|
34
|
-
:path => "#{@cdn_path}/#{params[:path]}"
|
62
|
+
:path => "#{@cdn_path}/#{params[:path]}",
|
63
|
+
:query => params[:query]
|
35
64
|
})
|
36
|
-
unless response.
|
65
|
+
unless response.body.empty?
|
37
66
|
response.body = JSON.parse(response.body)
|
38
67
|
end
|
39
68
|
response
|
@@ -45,12 +74,13 @@ module Fog
|
|
45
74
|
:expects => params[:expects],
|
46
75
|
:headers => {
|
47
76
|
'X-Auth-Token' => @auth_token
|
48
|
-
},
|
77
|
+
}.merge!(params[:headers] || {}),
|
49
78
|
:host => @storage_host,
|
50
79
|
:method => params[:method],
|
51
|
-
:path => "#{@storage_path}/#{params[:path]}"
|
80
|
+
:path => "#{@storage_path}/#{params[:path]}",
|
81
|
+
:query => params[:query]
|
52
82
|
})
|
53
|
-
unless response.
|
83
|
+
unless response.body.empty?
|
54
84
|
response.body = JSON.parse(response.body)
|
55
85
|
end
|
56
86
|
response
|