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
@@ -2,7 +2,7 @@ module Fog
2
2
  module Generators
3
3
  module Compute
4
4
  module VcloudDirector
5
- class EdgeGateway
5
+ class EdgeGatewayServiceConfiguration
6
6
  def initialize(configuration={})
7
7
  @configuration = configuration
8
8
  end
@@ -143,6 +143,7 @@ module Fog
143
143
  xml.SourcePort rule[:SourcePort] == "Any" ? "-1" : rule[:SourcePort]
144
144
  xml.SourcePortRange rule[:SourcePortRange]
145
145
  xml.SourceIp rule[:SourceIp]
146
+ xml.EnableLogging rule[:EnableLogging] if rule.key?(:EnableLogging)
146
147
  }
147
148
 
148
149
  end
@@ -22,6 +22,39 @@ module Fog
22
22
  )
23
23
  end
24
24
  end
25
+
26
+ class Mock
27
+ def delete_disk(id)
28
+ unless data[:disks][id]
29
+ raise Fog::Compute::VcloudDirector::Forbidden.new(
30
+ "No access to entity \"(com.vmware.vcloud.entity.disk:#{id})\""
31
+ )
32
+ end
33
+
34
+ owner = {
35
+ :href => make_href("disk/#{id}"),
36
+ :type => 'application/vnd.vmware.vcloud.disk+xml'
37
+ }
38
+ task_id = enqueue_task(
39
+ "Deleting Disk(#{id})", 'vdcDeleteDisk', owner,
40
+ :on_success => lambda do
41
+ data[:disks].delete(id)
42
+ end
43
+ )
44
+
45
+ body = {
46
+ :xmlns => xmlns,
47
+ :xmlns_xsi => xmlns_xsi,
48
+ :xsi_schemaLocation => xsi_schema_location,
49
+ }.merge(task_body(task_id))
50
+
51
+ Excon::Response.new(
52
+ :status => 202,
53
+ :headers => {'Content-Type' => "#{body[:type]};version=#{api_version}"},
54
+ :body => body
55
+ )
56
+ end
57
+ end
25
58
  end
26
59
  end
27
60
  end
@@ -10,6 +10,67 @@ module Fog
10
10
  # @param [String] id Object identifier of the media object.
11
11
  # @return [Excon::Response]
12
12
  # * body<~Hash>:
13
+ # * :href<~String> - The URI of the entity.
14
+ # * :type<~String> - The MIME type of the entity.
15
+ # * :id<~String> - The entity identifier, expressed in URN format.
16
+ # The value of this attribute uniquely identifies the entity,
17
+ # persists for the life of the entity, and is never reused.
18
+ # * :operationKey<~String> - Optional unique identifier to support
19
+ # idempotent semantics for create and delete operations.
20
+ # * :name<~String> - The name of the entity.
21
+ # * :cancelRequested<~String> - Whether user has requested this
22
+ # processing to be canceled.
23
+ # * :endTime<~String> - The date and time that processing of the
24
+ # task was completed. May not be present if the task is still
25
+ # being executed.
26
+ # * :expiryTime<~String> - The date and time at which the task
27
+ # resource will be destroyed and no longer available for
28
+ # retrieval. May not be present if the task has not been executed
29
+ # or is still being executed.
30
+ # * :operation<~String> - A message describing the operation that
31
+ # is tracked by this task.
32
+ # * :operationName<~String> - The short name of the operation that
33
+ # is tracked by this task.
34
+ # * :serviceNamespace<~String> - Identifier of the service that
35
+ # created the task.
36
+ # * :startTime<~String> - The date and time the system started
37
+ # executing the task. May not be present if the task has not been
38
+ # executed yet.
39
+ # * :status<~String> - The execution status of the task.
40
+ # * :Link<~Array<Hash>>:
41
+ # * :Description<~String> - Optional description.
42
+ # * :Owner<~Hash> - Reference to the owner of the task. This is
43
+ # typically the object that the task is creating or updating.
44
+ # * :href<~String> - Contains the URI to the entity.
45
+ # * :name<~String> - Contains the name of the entity.
46
+ # * :type<~String> - Contains the type of the entity.
47
+ # * :Error<~Hash> - Represents error information from a failed
48
+ # task.
49
+ # * :majorErrorCode<~String> - The class of the error. Matches
50
+ # the HTTP status code.
51
+ # * :message<~String> - An one line, human-readable message
52
+ # describing the error that occurred.
53
+ # * :minorErrorCode<~String> - Resource-specific error code.
54
+ # * :stackTrace<~String> - The stack trace of the exception.
55
+ # * :vendorSpecificErrorCode<~String> - A vendor- or
56
+ # implementation-specific error code that can reference
57
+ # specific modules or source lines for diagnostic purposes.
58
+ # * :User<~Hash> - The user who started the task.
59
+ # * :href<~String> - Contains the URI to the entity.
60
+ # * :name<~String> - Contains the name of the entity.
61
+ # * :type<~String> - Contains the type of the entity.
62
+ # * :Organization<~Hash> - The organization to which the :User
63
+ # belongs.
64
+ # * :href<~String> - Contains the URI to the entity.
65
+ # * :name<~String> - Contains the name of the entity.
66
+ # * :type<~String> - Contains the type of the entity.
67
+ # * :Progress<~String> - Read-only indicator of task progress as
68
+ # an approximate percentage between 0 and 100. Not available
69
+ # for all tasks.
70
+ # * :Params
71
+ # * :Details<~String> - Detailed message about the task. Also
72
+ # contained by the :Owner entity when task status is
73
+ # preRunning.
13
74
  #
