fog 0.3.16 → 0.3.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/Gemfile.lock +1 -1
  2. data/README.rdoc +17 -12
  3. data/fog.gemspec +10 -5
  4. data/lib/fog.rb +1 -1
  5. data/lib/fog/aws/models/storage/directory.rb +22 -0
  6. data/lib/fog/aws/models/storage/file.rb +15 -0
  7. data/lib/fog/aws/storage.rb +8 -0
  8. data/lib/fog/core/collection.rb +9 -8
  9. data/lib/fog/core/compute.rb +1 -1
  10. data/lib/fog/google/models/storage/directory.rb +23 -1
  11. data/lib/fog/google/models/storage/file.rb +16 -1
  12. data/lib/fog/google/parsers/storage/access_control_list.rb +16 -14
  13. data/lib/fog/local/models/storage/directory.rb +8 -0
  14. data/lib/fog/local/models/storage/file.rb +4 -0
  15. data/lib/fog/rackspace/cdn.rb +3 -3
  16. data/lib/fog/rackspace/models/storage/directory.rb +18 -0
  17. data/lib/fog/rackspace/models/storage/file.rb +7 -0
  18. data/lib/fog/rackspace/requests/cdn/{get_cdn_containers.rb → get_containers.rb} +3 -3
  19. data/lib/fog/rackspace/requests/cdn/{head_cdn_container.rb → head_container.rb} +3 -3
  20. data/lib/fog/rackspace/requests/cdn/{put_cdn_container.rb → put_container.rb} +3 -3
  21. data/lib/fog/rackspace/storage.rb +10 -0
  22. data/lib/fog/vcloud.rb +32 -153
  23. data/lib/fog/vcloud/collection.rb +18 -0
  24. data/lib/fog/vcloud/mock_data_classes.rb +701 -0
  25. data/lib/fog/vcloud/requests/get_network.rb +8 -8
  26. data/lib/fog/vcloud/requests/get_organization.rb +10 -10
  27. data/lib/fog/vcloud/requests/get_vdc.rb +18 -18
  28. data/lib/fog/vcloud/requests/get_versions.rb +3 -3
  29. data/lib/fog/vcloud/requests/login.rb +2 -2
  30. data/lib/fog/vcloud/terremark/ecloud.rb +65 -109
  31. data/lib/fog/vcloud/terremark/ecloud/models/catalog.rb +1 -0
  32. data/lib/fog/vcloud/terremark/ecloud/models/firewall_acls.rb +1 -0
  33. data/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb +1 -0
  34. data/lib/fog/vcloud/terremark/ecloud/models/ip.rb +1 -1
  35. data/lib/fog/vcloud/terremark/ecloud/models/ips.rb +1 -0
  36. data/lib/fog/vcloud/terremark/ecloud/models/network.rb +3 -2
  37. data/lib/fog/vcloud/terremark/ecloud/models/networks.rb +1 -0
  38. data/lib/fog/vcloud/terremark/ecloud/models/nodes.rb +1 -0
  39. data/lib/fog/vcloud/terremark/ecloud/models/public_ips.rb +1 -0
  40. data/lib/fog/vcloud/terremark/ecloud/models/server.rb +20 -8
  41. data/lib/fog/vcloud/terremark/ecloud/models/servers.rb +1 -0
  42. data/lib/fog/vcloud/terremark/ecloud/models/tasks.rb +1 -0
  43. data/lib/fog/vcloud/terremark/ecloud/models/vdcs.rb +2 -0
  44. data/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb +4 -8
  45. data/lib/fog/vcloud/terremark/ecloud/requests/add_node.rb +4 -7
  46. data/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb +18 -20
  47. data/lib/fog/vcloud/terremark/ecloud/requests/configure_node.rb +6 -7
  48. data/lib/fog/vcloud/terremark/ecloud/requests/configure_vapp.rb +40 -9
  49. data/lib/fog/vcloud/terremark/ecloud/requests/delete_internet_service.rb +2 -10
  50. data/lib/fog/vcloud/terremark/ecloud/requests/delete_node.rb +2 -6
  51. data/lib/fog/vcloud/terremark/ecloud/requests/delete_vapp.rb +13 -1
  52. data/lib/fog/vcloud/terremark/ecloud/requests/get_catalog.rb +6 -6
  53. data/lib/fog/vcloud/terremark/ecloud/requests/get_catalog_item.rb +6 -7
  54. data/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb +34 -33
  55. data/lib/fog/vcloud/terremark/ecloud/requests/get_network.rb +23 -24
  56. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb +10 -13
  57. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_ip.rb +15 -19
  58. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_ips.rb +20 -22
  59. data/lib/fog/vcloud/terremark/ecloud/requests/get_node.rb +12 -15
  60. data/lib/fog/vcloud/terremark/ecloud/requests/get_nodes.rb +11 -12
  61. data/lib/fog/vcloud/terremark/ecloud/requests/get_public_ip.rb +5 -4
  62. data/lib/fog/vcloud/terremark/ecloud/requests/get_public_ips.rb +9 -8
  63. data/lib/fog/vcloud/terremark/ecloud/requests/get_vapp.rb +33 -17
  64. data/lib/fog/vcloud/terremark/ecloud/requests/get_vdc.rb +54 -53
  65. data/lib/fog/vcloud/terremark/ecloud/requests/instantiate_vapp_template.rb +13 -19
  66. data/lib/fog/vcloud/terremark/ecloud/requests/power_off.rb +9 -2
  67. data/lib/fog/vcloud/terremark/ecloud/requests/power_on.rb +2 -4
  68. data/spec/vcloud/bin_spec.rb +3 -6
  69. data/spec/vcloud/models/vdc_spec.rb +8 -8
  70. data/spec/vcloud/requests/get_network_spec.rb +8 -8
  71. data/spec/vcloud/requests/get_organization_spec.rb +9 -9
  72. data/spec/vcloud/requests/get_vdc_spec.rb +7 -7
  73. data/spec/vcloud/requests/get_versions_spec.rb +1 -1
  74. data/spec/vcloud/requests/login_spec.rb +2 -2
  75. data/spec/vcloud/spec_helper.rb +45 -30
  76. data/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb +10 -14
  77. data/spec/vcloud/terremark/ecloud/models/ip_spec.rb +5 -8
  78. data/spec/vcloud/terremark/ecloud/models/ips_spec.rb +2 -2
  79. data/spec/vcloud/terremark/ecloud/models/network_spec.rb +15 -16
  80. data/spec/vcloud/terremark/ecloud/models/node_spec.rb +7 -7
  81. data/spec/vcloud/terremark/ecloud/models/nodes_spec.rb +1 -1
  82. data/spec/vcloud/terremark/ecloud/models/public_ip_spec.rb +4 -8
  83. data/spec/vcloud/terremark/ecloud/models/server_spec.rb +42 -0
  84. data/spec/vcloud/terremark/ecloud/models/vdc_spec.rb +7 -7
  85. data/spec/vcloud/terremark/ecloud/models/vdcs_spec.rb +1 -1
  86. data/spec/vcloud/terremark/ecloud/requests/add_internet_service_spec.rb +13 -18
  87. data/spec/vcloud/terremark/ecloud/requests/add_node_spec.rb +9 -5
  88. data/spec/vcloud/terremark/ecloud/requests/configure_internet_service_spec.rb +5 -7
  89. data/spec/vcloud/terremark/ecloud/requests/configure_node_spec.rb +22 -28
  90. data/spec/vcloud/terremark/ecloud/requests/configure_vapp_spec.rb +71 -0
  91. data/spec/vcloud/terremark/ecloud/requests/delete_internet_service_spec.rb +7 -9
  92. data/spec/vcloud/terremark/ecloud/requests/delete_node_spec.rb +3 -7
  93. data/spec/vcloud/terremark/ecloud/requests/delete_vapp_spec.rb +83 -0
  94. data/spec/vcloud/terremark/ecloud/requests/get_catalog_item_spec.rb +6 -5
  95. data/spec/vcloud/terremark/ecloud/requests/get_catalog_spec.rb +2 -2
  96. data/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb +31 -42
  97. data/spec/vcloud/terremark/ecloud/requests/get_network_ip_spec.rb +4 -7
  98. data/spec/vcloud/terremark/ecloud/requests/get_network_ips_spec.rb +1 -1
  99. data/spec/vcloud/terremark/ecloud/requests/get_network_spec.rb +19 -11
  100. data/spec/vcloud/terremark/ecloud/requests/get_node_spec.rb +8 -8
  101. data/spec/vcloud/terremark/ecloud/requests/get_nodes_spec.rb +11 -11
  102. data/spec/vcloud/terremark/ecloud/requests/get_public_ip_spec.rb +4 -5
  103. data/spec/vcloud/terremark/ecloud/requests/get_public_ips_spec.rb +6 -6
  104. data/spec/vcloud/terremark/ecloud/requests/get_vapp_spec.rb +36 -19
  105. data/spec/vcloud/terremark/ecloud/requests/get_vdc_spec.rb +21 -18
  106. data/spec/vcloud/terremark/ecloud/requests/instantiate_vapp_template_spec.rb +27 -17
  107. data/spec/vcloud/terremark/ecloud/requests/power_off_spec.rb +34 -0
  108. data/spec/vcloud/terremark/ecloud/requests/power_on_spec.rb +3 -4
  109. data/spec/vcloud/vcloud_spec.rb +2 -2
  110. data/tests/helpers/storage/directory_tests.rb +8 -0
  111. data/tests/helpers/storage/file_tests.rb +4 -0
  112. metadata +11 -6
