fog-maestrodev 1.14.0.20130806165225 → 1.15.0.20130829165835

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/changelog.txt +296 -0
  2. data/fog.gemspec +2 -2
  3. data/lib/fog/atmos/storage.rb +0 -3
  4. data/lib/fog/aws/cdn.rb +1 -2
  5. data/lib/fog/aws/compute.rb +52 -2
  6. data/lib/fog/aws/dns.rb +0 -1
  7. data/lib/fog/aws/models/auto_scaling/groups.rb +6 -3
  8. data/lib/fog/aws/models/compute/address.rb +1 -0
  9. data/lib/fog/aws/models/compute/flavors.rb +19 -0
  10. data/lib/fog/aws/models/compute/route_table.rb +69 -0
  11. data/lib/fog/aws/models/compute/route_tables.rb +92 -0
  12. data/lib/fog/aws/models/rds/instance_option.rb +21 -0
  13. data/lib/fog/aws/models/rds/instance_options.rb +30 -0
  14. data/lib/fog/aws/parsers/compute/associate_route_table.rb +20 -0
  15. data/lib/fog/aws/parsers/compute/create_route_table.rb +75 -0
  16. data/lib/fog/aws/parsers/compute/describe_account_attributes.rb +42 -0
  17. data/lib/fog/aws/parsers/compute/describe_route_tables.rb +85 -0
  18. data/lib/fog/aws/parsers/rds/describe_orderable_db_instance_options.rb +47 -0
  19. data/lib/fog/aws/rds.rb +5 -0
  20. data/lib/fog/aws/requests/auto_scaling/describe_auto_scaling_groups.rb +9 -1
  21. data/lib/fog/aws/requests/auto_scaling/describe_policies.rb +15 -1
  22. data/lib/fog/aws/requests/compute/associate_dhcp_options.rb +2 -2
  23. data/lib/fog/aws/requests/compute/associate_route_table.rb +75 -0
  24. data/lib/fog/aws/requests/compute/attach_internet_gateway.rb +2 -2
  25. data/lib/fog/aws/requests/compute/create_route.rb +89 -0
  26. data/lib/fog/aws/requests/compute/create_route_table.rb +70 -0
  27. data/lib/fog/aws/requests/compute/create_vpc.rb +16 -1
  28. data/lib/fog/aws/requests/compute/delete_dhcp_options.rb +2 -2
  29. data/lib/fog/aws/requests/compute/delete_internet_gateway.rb +2 -2
  30. data/lib/fog/aws/requests/compute/delete_network_interface.rb +2 -2
  31. data/lib/fog/aws/requests/compute/delete_route.rb +60 -0
  32. data/lib/fog/aws/requests/compute/delete_route_table.rb +51 -0
  33. data/lib/fog/aws/requests/compute/delete_subnet.rb +2 -2
  34. data/lib/fog/aws/requests/compute/delete_vpc.rb +2 -2
  35. data/lib/fog/aws/requests/compute/describe_account_attributes.rb +49 -0
  36. data/lib/fog/aws/requests/compute/describe_route_tables.rb +87 -0
  37. data/lib/fog/aws/requests/compute/detach_internet_gateway.rb +2 -2
  38. data/lib/fog/aws/requests/compute/detach_network_interface.rb +2 -2
  39. data/lib/fog/aws/requests/compute/disassociate_route_table.rb +57 -0
  40. data/lib/fog/aws/requests/compute/reset_network_interface_attribute.rb +2 -1
  41. data/lib/fog/aws/requests/elb/create_load_balancer.rb +23 -9
  42. data/lib/fog/aws/requests/iam/upload_server_certificate.rb +1 -1
  43. data/lib/fog/aws/requests/rds/describe_orderable_db_instance_options.rb +76 -0
  44. data/lib/fog/aws/storage.rb +0 -2
  45. data/lib/fog/brightbox/models/compute/collaboration.rb +10 -2
  46. data/lib/fog/brightbox/models/compute/collaborations.rb +26 -2
  47. data/lib/fog/brightbox/models/compute/user_collaboration.rb +16 -1
  48. data/lib/fog/brightbox/models/compute/user_collaborations.rb +10 -2
  49. data/lib/fog/cloudstack/models/compute/server.rb +4 -0
  50. data/lib/fog/core/collection.rb +18 -0
  51. data/lib/fog/core/credentials.rb +6 -1
  52. data/lib/fog/google/compute.rb +17 -0
  53. data/lib/fog/google/examples/get_list_images.rb +27 -0
  54. data/lib/fog/google/examples/get_list_snapshots.rb +20 -0
  55. data/lib/fog/google/examples/image_create.rb +18 -0
  56. data/lib/fog/google/examples/launch_micro_instance.rb +10 -5
  57. data/lib/fog/google/examples/network.rb +21 -0
  58. data/lib/fog/google/models/compute/disk.rb +16 -5
  59. data/lib/fog/google/models/compute/image.rb +36 -18
  60. data/lib/fog/google/models/compute/images.rb +36 -10
  61. data/lib/fog/google/models/compute/server.rb +41 -11
  62. data/lib/fog/google/models/compute/servers.rb +1 -1
  63. data/lib/fog/google/models/compute/snapshot.rb +36 -0
  64. data/lib/fog/google/models/compute/snapshots.rb +28 -0
  65. data/lib/fog/google/requests/compute/delete_disk.rb +5 -1
  66. data/lib/fog/google/requests/compute/get_disk.rb +2 -1
  67. data/lib/fog/google/requests/compute/get_snapshot.rb +34 -0
  68. data/lib/fog/google/requests/compute/insert_disk.rb +23 -7
  69. data/lib/fog/google/requests/compute/insert_image.rb +16 -9
  70. data/lib/fog/google/requests/compute/insert_server.rb +22 -10
  71. data/lib/fog/google/requests/compute/list_disks.rb +1 -1
  72. data/lib/fog/google/requests/compute/list_snapshots.rb +30 -0
  73. data/lib/fog/google/storage.rb +1 -3
  74. data/lib/fog/hp/storage.rb +0 -2
  75. data/lib/fog/internet_archive/storage.rb +0 -2
  76. data/lib/fog/local/storage.rb +0 -2
  77. data/lib/fog/ninefold/storage.rb +0 -1
  78. data/lib/fog/openstack/models/storage/file.rb +2 -0
  79. data/lib/fog/openstack/requests/compute/add_flavor_access.rb +1 -1
  80. data/lib/fog/openstack/requests/compute/create_volume.rb +8 -7
  81. data/lib/fog/openstack/requests/compute/list_tenants_with_flavor_access.rb +1 -1
  82. data/lib/fog/openstack/requests/compute/remove_flavor_access.rb +1 -1
  83. data/lib/fog/openstack/requests/image/create_image.rb +23 -23
  84. data/lib/fog/openstack/requests/image/update_image.rb +31 -33
  85. data/lib/fog/openstack/requests/storage/get_object_https_url.rb +3 -3
  86. data/lib/fog/openstack/requests/storage/post_set_meta_temp_url_key.rb +1 -1
  87. data/lib/fog/openstack/storage.rb +10 -11
  88. data/lib/fog/openstack.rb +10 -1
  89. data/lib/fog/rackspace/cdn.rb +13 -0
  90. data/lib/fog/rackspace/compute.rb +8 -4
  91. data/lib/fog/rackspace/compute_v2.rb +2 -0
  92. data/lib/fog/rackspace/databases.rb +4 -4
  93. data/lib/fog/rackspace/dns.rb +6 -6
  94. data/lib/fog/rackspace/examples/compute_v2/bootstrap_server.rb +98 -0
  95. data/lib/fog/rackspace/load_balancers.rb +5 -4
  96. data/lib/fog/rackspace/models/compute_v2/flavors.rb +1 -2
  97. data/lib/fog/rackspace/models/compute_v2/images.rb +35 -3
  98. data/lib/fog/rackspace/models/compute_v2/metadatum.rb +2 -2
  99. data/lib/fog/rackspace/models/identity/service_catalog.rb +34 -16
  100. data/lib/fog/rackspace/models/load_balancers/load_balancer.rb +8 -3
  101. data/lib/fog/rackspace/models/monitoring/alarm.rb +16 -8
  102. data/lib/fog/rackspace/models/monitoring/base.rb +2 -8
  103. data/lib/fog/rackspace/monitoring.rb +14 -6
  104. data/lib/fog/rackspace/requests/compute_v2/list_flavors_detail.rb +39 -0
  105. data/lib/fog/rackspace/requests/compute_v2/list_images.rb +15 -5
  106. data/lib/fog/rackspace/requests/compute_v2/list_images_detail.rb +53 -0
  107. data/lib/fog/rackspace/requests/identity/create_token.rb +1 -1
  108. data/lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb +12 -0
  109. data/lib/fog/rackspace/requests/load_balancers/get_stats.rb +31 -0
  110. data/lib/fog/rackspace/requests/monitoring/get_entity.rb +33 -0
  111. data/lib/fog/rackspace/service.rb +7 -0
  112. data/lib/fog/rackspace/storage.rb +6 -3
  113. data/lib/fog/rackspace.rb +8 -5
  114. data/lib/fog/riakcs/provisioning.rb +0 -1
  115. data/lib/fog/riakcs/usage.rb +2 -3
  116. data/lib/fog/storage.rb +2 -0
  117. data/lib/fog/vcloud/examples/README.md +54 -0
  118. data/lib/fog/vcloud/examples/creating_a_connection.md +20 -0
  119. data/lib/fog/vcloud/examples/creating_a_vapp.md +17 -0
  120. data/lib/fog/vcloud/examples/get_network_information.md +10 -0
  121. data/lib/fog/vcloud/examples/get_vapp_information.md +10 -0
  122. data/lib/fog/vcloud/examples/more_on_vapps.md +23 -0
  123. data/lib/fog/version.rb +1 -1
  124. data/lib/tasks/changelog_task.rb +1 -0
  125. data/tests/aws/models/elb/model_tests.rb +5 -0
  126. data/tests/aws/models/rds/instance_option_tests.rb +14 -0
  127. data/tests/aws/requests/compute/client_tests.rb +25 -0
  128. data/tests/aws/requests/compute/route_tests.rb +277 -0
  129. data/tests/aws/requests/rds/helper.rb +22 -0
  130. data/tests/aws/requests/rds/instance_option_tests.rb +21 -0
  131. data/tests/core/credential_tests.rb +21 -0
  132. data/tests/core/service_tests.rb +26 -0
  133. data/tests/openstack/authenticate_tests.rb +22 -0
  134. data/tests/openstack/models/storage/file_tests.rb +20 -1
  135. data/tests/openstack/requests/compute/flavor_tests.rb +27 -12
  136. data/tests/openstack/requests/compute/volume_tests.rb +10 -12
  137. data/tests/openstack/requests/image/image_tests.rb +30 -15
  138. data/tests/rackspace/block_storage_tests.rb +9 -4
  139. data/tests/rackspace/cdn_tests.rb +14 -0
  140. data/tests/rackspace/compute_tests.rb +10 -4
  141. data/tests/rackspace/compute_v2_tests.rb +9 -4
  142. data/tests/rackspace/databases_tests.rb +9 -4
  143. data/tests/rackspace/dns_tests.rb +9 -4
  144. data/tests/rackspace/helper.rb +21 -2
  145. data/tests/rackspace/identity_tests.rb +9 -4
  146. data/tests/rackspace/load_balancer_tests.rb +8 -4
  147. data/tests/rackspace/models/compute_v2/server_tests.rb +18 -21
  148. data/tests/rackspace/models/identity/service_catalog_tests.rb +54 -29
  149. data/tests/rackspace/models/load_balancers/load_balancer_tests.rb +5 -0
  150. data/tests/rackspace/models/monitoring/alarm_examples_tests.rb +1 -1
  151. data/tests/rackspace/models/monitoring/alarm_tests.rb +2 -2
  152. data/tests/rackspace/monitoring_tests.rb +9 -4
  153. data/tests/rackspace/requests/compute_v2/flavor_tests.rb +6 -0
  154. data/tests/rackspace/requests/compute_v2/image_tests.rb +4 -0
  155. data/tests/rackspace/requests/compute_v2/server_tests.rb +2 -2
  156. data/tests/rackspace/requests/load_balancers/get_stats_tests.rb +13 -0
  157. data/tests/rackspace/requests/load_balancers/helper.rb +9 -0
  158. data/tests/rackspace/requests/monitoring/alarm_tests.rb +4 -5
  159. data/tests/rackspace/requests/monitoring/entity_tests.rb +9 -1
  160. data/tests/rackspace/requests/storage/large_object_tests.rb +12 -4
  161. data/tests/rackspace/storage_tests.rb +23 -4
  162. data/tests/rackspace/url_encoding_tests.rb +3 -1
  163. metadata +117 -133
  164. checksums.yaml +0 -15
  165. data/lib/fog/aws/parsers/compute/associate_dhcp_options.rb +0 -24
  166. data/lib/fog/aws/parsers/compute/attach_internet_gateway.rb +0 -24
  167. data/lib/fog/aws/parsers/compute/delete_dhcp_options.rb +0 -24
  168. data/lib/fog/aws/parsers/compute/delete_internet_gateway.rb +0 -24
  169. data/lib/fog/aws/parsers/compute/delete_network_interface.rb +0 -24
  170. data/lib/fog/aws/parsers/compute/delete_subnet.rb +0 -24
  171. data/lib/fog/aws/parsers/compute/delete_vpc.rb +0 -24
  172. data/lib/fog/aws/parsers/compute/detach_internet_gateway.rb +0 -24
  173. data/lib/fog/aws/parsers/compute/detach_network_interface.rb +0 -24
