fog 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/fog.gemspec +13 -7
  2. data/lib/fog.rb +1 -1
  3. data/lib/fog/aws.rb +0 -4
  4. data/lib/fog/aws/parsers/ec2/get_console_output.rb +4 -2
  5. data/lib/fog/aws/requests/ec2/associate_address.rb +1 -1
  6. data/lib/fog/aws/requests/ec2/attach_volume.rb +2 -2
  7. data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +1 -1
  8. data/lib/fog/aws/requests/ec2/delete_security_group.rb +1 -1
  9. data/lib/fog/aws/requests/ec2/delete_snapshot.rb +1 -1
  10. data/lib/fog/aws/requests/ec2/delete_volume.rb +1 -1
  11. data/lib/fog/aws/requests/ec2/describe_addresses.rb +1 -1
  12. data/lib/fog/aws/requests/ec2/describe_instances.rb +2 -2
  13. data/lib/fog/aws/requests/ec2/describe_key_pairs.rb +1 -1
  14. data/lib/fog/aws/requests/ec2/describe_security_groups.rb +1 -1
  15. data/lib/fog/aws/requests/ec2/describe_snapshots.rb +1 -1
  16. data/lib/fog/aws/requests/ec2/describe_volumes.rb +1 -1
  17. data/lib/fog/aws/requests/ec2/detach_volume.rb +1 -1
  18. data/lib/fog/aws/requests/ec2/get_console_output.rb +2 -2
  19. data/lib/fog/aws/requests/ec2/reboot_instances.rb +1 -1
  20. data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +1 -1
  21. data/lib/fog/aws/requests/ec2/run_instances.rb +2 -1
  22. data/lib/fog/aws/requests/ec2/terminate_instances.rb +1 -1
  23. data/lib/fog/collection.rb +7 -3
  24. data/lib/fog/terremark/shared.rb +4 -2
  25. data/lib/fog/vcloud.rb +25 -3
  26. data/lib/fog/vcloud/collection.rb +66 -0
  27. data/lib/fog/vcloud/model.rb +49 -0
  28. data/lib/fog/vcloud/models/vdc.rb +36 -0
  29. data/lib/fog/vcloud/models/vdcs.rb +36 -0
  30. data/lib/fog/vcloud/parser.rb +4 -1
  31. data/lib/fog/vcloud/parsers/get_vdc.rb +26 -1
  32. data/lib/fog/vcloud/parsers/login.rb +2 -6
  33. data/lib/fog/vcloud/requests/get_organization.rb +1 -1
  34. data/lib/fog/vcloud/requests/get_vdc.rb +32 -1
  35. data/lib/fog/vcloud/terremark/ecloud.rb +2 -1
  36. data/lib/fog/vcloud/terremark/ecloud/models/vdc.rb +20 -0
  37. data/lib/fog/vcloud/terremark/ecloud/models/vdcs.rb +29 -0
  38. data/lib/fog/vcloud/terremark/ecloud/parsers/get_vdc.rb +3 -3
  39. data/lib/fog/vcloud/terremark/ecloud/requests/get_vdc.rb +1 -1
  40. data/lib/fog/vcloud/terremark/vcloud/requests/get_vdc.rb +1 -1
  41. data/spec/aws/models/ec2/snapshots_spec.rb +1 -1
  42. data/spec/shared_examples/servers_examples.rb +1 -1
  43. data/spec/vcloud/models/vdc_spec.rb +46 -0
  44. data/spec/vcloud/models/vdcs_spec.rb +1 -0
  45. data/spec/vcloud/requests/get_organization_spec.rb +2 -2
  46. data/spec/vcloud/requests/get_vdc_spec.rb +6 -3
  47. data/spec/vcloud/spec_helper.rb +44 -8
  48. data/spec/vcloud/terremark/ecloud/models/vdc_spec.rb +43 -0
  49. data/spec/vcloud/terremark/ecloud/models/vdcs_spec.rb +25 -0
  50. data/spec/vcloud/terremark/ecloud/requests/get_vdc_spec.rb +8 -8
  51. data/spec/vcloud/terremark/vcloud/requests/get_vdc_spec.rb +4 -4
  52. data/tests/aws/helper.rb +0 -8
  53. data/tests/aws/requests/ec2/address_tests.rb +3 -3
  54. data/tests/aws/requests/ec2/availability_zone_tests.rb +2 -2
  55. data/tests/aws/requests/ec2/instance_tests.rb +122 -0
  56. data/tests/aws/requests/ec2/key_pair_tests.rb +1 -1
  57. data/tests/aws/requests/ec2/region_tests.rb +2 -2
  58. data/tests/aws/requests/ec2/security_group_tests.rb +6 -6
  59. data/tests/aws/requests/ec2/snapshot_tests.rb +2 -2
  60. data/tests/aws/requests/ec2/volume_tests.rb +5 -5
  61. data/tests/helper.rb +19 -6
  62. data/tests/rackspace/requests/servers/list_images_detail_tests.rb +1 -1
  63. metadata +14 -8
  64. data/spec/aws/requests/ec2/describe_instances_spec.rb +0 -104
  65. data/spec/aws/requests/ec2/get_console_output_spec.rb +0 -35
  66. data/spec/aws/requests/ec2/reboot_instances_spec.rb +0 -30
  67. data/spec/aws/requests/ec2/run_instances_spec.rb +0 -48
  68. data/spec/aws/requests/ec2/terminate_instances_spec.rb +0 -35
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  ## If your rubyforge_project name is different, then edit it and comment out
8
8
  ## the sub! line in the Rakefile