@@ -103,16 +103,17 @@ module Fog
103
103
 
104
104
  def instantiate_vapp_template(catalog_item_uri, options = {})
105
105
  validate_instantiate_vapp_template_options(catalog_item_uri, options)
106
- catalog_item, _ = catalog_item_and_vdc_from_catalog_item_uri(catalog_item_uri)
106
+ catalog_item = mock_data.catalog_item_from_href(catalog_item_uri)
107
107
 
108
108
  xml = nil
109
- if vdc = vdc_from_uri(options[:vdc_uri])
110
- vapp_id = rand(1000)
111
- vapp_uri = Fog::Vcloud::Terremark::Ecloud::Mock.vapp_href(:id => vapp_id)
112
- options.update(:id => vapp_id.to_s, :href => vapp_uri, :disks => catalog_item[:disks], :ip => random_ip_in_network(options[:network_uri]), :status => 2)
113
- vdc[:vms] << options
114
-
115
- xml = generate_instantiate_vapp_template_response(vdc[:href], options[:name], vapp_uri)
109
+ if vdc = mock_data.vdc_from_href(options[:vdc_uri])
110
+ if network = mock_data.network_from_href(options[:network_uri])
111
+ new_vm = MockVirtualMachine.new({ :name => options[:name], :ip => network.random_ip, :cpus => options[:cpus], :memory => options[:memory] }, vdc)
112
+ new_vm.disks.push(*catalog_item.disks.dup)
113
+ vdc.virtual_machines << new_vm
114
+
115
+ xml = generate_instantiate_vapp_template_response(new_vm)
116
+ end
116
117
  end
