fog 1.16.0 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/.travis.yml +6 -0
  2. data/README.md +25 -0
  3. data/changelog.txt +108 -0
  4. data/fog.gemspec +7 -5
  5. data/lib/fog/aws.rb +8 -2
  6. data/lib/fog/aws/cloud_formation.rb +0 -1
  7. data/lib/fog/aws/compute.rb +1 -1
  8. data/lib/fog/aws/elb.rb +0 -1
  9. data/lib/fog/aws/iam.rb +4 -1
  10. data/lib/fog/aws/models/iam/access_key.rb +5 -1
  11. data/lib/fog/aws/models/iam/access_keys.rb +0 -1
  12. data/lib/fog/aws/parsers/compute/describe_reserved_instances.rb +2 -1
  13. data/lib/fog/aws/parsers/storage/get_bucket_tagging.rb +37 -0
  14. data/lib/fog/aws/requests/compute/copy_image.rb +1 -1
  15. data/lib/fog/aws/requests/compute/describe_reserved_instances.rb +1 -0
  16. data/lib/fog/aws/requests/compute/purchase_reserved_instances_offering.rb +1 -0
  17. data/lib/fog/aws/requests/iam/create_access_key.rb +22 -15
  18. data/lib/fog/aws/requests/iam/list_access_keys.rb +15 -11
  19. data/lib/fog/aws/requests/iam/update_access_key.rb +22 -0
  20. data/lib/fog/aws/requests/storage/delete_bucket_tagging.rb +46 -0
  21. data/lib/fog/aws/requests/storage/get_bucket_tagging.rb +53 -0
  22. data/lib/fog/aws/requests/storage/put_bucket_tagging.rb +60 -0
  23. data/lib/fog/aws/storage.rb +32 -19
  24. data/lib/fog/brightbox/models/compute/load_balancer.rb +47 -2
  25. data/lib/fog/core/logger.rb +4 -5
  26. data/lib/fog/core/service.rb +1 -1
  27. data/lib/fog/google/README.md +2 -2
  28. data/lib/fog/google/compute.rb +2 -1
  29. data/lib/fog/google/examples/bootstrap.rb +1 -1
  30. data/lib/fog/google/examples/get_list_images.rb +1 -2
  31. data/lib/fog/google/examples/network.rb +2 -0
  32. data/lib/fog/google/models/compute/disk.rb +23 -0
  33. data/lib/fog/google/models/compute/snapshot.rb +1 -0
  34. data/lib/fog/google/requests/compute/insert_server.rb +1 -1
  35. data/lib/fog/google/requests/compute/insert_snapshot.rb +49 -0
  36. data/lib/fog/google/storage.rb +54 -29
  37. data/lib/fog/hp.rb +0 -4
  38. data/lib/fog/hp/block_storage.rb +2 -2
  39. data/lib/fog/hp/cdn.rb +2 -2
  40. data/lib/fog/hp/compute.rb +2 -2
  41. data/lib/fog/hp/storage.rb +3 -3
  42. data/lib/fog/linode/compute.rb +1 -1
  43. data/lib/fog/linode/dns.rb +1 -1
  44. data/lib/fog/rackspace/block_storage.rb +0 -2
  45. data/lib/fog/vcloud_director/compute.rb +76 -2
  46. data/lib/fog/vcloud_director/generators/compute/{edge_gateway.rb → edge_gateway_service_configuration.rb} +2 -1
  47. data/lib/fog/vcloud_director/requests/compute/delete_disk.rb +33 -0
  48. data/lib/fog/vcloud_director/requests/compute/delete_media.rb +82 -2
  49. data/lib/fog/vcloud_director/requests/compute/get_disk.rb +99 -1
  50. data/lib/fog/vcloud_director/requests/compute/get_disk_owner.rb +45 -0
  51. data/lib/fog/vcloud_director/requests/compute/get_edge_gateway.rb +33 -19
  52. data/lib/fog/vcloud_director/requests/compute/get_media.rb +75 -4
  53. data/lib/fog/vcloud_director/requests/compute/get_media_owner.rb +34 -4
  54. data/lib/fog/vcloud_director/requests/compute/get_task.rb +122 -3
  55. data/lib/fog/vcloud_director/requests/compute/get_task_list.rb +80 -37
  56. data/lib/fog/vcloud_director/requests/compute/{get_vms_disks_attached_to.rb → get_vms_disk_attached_to.rb} +16 -2
  57. data/lib/fog/vcloud_director/requests/compute/post_cancel_task.rb +18 -0
  58. data/lib/fog/vcloud_director/requests/compute/post_clone_media.rb +52 -1
  59. data/lib/fog/vcloud_director/requests/compute/post_configure_edge_gateway_services.rb +14 -2
  60. data/lib/fog/vcloud_director/requests/compute/post_instantiate_vapp_template.rb +2 -2
  61. data/lib/fog/vcloud_director/requests/compute/post_upload_disk.rb +133 -0
  62. data/lib/fog/vcloud_director/requests/compute/post_upload_media.rb +48 -4
  63. data/lib/fog/vcloud_director/requests/compute/put_guest_customization_section_vapp.rb +103 -26
  64. data/lib/fog/vcloud_director/requests/compute/put_network_connection_system_section_vapp.rb +90 -32
  65. data/lib/fog/version.rb +1 -1
  66. data/lib/fog/vsphere/compute.rb +29 -14
  67. data/lib/fog/vsphere/models/compute/server.rb +18 -6
  68. data/lib/fog/vsphere/requests/compute/create_vm.rb +1 -0
  69. data/lib/fog/vsphere/requests/compute/vm_clone.rb +2 -9
  70. data/lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb +2 -2
  71. data/lib/fog/xenserver/requests/compute/create_server.rb +1 -1
  72. data/tests/aws/requests/compute/instance_tests.rb +1 -0
  73. data/tests/aws/requests/storage/bucket_tests.rb +19 -3
  74. data/tests/brightbox/compute/schema.rb +1 -0
  75. data/tests/core/credential_tests.rb +7 -1
  76. data/tests/core/parser_tests.rb +1 -1
  77. data/tests/rackspace/block_storage_tests.rb +1 -1
  78. data/tests/rackspace/cdn_tests.rb +1 -1
  79. data/tests/rackspace/compute_tests.rb +1 -1
  80. data/tests/rackspace/compute_v2_tests.rb +1 -1
  81. data/tests/rackspace/databases_tests.rb +1 -1
  82. data/tests/rackspace/dns_tests.rb +1 -1
  83. data/tests/rackspace/load_balancer_tests.rb +1 -1
  84. data/tests/rackspace/storage_tests.rb +1 -1
  85. data/tests/vcloud_director/ensure_list_tests.rb +30 -2
  86. data/tests/vcloud_director/requests/compute/disk_tests.rb +160 -5
  87. data/tests/vcloud_director/requests/compute/edge_gateway_tests.rb +59 -1
  88. data/tests/vcloud_director/requests/compute/helper.rb +5 -1
  89. data/tests/vcloud_director/requests/compute/media_tests.rb +109 -99
  90. data/tests/vcloud_director/requests/compute/schema_helper.rb +15 -2
  91. data/tests/vcloud_director/requests/compute/task_tests.rb +21 -6
  92. metadata +27 -21
