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
@@ -18,6 +18,7 @@ module Fog
18
18
  #all_request lambda { |public_ips| public_ips.connection.get_public_ips(public_ips.href) }
19
19
 
20
20
  def all
21
+ check_href!(:message => "the Public Ips href of the Vdc you want to enumerate")
21
22
  if data = connection.get_public_ips(href).body[:PublicIPAddress]
22
23
  load(data)
23
24
  end
@@ -80,8 +80,10 @@ module Fog
80
80
  end
81
81
 
82
82
  def cpus
83
- { :count => cpu_mess[:VirtualQuantity].to_i,
84
- :units => cpu_mess[:AllocationUnits] }
83
+ if cpu_mess
84
+ { :count => cpu_mess[:VirtualQuantity].to_i,
85
+ :units => cpu_mess[:AllocationUnits] }
86
+ end
85
87
  end
86
88
 
87
89
  def cpus=(qty)
@@ -90,8 +92,10 @@ module Fog
90
92
  end
91
93
 
92
94
  def memory
93
- { :amount => memory_mess[:VirtualQuantity].to_i,
94
- :units => memory_mess[:AllocationUnits] }
95
+ if memory_mess
96
+ { :amount => memory_mess[:VirtualQuantity].to_i,
97
+ :units => memory_mess[:AllocationUnits] }
98
+ end
95
99
  end
96
100
 
97
101
  def memory=(amount)
@@ -112,7 +116,7 @@ module Fog
112
116
  @disk_change = :added
113
117
  load_unless_loaded!
114
118
  virtual_hardware[:Item] << { :ResourceType => '17',
115
- :AddressOnParent => (disk_mess.map { |dm| dm[:AddressOnParent] }.sort.last.to_i + 1).to_s,
119
+ :AddressOnParent => (disk_mess.map { |dm| dm[:AddressOnParent] }.sort.last.to_i + 1).to_s,
116
120
  :VirtualQuantity => size.to_s }
117
121
  end
118
122
  true
@@ -168,17 +172,25 @@ module Fog
168
172
 
169
173
  def memory_mess
170
174
  load_unless_loaded!
171
- virtual_hardware[:Item].detect { |item| item[:ResourceType] == "4" }
175
+ if virtual_hardware && virtual_hardware[:Item]
176
+ virtual_hardware[:Item].detect { |item| item[:ResourceType] == "4" }
177
+ end
172
178
  end
173
179
 
174
180
  def cpu_mess
175
181
  load_unless_loaded!
176
- virtual_hardware[:Item].detect { |item| item[:ResourceType] == "3" }
182
+ if virtual_hardware && virtual_hardware[:Item]
183
+ virtual_hardware[:Item].detect { |item| item[:ResourceType] == "3" }
184
+ end
177
185
  end
178
186
 
179
187
  def disk_mess
180
188
  load_unless_loaded!
181
- virtual_hardware[:Item].select { |item| item[:ResourceType] == "17" }
189
+ if virtual_hardware && virtual_hardware[:Item]
190
+ virtual_hardware[:Item].select { |item| item[:ResourceType] == "17" }
191
+ else
192
+ []
193
+ end
182
194
  end
183
195
 
184
196
  def power_operation(op)
@@ -14,6 +14,7 @@ module Fog
14
14
  attribute :href, :aliases => :Href
15
15
 
16
16
  def all
17
+ check_href!(:parent => "Vdc")
17
18
  load(_vapps)
18
19
  end
19
20
 
@@ -12,6 +12,7 @@ module Fog
12
12
  attribute :href, :aliases => :Href
13
13
 
14
14
  def all
15
+ check_href!
15
16
  if data = connection.get_task_list(href).body[:Task]
16
17
  load(data)
17
18
  end
@@ -9,6 +9,8 @@ module Fog
9
9
 
10
10
  model Fog::Vcloud::Terremark::Ecloud::Vdc
