fog 1.12.1 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/.travis.yml +1 -1
  2. data/Gemfile +5 -0
  3. data/Rakefile +14 -4
  4. data/bin/fog +22 -0
  5. data/changelog.txt +262 -0
  6. data/fog.gemspec +8 -4
  7. data/lib/fog/aws.rb +11 -0
  8. data/lib/fog/aws/auto_scaling.rb +15 -18
  9. data/lib/fog/aws/beanstalk.rb +8 -10
  10. data/lib/fog/aws/cloud_formation.rb +9 -12
  11. data/lib/fog/aws/compute.rb +8 -10
  12. data/lib/fog/aws/credential_fetcher.rb +6 -6
  13. data/lib/fog/aws/elasticache.rb +13 -17
  14. data/lib/fog/aws/elb.rb +29 -31
  15. data/lib/fog/aws/iam.rb +10 -13
  16. data/lib/fog/aws/models/auto_scaling/group.rb +6 -3
  17. data/lib/fog/aws/models/compute/spot_request.rb +1 -11
  18. data/lib/fog/aws/models/rds/log_file.rb +26 -0
  19. data/lib/fog/aws/models/rds/log_files.rb +50 -0
  20. data/lib/fog/aws/models/rds/server.rb +3 -1
  21. data/lib/fog/aws/models/rds/snapshot.rb +1 -0
  22. data/lib/fog/aws/models/rds/snapshots.rb +20 -13
  23. data/lib/fog/aws/parsers/rds/db_parser.rb +1 -1
  24. data/lib/fog/aws/parsers/rds/describe_db_log_files.rb +44 -0
  25. data/lib/fog/aws/parsers/rds/download_db_logfile_portion.rb +26 -0
  26. data/lib/fog/aws/parsers/ses/verify_domain_identity.rb +26 -0
  27. data/lib/fog/aws/parsers/storage/complete_multipart_upload.rb +1 -1
  28. data/lib/fog/aws/parsers/sts/assume_role.rb +30 -0
  29. data/lib/fog/aws/rds.rb +27 -14
  30. data/lib/fog/aws/requests/auto_scaling/create_auto_scaling_group.rb +8 -0
  31. data/lib/fog/aws/requests/auto_scaling/update_auto_scaling_group.rb +8 -1
  32. data/lib/fog/aws/requests/compute/create_volume.rb +3 -3
  33. data/lib/fog/aws/requests/rds/create_db_instance.rb +3 -1
  34. data/lib/fog/aws/requests/rds/describe_db_log_files.rb +67 -0
  35. data/lib/fog/aws/requests/rds/download_db_logfile_portion.rb +63 -0
  36. data/lib/fog/aws/requests/ses/send_raw_email.rb +1 -1
  37. data/lib/fog/aws/requests/ses/verify_domain_identity.rb +30 -0
  38. data/lib/fog/aws/requests/storage/complete_multipart_upload.rb +6 -2
  39. data/lib/fog/aws/requests/storage/get_object.rb +1 -1
  40. data/lib/fog/aws/requests/sts/assume_role.rb +46 -0
  41. data/lib/fog/aws/ses.rb +26 -9
  42. data/lib/fog/aws/storage.rb +2 -1
  43. data/lib/fog/aws/sts.rb +31 -21
  44. data/lib/fog/bin.rb +0 -1
  45. data/lib/fog/bin/openstack.rb +5 -0
  46. data/lib/fog/brightbox/compute.rb +20 -212
  47. data/lib/fog/brightbox/compute/shared.rb +232 -0
  48. data/lib/fog/brightbox/models/compute/collaboration.rb +43 -0
  49. data/lib/fog/brightbox/models/compute/collaborations.rb +23 -0
  50. data/lib/fog/brightbox/models/compute/user_collaboration.rb +29 -0
  51. data/lib/fog/brightbox/models/compute/user_collaborations.rb +23 -0
  52. data/lib/fog/brightbox/requests/compute/accept_user_collaboration.rb +21 -0
  53. data/lib/fog/brightbox/requests/compute/create_collaboration.rb +23 -0
  54. data/lib/fog/brightbox/requests/compute/delete_collaboration.rb +28 -0
  55. data/lib/fog/brightbox/requests/compute/delete_user_collaboration.rb +28 -0
  56. data/lib/fog/brightbox/requests/compute/destroy_user_collaboration.rb +21 -0
  57. data/lib/fog/brightbox/requests/compute/get_collaboration.rb +21 -0
  58. data/lib/fog/brightbox/requests/compute/get_user_collaboration.rb +21 -0
  59. data/lib/fog/brightbox/requests/compute/list_collaborations.rb +19 -0
  60. data/lib/fog/brightbox/requests/compute/list_user_collaborations.rb +19 -0
  61. data/lib/fog/brightbox/requests/compute/reject_user_collaboration.rb +21 -0
  62. data/lib/fog/brightbox/requests/compute/resend_collaboration.rb +21 -0
  63. data/lib/fog/cloudsigma/docs/getting_started.md +59 -0
  64. data/lib/fog/core.rb +7 -2
  65. data/lib/fog/core/connection.rb +62 -29
  66. data/lib/fog/core/deprecated/connection.rb +24 -0
  67. data/lib/fog/core/parser.rb +1 -1
  68. data/lib/fog/digitalocean/examples/getting_started.md +1 -1
  69. data/lib/fog/digitalocean/models/compute/server.rb +2 -2
  70. data/lib/fog/google/compute.rb +31 -7
  71. data/lib/fog/google/models/compute/disk.rb +80 -0
  72. data/lib/fog/google/models/compute/disks.rb +28 -0
  73. data/lib/fog/google/models/compute/image.rb +36 -0
  74. data/lib/fog/google/models/compute/server.rb +46 -33
  75. data/lib/fog/google/models/compute/servers.rb +15 -8
  76. data/lib/fog/google/requests/compute/delete_server.rb +5 -2
  77. data/lib/fog/google/requests/compute/get_disk.rb +3 -0
  78. data/lib/fog/google/requests/compute/get_server.rb +7 -1
  79. data/lib/fog/google/requests/compute/insert_disk.rb +8 -2
  80. data/lib/fog/google/requests/compute/insert_server.rb +51 -22
  81. data/lib/fog/google/requests/compute/list_machine_types.rb +3 -2
  82. data/lib/fog/google/requests/storage/get_object.rb +1 -1
  83. data/lib/fog/hp/requests/storage/get_object.rb +1 -1
  84. data/lib/fog/hp/storage.rb +26 -9
  85. data/lib/fog/ibm/requests/compute/create_instance.rb +20 -15
  86. data/lib/fog/internet_archive/requests/storage/get_object.rb +1 -1
  87. data/lib/fog/{core/json.rb → json.rb} +13 -2
  88. data/lib/fog/metering.rb +25 -0
  89. data/lib/fog/openstack.rb +1 -0
  90. data/lib/fog/openstack/metering.rb +215 -0
  91. data/lib/fog/openstack/models/compute/flavors.rb +2 -2
  92. data/lib/fog/openstack/models/compute/metadata.rb +1 -1
  93. data/lib/fog/openstack/models/compute/server.rb +5 -2
  94. data/lib/fog/openstack/models/image/images.rb +1 -1
  95. data/lib/fog/openstack/models/metering/meter.rb +0 -0
  96. data/lib/fog/openstack/models/metering/meters.rb +0 -0
  97. data/lib/fog/openstack/models/metering/resource.rb +24 -0
  98. data/lib/fog/openstack/models/metering/resources.rb +25 -0
  99. data/lib/fog/openstack/models/volume/volume.rb +3 -1
  100. data/lib/fog/openstack/models/volume/volumes.rb +2 -1
  101. data/lib/fog/openstack/network.rb +1 -1
  102. data/lib/fog/openstack/requests/compute/create_flavor.rb +1 -1
  103. data/lib/fog/openstack/requests/compute/create_server.rb +19 -1
  104. data/lib/fog/openstack/requests/compute/detach_volume.rb +2 -1
  105. data/lib/fog/openstack/requests/compute/list_flavors_detail.rb +4 -3
  106. data/lib/fog/openstack/requests/compute/list_security_groups.rb +1 -1
  107. data/lib/fog/openstack/requests/identity/create_tenant.rb +2 -2
  108. data/lib/fog/openstack/requests/metering/get_resource.rb +32 -0
  109. data/lib/fog/openstack/requests/metering/get_samples.rb +55 -0
  110. data/lib/fog/openstack/requests/metering/get_statistics.rb +56 -0
  111. data/lib/fog/openstack/requests/metering/list_meters.rb +50 -0
  112. data/lib/fog/openstack/requests/metering/list_resources.rb +32 -0
  113. data/lib/fog/openstack/requests/volume/create_volume.rb +4 -2
  114. data/lib/fog/rackspace.rb +16 -1
  115. data/lib/fog/rackspace/block_storage.rb +13 -28
  116. data/lib/fog/rackspace/cdn.rb +10 -24
  117. data/lib/fog/rackspace/compute.rb +17 -45
  118. data/lib/fog/rackspace/compute_v2.rb +13 -33
  119. data/lib/fog/rackspace/databases.rb +13 -29
  120. data/lib/fog/rackspace/dns.rb +27 -23
  121. data/lib/fog/rackspace/identity.rb +10 -26
  122. data/lib/fog/rackspace/load_balancers.rb +13 -29
  123. data/lib/fog/rackspace/mock_data.rb +3 -3
  124. data/lib/fog/rackspace/models/compute/server.rb +1 -1
  125. data/lib/fog/rackspace/models/dns/zones.rb +34 -21
  126. data/lib/fog/rackspace/models/identity/users.rb +2 -2
  127. data/lib/fog/rackspace/models/storage/file.rb +1 -0
  128. data/lib/fog/rackspace/requests/dns/list_domains.rb +2 -2
  129. data/lib/fog/rackspace/requests/storage/delete_multiple_objects.rb +75 -0
  130. data/lib/fog/rackspace/requests/storage/delete_static_large_object.rb +50 -0
  131. data/lib/fog/rackspace/requests/storage/get_object.rb +3 -1
  132. data/lib/fog/rackspace/requests/storage/put_dynamic_obj_manifest.rb +44 -0
  133. data/lib/fog/rackspace/requests/storage/put_object_manifest.rb +3 -30
  134. data/lib/fog/rackspace/requests/storage/put_static_obj_manifest.rb +60 -0
  135. data/lib/fog/rackspace/service.rb +43 -1
  136. data/lib/fog/rackspace/storage.rb +25 -43
  137. data/lib/fog/riakcs/provisioning.rb +2 -1
  138. data/lib/fog/riakcs/usage.rb +2 -1
  139. data/lib/fog/vcloud/requests/compute/configure_vm_cpus.rb +1 -1
  140. data/lib/fog/vcloud/requests/compute/configure_vm_memory.rb +1 -1
  141. data/lib/fog/version.rb +1 -1
  142. data/lib/fog/vsphere/requests/compute/get_folder.rb +1 -1
  143. data/lib/fog/xenserver/compute.rb +2 -0
  144. data/lib/fog/xenserver/models/compute/server.rb +9 -7
  145. data/lib/fog/xenserver/requests/compute/snapshot_revert.rb +22 -0
  146. data/lib/fog/xenserver/requests/compute/snapshot_server.rb +22 -0
  147. data/lib/fog/xml.rb +21 -0
  148. data/lib/fog/xml/sax_parser_connection.rb +43 -0
  149. data/lib/tasks/changelog_task.rb +1 -0
  150. data/tests/aws/models/auto_scaling/groups_test.rb +22 -0
  151. data/tests/aws/requests/compute/volume_tests.rb +3 -3
  152. data/tests/aws/requests/rds/helper.rb +14 -0
  153. data/tests/aws/requests/rds/log_file_tests.rb +19 -0
  154. data/tests/aws/requests/ses/verified_domain_identity_tests.rb +16 -0
  155. data/tests/aws/requests/sts/assume_role_tests.rb +19 -0
  156. data/tests/brightbox/requests/compute/collaboration_tests.rb +41 -0
  157. data/tests/brightbox/requests/compute/helper.rb +46 -2
  158. data/tests/brightbox/requests/compute/user_collaboration_tests.rb +67 -0
  159. data/tests/core/connection_tests.rb +26 -0
  160. data/tests/helper.rb +13 -0
  161. data/tests/openstack/requests/metering/meter_tests.rb +52 -0
  162. data/tests/openstack/requests/metering/resource_tests.rb +19 -0
  163. data/tests/openvz/helper.rb +14 -8
  164. data/tests/rackspace/block_storage_tests.rb +9 -0
  165. data/tests/rackspace/compute_tests.rb +9 -0
  166. data/tests/rackspace/compute_v2_tests.rb +9 -0
  167. data/tests/rackspace/databases_tests.rb +9 -0
  168. data/tests/rackspace/dns_tests.rb +20 -0
  169. data/tests/rackspace/helper.rb +12 -1
  170. data/tests/rackspace/identity_tests.rb +25 -0
  171. data/tests/rackspace/load_balancer_tests.rb +10 -0
  172. data/tests/rackspace/models/block_storage/volume_tests.rb +2 -2
  173. data/tests/rackspace/models/compute_v2/metadata_tests.rb +2 -2
  174. data/tests/rackspace/models/compute_v2/server_tests.rb +22 -21
  175. data/tests/rackspace/models/dns/zones_tests.rb +19 -5
  176. data/tests/rackspace/models/storage/file_tests.rb +22 -6
  177. data/tests/rackspace/rackspace_tests.rb +35 -0
  178. data/tests/rackspace/requests/block_storage/snapshot_tests.rb +2 -3
  179. data/tests/rackspace/requests/block_storage/volume_type_tests.rb +4 -11
  180. data/tests/rackspace/requests/compute_v2/address_tests.rb +1 -1
  181. data/tests/rackspace/requests/compute_v2/attachment_tests.rb +8 -9
  182. data/tests/rackspace/requests/compute_v2/flavor_tests.rb +1 -1
  183. data/tests/rackspace/requests/compute_v2/metadata_tests.rb +4 -4
  184. data/tests/rackspace/requests/databases/database_tests.rb +23 -20
  185. data/tests/rackspace/requests/databases/user_tests.rb +6 -6
  186. data/tests/rackspace/requests/identity/user_tests.rb +4 -1
  187. data/tests/rackspace/requests/load_balancers/usage_tests.rb +4 -2
  188. data/tests/rackspace/requests/storage/large_object_tests.rb +303 -59
  189. data/tests/rackspace/requests/storage/object_tests.rb +73 -18
  190. data/tests/rackspace/service_tests.rb +83 -0
  191. data/tests/rackspace/storage_tests.rb +9 -0
  192. data/tests/xenserver/models/compute/server_tests.rb +11 -1
  193. metadata +89 -19
  194. data/tests/core/user_agent_tests.rb +0 -6