@@ -7,6 +7,17 @@ module Fog
7
7
  # @param [String] id Object identifier of the media object.
8
8
  # @return [Excon::Response]
9
9
  # * body<~Hash>:
10
+ # * :href<~String> - The URI of the media object.
11
+ # * :type<~String> - The MIME type of the media object.
12
+ # * :Link<~Hash>:
13
+ # * :href<~String> -
14
+ # * :type<~String> -
15
+ # * :rel<~String> -
16
+ # * :User<~Hash> - Reference to the user who is the owner of this
17
+ # media object.
18
+ # * :href<~String> - The URI of the user.
19
+ # * :name<~String> - The name of the user.
20
+ # * :type<~String> - The MIME type of the user.
10
21
  #
11
22
  # @raise [Fog::Compute::VcloudDirector::Forbidden]
12
23
  #
@@ -25,14 +36,33 @@ module Fog
25
36
 
26
37
  class Mock
27
38
  def get_media_owner(id)
28
- unless media = data[:medias][id]
39
+ unless data[:medias][id]
29
40
  raise Fog::Compute::VcloudDirector::Forbidden.new(
30
- "No access to entity \"com.vmware.vcloud.entity.media:#{id}\"."
41
+ 'No access to entity "com.vmware.vcloud.entity.media:%s".' % id
31
42
  )