117
118
 
118
119
  if xml
@@ -124,23 +125,16 @@ module Fog
124
125
 
125
126
  private
126
127
 
127
- def random_ip_in_network(network_uri)
128
- network = mock_data[:organizations].map { |org| org[:vdcs].map { |vdc| vdc[:networks] } }.flatten.detect { |network| network[:href] == network_uri }
129
- subnet_ipaddr = IPAddr.new(network[:subnet])
130
- ips = subnet_ipaddr.to_range.to_a[3..-2]
131
- ips[rand(ips.size)].to_s
132
- end
133
-
134
- def generate_instantiate_vapp_template_response(vdc_uri, vapp_name, vapp_uri)
128
+ def generate_instantiate_vapp_template_response(vapp)
135
129
  builder = Builder::XmlMarkup.new
136
130
  builder.VApp(xmlns.merge(
137
- :href => vapp_uri,
131
+ :href => vapp.href,
138
132
  :type => "application/vnd.vmware.vcloud.vApp+xml",
139
- :name => vapp_name,
133
+ :name => vapp.name,
140
134
  :status => 0,
141
135
  :size => 4
142
136
  )) {
143
- builder.Link(:rel => "up", :href => vdc_uri, :type => "application/vnd.vmware.vcloud.vdc+xml")
137
+ builder.Link(:rel => "up", :href => vapp._parent.href, :type => "application/vnd.vmware.vcloud.vdc+xml")
144
138
  }
145
139
  end
146
140
  end
@@ -8,8 +8,15 @@ module Fog
8
8
  end
9
9
 
10
10
  class Mock
11
- def power_off(off_uri)
12
- Fog::Mock.not_implemented
11
+ def power_off(vapp_uri)
12
+ if vapp = mock_data.virtual_machine_from_href(vapp_uri)
13
+ vapp.power_off!
14
+
15
+ builder = Builder::XmlMarkup.new
16
+ mock_it 200, builder.Task(xmlns)
17
+ else
18
+ mock_error 200, "401 Unauthorized"
19
+ end
13
20
  end
14
21
  end
15
22
  end