9
9
  s.name = 'fog'
10
- s.version = '0.1.4'
11
- s.date = '2010-05-26'
10
+ s.version = '0.1.5'
11
+ s.date = '2010-05-27'
12
12
  s.rubyforge_project = 'fog'
13
13
 
14
14
  ## Make sure your summary is short. The description may be as long
@@ -354,6 +354,10 @@ Gem::Specification.new do |s|
354
354
  lib/fog/terremark/vcloud.rb
355
355
  lib/fog/vcloud.rb
356
356
  lib/fog/vcloud/bin.rb
357
+ lib/fog/vcloud/collection.rb
358
+ lib/fog/vcloud/model.rb
359
+ lib/fog/vcloud/models/vdc.rb
360
+ lib/fog/vcloud/models/vdcs.rb
357
361
  lib/fog/vcloud/parser.rb
358
362
  lib/fog/vcloud/parsers/get_organization.rb
359
363
  lib/fog/vcloud/parsers/get_vdc.rb
@@ -365,6 +369,8 @@ Gem::Specification.new do |s|
365
369
  lib/fog/vcloud/requests/login.rb
366
370
  lib/fog/vcloud/terremark/all.rb
367
371
  lib/fog/vcloud/terremark/ecloud.rb
372
+ lib/fog/vcloud/terremark/ecloud/models/vdc.rb
373
+ lib/fog/vcloud/terremark/ecloud/models/vdcs.rb
368
374
  lib/fog/vcloud/terremark/ecloud/parsers/get_vdc.rb
369
375
  lib/fog/vcloud/terremark/ecloud/requests/get_vdc.rb
370
376
  lib/fog/vcloud/terremark/ecloud/requests/login.rb
@@ -389,11 +395,6 @@ Gem::Specification.new do |s|
389
395
  spec/aws/models/s3/file_spec.rb
390
396
  spec/aws/models/s3/files_spec.rb
391
397
  spec/aws/requests/ec2/describe_images_spec.rb