14
75
  # @raise [Fog::Compute::VcloudDirector::Forbidden]
15
76
  #
@@ -33,8 +94,27 @@ module Fog
33
94
  )
34
95
  end
35
96
 
36
- Fog::Mock.not_implemented
37
- media.is_used_here # avoid warning from syntax checker
97
+ owner = {
98
+ :href => make_href("media/#{id}"),
99
+ :type => 'application/vnd.vmware.vcloud.media+xml'
100
+ }
101
+ task_id = enqueue_task(
102
+ "Deleting Media File(#{media[:file][:uuid]})", 'vdcDeleteMedia', owner,
103
+ :on_success => lambda do
104
+ data[:medias].delete(id)
105
+ end
106
+ )
107
+ body = {
108
+ :xmlns => xmlns,
109
+ :xmlns_xsi => xmlns_xsi,
110
+ :xsi_schemaLocation => xsi_schema_location,
111
+ }.merge(task_body(task_id))
112
+
113
+ Excon::Response.new(
114
+ :status => 202,
115
+ :headers => {'Content-Type' => "#{body[:type]};version=#{api_version}"},
116
+ :body => body
117
+ )
38
118
  end
39
119
  end
40
120
  end
@@ -7,17 +7,115 @@ module Fog
7
7
  # @param [String] id Object identifier of the disk.
8
8
  # @return [Excon::Response]
9
9
  # * body<~Hash>:
10
+ # * :href<~String> - The URI of the disk.
11
+ # * :type<~String> - The MIME type of the disk.
12
+ # * :id<~String> - The disk identifier, expressed in URN format.
13
+ # * :name<~String> - The name of the disk.
14
+ # * :status<~String> - Creation status of the disk.
15
+ # * :busSubType<~String> - Disk bus sub type.
16
+ # * :busType<~String> - Disk bus type.
17
+ # * :size<~String> - Size of the disk.
18
+ # * :Description<~String> - Optional description.
19
+ # * :Tasks<~Hash> - A list of queued, running, or recently
20
+ # completed tasks associated with this disk.
21
+ # * :StorageProfile<~Hash> - Storage profile of the disk.
22
+ # * :Owner<~Hash> - Disk owner.
23
+ #
24
+ # @raise [Fog::Compute::VcloudDirector::Forbidden]
10
25
  #
11
26
  # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-Disk.html
12
27
  # @since vCloud API version 5.1
13
28
  def get_disk(id)