@@ -0,0 +1,80 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class Google
6
+
7
+ class Disk < Fog::Model
8
+
9
+ identity :name
10
+
11
+ attribute :kind, :aliases => 'kind'
12
+ attribute :id, :aliases => 'id'
13
+ attribute :creation_timestamp, :aliases => 'creationTimestamp'
14
+ attribute :zone_name, :aliases => 'zone'
15
+ attribute :status, :aliases => 'status'
16
+ attribute :description, :aliases => 'description'
17
+ attribute :size_gb, :aliases => 'sizeGb'
18
+ attribute :self_link, :aliases => 'selfLink'
19
+ attribute :image_name, :aliases => 'image'
20
+
21
+ def save
22
+ data = service.insert_disk(name, size_gb, zone_name, image_name).body
23
+ data = service.backoff_if_unfound {service.get_disk(name, zone_name).body}
24
+ service.disks.merge_attributes(data)
25
+ end
26
+
27
+ def destroy
28
+ requires :name, :zone
29
+ service.delete_disk(name, zone)
30
+ end
31
+
32
+ def zone
33
+ if self.zone_name.is_a? String
34
+ service.get_zone(self.zone_name.split('/')[-1]).body["name"]
35
+ elsif zone_name.is_a? Excon::Response
36
+ service.get_zone(zone_name.body["name"]).body["name"]
37
+ else
38
+ self.zone_name
39
+ end
40
+ end
41
+
42
+ def get_as_boot_disk(writable=true)
43
+ mode = writable ? 'READ_WRITE' : 'READ_ONLY'
44
+ return {
45
+ 'name' => name,
46
+ 'type' => 'PERSISTENT',
47
+ 'boot' => true,
48
+ 'source' => self_link,
49
+ 'mode' => mode
50
+ }
51
+ end
52
+
53
+ def ready?
54
+ data = service.get_disk(self.name, self.zone_name).body
55
+ data['zone_name'] = self.zone_name
56
+ self.merge_attributes(data)
57
+ self.status == RUNNING_STATE
58
+ end
59
+
60
+ def reload
61
+ requires :identity
62
+ requires :zone_name
63
+
64
+ return unless data = begin
65
+ collection.get(identity, zone_name)
66
+ rescue Excon::Errors::SocketError
67
+ nil
68
+ end
69
+
70
+ new_attributes = data.attributes
71
+ merge_attributes(new_attributes)
72
+ self
73
+ end
74
+
75
+ RUNNING_STATE = "READY"
76
+
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,28 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/google/models/compute/disk'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Google
7
+
8
+ class Disks < Fog::Collection
9
+
10
+ model Fog::Compute::Google::Disk
11
+
12
+ def all(zone)
13
+ data = service.list_disks(zone).body["items"]
14
+ load(data)
15
+ end
16
+
17
+ def get(identity, zone)
18
+ data = service.get_disk(identity, zone).body
19
+ new(data)
20
+ rescue Excon::Errors::NotFound
21
+ nil
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -12,6 +12,42 @@ module Fog
12
12
  attribute :creation_timestamp, :aliases => 'creationTimestamp'