@@ -0,0 +1,76 @@
1
+ module Fog
2
+ module AWS
3
+ class RDS
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/rds/describe_orderable_db_instance_options'
7
+
8
+ # Describe all or specified load db instances
9
+ # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DescribeDBInstances.html
10
+ # ==== Parameters
11
+ # * Engine <~String> - The name of the engine to retrieve DB Instance options for. Required.
12
+ # * Options <~Hash> - Hash of options. Optional. The following keys are used:
13
+ # * :db_instance_class <~String> - Filter available offerings matching the specified DB Instance class. Optional.
14
+ # * :engine_version <~String> - Filters available offerings matching the specified engine version. Optional.
15
+ # * :license_model <~String> - Filters available offerings matching the specified license model. Optional.
16
+ # * :marker <~String> - The pagination token provided in the previous request. If this parameter is specified the response includes only records beyond the marker, up to MaxRecords. Optional.
17
+ # * :max_records <~Integer> - The maximum number of records to include in the response. If more records exist, a pagination token is included in the response. Optional.
18
+ # * :vpc <~Boolean> - Filter to show only the available VPC or non-VPC offerings. Optional.
19
+ # ==== Returns
20
+ # * response<~Excon::Response>:
21
+ # * body<~Hash>:
22
+ def describe_orderable_db_instance_options(engine=nil, opts={})
23
+ params = {}
24
+ params['Engine'] = engine if engine
25
+ params['DBInstanceClass'] = opts[:db_instance_class] if opts[:db_instance_class]
26
+ params['EngineVersion'] = opts[:engine_version] if opts[:engine_version]
27
+ params['LicenseModel'] = opts[:license_model] if opts[:license_model]
28
+ params['Marker'] = opts[:marker] if opts[:marker]
29
+ params['MaxRecords'] = opts[:max_records] if opts[:max_records]
30
+ params['Vpc'] = opts[:vpc] if opts[:vpc]
31
+
32
+ request({
33
+ 'Action' => 'DescribeOrderableDBInstanceOptions',
34
+ :parser => Fog::Parsers::AWS::RDS::DescribeOrderableDBInstanceOptions.new
35
+ }.merge(params))
36
+ end
37
+
38
+ end
39
+
40
+ class Mock
41
+
42
+ def describe_orderable_db_instance_options(engine=nil, opts={})
43
+ instance_options = []
44
+ response = Excon::Response.new
45
+ if engine
46
+ (opts[:db_instance_class] || %w(db.m2.xlarge db.m1.large)).each do |size|
47
+ instance_options << {'MultiAZCapable' => true,
48
+ 'Engine' => engine,
49
+ 'LicenseModel' => opts[:license_model] || 'general-public-license',
50
+ 'ReadReplicaCapable' => true,
51
+ 'EngineVersion' => opts[:engine_version] || '5.6.12',
52
+ 'AvailabilityZones' => [
53
+ {'Name' => 'us-east-1b', 'ProvisionedIopsCapable' => true},
54
+ {'Name' => 'us-east-1c', 'ProvisionedIopsCapable' => true},
55
+ {'Name' => 'us-east-1d', 'ProvisionedIopsCapable' => false},
56
+ {'Name' => 'us-east-1e', 'ProvisionedIopsCapable' => true}],
57
+ 'DBInstanceClass' => size,
58
+ 'Vpc' => opts[:vpc].nil? ? true : opts[:vpc]}
59
+
60
+ end
61
+ else
62
+ raise Fog::AWS::RDS::NotFound.new('An engine must be specified to retrieve orderable instance options')
63
+ end
64
+
65
+ response.status = 200
66
+ response.body = {
67
+ 'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id },
68
+ 'DescribeOrderableDBInstanceOptionsResult' => { 'OrderableDBInstanceOptions' => instance_options }
69
+ }
70
+ response
71
+ end
72
+
73
+ end
74
+ end
75
+ end
76
+ end
@@ -335,7 +335,6 @@ module Fog
335
335
  end