14
- request(
29
+ response = request(
15
30
  :expects => 200,
16
31
  :idempotent => true,
17
32
  :method => 'GET',
18
33
  :parser => Fog::ToHashDocument.new,
19
34
  :path => "disk/#{id}"
20
35
  )
36
+ ensure_list! response.body, :Link
37
+ ensure_list! response.body, :Tasks, :Task
38
+ ensure_list! response.body, :Files, :File
39
+ response
40
+ end
41
+ end
42
+
43
+ class Mock
44
+ def get_disk(id)
45
+ unless data[:disks][id]
46
+ raise Fog::Compute::VcloudDirector::Forbidden.new(
47
+ 'No access to entity "com.vmware.vcloud.entity.disk:%s".' % id
48
+ )
49
+ end
50
+
51
+ body = {
52
+ :xmlns => xmlns,
53
+ :xmlns_xsi => xmlns_xsi,
54
+ :xsi_schemaLocation => xsi_schema_location
55
+ }.merge(disk_body(id))
56
+
57
+ Excon::Response.new(
58
+ :status => 200,
59
+ :headers => {'Content-Type' => "#{body[:type]};version=#{@version}"},
60
+ :body => body
61
+ )
62
+ end
63
+
64
+ private
65
+
66
+ def disk_body(id)
67
+ disk = data[:disks][id]
68
+ storage_class_id = disk[:vdc_storage_class]
69
+
70
+ body = {
71
+ :href => make_href("disk/#{id}"),
72
+ :type => 'application/vnd.vmware.vcloud.disk+xml',
73
+ :id => "urn:vcloud:disk:#{id}",
74
+ :name => disk[:name],
75
+ :status => disk[:status].to_s,
76
+ :busSubType => disk[:bus_sub_type],
77
+ :busType => disk[:bus_type],
78
+ :size => disk[:size].to_s,
79
+ :Link => [
80
+ {
81
+ :href => make_href("vdc/#{disk[:vdc_id]}"),
82
+ :rel => 'up',
83
+ :type => 'application/vnd.vmware.vcloud.vdc+xml'
84
+ }
85
+ ],
86
+ :Description => disk[:description],
87
+ :Tasks => {
88
+ # FIXME: there's only one for now
89
+ :Task => disk[:tasks].map {|task_id| task_body(task_id)}.first
90
+ },
91
+ :Files => {
92
+ :File => []
93
+ },
94
+ :StorageProfile => {
95
+ :href => make_href("vdcStorageProfile/#{storage_class_id}"),
96
+ :name => data[:vdc_storage_classes][storage_class_id][:name],
97
+ :type => 'application/vnd.vmware.vcloud.vdcStorageProfile+xml',
98
+ },
99
+ :Owner => {
100
+ :type => 'application/vnd.vmware.vcloud.owner+xml',
101
+ :User => {
102
+ :href => make_href("admin/user/#{user_uuid}"),
103
+ :name => user_name,
104
+ :type => 'application/vnd.vmware.admin.user+xml',
105
+ }
106
+ }
107
+ }
108
+
109
+ if api_version.to_f >= 5.1
110
+ storage_class_id = disk[:vdc_storage_class]
111
+ body[:VdcStorageProfile] = {
112
+ :href => make_href("vdcStorageProfile/#{storage_class_id}"),
113
+ :name => data[:vdc_storage_classes][storage_class_id][:name],
114
+ :type => 'application/vnd.vmware.vcloud.vdcStorageProfile+xml',
115
+ }
116
+ end
117
+
118
+ body
21
119
  end
22
120
  end
23
121
  end
@@ -7,6 +7,19 @@ module Fog
7
7
  # @param [String] id Object identifier of the disk.
8
8
  # @return [Excon::Response]
9
9
  # * body<~Hash>:
10
+ # * :href<~String> - The URI of the disk.
11
+ # * :type<~String> - The MIME type of the disk.
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
+ # disk.
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.
21
+ #
22
+ # @raise [Fog::Compute::VcloudDirector::Forbidden]
10
23
  #
11
24
  # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-DiskOwner.html
12
25
  # @since vCloud API version 5.1
@@ -20,6 +33,38 @@ module Fog
20
33
  )