13
13
  attribute :description
14
14
  attribute :preferred_kernel, :aliases => 'preferredKernel'
15
+ attribute :project
16
+
17
+ def reload
18
+ requires :name
19
+
20
+ data = {}
21
+
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
35
+
36
+ raise ArgumentError, 'Specified image was not found' if data.empty?
37
+
38
+ self.merge_attributes(data)
39
+ self
40
+ end
41
+
42
+ def save
43
+ requires :name
44
+
45
+ reload
46
+ end
47
+
48
+ def resource_url
49
+ "#{self.project}/global/images/#{name}"
50
+ end
15
51
 
16
52
  end
17
53
  end
@@ -13,11 +13,13 @@ module Fog
13
13
  attribute :state, :aliases => 'status'
14
14
  attribute :zone_name, :aliases => 'zone'
15
15
  attribute :machine_type, :aliases => 'machineType'
16
+ attribute :disks, :aliases => 'disks'
17
+ attribute :kernel, :aliases => 'kernel'
16
18
  attribute :metadata
17
19
 
18
20
  def destroy
19
- requires :name
20
- service.delete_server(name)
21
+ requires :name, :zone
22
+ service.delete_server(name, zone)
21
23
  end
22
24
 
23
25
  def image
@@ -25,53 +27,64 @@ module Fog
25
27
  end