392
- spec/aws/requests/ec2/describe_instances_spec.rb
393
- spec/aws/requests/ec2/get_console_output_spec.rb
394
- spec/aws/requests/ec2/reboot_instances_spec.rb
395
- spec/aws/requests/ec2/run_instances_spec.rb
396
- spec/aws/requests/ec2/terminate_instances_spec.rb
397
398
  spec/aws/requests/s3/copy_object_spec.rb
398
399
  spec/aws/requests/s3/delete_bucket_spec.rb
399
400
  spec/aws/requests/s3/delete_object_spec.rb
@@ -438,11 +439,15 @@ Gem::Specification.new do |s|
438
439
  spec/slicehost/models/servers_spec.rb
439
440
  spec/spec_helper.rb
440
441
  spec/vcloud/bin_spec.rb
442
+ spec/vcloud/models/vdc_spec.rb
443
+ spec/vcloud/models/vdcs_spec.rb
441
444
  spec/vcloud/requests/get_organization_spec.rb
442
445
  spec/vcloud/requests/get_vdc_spec.rb
443
446
  spec/vcloud/requests/get_versions_spec.rb
444
447
  spec/vcloud/requests/login_spec.rb
445
448
  spec/vcloud/spec_helper.rb
449
+ spec/vcloud/terremark/ecloud/models/vdc_spec.rb
450
+ spec/vcloud/terremark/ecloud/models/vdcs_spec.rb
446
451
  spec/vcloud/terremark/ecloud/requests/get_vdc_spec.rb
447
452
  spec/vcloud/terremark/ecloud/requests/login_spec.rb
448
453
  spec/vcloud/terremark/vcloud/requests/get_vdc_spec.rb
@@ -450,6 +455,7 @@ Gem::Specification.new do |s|
450
455
  tests/aws/helper.rb
451
456
  tests/aws/requests/ec2/address_tests.rb
452
457
  tests/aws/requests/ec2/availability_zone_tests.rb
458
+ tests/aws/requests/ec2/instance_tests.rb
453
459
  tests/aws/requests/ec2/key_pair_tests.rb
454
460
  tests/aws/requests/ec2/region_tests.rb
455
461
  tests/aws/requests/ec2/security_group_tests.rb
data/lib/fog.rb CHANGED
@@ -47,7 +47,7 @@ require 'fog/vcloud'
47
47
  module Fog
48
48
 
49
49
  unless const_defined?(:VERSION)
50
- VERSION = '0.1.4'
50
+ VERSION = '0.1.5'
51
51
  end
52
52
 
53
53
  module Mock
@@ -57,10 +57,6 @@ module Fog
57
57
  "ip-#{ip_address.gsub('.','-')}.ec2.internal"
58
58
  end
59
59
 
60
- def self.console_output
61
- 'This is my console. There are many like it, but this one is mine. My console is my best friend. It is my life. I must master it as I master my life. My console, without me, is useless. Without my console, I am useless.'
62
- end
63
-
64
60
  def self.etag
65
61
  hex(32)
66
62
  end
@@ -14,8 +14,10 @@ module Fog
14
14
  when 'instanceId', 'requestId'
15
15
  @response[name] = @value
16
16
  when 'output'
17
- if @value
18
- @response[name] = Base64.decode64(@value)
17
+ @response[name] = if @value
18
+ Base64.decode64(@value)
19
+ else
20
+ nil
19
21
  end
20
22
  when 'timestamp'
21
23
  @response[name] = Time.parse(@value)
@@ -45,7 +45,7 @@ module Fog
45
45
  }
46
46
  response
47
47
  elsif !instance
48
- raise Fog::AWS::EC2::Error.new("InvalidInstanceID.NotFound => The instance ID '#{instance_id}' does not exist")
48
+ raise Fog::AWS::EC2::NotFound.new("The instance ID '#{instance_id}' does not exist")
49
49
  elsif !address
50
50
  raise Fog::AWS::EC2::Error.new("AuthFailure => The address '#{public_ip}' does not belong to you.")
51
51
  end