@@ -9,10 +9,8 @@ module Fog
9
9
 
10
10
  class Mock
11
11
  def power_on(vapp_uri)
12
- vapp, vdc = vapp_and_vdc_from_vapp_uri(vapp_uri)
13
-
14
- if vapp
15
- vapp[:status] = 4
12
+ if vapp = mock_data.virtual_machine_from_href(vapp_uri)
13
+ vapp.power_on!
16
14
 
17
15
  builder = Builder::XmlMarkup.new
18
16
  mock_it 200, builder.Task(xmlns)
@@ -1,21 +1,18 @@
1
- require 'spec_helper'
1
+ require 'spec/vcloud/spec_helper'
2
2
 
3
3
  describe Vcloud do
4
4
  it { should be_initialized }
5
5
 
6
- it { should have(3).services }
6
+ it { should have_at_least(1).services }
7
7
 
8
8
  describe "#registered_services" do
9
9
  subject { Vcloud.registered_services }
10
10
 
11
- it { should == ":ecloud, :etest, :vcloud" }
11
+ it { should have_at_least(1).services }
12
12
  end
13
13
 
14
14
  describe "when indexing it like an array" do
15
15
  describe "with a service that exists" do
16
- before do
17
- Fog::Vcloud.should_receive(:new).and_return(true)
18
- end
19
16
  it "should return something when indexed with a configured service" do
20
17
  Vcloud[:ecloud].should_not be_nil
21
18
  end
@@ -21,24 +21,24 @@ if Fog.mocking?
21
21
  end
22
22
 
23
23
  context "as a collection member" do
24
- subject { @vcloud.vdcs[0].reload; @vcloud.vdcs[0] }
24
+ subject { @vcloud.vdcs[0].reload }
25
25
 
26
26
  it { should be_an_instance_of Fog::Vcloud::Vdc }
27
27
 
28
- its(:href) { should == @mock_vdc[:href] }
29
- its(:identity) { should == @mock_vdc[:href] }
30
- its(:name) { should == @mock_vdc[:name] }
28
+ its(:href) { should == @mock_vdc.href }
29
+ its(:identity) { should == @mock_vdc.href }
30
+ its(:name) { should == @mock_vdc.name }
31
31
  its(:other_links) { should have(7).items }
32
32
  its(:resource_entities) { should have(3).items }
33
33
  its(:available_networks) { should have(2).items }
34
34
 
35
35
  its(:compute_capacity) { should be_an_instance_of Hash }
36
- its(:compute_capacity) { should == {:Cpu =>
37
- {:Units => "Mhz", :Allocated => @mock_vdc[:cpu][:allocated], :Limit => @mock_vdc[:cpu][:allocated]},
36
+ its(:compute_capacity) { should == {:Cpu =>
37
+ {:Units => "Mhz", :Allocated => @mock_vdc.cpu_allocated.to_s, :Limit => @mock_vdc.cpu_allocated.to_s},
38
38
  :Memory =>
39
- {:Units => "MB", :Allocated => @mock_vdc[:memory][:allocated], :Limit => @mock_vdc[:memory][:allocated]}} }
39
+ {:Units => "MB", :Allocated => @mock_vdc.memory_allocated.to_s, :Limit => @mock_vdc.memory_allocated.to_s}} }
40
40
  its(:storage_capacity) { should be_an_instance_of Hash }
41
- its(:storage_capacity) { should == {:Limit => @mock_vdc[:storage][:allocated], :Units=>"MB", :Allocated => @mock_vdc[:storage][:allocated]} }
41
+ its(:storage_capacity) { should == {:Limit => @mock_vdc.storage_allocated.to_s, :Units=>"MB", :Allocated => @mock_vdc.storage_allocated.to_s} }
42
42
 
43
43
  its(:vm_quota) { should == "0" }
44
44
  its(:nic_quota) { should == "0" }
@@ -8,7 +8,7 @@ if Fog.mocking?
8
8
 
9
9
  describe :get_network, :type => :vcloud_request do
10
10
  context "with a valid network uri" do
11
- before { @network = @vcloud.get_network(URI.parse(@mock_network[:href])) }
11
+ before { @network = @vcloud.get_network(URI.parse(@mock_network.href)) }
12
12
  subject { @network }
13
13
 
14
14
  it_should_behave_like "all responses"
@@ -21,13 +21,13 @@ if Fog.mocking?
21
21
 
22
22
  it_should_behave_like "it has the standard vcloud v0.8 xmlns attributes" # 3 keys