336
336
 
337
337
  def initialize(options={})
338
- require 'mime/types'
339
338
  @use_iam_profile = options[:use_iam_profile]
340
339
  setup_credentials(options)
341
340
  @region = options[:region] || DEFAULT_REGION
@@ -387,7 +386,6 @@ module Fog
387
386
  # * S3 object with connection to aws.
388
387
  def initialize(options={})
389
388
  require 'fog/core/parser'
390
- require 'mime/types'
391
389
 
392
390
  @use_iam_profile = options[:use_iam_profile]
393
391
  setup_credentials(options)
@@ -25,14 +25,22 @@ module Fog
25
25
  :email => email
26
26
  }.delete_if { |k, v| v.nil? || v == "" }
27
27
 
28
- data = connection.create_collaboration(options)
28
+ data = service.create_collaboration(options)
29
+ merge_attributes(data)
30
+ true
31
+ end
32
+
33
+ def resend
34
+ requires :identity
35
+ data = service.resend_collaboration(identity)
29
36
  merge_attributes(data)
30
37
  true
31
38
  end
32
39
 
33
40
  def destroy
34
41
  requires :identity
35
- connection.destroy_collaboration(identity)
42
+ data = service.destroy_collaboration(identity)
43
+ merge_attributes(data)
36
44
  true