@@ -56,9 +56,9 @@ module Fog
56
56
  }.merge!(data)
57
57
  response
58
58
  elsif !instance
59
- raise Fog::AWS::EC2::Error.new("InvalidInstanceID.NotFound => The instance ID '#{instance_id}' does not exist.")
59
+ raise Fog::AWS::EC2::NotFound.new("The instance ID '#{instance_id}' does not exist.")
60
60
  elsif !volume
61
- raise Fog::AWS::EC2::Error.new("InvalidVolume.NotFound => The volume '#{volume_id}' does not exist.")
61
+ raise Fog::AWS::EC2::NotFound.new("The volume '#{volume_id}' does not exist.")
62
62
  end
63
63
  else
64
64
  message = 'MissingParameter => '
@@ -76,7 +76,7 @@ module Fog
76
76
  }
77
77
  response
78
78
  else
79
- raise Fog::AWS::EC2::Error.new("InvalidGroup.NotFound => The security group '#{options['GroupName']}' does not exist")
79
+ raise Fog::AWS::EC2::NotFound.new("The security group '#{options['GroupName']}' does not exist")
80
80
  end
81
81
  end
82
82
 
@@ -36,7 +36,7 @@ module Fog
36
36
  }
37
37
  response
38
38
  else
39
- raise Fog::AWS::EC2::Error.new("InvalidGroup.NotFound => The security group '#{name}' does not exist")
39
+ raise Fog::AWS::EC2::NotFound.new("The security group '#{name}' does not exist")
40
40
  end
41
41
  end
42
42
  end
@@ -36,7 +36,7 @@ module Fog
36
36
  }
37
37
  response
38
38
  else
39
- raise Fog::AWS::EC2::Error.new("InvalidSnapshot.NotFound => The snapshot '#{snapshot_id}' does not exist.")
39
+ raise Fog::AWS::EC2::NotFound.new("The snapshot '#{snapshot_id}' does not exist.")
40
40
  end
41
41
  end
42
42
 
@@ -38,7 +38,7 @@ module Fog
38
38
  }
39
39
  response
40
40
  else
41
- raise Fog::AWS::EC2::Error.new("InvalidVolume.NotFound => The volume '#{volume_id}' does not exist.")
41
+ raise Fog::AWS::EC2::NotFound.new("The volume '#{volume_id}' does not exist.")
42
42
  end
43
43
  end
44
44
 
@@ -44,7 +44,7 @@ module Fog
44
44
  }
45
45
  response
46
46
  else
47
- raise Fog::AWS::EC2::Error.new("InvalidAddress.NotFound => Address #{public_ip.inspect} not found.")
47
+ raise Fog::AWS::EC2::NotFound.new("Address #{public_ip.inspect} not found.")
48
48
  end
49
49
  end
50
50
 
@@ -107,7 +107,7 @@ module Fog
107
107
  'ownerId' => instance['ownerId'],
108
108
  'reservationId' => instance['reservationId']
109
109
  }
110
- reservation_set[instance['reservationId']]['instancesSet'] << instance.reject{|key,value| !['amiLaunchIndex', 'blockDeviceMapping', 'dnsName', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'ipAddress', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'placement', 'privateDnsName', 'privateIpAddress', 'productCodes', 'ramdiskId', 'reason', 'rootDeviceType'].include?(key)}
110
+ reservation_set[instance['reservationId']]['instancesSet'] << instance.reject{|key,value| !['amiLaunchIndex', 'architecture', 'blockDeviceMapping', 'dnsName', 'imageId', 'instanceId', 'instanceState', 'instanceType', 'ipAddress', 'kernelId', 'keyName', 'launchTime', 'monitoring', 'placement', 'privateDnsName', 'privateIpAddress', 'productCodes', 'ramdiskId', 'reason', 'rootDeviceType'].include?(key)}
111
111
  end
112
112
  end
113
113
 
@@ -117,7 +117,7 @@ module Fog
117
117
  }