23
23
  it { should have_key_with_value :type, "application/vnd.vmware.vcloud.network+xml" }
24
- it { should have_key_with_value :Features, "" }
25
- it { should have_key_with_value :Description, @mock_network[:name] }
26
- it { should have_key_with_value :href, @mock_network[:href] }
27
- it { should have_key_with_value :name, @mock_network[:name] }
28
- it { should have_key_with_value :Configuration, {:Gateway => @mock_network[:gateway],
29
- :Netmask => @mock_network[:netmask],
30
- :Dns => @mock_network[:dns] } }
24
+ it { should have_key_with_value :Features, {:FenceMode => "isolated"} }
25
+ it { should have_key_with_value :Description, @mock_network.name }
26
+ it { should have_key_with_value :href, @mock_network.href }
27
+ it { should have_key_with_value :name, @mock_network.name }
28
+ it { should have_key_with_value :Configuration, {:Gateway => @mock_network.gateway,
29
+ :Netmask => @mock_network.netmask,
30
+ :Dns => @mock_network.dns } }
31
31
  end
32
32
  end
33
33
  context "with a network uri that doesn't exist" do
@@ -23,20 +23,20 @@ if Fog.mocking?
23
23
  it { should have(6).keys }
24
24
 
25
25
  it_should_behave_like "it has the standard vcloud v0.8 xmlns attributes" # 3 keys
26
- it { should have_key_with_value :href, @mock_organization[:info][:href] }
27
- it { should have_key_with_value :name, @mock_organization[:info][:name] }
28
- it { should have_key_with_array :Link, @mock_organization[:vdcs].map { |vdc|
26
+ it { should have_key_with_value :href, @mock_organization.href }
27
+ it { should have_key_with_value :name, @mock_organization.name }
28
+ it { should have_key_with_array :Link, @mock_organization.vdcs.map { |vdc|
29
29
  [{ :type => "application/vnd.vmware.vcloud.vdc+xml",
30
- :href => vdc[:href],
31
- :name => vdc[:name],
30
+ :href => vdc.href,
31
+ :name => vdc.name,
32
32
  :rel => "down" },
33
33
  { :type => "application/vnd.vmware.vcloud.catalog+xml",
34
- :href => vdc[:href] + "/catalog",
35
- :name => vdc[:name] + " Catalog",
34
+ :href => vdc.catalog.href,
35
+ :name => vdc.catalog.name,
36
36
  :rel => "down" },
37
37
  { :type => "application/vnd.vmware.vcloud.tasksList+xml",
38
- :href => vdc[:href] + "/tasksList",
39
- :name => vdc[:name] + " Tasks List",
38
+ :href => vdc.task_list.href,
39
+ :name => vdc.task_list.name,
40
40
  :rel => "down" }]
41
41
  }.flatten }
42
42
 
@@ -12,7 +12,7 @@ if Fog.mocking?
12
12
 
13
13
  describe :get_vdc, :type => :vcloud_request do
14
14
  context "with a valid vdc uri" do
15
- before { @vdc = @vcloud.get_vdc(URI.parse(@mock_vdc[:href])) }
15
+ before { @vdc = @vcloud.get_vdc(URI.parse(@mock_vdc.href)) }
16
16
  subject { @vdc }
17
17
 
18
18
  it_should_behave_like "all responses"
@@ -25,10 +25,10 @@ if Fog.mocking?
25
25
 
26
26
  it_should_behave_like "it has the standard vcloud v0.8 xmlns attributes" # 3 keys
27
27
 
28
- its(:name) { should == @mock_vdc[:name] }
29
- its(:href) { should == @mock_vdc[:href] }
28
+ its(:name) { should == @mock_vdc.name }
29
+ its(:href) { should == @mock_vdc.href }
30
30
  its(:VmQuota) { should == "0" }
31
- its(:Description) { should == @mock_vdc[:name] + " VDC" }
31
+ its(:Description) { should == @mock_vdc.name + " VDC" }
32
32
  its(:NicQuota) { should == "0" }
33
33
  its(:IsEnabled) { should == "true" }
34
34
  its(:NetworkQuota) { should == "0" }
@@ -40,10 +40,10 @@ if Fog.mocking?
40
40
  specify { resource_entities.should have(3).vapps }
41
41
  #FIXME: test for the resources
42
42
 
43
- its(:ComputeCapacity) { should == {:Memory => { :Units => "MB", :Allocated => @mock_vdc[:memory][:allocated], :Limit => @mock_vdc[:memory][:allocated] },
44
- :Cpu => { :Units => "Mhz", :Allocated => @mock_vdc[:cpu][:allocated], :Limit => @mock_vdc[:cpu][:allocated] } } }
43
+ its(:ComputeCapacity) { should == {:Memory => { :Units => "MB", :Allocated => @mock_vdc.memory_allocated.to_s, :Limit => @mock_vdc.memory_allocated.to_s },
44
+ :Cpu => { :Units => "Mhz", :Allocated => @mock_vdc.cpu_allocated.to_s, :Limit => @mock_vdc.cpu_allocated.to_s } } }
45
45
 
46
- its(:StorageCapacity) { should == {:Units => "MB", :Allocated => @mock_vdc[:storage][:allocated], :Limit => @mock_vdc[:storage][:allocated] } }
46
+ its(:StorageCapacity) { should == {:Units => "MB", :Allocated => @mock_vdc.storage_allocated.to_s, :Limit => @mock_vdc.storage_allocated.to_s } }
47
47
 
48
48
  let(:available_networks) { subject[:AvailableNetworks][:Network] }
49
49
  specify { available_networks.should have(2).networks }
@@ -44,7 +44,7 @@ if Fog.mocking?
44
44
 
45
45
  describe "body" do
46
46
  subject { @vcloud.get_versions( @vcloud.versions_uri ).body }
47
- its(:VersionInfo) { should == { :LoginUrl => @mock_version[:login_url] , :Version => @mock_version[:version] } }
47
+ its(:VersionInfo) { should == { :LoginUrl => @mock_version.login_url , :Version => @mock_version.version } }
48
48
  end
49
49
  end
50
50
  else
@@ -12,8 +12,8 @@ if Fog.mocking?
12
12
  describe "#body" do
13
13
  subject { @vcloud.login.body }
14
14
  its(:Org) { should == { :type => "application/vnd.vmware.vcloud.org+xml",
15
- :href => @mock_organization[:info][:href],
16
- :name => @mock_organization[:info][:name]} }
15
+ :href => @mock_organization.href,
16
+ :name => @mock_organization.name} }
17
17
  end