26
28
 
27
29
  def public_ip_address
28
- if self.network_interfaces.count
29
- self.network_interfaces[0]["networkIP"]
30
- else
31
- nil
30
+ ip = nil
31
+ if self.network_interfaces
32
+ self.network_interfaces.each do |netif|
33
+ netif["accessConfigs"].each do |access_config|
34
+ if access_config["name"] == "External NAT"
35
+ ip = access_config['natIP']
36
+ end
37
+ end
38
+ end
32
39
  end
40
+
41
+ ip
33
42
  end
34
43
 
35
44
  def ready?
36
- data = service.get_server(self.name, self.zone_name).body
37
- data['zone_name'] = self.zone_name
38
- self.merge_attributes(data)
39
- self.state == RUNNING_STATE
45
+ self.state == RUNNING
40
46
  end
41
47
 
42
48
  def zone
43
- service.get_zone(self.zone_name.split('/')[-1])
49
+ if self.zone_name.is_a? String
50
+ service.get_zone(self.zone_name.split('/')[-1]).body["name"]
51
+ elsif zone_name.is_a? Excon::Response
52
+ service.get_zone(zone_name.body["name"]).body["name"]
53
+ else
54
+ self.zone_name
55
+ end
56
+ end
57
+
58
+ def reload
59
+ data = service.get_server(self.name, self.zone).body
60
+ self.merge_attributes(data)
44
61
  end