37
45
  end
38
46
 
@@ -8,13 +8,37 @@ module Fog
8
8
  model Fog::Compute::Brightbox::Collaboration
9
9
 
10
10
  def all
11
- data = connection.list_collaborations
11
+ data = service.list_collaborations
12
12
  load(data)
13
13
  end
14
14
 
15
+ def get(identifier)
16
+ return nil if identifier.nil? || identifier == ""
17
+ data = service.get_collaboration(identifier)
18
+ new(data)
19
+ rescue Excon::Errors::NotFound
20
+ nil
21
+ end
22
+
23
+ # Invites a user (via an email) to collaborate on the currently scoped
24
+ # account at the +role+ level.
25
+ #
26
+ # @param [String] email The email address to use for the invitation
27
+ # @param [String] role The role being granted. Only (+admin+ is
28
+ # currently supported
29
+ # @return [Fog::Compute::Brightbox::Collaboration]
30
+ #
31
+ def invite(email, role)
32
+ return nil if email.nil? || email == ""
33
+ return nil if role.nil? || role == ""
34
+ options = {:email => email, :role => role}
35
+ data = service.create_collaboration(options)
36
+ new(data)
37
+ end
38
+
15
39
  def destroy
16
40
  requires :identity
17
- connection.destroy_collaboration(identity)
41
+ service.destroy_collaboration(identity)
18
42
  true