11
11
 
12
+ undef_method :create
13
+
12
14
  def all
13
15
  data = connection.get_organization(organization_uri).body[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" }
14
16
  data.each { |link| link.delete_if { |key, value| [:rel].include?(key) } }
@@ -124,14 +124,10 @@ module Fog
124
124
 
125
125
  internet_services_uri = ensure_unparsed(internet_services_uri)
126
126
 
127
- if ip = ip_from_uri(internet_services_uri)
128
- id = rand(1000)
129
- new_service = service_data.merge!( { :href => Fog::Vcloud::Terremark::Ecloud::Mock.internet_service_href( { :id => id } ),
130
- :id => id.to_s,
131
- :timeout => 2,
132
- :nodes => [] } )
133
- ip[:services] << new_service
134
- xml = generate_internet_service_response( service_data, ip )
127
+ if public_ip_internet_service_collection = mock_data.public_ip_internet_service_collection_from_href(internet_services_uri)
128
+ new_public_ip_internet_service = MockPublicIpInternetService.new(service_data, public_ip_internet_service_collection)
129
+ public_ip_internet_service_collection.items << new_public_ip_internet_service
130
+ xml = generate_internet_service_response(new_public_ip_internet_service)
135
131
 
136
132
  mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}
137
133
  else
@@ -51,13 +51,10 @@ module Fog
51
51
 
52
52
  def add_node(nodes_uri, node_data)
53
53
  validate_node_data(node_data)
54
- nodes_uri = ensure_unparsed(nodes_uri)
55
- service_uri = nodes_uri.gsub('/nodeServices','')
56
- ip, service = mock_ip_and_service_from_service_url(service_uri)
57
- if ip and service
58
- id = rand(1000)
59
- service[:nodes] << node_data.merge!( :id => id.to_s, :href => Fog::Vcloud::Terremark::Ecloud::Mock.extension_url + "/nodeService/#{id}" )
60
- mock_it 200, mock_node_service_response(node_data, ecloud_xmlns), { 'Content-Type' => 'application/vnd.tmrk.ecloud.nodeService+xml' }
54
+ if node_collection = mock_data.public_ip_internet_service_node_collection_from_href(ensure_unparsed(nodes_uri))
55
+ new_node = MockPublicIpInternetServiceNode.new(node_data, node_collection)
56
+ node_collection.items << new_node
57
+ mock_it 200, mock_node_service_response(new_node), { 'Content-Type' => 'application/vnd.tmrk.ecloud.nodeService+xml' }
61
58
  else
62
59
  mock_error 200, "401 Unauthorized"
63
60
  end
@@ -5,26 +5,26 @@ module Fog
5
5
  module Shared
6
6
  private
7
7
 
8
- def generate_internet_service_response(service_data,ip_address_data)
8
+ def generate_internet_service_response(public_ip_internet_service)
9
9
  builder = Builder::XmlMarkup.new
10
10
  builder.InternetService(:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance",
11
11
  :xmlns => "urn:tmrk:eCloudExtensions-2.3") {
12
- builder.Id(service_data[:id])
13
- builder.Href(service_data[:href].to_s)
14
- builder.Name(service_data[:name])
15
- builder.Protocol(service_data[:protocol])
16
- builder.Port(service_data[:port])
17
- builder.Enabled(service_data[:enabled])
18
- builder.Description(service_data[:description])
19
- builder.Timeout(service_data[:timeout])
20
- builder.RedirectURL(service_data[:redirect_url])
12
+ builder.Id(public_ip_internet_service.object_id)
13
+ builder.Href(public_ip_internet_service.href)
14
+ builder.Name(public_ip_internet_service.name)
15
+ builder.Protocol(public_ip_internet_service.protocol)
16
+ builder.Port(public_ip_internet_service.port)
17
+ builder.Enabled(public_ip_internet_service.enabled)
18
+ builder.Description(public_ip_internet_service.description)
19
+ builder.Timeout(public_ip_internet_service.timeout)
20
+ builder.RedirectURL(public_ip_internet_service.redirect_url)
21
21
  builder.PublicIpAddress {
22
- builder.Id(ip_address_data[:id])
23
- builder.Href(ip_address_data[:href].to_s)
24
- builder.Name(ip_address_data[:name])
22
+ builder.Id(public_ip_internet_service._parent._parent.object_id)
23
+ builder.Href(public_ip_internet_service._parent._parent.href)
24
+ builder.Name(public_ip_internet_service._parent._parent.name)
25
25
  }
26
- if monitor = service_data[:monitor]
27
- generate_monitor_section(builder,monitor)
26
+ if monitor = public_ip_internet_service.monitor
27
+ generate_monitor_section(builder, public_ip_internet_service.monitor)
28
28
  end
29
29
  }