45
62
 
46
63
  def save
47
64
  requires :name
48
- requires :image_name
49
65
  requires :machine_type
50
66
  requires :zone_name
51
67
 
52
- data = service.insert_server(
53
- name,
54
- image_name,
55
- zone_name,
56
- machine_type)
57
-
58
- data = service.get_server(self.name, self.zone_name).body
59
- service.servers.merge_attributes(data)
60
- end
68
+ if self.metadata.nil?
69
+ self.metadata = {}
70
+ end
61
71
 
62
- def setup(credentials = {})
63
- requires :public_ip_address, :public_key, :username
64
- service.set_metadata(self.instance, self.zone, {'sshKeys' => self.public_key })
65
- rescue Errno::ECONNREFUSED
66
- sleep(1)
67
- retry
68
- end
72
+ self.metadata.merge!({
73
+ "sshKeys" => "#{username}:#{File.read(public_key_path).strip}"
74
+ }) if public_key_path
69
75
 
70
- def sshable?(options={})
71
- service.set_metadata(self.instance, self.zone, {'sshKeys' => self.public_key })
72
- ready? && !public_ip_address.nil? && public_key && metadata['sshKeys']
73
- rescue SystemCallError, Net::SSH::AuthenticationFailed, Timeout::Error
74
- false
76
+ options = {
77
+ 'image' => image_name,
78
+ 'machineType' => machine_type,
79
+ 'networkInterfaces' => network_interfaces,
80
+ 'disks' => disks,
81
+ 'kernel' => kernel,
82
+ 'metadata' => metadata
83
+ }
84
+ options.delete_if {|key, value| value.nil?}
85
+ service.insert_server(name, zone_name, options)
86
+ data = service.backoff_if_unfound {service.get_server(self.name, self.zone_name).body}
87
+ service.servers.merge_attributes(data)
75
88
  end