32
43
  end
33
44
 
34
- Fog::Mock.not_implemented
35
- media.is_used_here # avoid warning from syntax checker
45
+ body = {
46
+ :xmlns => xmlns,
47
+ :xmlns_xsi => xmlns_xsi,
48
+ :xsi_schemaLocation => xsi_schema_location,
49
+ :Link => {
50
+ :href => make_href("media/#{id}"),
51
+ :type => 'application/vnd.vmware.vcloud.media+xml',
52
+ :rel => 'up'
53
+ },
54
+ :User => {
55
+ :href => make_href("admin/user/#{user_uuid}"),
56
+ :name => user_name,
57
+ :type => 'application/vnd.vmware.admin.user+xml',
58
+ }
59
+ }
60
+
61
+ Excon::Response.new(
62
+ :status => 200,
63
+ :headers => {'Content-Type' => "#{body[:type]};version=#{@version}"},
64
+ :body => body
65
+ )
36
66
  end
37
67
  end
38
68
  end
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module Fog
2
4
  module Compute
3
5
  class VcloudDirector
@@ -7,6 +9,66 @@ module Fog
7
9
  # @param [String] id The object identifier of the task.
8
10
  # @return [Excon::Response]
9
11
  # * body<~Hash>:
12
+ # * :href<~String> - The URI of the entity.
13
+ # * :type<~String> - The MIME type of the entity.
14
+ # * :id<~String> - The entity identifier, expressed in URN format.
15
+ # The value of this attribute uniquely identifies the entity,
16
+ # persists for the life of the entity, and is never reused.
17
+ # * :operationKey<~String> - Optional unique identifier to support
18
+ # idempotent semantics for create and delete operations.
19
+ # * :name<~String> - The name of the entity.
20
+ # * :cancelRequested<~String> - Whether user has requested this
21
+ # processing to be canceled.
22
+ # * :endTime<~String> - The date and time that processing of the
23
+ # task was completed. May not be present if the task is still
24
+ # being executed.
25
+ # * :expiryTime<~String> - The date and time at which the task
26
+ # resource will be destroyed and no longer available for
27
+ # retrieval. May not be present if the task has not been executed
28
+ # or is still being executed.
29
+ # * :operation<~String> - A message describing the operation that
30
+ # is tracked by this task.
31
+ # * :operationName<~String> - The short name of the operation that
32
+ # is tracked by this task.
33
+ # * :serviceNamespace<~String> - Identifier of the service that
34
+ # created the task.
35
+ # * :startTime<~String> - The date and time the system started
36
+ # executing the task. May not be present if the task has not been
37
+ # executed yet.
38
+ # * :status<~String> - The execution status of the task.
39
+ # * :Link<~Array<Hash>>:
40
+ # * :Description<~String> - Optional description.
41
+ # * :Owner<~Hash> - Reference to the owner of the task. This is
42
+ # typically the object that the task is creating or updating.
43
+ # * :href<~String> - Contains the URI to the entity.
44
+ # * :name<~String> - Contains the name of the entity.
45
+ # * :type<~String> - Contains the type of the entity.
46
+ # * :Error<~Hash> - Represents error information from a failed
47
+ # task.
48
+ # * :majorErrorCode<~String> - The class of the error. Matches
49
+ # the HTTP status code.
50
+ # * :message<~String> - An one line, human-readable message
51
+ # describing the error that occurred.
52
+ # * :minorErrorCode<~String> - Resource-specific error code.
53
+ # * :stackTrace<~String> - The stack trace of the exception.
54
+ # * :vendorSpecificErrorCode<~String> - A vendor- or
55
+ # implementation-specific error code that can reference
56
+ # specific modules or source lines for diagnostic purposes.
57
+ # * :User<~Hash> - The user who started the task.
58
+ # * :href<~String> - Contains the URI to the entity.
59
+ # * :name<~String> - Contains the name of the entity.
60
+ # * :type<~String> - Contains the type of the entity.
61
+ # * :Organization<~Hash> - The organization to which the :User
62
+ # belongs.
63
+ # * :href<~String> - Contains the URI to the entity.
64
+ # * :name<~String> - Contains the name of the entity.
65
+ # * :type<~String> - Contains the type of the entity.
66
+ # * :Progress<~String> - Read-only indicator of task progress as an
67
+ # approximate percentage between 0 and 100. Not available for all
68
+ # tasks.
69
+ # * :Params
70
+ # * :Details<~String> - Detailed message about the task. Also
71
+ # contained by the :Owner entity when task status is preRunning.
10
72
  #