30
30
  end
@@ -79,11 +79,9 @@ module Fog
79
79
 
80
80
  xml = nil
81
81
 
82
- if ip = ip_from_uri(ip_address_data[:href])
83
- if service = ip[:services].detect { |service| service[:id] == internet_service_uri.split('/')[-1] }
84
- ip[:services][ip[:services].index(service)] = service_data
85
- xml = generate_internet_service_response(service_data, ip)
86
- end
82
+ if public_ip_internet_service = mock_data.public_ip_internet_service_from_href(internet_service_uri)
83
+ public_ip_internet_service.update(service_data.reject {|k, v| [:id, :href].include?(k) })
84
+ xml = generate_internet_service_response(public_ip_internet_service)
87
85
  end
88
86
 
89
87
  if xml
@@ -39,15 +39,14 @@ module Fog
39
39
  include Shared
40
40
 
41
41
  def configure_node(node_uri, node_data)
42
- node_uri = ensure_unparsed(node_uri)
43
-
44
42
  validate_node_data(node_data, true)
45
43
 
46
- if node = mock_node_from_url(node_uri)
47
- node[:name] = node_data[:name]
48
- node[:enabled] = node_data[:enabled]
49
- node[:description] = node_data[:description]
50
- mock_it 200, mock_node_service_response(node, ecloud_xmlns), { 'Content-Type' => 'application/vnd.tmrk.ecloud.nodeService+xml' }
44
+ if node = mock_data.public_ip_internet_service_node_from_href(ensure_unparsed(node_uri))
45
+ node.update(node_data)
46
+ #if node_data[:enabled]
47
+ # node.enabled = (node_data[:enabled] == "true") ? true : false
48
+ #end
49
+ mock_it 200, mock_node_service_response(node), { 'Content-Type' => 'application/vnd.tmrk.ecloud.nodeService+xml' }
51
50
  else
52
51
  mock_error 200, "401 Unauthorized"
53
52
  end
@@ -2,7 +2,19 @@ module Fog
2
2
  class Vcloud
3
3
  module Terremark
4
4
  class Ecloud
5
+ module Shared
6
+ private
7
+
8
+ def validate_vapp_data(vapp_data)
9
+ valid_opts = [:name, :cpus, :memory, :disks]
10
+ unless valid_opts.all? { |opt| vapp_data.keys.include?(opt) }
11
+ raise ArgumentError.new("Required Vapp data missing: #{(valid_opts - vapp_data.keys).map(&:inspect).join(", ")}")
12
+ end
13
+ end
14
+ end
15
+
5
16
  class Real
17
+ include Shared
6
18
 
7
19
  def generate_configure_vapp_request(vapp_uri, vapp_data)
8
20
  rasd_xmlns = { "xmlns" => "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" }
@@ -42,7 +54,7 @@ module Fog
42
54
 
43
55
  #puts xml.root.to_s
44
56
  xml.root.to_s
45
-
57
+
46
58
  #builder = Builder::XmlMarkup.new