21
34
  end
22
35
  end
36
+
37
+ class Mock
38
+ def get_disk_owner(id)
39
+ unless data[:disks][id]
40
+ raise Fog::Compute::VcloudDirector::Forbidden.new(
41
+ 'No access to entity "com.vmware.vcloud.entity.disk:%s".' % id
42
+ )
43
+ end
44
+
45
+ body = {
46
+ :xmlns => xmlns,
47
+ :xmlns_xsi => xmlns_xsi,
48
+ :xsi_schemaLocation => xsi_schema_location,
49
+ :Link => {
50
+ :href => make_href("disk/#{id}"),
51
+ :type => 'application/vnd.vmware.vcloud.disk+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
+ )
66
+ end
67
+ end
23
68
  end
24
69
  end
25
70
  end
@@ -13,13 +13,38 @@ module Fog
13
13
  # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-EdgeGateway.html
14
14
  # @since vCloud API version 5.1
15
15
  def get_edge_gateway(id)
16
- request(
17
- :expects => 200,
18
- :idempotent => true,
19
- :method => 'GET',
20
- :parser => Fog::ToHashDocument.new,
21
- :path => "admin/edgeGateway/#{id}"
16
+ response = request(
17
+ :expects => 200,
18
+ :idempotent => true,
19
+ :method => 'GET',
20
+ :parser => Fog::ToHashDocument.new,
21
+ :path => "admin/edgeGateway/#{id}"
22
22
  )
23
+
24
+ edge_gateway_service_configuration = response.body[:Configuration][:EdgeGatewayServiceConfiguration]
25
+
26
+ ensure_list! edge_gateway_service_configuration[:FirewallService], :FirewallRule if edge_gateway_service_configuration[:FirewallService]
27
+ ensure_list! edge_gateway_service_configuration[:NatService], :NatRule if edge_gateway_service_configuration[:NatService]
28
+
29
+ if edge_gateway_service_configuration[:LoadBalancerService]
30
+
31
+ ensure_list! edge_gateway_service_configuration[:LoadBalancerService], :Pool
32
+ edge_gateway_service_configuration[:LoadBalancerService][:Pool].each do |pool|
33
+ ensure_list! pool, :ServicePort
34
+ ensure_list! pool, :Member
35
+ pool[:Member].each do |member|
36
+ ensure_list! member, :ServicePort
37
+ end
38
+ end
39
+
40
+ ensure_list! edge_gateway_service_configuration[:LoadBalancerService], :VirtualServer
41
+ edge_gateway_service_configuration[:LoadBalancerService][:VirtualServer].each do |virtual_server|
42
+ ensure_list! virtual_server, :ServiceProfile
43
+ end
44
+
45
+ end
46
+
47
+ response
23
48
  end
24
49
  end
25
50
 
@@ -32,7 +57,6 @@ module Fog
32
57
  end
33
58
 
34
59
  vdc_id = edge_gateway[:vdc]
35
-
36
60
  body = {
37
61
  :xmlns => xmlns,
38
62
  :xmlns_xsi => xmlns_xsi,
@@ -55,18 +79,8 @@ module Fog
55
79
  {:rel => "edgeGateway:syncSyslogSettings",
56
80
  :href => make_href("admin/edgeGateway/#{id}/action/syncSyslogServerSettings")}],
57
81
  :Description => "vCloud CI (nft00052i2)",
58
- :Configuration =>
59
- {:GatewayBackingConfig => "compact",
60
- :GatewayInterfaces =>
61
- {:GatewayInterface => []},
62
- :EdgeGatewayServiceConfiguration =>
63
- {:FirewallService =>
64
- {:IsEnabled => "true",
65
- :DefaultAction => "drop",
66
- :LogDefaultAction => "false"},
67
- :NatService => {:IsEnabled => "true"}},
68
- :HaEnabled => "false",
69
- :UseDefaultRouteForDnsRelay => "false"}}
82
+ :Configuration => edge_gateway[:Configuration].dup
83
+ }
70
84
 