11
73
  # @raise [Fog::Compute::VcloudDirector::Forbidden]
12
74
  #
@@ -25,14 +87,71 @@ module Fog
25
87
 
26
88
  class Mock
27
89
  def get_task(id)
28
- unless task = data[:tasks][id]
90
+ unless data[:tasks][id]
29
91
  raise Fog::Compute::VcloudDirector::Forbidden.new(
30
92
  'This operation is denied.'
31
93
  )
32
94
  end
33
95
 
34
- Fog::Mock.not_implemented
35
- task.is_used_here # avoid warning from syntax checker
96
+ body = {
97
+ :xmlns => xmlns,
98
+ :xmlns_xsi => xmlns_xsi,
99
+ :xsi_schemaLocation => xsi_schema_location
100
+ }.merge(task_body(id))
101
+
102
+ Excon::Response.new(
103
+ :status => 200,
104
+ :headers => {'Type' => "application/#{body[:type]};version=#{api_version}"},
105
+ :body => body
106
+ )
107
+ end
108
+
109
+ private
110
+
111
+ # @param [String] id Object identifier of the task.
112
+ # @return [Hash]
113
+ def task_body(id)
114
+ task = data[:tasks][id]
115
+
116
+ body = {
117
+ :href => make_href("tasks/#{id}"),
118
+ :type => 'application/vnd.vmware.vcloud.task+xml',
119
+ :id => "urn:vcloud:tasl:#{id}",
120
+ :name => task[:name],
121
+ :cancelRequested => task[:cancel_requested].to_s,
122
+ :expiryTime => task[:expiry_time].strftime('%Y-%m-%dT%H:%M:%S%z'),
123
+ :operation => task[:operation],
124
+ :operationName => task[:operation_name],
125
+ :serviceNamespace => task[:service_namespace],
126
+ :status => task[:status],
127
+ :Link => [],
128
+ :Owner => task[:owner],
129
+ :User => { # for now, always the current user
130
+ :href => make_href("admin/user/#{user_uuid}"),
131
+ :name => user_name,
132
+ :type => 'application/vnd.vmware.admin.user+xml',
133
+ },
134
+ :Organization => { # for now, always the current org
135
+ :href => make_href("org/#{data[:org][:uuid]}"),
136
+ :name => data[:org][:name],
137
+ :type => 'application/vnd.vmware.vcloud.org+xml',
138
+ },
139
+ :Progress => task[:progress].to_s,
140
+ :Details => task[:details] || '',
141
+ }
142
+ body[:endTime] = task[:end_time].strftime('%Y-%m-%dT%H:%M:%S%z') if task[:end_time]
143
+ body[:startTime] = task[:start_time].strftime('%Y-%m-%dT%H:%M:%S%z') if task[:start_time]
144
+ body[:Description] = task[:description] if task[:description]
145
+
146
+ if task[:status] == 'running'
147
+ body[:Link] << {
148
+ :href => make_href("task/#{id}/action/cancel"),
149
+ :type => 'application/vnd.vmware.vcloud.task+xml',
150
+ :rel => 'cancel',
151
+ }
152
+ end
153
+
154
+ body
36
155
  end