47
59
  #builder.Vapp(:href => vapp_uri.to_s,
48
60
  # :type => 'application/vnd.vmware.vcloud.vApp+xml',
@@ -82,13 +94,6 @@ module Fog
82
94
  #}
83
95
  end
84
96
 
85
- def validate_vapp_data(vapp_data)
86
- valid_opts = [:name, :cpus, :memory, :disks]
87
- unless valid_opts.all? { |opt| vapp_data.keys.include?(opt) }
88
- raise ArgumentError.new("Required Vapp data missing: #{(valid_opts - vapp_data.keys).map(&:inspect).join(", ")}")
89
- end
90
- end
91
-
92
97
  def configure_vapp(vapp_uri, vapp_data)
93
98
  validate_vapp_data(vapp_data)
94
99
 
@@ -105,8 +110,34 @@ module Fog
105
110
  end
106
111
 
107
112
  class Mock
113
+ include Shared
114
+
108
115
  def configure_vapp(vapp_uri, vapp_data)
109
- Fog::Mock.not_implemented
116
+ validate_vapp_data(vapp_data)
117
+
118
+ if vapp = mock_data.virtual_machine_from_href(vapp_uri)
119
+ vapp_data.each do |key, value|
120
+ case key
121
+ when :cpus, :memory
122
+ vapp[key] = value
123
+ when :disks
124
+ addresses_to_delete = vapp.disks.map {|d| d.address } - value.map {|d| d[:number] }
125
+ addresses_to_delete.each do |address_to_delete|
126
+ vapp.disks.delete(vapp.disks.at_address(address_to_delete))
127
+ end
128
+
129
+ current_addresses = vapp.disks.map {|d| d.address }
130
+ disks_to_add = value.find_all {|d| !current_addresses.include?(d[:number]) }
131
+ disks_to_add.each do |disk_to_add|
132
+ vapp.disks << MockVirtualMachineDisk.new(:size => disk_to_add[:size] / 1024, :address => disk_to_add[:number])
133
+ end
134
+ end
135
+ end
136
+
137
+ mock_it 200, '', { "Location" => mock_data.base_url + "/some_tasks/1234" }
138
+ else
139
+ mock_error 200, "401 Unauthorized"
140
+ end
110
141
  end
111
142
  end
112
143
  end
@@ -8,18 +8,10 @@ module Fog
8
8
  end
9
9
 
10
10
  class Mock
11
-
12
11
  def delete_internet_service(service_uri)
12
+ if public_ip_internet_service = mock_data.public_ip_internet_service_from_href(service_uri)
13
+ public_ip_internet_service._parent.items.delete(public_ip_internet_service)
13
14
 
14
- deleted = false
15
- if ip = mock_ip_from_service_url(service_uri)
16
- if service = ip[:services].detect { |service| service[:href] == service_uri }
17
- ip[:services].delete(service)
18
- deleted = true
19
- end
20
- end
21
-
22
- if deleted
23
15
  mock_it 200, '', { }
24
16
  else
25
17
  mock_error 200, "401 Unauthorized"
@@ -10,12 +10,8 @@ module Fog
10
10
  class Mock
11
11
 
12
12
  def delete_node(node_uri)
13
- node_uri = ensure_unparsed(node_uri)
14
-
15
- node = mock_node_from_url(node_uri)
16
- service = mock_service_from_node_url(node_uri)
17
- if node and service
18
- service[:nodes].delete(node)
13
+ if node = mock_data.public_ip_internet_service_node_from_href(ensure_unparsed(node_uri))
14
+ node._parent.items.delete(node)
19
15
  mock_it 200, '', {}
20
16
  else
21
17
  mock_error 200, "401 Unauthorized"
@@ -9,7 +9,19 @@ module Fog
9
9
 
10
10
  class Mock
11
11
  def delete_vapp(vapp_uri)