76
89
 
77
90
  end
@@ -22,20 +22,20 @@ module Fog
22
22
  end
23
23
 
24
24
  def get(identity, zone=nil)
25
- data = nil
25
+ response = nil
26
26
  if zone.nil?
27
27
  service.list_zones.body['items'].each do |zone|
28
- data = service.get_server(identity, zone['name']).body
29
- break if data["code"] == 200
28
+ response = service.get_server(identity, zone['name'])
29
+ break if response.status == 200
30
30
  end
31
31
  else
32
- data = service.get_server(identity, zone).body
32
+ response = service.get_server(identity, zone)
33
33
  end
34
34
 
35
- if data["code"] != 200
35
+ if response.nil? or response.status != 200
36
36
  nil
37
37
  else
38
- new(data)
38
+ new(response.body)
39
39
  end
40
40
  rescue Excon::Errors::NotFound
41
41
  nil
@@ -44,15 +44,22 @@ module Fog
44
44
  def bootstrap(new_attributes = {})
45
45
  defaults = {
46
46
  :name => "fog-#{Time.now.to_i}",
47
- :image_name => "gcel-12-04-v20130225",
47
+ :image_name => "debian-7-wheezy-v20130617",
48
48
  :machine_type => "n1-standard-1",
49
49
  :zone_name => "us-central1-a",
50
50
  :private_key_path => File.expand_path("~/.ssh/id_rsa"),
51
51
  :public_key_path => File.expand_path("~/.ssh/id_rsa.pub"),
52
+ :username => ENV['USER'],
52
53
  }
54
+ if new_attributes[:disks]
55
+ new_attributes[:disks].each do |disk|
56
+ defaults.delete :image_name if disk['boot']
57
+ end
58
+ end
53
59
 
54
60
  server = create(defaults.merge(new_attributes))
55
- server.wait_for(Fog.timeout, 30) { ready? }
61
+ server.wait_for { sshable? }
62
+
56
63
  server
57
64
  end
58
65
  end
@@ -15,11 +15,14 @@ module Fog
15
15
  def delete_server(server_name, zone_name=nil)
16
16
  if zone_name.nil?
17
17
  list_zones.body['items'].each do |zone|
18
- data = get_server(server_name, zone['name']).body
19
- if data["error"].nil?
18
+ if get_server(server_name, zone['name']).status == 200
20
19
  zone_name = zone['name']
21
20
  end
22
21
  end
22
+ else
23
+ if zone_name.is_a? Excon::Response
24
+ zone_name = zone_name.body["name"]
25
+ end
23
26
  end
24
27
 
25
28
  api_method = @compute.instances.delete
@@ -13,6 +13,9 @@ module Fog
13
13
  class Real
14
14
 
15
15
  def get_disk(disk_name, zone_name=@default_zone)
16
+ if zone_name.start_with? 'http'
17
+ zone_name = zone_name.split('/')[-1]
18
+ end
16
19
  api_method = @compute.disks.get