37
156
  end
38
157
  end
@@ -11,7 +11,78 @@ module Fog
11
11
  # @param [String] id Object identifier of the organization.
12
12
  # @return [Excon::Response]
13
13
  # * body<~Hash>:
14
+ # * :href<~String> - The URI of the entity.
15
+ # * :type<~String> - The MIME type of the entity.
16
+ # * :id<~String> - The entity identifier, expressed in URN format.
17
+ # The value of this attribute uniquely identifies the entity,
18
+ # persists for the life of the entity, and is never reused.
19
+ # * :name<~String> - The name of the entity.
20
+ # * :Task<~Array<Hash>>:
21
+ # * :href<~String> - The URI of the entity.
22
+ # * :type<~String> - The MIME type of the entity.
23
+ # * :id<~String> - The entity identifier, expressed in URN
24
+ # format. The value of this attribute uniquely identifies the
25
+ # entity, persists for the life of the entity, and is never
26
+ # reused.
27
+ # * :operationKey<~String> - Optional unique identifier to
28
+ # support idempotent semantics for create and delete
29
+ # operations.
30
+ # * :name<~String> - The name of the entity.
31
+ # * :cancelRequested<~String> - Whether user has requested this
32
+ # processing to be canceled.
33
+ # * :endTime<~String> - The date and time that processing of the
34
+ # task was completed. May not be present if the task is still
35
+ # being executed.
36
+ # * :expiryTime<~String> - The date and time at which the task
37
+ # resource will be destroyed and no longer available for
38
+ # retrieval. May not be present if the task has not been
39
+ # executed or is still being executed.
40
+ # * :operation<~String> - A message describing the operation that
41
+ # is tracked by this task.
42
+ # * :operationName<~String> - The short name of the operation
43
+ # that is tracked by this task.
44
+ # * :serviceNamespace<~String> - Identifier of the service that
45
+ # created the task.
46
+ # * :startTime<~String> - The date and time the system started
47
+ # executing the task. May not be present if the task has not
48
+ # been executed yet.
49
+ # * :status<~String> - The execution status of the task.
50
+ # * :Link<~Array<Hash>>:
51
+ # * :Description<~String> - Optional description.
52
+ # * :Owner<~Hash> - Reference to the owner of the task. This is
53
+ # typically the object that the task is creating or updating.
54
+ # * :href<~String> - Contains the URI to the entity.
55
+ # * :name<~String> - Contains the name of the entity.
56
+ # * :type<~String> - Contains the type of the entity.
57
+ # * :Error<~Hash> - Represents error information from a failed
58
+ # task.
59
+ # * :majorErrorCode<~String> - The class of the error. Matches
60
+ # the HTTP status code.
61
+ # * :message<~String> - An one line, human-readable message
62
+ # describing the error that occurred.
63
+ # * :minorErrorCode<~String> - Resource-specific error code.
64
+ # * :stackTrace<~String> - The stack trace of the exception.
65
+ # * :vendorSpecificErrorCode<~String> - A vendor- or
66
+ # implementation-specific error code that can reference
67
+ # specific modules or source lines for diagnostic purposes.
68
+ # * :User<~Hash> - The user who started the task.
69
+ # * :href<~String> - Contains the URI to the entity.
70
+ # * :name<~String> - Contains the name of the entity.
71
+ # * :type<~String> - Contains the type of the entity.
72
+ # * :Organization<~Hash> - The organization to which the :User
73
+ # belongs.
74
+ # * :href<~String> - Contains the URI to the entity.
75
+ # * :name<~String> - Contains the name of the entity.
76
+ # * :type<~String> - Contains the type of the entity.
77
+ # * :Progress<~String> - Read-only indicator of task progress as
78
+ # an approximate percentage between 0 and 100. Not available
79
+ # for all tasks.
80
+ # * :Params
81
+ # * :Details<~String> - Detailed message about the task. Also
82
+ # contained by the :Owner entity when task status is
83
+ # preRunning.
14
84
  #