71
85
  body[:Configuration][:GatewayInterfaces][:GatewayInterface] += edge_gateway[:networks].map do |network|
72
86
  extras = {
@@ -13,26 +13,97 @@ module Fog
13
13
  # @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-Media.html
14
14
  # @since vCloud API version 0.9
15
15
  def get_media(id)
16
- request(
16
+ response = request(
17
17
  :expects => 200,
18
18
  :idempotent => true,
19
19
  :method => 'GET',
20
20
  :parser => Fog::ToHashDocument.new,
21
21
  :path => "media/#{id}"
22
22
  )
23
+ ensure_list! response.body, :Files, :File
24
+ response
23
25
  end
24
26
  end
25
27
 
26
28
  class Mock
27
29
  def get_media(id)
28
- unless media = data[:medias][id]
30
+ unless data[:medias][id]
29
31
  raise Fog::Compute::VcloudDirector::Forbidden.new(
30
32
  "No access to entity \"(com.vmware.vcloud.entity.media:#{id})\"."
31
33
  )
32
34
  end
33
35
 
34
- Fog::Mock.not_implemented
35
- media.is_used_here # avoid warning from syntax checker
36
+ body = {
37
+ :xmlns => xmlns,
38
+ :xmlns_xsi => xmlns_xsi,
39
+ :xsi_schemaLocation => xsi_schema_location
40
+ }.merge(media_body(id))
41
+
42
+ Excon::Response.new(
43
+ :status => 200,
44
+ :headers => {'Content-Type' => "#{body[:type]};version=>#{@api_version}"},
45
+ :body => body
46
+ )
47
+ end
48
+
49
+ private
50
+
51
+ def media_body(id)
52
+ media = data[:medias][id]
53
+
54
+ body = {
55
+ :size => media[:size].to_s,
56
+ :imageType => media[:image_type],
57
+ :status => media[:status].to_s,
58
+ :name => media[:name],
59
+ :id => "urn:vcloud:media:#{id}",
60
+ :type => 'application/vnd.vmware.vcloud.media+xml',
61
+ :href => make_href("media/#{id}"),
62
+ :Link => {
63
+ :href => make_href("vdc/#{media[:vdc_id]}"),
64
+ :type => 'application/vnd.vmware.vcloud.vdc+xml',
65
+ :rel => 'up'
66
+ },
67
+ :Description => media[:description] || '',
68
+ :Tasks => {
69
+ # FIXME: there's only one for now
70
+ :Task => media[:tasks].map {|task_id| task_body(task_id)}.first
71
+ },
72
+ :Files => {
73
+ :File => []
74
+ },
75
+ :Owner => {
76
+ :type => 'application/vnd.vmware.vcloud.owner+xml',
77
+ :User => {
78
+ :href => make_href("admin/user/#{user_uuid}"),
79
+ :name => user_uuid,
80
+ :type => 'application/vnd.vmware.admin.user+xml',
81
+ }
82
+ }
83
+ }
84
+
85
+ if media[:status] == 0
86
+ body[:Files][:File] << {
87
+ :size => media[:size].to_s,
88
+ :bytesTransferred => media[:file][:bytes_transferred].to_s,
89
+ :name => 'file',
90
+ :Link=> {
91
+ :href => make_href("transfer/#{media[:file][:uuid]}/file"),
92
+ :rel => 'upload:default'
93
+ }
94
+ }
95
+ end
96
+
97
+ if api_version.to_f >= 5.1
98
+ storage_class_id = media[:vdc_storage_class]
99
+ body[:VdcStorageProfile] = {
100
+ :href => make_href("vdcStorageProfile/#{storage_class_id}"),
101
+ :name => data[:vdc_storage_classes][storage_class_id][:name],
102
+ :type => 'application/vnd.vmware.vcloud.vdcStorageProfile+xml',
103
+ }
104
+ end
105
+
106
+ body
36
107
  end
37
108
  end
38
109
  end