19
43
  end
20
44
  end
@@ -17,9 +17,24 @@ module Fog
17
17
  account['id'] || account[:id]
18
18
  end
19
19
 
20
+ def accept
21
+ requires :identity
22
+ data = service.accept_user_collaboration(identity)
23
+ merge_attributes(data)
24
+ true
25
+ end
26
+
27
+ def reject
28
+ requires :identity
29
+ data = service.reject_user_collaboration(identity)
30
+ merge_attributes(data)
31
+ true
32
+ end
33
+
20
34
  def destroy
21
35
  requires :identity
22
- connection.destroy_user_collaboration(identity)
36
+ data = service.destroy_user_collaboration(identity)
37
+ merge_attributes(data)
23
38
  true
24
39
  end
25
40
 
@@ -8,13 +8,21 @@ module Fog
8
8
  model Fog::Compute::Brightbox::UserCollaboration
9
9
 
10
10
  def all
11
- data = connection.list_user_collaborations
11
+ data = service.list_user_collaborations
12
12
  load(data)
13
13
  end
14
14
 
15
+ def get(identifier)
16
+ return nil if identifier.nil? || identifier == ""
17
+ data = service.get_user_collaboration(identifier)
18
+ new(data)
19
+ rescue Excon::Errors::NotFound
20
+ nil
21
+ end
22
+
15
23
  def destroy
16
24
  requires :identity
17
- connection.destroy_user_collaboration(identity)
25
+ service.destroy_user_collaboration(identity)
18
26
  true
19
27
  end
20
28
  end
@@ -34,6 +34,8 @@ module Fog
34
34
  attribute :root_device_id, :aliases => 'rootdeviceid'
35
35
  attribute :root_device_type, :aliases => 'rootdevicetype'
36
36
  attribute :group
37
+ attribute :key_name, :aliases => 'keypair'
38
+ attribute :user_data, :aliases => 'userdata'
37
39
  attribute :security_group_list, :type => :array, :aliases => 'securitygroup'
38
40
  attribute :nics, :type => :array, :aliases => 'nic'
39
41
 
@@ -92,6 +94,8 @@ module Fog
92
94
  'ipaddress' => ip_address,
93
95
  'iptonetworklist' => ip_to_network_list,