85
+ # @raise [Fog::Compute::VcloudDirector::BadRequest]
15
86
  # @raise [Fog::Compute::VcloudDirector::Forbidden]
16
87
  #
17
88
  # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-TaskList.html
@@ -37,43 +108,15 @@ module Fog
37
108
  )
38
109
  end
39
110
 
40
- body =
41
- {:xmlns=>xmlns,
42
- :xmlns_xsi=>xmlns_xsi,
43
- :name=>"Tasks Lists",
44
- :type=>"application/vnd.vmware.vcloud.tasksList+xml",
45
- :href=>make_href("tasksList/#{id}"),
46
- :xsi_schemaLocation=>xsi_schema_location}
47
-
48
- tasks = data[:tasks].map do |task_id, task|
49
- {:status => task[:status],
50
- :startTime => task[:startTime].iso8601,
51
- :operationName => task[:operationName],
52
- :operation => task[:operation],
53
- :expiryTime => task[:expiryTime].utc.iso8601,
54
- :endTime => task[:endTime].iso8601,
55
- :cancelRequested => task[:cancelRequested].to_s,
56
- :name => task[:name],
57
- :id => "urn:vcloud:task:#{id}",
58
- :type => 'application/vnd.vmware.vcloud.task+xml',
59
- :href => make_href("task/#{task_id}"),
60
- :Owner =>
61
- {:type => "application/vnd.vmware.vcloud.vApp+xml",
62
- :name => "vApp_#{user_name}_0",
63
- :href=> make_href("vApp/vapp-#{uuid}")},
64
- :User =>
65
- {:type => "application/vnd.vmware.admin.user+xml",
66
- :name => user_name,
67
- :href => make_href("admin/user/#{user_uuid}")},
68
- :Organization =>
69
- {:type => "application/vnd.vmware.vcloud.org+xml",
70
- :name => org_name,
71
- :href => make_href("org/#{org_uuid}")},
72
- :Progress => task[:Progress].to_s,
73
- :Details => task[:Details] || ''}
74
- end
75
- tasks = tasks.first if tasks.size == 1
76
- body[:Task] = tasks
111
+ body = {
112
+ :xmlns => xmlns,
113
+ :xmlns_xsi => xmlns_xsi,
114
+ :xsi_schemaLocation => xsi_schema_location,
115
+ :href => make_href("tasksList/#{id}"),
116
+ :type => "application/vnd.vmware.vcloud.tasksList+xml",
117
+ :name => "Tasks Lists",
118
+ :Task => data[:tasks].keys.map {|task_id| task_body(task_id)}
119
+ }
77
120
 