18
18
  end
19
19
  else
@@ -216,16 +216,36 @@ Spec::Example::ExampleGroupFactory.register(:vcloud_request, Class.new(Spec::Exa
216
216
  Spec::Example::ExampleGroupFactory.register(:tmrk_ecloud_request, Class.new(Spec::Example::ExampleGroup))
217
217
  Spec::Example::ExampleGroupFactory.register(:tmrk_vcloud_request, Class.new(Spec::Example::ExampleGroup))
218
218
 
219
+ def setup_generic_mock_data
220
+ @mock_version = @mock_data.versions.first
221
+ @mock_organization = @mock_data.organizations.first
222
+ @mock_vdc = @mock_organization.vdcs.first
223
+ @mock_vm = @mock_vdc.virtual_machines.first
224
+ @mock_network = @mock_vdc.networks.first
225
+ end
226
+
219
227
  def setup_ecloud_mock_data
220
- @base_url = Fog::Vcloud::Terremark::Ecloud::Mock.base_url
221
- @mock_data = Fog::Vcloud::Terremark::Ecloud::Mock.data
222
- @mock_version = @mock_data[:versions].first
223
- @mock_organization = @mock_data[:organizations].first
224
- @mock_vdc = @mock_organization[:vdcs].first
225
- @mock_public_ip = @mock_vdc[:public_ips].first
226
- @mock_service = @mock_public_ip[:services].first
227
- @mock_node = @mock_service[:nodes].first
228
- @mock_network = @mock_vdc[:networks].first
228
+ @base_url = Fog::Vcloud::Terremark::Ecloud::Mock.base_url
229
+ @mock_data = Fog::Vcloud::Terremark::Ecloud::Mock.data
230
+ setup_generic_mock_data
231
+ @mock_vdc_service_collection = @mock_vdc.internet_service_collection
232
+ @mock_public_ip_collection = @mock_vdc.public_ip_collection
233
+ @mock_public_ip = @mock_public_ip_collection.items.first
234
+ @mock_service_collection = @mock_public_ip.internet_service_collection
235
+ @mock_service = @mock_service_collection.items.first
236
+ @mock_node_collection = @mock_service.node_collection
237
+ @mock_node = @mock_node_collection.items.first
238
+ @mock_catalog = @mock_vdc.catalog
239
+ @mock_catalog_item = @mock_catalog.items.first
240
+ @mock_network_ip_collection = @mock_network.ip_collection
241
+ @mock_network_ip = @mock_network_ip_collection.items.values.first
242
+ @mock_network_extensions = @mock_network.extensions
243
+ end
244
+
245
+ def setup_vcloud_mock_data
246
+ @base_url = Fog::Vcloud::Mock.base_url
247
+ @mock_data = Fog::Vcloud::Mock.data
248
+ setup_generic_mock_data
229
249
  end
230
250
 
231
251
  Spec::Runner.configure do |config|
@@ -238,27 +258,17 @@ Spec::Runner.configure do |config|
238
258
  end
239
259
 
240
260
  config.before(:all, :type => :mock_vcloud_model) do
241
- @base_url = Fog::Vcloud::Mock.base_url
242
- @mock_data = Fog::Vcloud::Mock.data
243
- @mock_version = @mock_data[:versions][0]
244
- @mock_organization = @mock_data[:organizations][0]
245
- @mock_vdc = @mock_organization[:vdcs][0]
246
- @mock_network = @mock_vdc[:networks][0]
247
- end
248
- config.before(:all, :type => :mock_vcloud_request) do
249
- @mock_data = Fog::Vcloud::Mock.data
250
- @base_url = Fog::Vcloud::Mock.base_url
251
- @mock_version = @mock_data[:versions][0]
252
- @mock_organization = @mock_data[:organizations][0]
253
- @mock_vdc = @mock_organization[:vdcs][0]
254
- @mock_network = @mock_vdc[:networks][0]
255
- end
256
- config.before(:all, :type => :mock_vcloud_model) do
261
+ Fog::Vcloud::Mock.data_reset
262
+ setup_vcloud_mock_data
257
263
  @vcloud = Fog::Vcloud.new(:username => "foo", :password => "bar", :versions_uri => "http://fakey.com/api/versions")
258
264
  end
259
- config.before(:each, :type => :mock_vcloud_request) do
265
+
266
+ config.before(:all, :type => :mock_vcloud_request) do
267
+ Fog::Vcloud::Mock.data_reset
268
+ setup_vcloud_mock_data
260
269
  @vcloud = Fog::Vcloud.new(:username => "foo", :password => "bar", :versions_uri => "http://fakey.com/api/versions")
261
270
  end
271
+
262
272
  config.before(:each, :type => :mock_tmrk_ecloud_request) do
263
273
  Fog::Vcloud::Mock.data_reset
264
274
  Fog::Vcloud::Terremark::Ecloud::Mock.data_reset
@@ -312,6 +322,11 @@ Spec::Matchers.define :have_key_with_array do |expected_key, expected_array|
312
322
  match do |actual|
313
323
  actual[expected_key].all? { |item| expected_array.include?(item) } && actual[expected_key].length == expected_array.length
314
324
  end
325
+ failure_message_for_should do |actual|
326
+ "Items not found in array:\n#{expected_array.select { |expected_item| !actual[expected_key].include?(expected_item) }.map { |item| item.inspect }.join("\n")}\n" +
327
+ "Orignal items:\n#{actual[expected_key].map { |item| item.inspect }.join("\n") }\n"+
328
+ "Length Difference: #{expected_array.length - actual[expected_key].length}"
329
+ end
315
330
  end
316
331
 
317
332
  Spec::Matchers.define :have_headers_denoting_a_content_type_of do |expected|
@@ -332,8 +347,8 @@ Spec::Matchers.define :be_a_vapp_link_to do |expected|
332
347
  match do |actual|
333
348
  actual.is_a?(Hash) and
334
349
  actual[:type] == "application/vnd.vmware.vcloud.vApp+xml" and
335
- actual[:href] == expected[:href] and
336
- actual[:name] == expected[:name]
350
+ actual[:href] == expected.href and
351
+ actual[:name] == expected.name
337
352
  end
338
353
  end
339
354
 
@@ -341,8 +356,8 @@ Spec::Matchers.define :be_a_network_link_to do |expected|
341
356
  match do |actual|
342
357
  actual.is_a?(Hash) and
343
358
  actual[:type] == "application/vnd.vmware.vcloud.network+xml" and
344
- actual[:href] == expected[:href] and
345
- actual[:name] == expected[:name]
359
+ actual[:href] == expected.href and
360
+ actual[:name] == expected.name
346
361
  end
347
362
  end
348
363
 
@@ -2,10 +2,6 @@ require File.join(File.dirname(__FILE__),'..','..','..','spec_helper')
2
2
 
3
3
  if Fog.mocking?
4
4
  describe "Fog::Vcloud::Terremark::Ecloud::InternetService", :type => :mock_tmrk_ecloud_model do
5
- before do
6
- @mock_service_uri = "#{@base_url}/extensions/internetService/#{@mock_service[:id]}"
7
- end
8
-
9
5
  subject { @vcloud.vdcs[0].public_ips[0].internet_services[0] }
10
6
 
11
7
  describe :class do
@@ -35,17 +31,17 @@ if Fog.mocking?
35
31
 
36
32
  it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::InternetService }
37
33
 
38
- its(:href) { should == @mock_service_uri }
39
- its(:identity) { should == @mock_service_uri }
40
- its(:name) { should == @mock_service[:name] }
41
- its(:id) { should == @mock_service[:id] }
42
- its(:protocol) { should == @mock_service[:protocol] }
43
- its(:port) { should == @mock_service[:port] }
44
- its(:enabled) { should == @mock_service[:enabled] }
45
- its(:description) { should == @mock_service[:description] }
34
+ its(:href) { should == @mock_service.href }
35
+ its(:identity) { should == @mock_service.href }
36
+ its(:name) { should == @mock_service.name }
37
+ its(:id) { should == @mock_service.object_id.to_s }
38
+ its(:protocol) { should == @mock_service.protocol }
39
+ its(:port) { should == @mock_service.port.to_s }
40
+ its(:enabled) { should == @mock_service.enabled.to_s }
41
+ its(:description) { should == @mock_service.description }
46
42
  its(:public_ip) { should == public_ip }
47
- its(:timeout) { should == @mock_service[:timeout] }
48
- its(:redirect_url) { should == @mock_service[:redirect_url] }
43
+ its(:timeout) { should == @mock_service.timeout.to_s }
44
+ its(:redirect_url) { should == @mock_service.redirect_url }
49
45
  its(:monitor) { should == nil }
50
46
 
51
47
  specify { composed_public_ip_data[:href].should == public_ip[:Href].to_s }
@@ -12,22 +12,19 @@ if Fog.mocking?
12
12
  end
13
13
 
14
14
  context "with no uri" do
15
-
16
15
  subject { Fog::Vcloud::Terremark::Ecloud::Ip.new() }
17
- it { should have_all_attributes_be_nil }
18
16
 
17
+ it { should have_all_attributes_be_nil }
19
18
  end
20
19
 
21
20
  context "as a collection member" do
22
- subject { @vcloud.vdcs[0].networks[0].ips[0].reload; @vcloud.vdcs[0].networks[0].ips[0] }
23
- let(:status) { @mock_network[:ips].keys.include?(@vcloud.vdcs[0].networks[0].ips[0].name) ? "Assigned" : nil }
24
- let(:server) { @mock_network[:ips][@vcloud.vdcs[0].networks[0].ips[0].name] }
21
+ subject { @ip = @vcloud.vdcs[0].networks[0].ips[0] }
25
22
 
26
23
  it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::Ip }