94
96
  'projectid' => project_id,
97
+ 'keypair' => key_name,
98
+ 'userdata' => user_data,
95
99
  }
96
100
 
97
101
  options.merge!('networkids' => network_ids) if network_ids
@@ -142,4 +142,22 @@ module Fog
142
142
  end
143
143
 
144
144
  end
145
+
146
+ # Base class for collection classes whose 'all' method returns only a single page of results and passes the
147
+ # 'Marker' option along as self.filters[:marker]
148
+ class PagedCollection < Collection
149
+
150
+ def each(filters=filters)
151
+ if block_given?
152
+ begin
153
+ page = self.all(filters)
154
+ # We need to explicitly use the base 'each' method here on the page, otherwise we get infinite recursion
155
+ base_each = Fog::Collection.instance_method(:each)
156
+ base_each.bind(page).call { |item| yield item }
157
+ end while self.filters[:marker]
158
+ end
159
+ self
160
+ end
161
+
162
+ end
145
163
  end
@@ -50,11 +50,16 @@ module Fog
50
50
  @credentials = new_credentials
51
51
  end
52
52
 
53
+ def self.symbolize_credential?(key)
54
+ ![:headers].include?(key)
55
+ end
56
+
53
57
  def self.symbolize_credentials(args)
54
58
  if args.is_a? Hash
55
59
  copy = Array.new
56
60
  args.each do |key, value|
57
- copy.push(key.to_sym, self.symbolize_credentials(value))
61
+ obj = symbolize_credential?(key) ? self.symbolize_credentials(value) : value
62
+ copy.push(key.to_sym, obj)
58
63
  end
59
64
  Hash[*copy]
60
65
  else
@@ -19,6 +19,7 @@ module Fog
19
19
  request :list_zones
20
20
  request :list_global_operations
21
21
  request :list_zone_operations
22
+ request :list_snapshots
22
23
 
23
24
  request :get_server
24
25
  request :get_disk
@@ -27,6 +28,7 @@ module Fog
27
28
  request :get_machine_type
28
29
  request :get_network
29
30
  request :get_zone
31
+ request :get_snapshot
30
32
 
31
33
  request :delete_disk
32
34
  request :delete_firewall
@@ -56,6 +58,9 @@ module Fog
56
58
  model :disk
57
59
  collection :disks
58
60
 
61
+ model :snapshot
62
+ collection :snapshots
63
+
59
64
  class Mock
60
65
  include Collections
61
66
 
@@ -107,6 +112,18 @@ module Fog
107
112
  @default_network = 'default'
108
113
  end
109
114
 
115
+ # TODO: Total hack, create zone and zones model.
116
+ def zones
117
+ zones = []
118
+ self.list_zones.data[:body]["items"].each do |z|
119
+ if z["status"] == "UP"
120
+ zones.push z["name"]
121
+ end
122
+ end
123
+
124
+ return zones
125
+ end
126
+
110
127
  def build_result(api_method, parameters, body_object=nil)
111
128
  if body_object