17
20
  parameters = {
18
21
  'project' => @project,
@@ -13,10 +13,16 @@ module Fog
13
13
  class Real
14
14
 
15
15
  def get_server(server_name, zone_name)
16
+ if zone_name.is_a? Excon::Response
17
+ zone = zone_name.body["name"]
18
+ else
19
+ zone = zone_name
20
+ end
21
+
16
22
  api_method = @compute.instances.get
17
23
  parameters = {
18
24
  'project' => @project,
19
- 'zone' => zone_name,
25
+ 'zone' => zone,
20
26
  'instance' => server_name
21
27
  }
22
28
 
@@ -12,19 +12,25 @@ module Fog
12
12
 
13
13
  class Real
14
14
 
15
- def insert_disk(disk_name, disk_size, zone_name=@default_zone)
15
+ def insert_disk(disk_name, disk_size, zone_name=@default_zone, image_name=nil)
16
16
  api_method = @compute.disks.insert
17
17
  parameters = {
18
18
  'project' => @project,
19
19
  'zone' => zone_name
20
20
  }
21
+ if image_name
22
+ # We don't know the owner of the image.
23
+ image = images.create({:name => image_name})
24
+ @image_url = @api_url + image.resource_url
25
+ parameters['sourceImage'] = @image_url
26
+ end
21
27
  body_object = {
22
28
  'name' => disk_name,
23
29
  'sizeGb' => disk_size,
24
30
  }
25
31
 
26
32
  result = self.build_result(api_method, parameters,
27
- body_object=body_object)
33
+ body_object)
28
34
  response = self.build_response(result)
29
35
  end
30
36
 
@@ -12,38 +12,67 @@ module Fog
12
12
 
13
13
  class Real
14
14
 
15
- def insert_server(server_name, image_name,
16
- zone_name, machine_name,
17
- network_name=@default_network)
18
-
19
- # We need to check if the image is owned by the user or a global image.
20
- if get_image(image_name, @project).data['code'] == 200
21
- image_url = @api_url + @project + "/global/images/#{image_name}"
22
- else
23
- image_url = @api_url + "google/global/images/#{image_name}"
24
- end
15
+ def format_metadata(metadata)
16
+ { "items" => metadata.map {|k,v| {"key" => k, "value" => v}} }
17
+ end
25
18
 
19
+ def insert_server(server_name, zone_name, options={}, *deprecated_args)
20
+ if deprecated_args.length > 0 or not options.is_a? Hash
21
+ raise ArgumentError.new 'Too many parameters specified. This may be the cause of code written for an outdated'\
22
+ ' version of fog. Usage: server_name, zone_name, [options]'
23
+ end
26
24
  api_method = @compute.instances.insert
27
25
  parameters = {
28
- 'project' => @project,
29
- 'zone' => zone_name,
30
- }
31
- body_object = {
32
- 'name' => server_name,
33
- 'image' => image_url,
34
- 'machineType' => @api_url + @project + "/global/machineTypes/#{machine_name}",
35
- 'networkInterfaces' => [{
36
- 'network' => @api_url + @project + "/global/networks/#{network_name}"
37
- }]
26
+ 'project' => @project,
27
+ 'zone' => zone_name,
38
28
  }
29
+ body_object = {:name => server_name}
30
+
31
+ if options.has_key? 'image'
32
+ image_name = options.delete 'image'
33
+ # We don't know the owner of the image.
34
+ image = images.create({:name => image_name})
35
+ @image_url = @api_url + image.resource_url
36
+ body_object['image'] = @image_url
37
+ end
38
+ body_object['machineType'] = @api_url + @project + "/zones/#{zone_name}/machineTypes/#{options.delete 'machineType'}"
39
+ networkInterfaces = []
40
+ if @default_network
41
+ networkInterfaces << {
42
+ 'network' => @api_url + @project + "/global/networks/#{@default_network}",
43
+ 'accessConfigs' => [
44
+ {'type' => 'ONE_TO_ONE_NAT',
45
+ 'name' => 'External NAT'}
46
+ ]
47
+ }
48
+ end
49
+ # TODO: add other networks
50
+ body_object['networkInterfaces'] = networkInterfaces
51
+
52
+ if options['disks']
53
+ disks = []
54
+ options.delete('disks').each do |disk|
55
+ if disk.is_a? Disk
56
+ disks << disk.get_object
57
+ else
58
+ disks << disk
59
+ end
60
+ end
61
+ body_object['disks'] = disks
62
+ end
63
+
64
+ options['metadata'] = format_metadata options['metadata'] if options['metadata']
65
+
66
+ if options['kernel']
67
+ body_object['kernel'] = @api_url + "google/global/kernels/#{options.delete 'kernel'}"
68
+ end
69
+ body_object.merge! options # Adds in all remaining options that weren't explicitly handled.
39
70
 
40
71
  result = self.build_result(api_method, parameters,
41
72
  body_object=body_object)
42
73
  response = self.build_response(result)
43
74
  end
44
-
45
75
  end
46
-
47
76
  end
48
77
  end
49
78
  end