118
118
  response
119
119
  else
120
- raise Fog::AWS::EC2::Error.new("InvalidInstanceID.NotFound => The instance ID #{instance_id.inspect} does not exist")
120
+ raise Fog::AWS::EC2::NotFound.new("The instance ID #{instance_id.inspect} does not exist")
121
121
  end
122
122
  end
123
123
 
@@ -46,7 +46,7 @@ module Fog
46
46
  }
47
47
  response
48
48
  else
49
- raise Fog::AWS::EC2::Error.new("InvalidKeyPair.NotFound => The key pair #{key_name.inspect} does not exist")
49
+ raise Fog::AWS::EC2::NotFound.new("The key pair #{key_name.inspect} does not exist")
50
50
  end
51
51
  end
52
52
 
@@ -54,7 +54,7 @@ module Fog
54
54
  }
55
55
  response
56
56
  else
57
- raise Fog::AWS::EC2::Error.new("InvalidGroup.NotFound => The security group #{group_name.inspect} does not exist")
57
+ raise Fog::AWS::EC2::NotFound.new("The security group #{group_name.inspect} does not exist")
58
58
  end
59
59
  end
60
60
 
@@ -68,7 +68,7 @@ module Fog
68
68
  }
69
69
  response
70
70
  else
71
- raise Fog::AWS::EC2::Error.new("InvalidSnapshot.NotFound => The snapshot #{snapshot_id.inspect} does not exist.")
71
+ raise Fog::AWS::EC2::NotFound.new("The snapshot #{snapshot_id.inspect} does not exist.")
72
72
  end
73
73
  end
74
74
 
@@ -74,7 +74,7 @@ module Fog
74
74
  }
75
75
  response
76
76
  else
77
- raise Fog::AWS::EC2::Error.new("InvalidVolume.NotFound => The volume #{volume_id.inspect} does not exist.")
77
+ raise Fog::AWS::EC2::NotFound.new("The volume #{volume_id.inspect} does not exist.")
78
78
  end
79
79
  end
80
80
 
@@ -46,7 +46,7 @@ module Fog
46
46
  }.merge!(data)
47
47
  response
48
48
  else
49
- raise Fog::AWS::EC2::Error.new("InvalidVolume.NotFound => The volume '#{volume_id}' does not exist.")
49
+ raise Fog::AWS::EC2::NotFound.new("The volume '#{volume_id}' does not exist.")
50
50
  end
51
51
  end
52
52
 
@@ -34,13 +34,13 @@ module Fog
34
34
  response.status = 200
35
35
  response.body = {
36
36
  'instanceId' => instance_id,
37
- 'output' => Fog::AWS::Mock.console_output,
37
+ 'output' => nil,
38
38
  'requestId' => Fog::AWS::Mock.request_id,
39
39
  'timestamp' => Time.now
40
40
  }
41
41
  response
42
42
  else;
43
- raise Fog::AWS::EC2::Error.new("InvalidInstanceID.NotFound => The instance ID '#{instance_id}' does not exist")
43
+ raise Fog::AWS::EC2::NotFound.new("The instance ID '#{instance_id}' does not exist")
44
44
  end
45
45
  end
46
46
 
@@ -40,7 +40,7 @@ module Fog
40
40
  }
41
41
  response
42
42
  else
43
- raise Fog::AWS::EC2::Error.new("InvalidInstanceID.NotFound => The instance ID #{instance_id.inspect} does not exist")
43
+ raise Fog::AWS::EC2::NotFound.new("The instance ID #{instance_id.inspect} does not exist")
44
44
  end
45
45
  end
46
46
 
@@ -64,7 +64,7 @@ module Fog
64
64
  }
65
65
  response
66
66
  else
67
- raise Fog::AWS::EC2::Error.new("InvalidGroup.NotFound => The security group '#{options['GroupName']}' does not exist")
67
+ raise Fog::AWS::EC2::NotFound.new("The security group '#{options['GroupName']}' does not exist")
68
68
  end