78
121
  Excon::Response.new(
79
122
  :status => 200,
@@ -10,14 +10,28 @@ module Fog
10
10
  #
11
11
  # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-VmsDisksAttachedTo.html
12
12
  # @since vCloud API version 5.1
13
- def get_vms_disks_attached_to(id)
14
- request(
13
+ def get_vms_disk_attached_to(id)
14
+ response = request(
15
15
  :expects => 200,
16
16
  :idempotent => true,
17
17
  :method => 'GET',
18
18
  :parser => Fog::ToHashDocument.new,
19
19
  :path => "disk/#{id}/attachedVms"
20
20
  )
21
+ ensure_list! response.body, :VmReference
22
+ response
23
+ end
24
+ end
25
+
26
+ class Mock
27
+ def get_vms_disk_attached_to(id)
28
+ unless data[:disks][id]
29
+ raise Fog::Compute::VcloudDirector::Forbidden.new(
30
+ 'No access to entity "com.vmware.vcloud.entity.disk:%s".' % id
31
+ )
32
+ end
33
+
34
+ Fog::Mock.not_implemented
21
35
  end
22
36
  end
23
37
  end
@@ -20,6 +20,24 @@ module Fog
20
20
  )
21
21
  end
22
22
  end
23
+
24
+ class Mock
25
+ def post_cancel_task(id)
26
+ unless task = data[:tasks][id]
27
+ raise Fog::Compute::VcloudDirector::Forbidden.new(
28
+ 'No access to entity "com.vmware.vcloud.entity.task:%s"' % id
29
+ )
30
+ end
31
+
32
+ # @note Tasks don't actually get cancelled (confirmed VCloud Director
33
+ # bug) so we'll emulate that. Set the flag and we're done!
34
+ task[:cancel_requested] = true
35
+
36
+ Excon::Response.new(
37
+ :status => 204
38
+ )
39
+ end
40
+ end
23
41
  end
24
42
  end
25
43
  end
@@ -36,7 +36,7 @@ module Fog
36
36
  }
37
37
  end.to_xml
38
38
 
39
- request(
39
+ response = request(
40
40
  :body => body,
41
41
  :expects => 201,
42
42
  :headers => {'Content-Type' => 'application/vnd.vmware.vcloud.cloneMediaParams+xml'},
@@ -44,6 +44,57 @@ module Fog
44
44
  :parser => Fog::ToHashDocument.new,
45
45
  :path => "vdc/#{vdc_id}/action/cloneMedia"
46
46
  )
47
+ ensure_list! response.body, :Files, :File
48
+ response
49
+ end
50
+ end
51
+
52
+ class Mock
53
+ def post_clone_media(vdc_id, source_id, options={})
54
+ # TODO: check this happens.
55
+ unless source_media = data[:medias][source_id]
56
+ raise Fog::Compute::VcloudDirector::Forbidden.new(
57
+ "No access to entity \"(com.vmware.vcloud.entity.media:#{source_id})\"."
58
+ )
59
+ end
60
+ unless data[:vdcs][vdc_id]
61
+ raise Fog::Compute::VcloudDirector::Forbidden.new(
62
+ "No access to entity \"(com.vmware.vcloud.entity.vdc:#{vdc_id})\"."
63
+ )
64
+ end
65
+
66
+ media_id = uuid
67
+ media_name = "#{source_media[:name]}-copy-#{uuid}"
68
+
69
+ owner = {
70
+ :href => make_href("media/#{media_id}"),
71
+ :type => 'application/vnd.vmware.vcloud.media+xml'
72
+ }
73
+ task_id = enqueue_task(
74
+ "Copy Media File #{media_name}(#{media_id})", 'vdcCopyMedia', owner,
75
+ :on_success => lambda do
76
+ data[:medias][media_id][:status] = 1
77
+ end
78
+ )
79
+
80
+ media = source_media.dup.merge(
81
+ :name => media_name,
82
+ :status => 0,
83
+ :tasks => [task_id]
84
+ )
85
+ data[:medias][media_id] = media
86
+
87
+ body = {
88
+ :xmlns => xmlns,
89
+ :xmlns_xsi => xmlns_xsi,
90
+ :xsi_schemaLocation => xsi_schema_location
91
+ }.merge(media_body(media_id))
92
+
93
+ Excon::Response.new(
94
+ :status => 201,
95
+ :headers => {'Content-Type' => "#{body[:type]};version=#{api_version}"},
96
+ :body => body
97
+ )
47
98
  end
48
99
  end
49
100
  end