27
24
 
28
- its(:name) { should == IPAddr.new(@mock_network[:name]).to_range.to_a[3].to_s }
29
- its(:status) { should == status }
30
- its(:server) { should == server }
25
+ its(:name) { should == @mock_data.network_ip_from_href(@ip.href).name }
26
+ its(:status) { should == @mock_data.network_ip_from_href(@ip.href).status }
27
+ its(:server) { should == @mock_data.network_ip_from_href(@ip.href).used_by.name }
31
28
 
32
29
  end
33
30
  end
@@ -4,7 +4,7 @@ if Fog.mocking?
4
4
  describe "Fog::Vcloud::Terremark::Ecloud::Ips", :type => :mock_tmrk_ecloud_model do
5
5
  subject { @vcloud }
6
6
 
7
- it { should_not respond_to :ips }
7
+ it { should respond_to :ips }
8
8
 
9
9
  describe :class do
10
10
  subject { @vcloud.vdcs[0].networks[0].ips.class }
@@ -12,7 +12,7 @@ if Fog.mocking?
12
12
  end
13
13
 
14
14
  describe :ips do
15
- subject { @vcloud.vdcs[0].networks[0].ips.reload; @vcloud.vdcs[0].networks[0].ips }
15
+ subject { @vcloud.vdcs[0].networks[0].ips.reload }
16
16
  it { should_not respond_to :create }
17
17
 
18
18
  it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::Ips }