69
69
  end
70
70
 
@@ -122,7 +122,7 @@ module Fog
122
122
  'instanceState' => { 'code' => 0, 'name' => 'pending' },
123
123
  'instanceType' => options['InstanceType'] || 'm1.small',
124
124
  'kernelId' => options['KernelId'] || Fog::AWS::Mock.kernel_id,
125
- 'keyName' => options['KeyName'] || '',
125
+ # 'keyName' => options['KeyName'],
126
126
  'launchTime' => Time.now,
127
127
  'monitoring' => { 'state' => options['Monitoring.Enabled'] || false },
128
128
  'placement' => { 'availabilityZone' => options['Placement.AvailabilityZone'] || Fog::AWS::Mock.availability_zone },
@@ -134,6 +134,7 @@ module Fog
134
134
  }
135
135
  instances_set << instance
136
136
  @data[:instances][instance_id] = instance.merge({
137
+ 'architecture' => 'i386',
137
138
  'groupSet' => group_set,
138
139
  'ownerId' => @owner_id,
139
140
  'privateIpAddress' => nil,
@@ -80,7 +80,7 @@ module Fog
80
80
 
81
81
  response
82
82
  else
83
- raise Fog::AWS::EC2::Error.new("InvalidInstanceID.NotFound => The instance ID '#{instance_id}' does not exist")
83
+ raise Fog::AWS::EC2::NotFound.new("The instance ID '#{instance_id}' does not exist")
84
84
  end
85
85
  end
86
86
 
@@ -35,10 +35,14 @@ module Fog
35
35
  end
36
36
  end
37
37
 
38
- def self.model(new_model)
39
- @model = new_model
38
+ def self.model(new_model=nil)
39
+ if new_model == nil
40
+ @model
41
+ else
42
+ @model = new_model
43
+ end
40
44
  end
41
-
45
+
42
46
  def self.aliases
43
47
  @aliases ||= {}
44
48
  end
@@ -85,7 +85,8 @@ module Fog
85
85
  module Mock
86
86
  include Common
87
87
 
88
- DATA = {
88
+ def self.mock_data
89
+ {
89
90
  :organizations =>
90
91
  [
91
92
  {
@@ -167,6 +168,7 @@ module Fog
167
168
  }
168
169
  ]
169
170
  }
171
+ end
170
172
 
171
173
  def self.error_headers
172
174
  {"X-Powered-By"=>"ASP.NET",
@@ -199,7 +201,7 @@ module Fog
199
201
  self.class.instance_eval '
200
202
  def self.data
201
203
  @data ||= Hash.new do |hash, key|
202
- hash[key] = Fog::Terremark::Shared::Mock::DATA
204
+ hash[key] = Fog::Terremark::Shared::Mock.mock_data
203
205
  end
204
206
  end'
205
207
  self.class.instance_eval '
@@ -39,7 +39,7 @@ module Fog
39
39
  end
40
40
  org_list = @login_results.body.organizations
41
41
  if organization = @login_results.body.organizations.first
42
- URI.parse(organization[:href])
42
+ organization[:href]
43
43
  else
44
44
  nil
45
45
  end
@@ -132,6 +132,23 @@ module Fog
132
132
  :versions => [
133
133
  { :version => "v0.8", :login_url => "https://fakey.com/api/v0.8/login", :supported => true }
134
134
  ],
135
+ :vdc_resources => [
136
+ {
137
+ :type => "application/vnd.vmware.vcloud.vApp+xml",
138
+ :href => "https://fakey.com/api/v0.8/vapp/61",
139
+ :name => "Foo App 1"
140
+ },
141
+ {
142
+ :type => "application/vnd.vmware.vcloud.vApp+xml",
143
+ :href => "https://fakey.com/api/v0.8/vapp/62",
144
+ :name => "Bar App 1"
145
+ },
146
+ {
147
+ :type => "application/vnd.vmware.vcloud.vApp+xml",
148
+ :href => "https://fakey.com/api/v0.8/vapp/63",
149
+ :name => "Bar App 2"
150
+ }
151
+ ],
135
152
  :organizations =>
136
153
  [
137
154
  {
@@ -250,7 +267,11 @@ module Fog
250
267
  class <<self
251
268
  def new(credentials = {})
252
269
  unless @required
270
+ require 'fog/vcloud/model'
271
+ require 'fog/vcloud/collection'
253
272
  require 'fog/vcloud/parser'
273
+ require 'fog/vcloud/models/vdc'
274
+ require 'fog/vcloud/models/vdcs'
254
275
  require 'fog/vcloud/terremark/vcloud'
255
276
  require 'fog/vcloud/terremark/ecloud'
256
277
  require 'fog/vcloud/requests/get_organization'
@@ -263,11 +284,12 @@ module Fog
263
284
  require 'fog/vcloud/parsers/login'
264
285
 
265
286
  Struct.new("VcloudLink", :rel, :href, :type, :name)
266
- Struct.new("VcloudVdc", :links, :href, :type, :name, :xmlns, :allocation_model, :description)
287
+ Struct.new("VcloudVdc", :links, :resource_entities, :networks, :cpu_capacity, :storage_capacity, :memory_capacity, :href, :type, :name, :xmlns,
288
+ :allocation_model, :network_quota, :nic_quota, :vm_quota, :enabled, :description)
267
289
  Struct.new("VcloudOrganization", :links, :name, :href, :type, :xmlns, :description)
268
290
  Struct.new("VcloudVersion", :version, :login_url, :supported)
269
291
  Struct.new("VcloudOrgList", :organizations, :xmlns)
270
- Struct.new("VcloudOrgLink", :name, :href, :type)
292
+ Struct.new("VcloudXCapacity", :units, :allocated, :used, :limit)
271
293
  @required = true
272
294
  end
273
295
 
@@ -0,0 +1,66 @@
1
+ module Fog
2
+ module Vcloud
3
+ class Collection < Fog::Collection
4
+
5
+ class << self
6
+
7
+ def inherited(klass)
8
+ klass.instance_variable_set(:@model, @model)
9
+ klass.all_request @all_request
10
+ klass.vcloud_type @vcloud_type
11
+ klass.get_request @get_request
12
+ end
13
+
14
+ def all_request(all_request=nil)
15
+ unless all_request
16
+ @all_request
17
+ else
18
+ @all_request = all_request
19
+ class_eval <<-EOS, __FILE__, __LINE__
20
+ def all
21
+ data = self.class.all_request.call(self).body.links.select do |link|
22
+ link.type == self.class.vcloud_type
23
+ end.map { |link| {:href => link.href, :name => link.name } }
24
+ load(data)
25
+ end
26
+ EOS
27
+ end
28
+ end
29
+
30
+ def vcloud_type(vcloud_type=nil)
31
+ unless vcloud_type
32
+ @vcloud_type
33
+ else
34
+ @vcloud_type = vcloud_type
35
+ end
36
+ end
37
+
38
+ def get_request(get_request=nil)
39
+ unless get_request
40
+ @get_request
41
+ else
42
+ @get_request = get_request
43
+ class_eval <<-EOS, __FILE__, __LINE__
44
+ def get(uri)
45
+ item = new(:href => uri)
46
+ item.reload
47
+ end
48
+ def get_raw(uri)
49
+ connection.#{@get_request}(uri)
50
+ end
51
+ EOS
52
+ end
53
+ end
54
+ end
55
+
56
+ def [](index)
57
+ self.slice(index).reload
58
+ end
59
+
60
+ def reload
61
+ self.all
62
+ end
63
+
64
+ end
65
+ end
66
+ end