112
129
  result = @client.execute(
@@ -0,0 +1,27 @@
1
+ def test
2
+ connection = Fog::Compute.new({ :provider => "Google" })
3
+
4
+ # puts 'Listing images in all projects...'
5
+ # puts '---------------------------------'
6
+ images = connection.images.all
7
+ raise 'Could not LIST the images' unless images
8
+ # puts images.inspect
9
+
10
+ # puts 'Fetching a single image from a global project...'
11
+ # puts '------------------------------------------------'
12
+ img = connection.images.get('debian-6-squeeze-v20130515')
13
+ raise 'Could not GET the image' unless img
14
+ # puts img.inspect
15
+
16
+ # First, get the name of an image that is in the users 'project' (not global)
17
+ custom_img_name = images.detect { |img| img.project == img.service.project }
18
+ # Run the next test only if there is a custom image available
19
+ if custom_img_name
20
+ # puts 'Fetching a single image from the custom project'
21
+ # puts '----------------------------------------------'
22
+ img = connection.images.get(custom_img_name)
23
+ raise 'Could not GET the (custom) image' unless img
24
+ # puts img.inspect
25
+ end
26
+
27
+ end
@@ -0,0 +1,20 @@
1
+ def test
2
+
3
+ connection = Fog::Compute.new({ :provider => "Google" })
4
+
5
+ # puts 'Listing snapshots...'
6
+ # puts '---------------------------------'
7
+ snapshots = connection.snapshots.all
8
+ raise 'Could not LIST the snapshots' unless snapshots
9
+ # puts snapshots.inspect
10
+
11
+ # puts 'Fetching a single snapshot...'
12
+ # puts '------------------------------------------------'
13
+ snap = snapshots.first
14
+ if !snap.nil?
15
+ snap = connection.snapshots.get(snap)
16
+ raise 'Could not GET the snapshot' unless snap
17
+ # puts snap.inspect
18
+ end
19
+
20
+ end
@@ -0,0 +1,18 @@
1
+ def test
2
+ connection = Fog::Compute.new({ :provider => "Google" })
3
+
4
+ rawdisk = {
5
+ :source => nil, # 'http://some_valid_url_to_rootfs_tarball'
6
+ :container_type => 'TAR',
7
+ }
8
+
9
+ # Can't test this unless the 'source' points to a valid URL
10
+ return if rawdisk[:source].nil?
11
+
12
+ img = connection.image.create(:name => 'test-image',
13
+ :preferred_kernel => 'gce-v20130603',
14
+ :description => 'Test image (via fog)',
15
+ :raw_disk => rawdisk)
16
+
17
+ img.reload # will raise if image was not saved correctly
18
+ end
@@ -1,16 +1,21 @@
1
1
  def test
2
2
  connection = Fog::Compute.new({ :provider => "Google" })
3
3
  time = Time.now.utc.to_i
4
- disk = connection.disks.create({:name => 'foggydisk', :size_gb => 10, :zone_name => 'us-central1-a', :image_name => 'centos-6-v20130522'})
4
+ disk = connection.disks.create({
5
+ :name => 'foggydisk',
6
+ :size_gb => 10,
7
+ :zone_name => 'us-central1-a',
8
+ :source_image => 'centos-6-v20130522',
9
+ })
5
10
 
6
11
  disk.wait_for { disk.ready? }
7
12
  params = {
8
13
  :name => "fog-smoke-test-#{Time.now.to_i}",
9
14
  :machine_type => "f1-micro",
10
- :zone_name => "us-central1-a",
11
- :disks => [ disk.get_as_boot_disk(true) ],
12
- :kernel => 'gce-v20130522',
13
- :user => ENV['USER']
15
+ :zone_name => "us-central1-a",
16
+ :disks => [ disk.get_as_boot_disk(true) ],
17
+ :user => ENV['USER'],
18
+ :kernel => 'gce-v20130522',
14
19
  }
15
20
 
16
21
  server = connection.servers.bootstrap params
@@ -0,0 +1,21 @@
1
+ def test
2
+ connection = Fog::Compute.new({ :provider => "Google" })
3
+
4
+ # we create a new private network
5
+ connection.insert_network('my-private-network', '10.240.0.0/16')
6
+
7
+ server = connection.servers.create({
8
+ :name => "fog-smoke-test-#{Time.now.to_i}",
9
+ :image_name => "debian-7-wheezy-v20130522",
10
+ :machine_type => "n1-standard-1",
11
+ :zone_name => "us-central1-a",
12
+ :private_key_path => File.expand_path("~/.ssh/id_rsa"),
13
+ :public_key_path => File.expand_path("~/.ssh/id_rsa.pub"),
14
+ :network => 'my-private-network',
15
+ :external_ip => false,
16
+ :user => ENV['USER'],
17
+ })
18
+
19
+ # The network won't have any firewall rules, so we won't be able to ssh in.
20
+ server.wait_for { ready? }
21
+ end
@@ -16,17 +16,28 @@ module Fog
16
16
  attribute :description, :aliases => 'description'
17
17
  attribute :size_gb, :aliases => 'sizeGb'
18
18
  attribute :self_link, :aliases => 'selfLink'
19
- attribute :image_name, :aliases => 'image'
19
+ attribute :source_image, :aliases => 'sourceImage'
20
+ attribute :source_snapshot, :aliases => 'sourceSnapshot'
21
+ attribute :source_snapshot_id, :aliases => 'sourceSnapshot'
20
22
 
21
23
  def save
22
- data = service.insert_disk(name, size_gb, zone_name, image_name).body
24
+ requires :name
25
+ requires :zone_name
26
+
27
+ options = {}
28
+ if source_image.nil?
29
+ options['sourceSnapshot'] = source_snapshot
30
+ options['sizeGb'] = size_gb
31
+ end
32
+
33
+ data = service.insert_disk(name, zone_name, source_image, options).body
23
34
  data = service.backoff_if_unfound {service.get_disk(name, zone_name).body}
24
35
  service.disks.merge_attributes(data)
25
36
  end
26
37
 
27
38
  def destroy
28
- requires :name, :zone
29
- service.delete_disk(name, zone)
39
+ requires :name, :zone_name
40
+ service.delete_disk(name, zone_name)
30
41
  end
31
42
 
32
43
  def zone
@@ -77,4 +88,4 @@ module Fog
77
88
  end
78
89
  end
79
90
  end
80
- end
91
+ end
@@ -12,28 +12,28 @@ module Fog
12
12
  attribute :creation_timestamp, :aliases => 'creationTimestamp'
13
13
  attribute :description
14
14
  attribute :preferred_kernel, :aliases => 'preferredKernel'
15
+
16
+ # This attribute is not available in the representation of an
17
+ # 'image' returned by the GCE servser (see GCE API). However,
18
+ # images are a global resource and a user can query for images
19
+ # across projects. Therefore we try to remember which project
20
+ # the image belongs to by tracking it in this attribute.
15
21
  attribute :project
16
22
 
17
- def reload
18
- requires :name
23
+ # A RawDisk, e.g. -
24
+ # {
25
+ # :source => url_to_gcs_file,
26
+ # :container_type => 'TAR',
27
+ # :sha1Checksum => ,
28
+ # }
29
+ attribute :raw_disk
19
30
 
20
- data = {}
31
+ attribute :status
21
32
 
22
- # Try looking for the image in known projects
23
- [
24
- self.service.project,
25
- 'google',
26
- 'debian-cloud',
27
- 'centos-cloud',
28
- ].each do |owner|
29
- begin
30
- data = service.get_image(name, owner).body
31
- data[:project] = owner
32
- rescue
33
- end
34
- end
33
+ def reload
34
+ requires :name
35
35
 
36
- raise ArgumentError, 'Specified image was not found' if data.empty?
36
+ data = service.get_image(name, self.project).body
37
37
 
38
38
  self.merge_attributes(data)
39
39
  self
@@ -41,8 +41,26 @@ module Fog
41
41
 
42
42
  def save
43
43
  requires :name
44
+ requires :preferred_kernel
45
+ requires :raw_disk
46
+
47
+ options = {
48
+ 'preferredKernel' => preferred_kernel,
49
+ 'rawDisk' => raw_disk,
50
+ 'description' => description,
51
+ }
52
+
53
+ service.insert_image(name, options)
54
+
55
+ data = service.backoff_if_unfound {
56
+ service.get_image(self.name).body
57
+ }
58
+
59
+ # Track the name of the project in which we insert the image
60
+ data.merge!('project' => service.project)
61
+ self.project = self.service.project
44
62
 
45
- reload
63
+ service.images.merge_attributes(data)
46
64
  end
47
65
 
48
66
  def resource_url
@@ -9,27 +9,53 @@ module Fog
9
9
 
10
10
  model Fog::Compute::Google::Image
11
11
 
12
+ GLOBAL_PROJECTS = [ 'google',
13
+ 'debian-cloud',
14
+ 'centos-cloud',
15
+ ]
16
+
12
17
  def all
13
18
  data = []
14
- [ self.service.project,
15
- 'google',
16
- 'debian-cloud',
17
- 'centos-cloud',
18
- ].each do |project|
19
- data += service.list_images(project).body["items"]
19
+ all_projects = GLOBAL_PROJECTS + [ self.service.project ]
20
+
21
+ all_projects.each do |project|
22
+ images = service.list_images(project).body["items"] || []
23
+
24
+ # Keep track of the project in which we found the image(s)
25
+ images.each { |img| img[:project] = project }
26
+ data += images
20
27
  end
28
+
21
29
  load(data)
22
30
  end
23
31
 
24
32
  def get(identity)
25
- data = connection.get_image(identity).body
33
+ # Search own project before global projects
34
+ all_projects = [ self.service.project ] + GLOBAL_PROJECTS
35
+
36
+ data = nil
37
+ all_projects.each do |project|
38
+ begin
39
+ data = service.get_image(identity, project).body
40
+ data[:project] = project
41
+ rescue Fog::Errors::Error
42
+ next
43
+ else
44
+ break
45
+ end
46
+ end
47
+
48
+ # If it wasn't found in any project, raise
49
+ if data.nil?
50
+ raise Fog::Errors::Error.new('Unable to find the specified image '\
51
+ 'in the following projects: '\
52
+ "#{all_projects.join(', ')}")
53
+ end
54
+
26
55
  new(data)
27
- rescue Excon::Errors::NotFound
28
- nil
29
56
  end
30
57
 
31
58
  end
32
-
33
59
  end
34
60
  end
35
61
  end