12
- Fog::Mock.not_implemented
12
+ if virtual_machine = mock_data.virtual_machine_from_href(vapp_uri)
13
+ vdc = virtual_machine._parent
14
+
15
+ if vdc.internet_service_collection.items.detect {|is| is.node_collection.items.any? {|isn| isn.ip_address == virtual_machine.ip } } ||
16
+ virtual_machine.status != 2
17
+ mock_it 202, '', {}
18
+ else
19
+ vdc.virtual_machines.delete(virtual_machine)
20
+ mock_it 202, '', { "Location" => mock_data.base_url + "/some_tasks/1234" }
21
+ end
22
+ else
23
+ mock_error 200, "401 Unauthorized"
24
+ end
13
25
  end
14
26
  end
15
27
  end
@@ -12,20 +12,20 @@ module Fog
12
12
  catalog_uri = ensure_unparsed(catalog_uri)
13
13
  xml = nil
14
14
 
15
- if vdc = vdc_from_uri(catalog_uri)
15
+ if catalog = mock_data.catalog_from_href(catalog_uri)
16
16
  builder = Builder::XmlMarkup.new
17
17
 
18
18
  xml = builder.Catalog(xmlns.merge(
19
19
  :type => "application/vnd.vmware.vcloud.catalog+xml",
20
- :href => catalog_uri,
21
- :name => vdc[:catalog][:name]
20
+ :href => catalog.href,
21
+ :name => catalog.name
22
22
  )) do |xml|
23
23
  xml.CatalogItems do |xml|
24
- vdc[:catalog][:items].each do |catalog_item|
24
+ catalog.items.each do |catalog_item|
25
25
  xml.CatalogItem(
26
26
  :type => "application/vnd.vmware.vcloud.catalogItem+xml",
27
- :href => "#{self.class.base_url}/catalogItem/#{catalog_item[:id]}-#{vdc[:id]}",
28
- :name => catalog_item[:name]
27
+ :href => catalog_item.href,
28
+ :name => catalog_item.name
29
29
  )
30
30
  end
31
31
  end
@@ -15,22 +15,21 @@ module Fog
15
15
  #
16
16
 
17
17
  def get_catalog_item(catalog_item_uri)
18
- if catalog_item_and_vdc = catalog_item_and_vdc_from_catalog_item_uri(catalog_item_uri)
19
- catalog_item, vdc = catalog_item_and_vdc
18
+ if catalog_item = mock_data.catalog_item_from_href(catalog_item_uri)
20
19
  builder = Builder::XmlMarkup.new
21
20
 
22
- xml = builder.CatalogItem(xmlns.merge(:href => catalog_item_uri, :name => catalog_item[:name])) do
21
+ xml = builder.CatalogItem(xmlns.merge(:href => catalog_item.href, :name => catalog_item.name)) do
23
22
  builder.Link(
24
23
  :rel => "down",
25
- :href => Fog::Vcloud::Terremark::Ecloud::Mock.catalog_item_customization_href(:id => catalog_item[:id]),
24
+ :href => catalog_item.customization.href,
26
25
  :type => "application/vnd.tmrk.ecloud.catalogItemCustomizationParameters+xml",
27
- :name => "Customization Options"
26
+ :name => catalog_item.customization.name
28
27
  )
29
28
 
30
29
  builder.Entity(
31
- :href => Fog::Vcloud::Terremark::Ecloud::Mock.vapp_template_href(:id => catalog_item[:id]),
30
+ :href => catalog_item.vapp_template.href,
32
31
  :type => "application/vnd.vmware.vcloud.vAppTemplate+xml",
33
- :name => catalog_item[:name]
32
+ :name => catalog_item.vapp_template.name
34
33
  )
35
34
 
36
35
  builder.Property(0, :key => "LicensingCost")
@@ -8,50 +8,23 @@ module Fog
8
8
  end
9
9
 
10
10
  class Mock
11
-
12
11
  #
13
12
  #Based off of:
14
13
  #http://support.theenterprisecloud.com/kb/default.asp?id=580&Lang=1&SID=
15
14
  #http://support.theenterprisecloud.com/kb/default.asp?id=560&Lang=1&SID=
16
15
  #
17
16
  #
18
- def self.internet_services_for_ip(xml,ip)
19
- ip[:services].each do |service|
20
- xml.InternetService {
21
- xml.Id(service[:id])
22
- xml.Href(Fog::Vcloud::Terremark::Ecloud::Mock.internet_service_href(service))
23
- xml.Name(service[:name])
24
- xml.PublicIpAddress {
25
- xml.Id(ip[:id])
26
- xml.Href(Fog::Vcloud::Terremark::Ecloud::Mock.public_ip_href(ip))
27
- xml.Name(ip[:name])
28
- }
29
- xml.Port(service[:port])
30
- xml.Protocol(service[:protocol])
31
- xml.Enabled(service[:enabled])
32
- xml.Timeout(service[:timeout])
33
- xml.Description(service[:description])
34
- xml.RedirectURL(service[:redirect_url])
35
- xml.Monitor
36
- }
37
- end
38
- end
39
17
 
40
18
  def get_internet_services(internet_services_uri)
41
19
  internet_services_uri = ensure_unparsed(internet_services_uri)
42
20
  xml = nil
43
- builder = Builder::XmlMarkup.new
44
- if vdc = vdc_from_uri(internet_services_uri)
45
- xml = builder.InternetServices( :xmlns => "urn:tmrk:eCloudExtensions-2.3",:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance" ) { |xml|
46
- vdc[:public_ips].each do |ip|
47
- Fog::Vcloud::Terremark::Ecloud::Mock.internet_services_for_ip(xml,ip)
48
- end
49
- }
50
- elsif ip = ip_from_uri(internet_services_uri)
51
- xml = builder.InternetServices( :xmlns => "urn:tmrk:eCloudExtensions-2.3",:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance" ) { |xml|
52
- Fog::Vcloud::Terremark::Ecloud::Mock.internet_services_for_ip(xml,ip)
53
- }
21
+
22
+ if vdc_internet_service_collection = mock_data.vdc_internet_service_collection_from_href(internet_services_uri)
23
+ xml = generate_internet_services(vdc_internet_service_collection.items)
24
+ elsif public_ip_internet_service_collection = mock_data.public_ip_internet_service_collection_from_href(internet_services_uri)
25
+ xml = generate_internet_services(public_ip_internet_service_collection.items)
54
26
  end
27
+
55
28
  if xml
56
29
  mock_it 200,
57
30
  xml, { 'Content-Type' => 'application/vnd.tmrk.ecloud.internetServicesList+xml' }
@@ -59,6 +32,34 @@ module Fog
59
32
  mock_error 200, "401 Unauthorized"
60
33
  end
61
34
  end
35
+
36
+ private
37
+
38
+ def generate_internet_services(services)
39
+ builder = Builder::XmlMarkup.new
40
+
41
+ builder.InternetServices(:xmlns => "urn:tmrk:eCloudExtensions-2.3",:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") {|xml|
42
+ services.each do |service|
43
+ xml.InternetService {
44
+ xml.Id service.object_id
45
+ xml.Href service.href
46
+ xml.Name service.name
47
+ xml.PublicIpAddress {
48
+ xml.Id service._parent._parent.object_id
49
+ xml.Href service._parent._parent.href
50
+ xml.Name service._parent._parent.name
51
+ }
52
+ xml.Port service.port
53
+ xml.Protocol service.protocol
54
+ xml.Enabled service.enabled
55
+ xml.Timeout service.timeout
56
+ xml.Description service.description
57
+ xml.RedirectURL service.redirect_url
58
+ xml.Monitor
59
+ }
60
+ end
61
+ }
62
+ end
62
63
  end
63
64
  end
64
65
  end