Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update to Google Compute Engine API v1 #2494

Merged
merged 3 commits into from

6 participants

@carlossg

plus some disk goodies

@coveralls

Coverage Status

Coverage remained the same when pulling 11d48c6 on maestrodev:gce-v1 into 13090e9 on fog:master.

carlossg and others added some commits
@carlossg carlossg [google][compute] Update to API v1
Simplify attachment of boot disk, get_as_boot_disk no longer needed
Add missing Disk.get_object method
Allow setting deviceName when attaching a disk
Add disks mocks
4c2736d
@dougforpres dougforpres [google][compute] Add support for blank disks (i.e. remove code that …
…required only image or snapshot based disks to be created)
dd72a93
@carlossg carlossg [google] Handle 500 errors from GCE fafebc1
@carlossg

travis is failing in other providers' tests, rebasing against v1.19.0 to see if that works

@coveralls

Coverage Status

Coverage remained the same when pulling dd72a93 on maestrodev:gce-v1 into 13090e9 on fog:master.

@geemus
Owner

Thanks!

@icco - could you review? Thanks!

@icco
Collaborator

This looks pretty good. Beat me to it :p

Thanks!

@icco icco merged commit e3d283e into from
@icco icco was assigned
@allomov

@carlossg just was working on the similar thing. glad to see someone how is interested too. GCE rocks :metal:

@allomov allomov referenced this pull request from a commit in allomov/fog
@allomov allomov merge with master after #2494 changes aa27e20
@geemus
Owner
@carlossg carlossg deleted the branch
@icco icco referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@allomov

@carlossg I think this disk should be removed somewhere. what do you think ?

for the live tests, yes, should be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 19, 2013
  1. @carlossg

    [google][compute] Update to API v1

    carlossg authored
    Simplify attachment of boot disk, get_as_boot_disk no longer needed
    Add missing Disk.get_object method
    Allow setting deviceName when attaching a disk
    Add disks mocks
  2. @dougforpres @carlossg

    [google][compute] Add support for blank disks (i.e. remove code that …

    dougforpres authored carlossg committed
    …required only image or snapshot based disks to be created)
  3. @carlossg
This page is out of date. Refresh to see the latest.
View
64 lib/fog/google/compute.rb
@@ -76,7 +76,7 @@ module Shared
def shared_initialize(options = {})
@project = options[:google_project]
- @api_version = 'v1beta16'
+ @api_version = 'v1'
end
def build_excon_response(body, status=200)
@@ -84,7 +84,11 @@ def build_excon_response(body, status=200)
response.body = body
if response.body and response.body["error"]
response.status = response.body["error"]["code"]
- msg = response.body["error"]["errors"].map{|error| error["message"]}.join(", ")
+ if response.body["error"]["errors"]
+ msg = response.body["error"]["errors"].map{|error| error["message"]}.join(", ")
+ else
+ msg = "Error [#{response.body["error"]["code"]}]: #{response.body["error"]["message"] || "GCE didn't return an error message"}"
+ end
case response.status
when 404
raise Fog::Errors::NotFound.new(msg)
@@ -144,7 +148,6 @@ def self.data(api_version)
"name" => "centos-6-2-v20120621",
"description" => "CentOS 6.2; Created Thu, 21 Jun 2012 14:22:21 +0000",
"sourceType" => "RAW",
- "preferredKernel" => "https://www.googleapis.com/compute/#{api_version}/projects/google/global/kernels/gce-20120621",
"rawDisk" => {
"containerType" => "TAR",
"source" => ""
@@ -163,7 +166,6 @@ def self.data(api_version)
"name" => "centos-6-v20120912",
"description" => "CentOS 6; Created Wed, 12 Sep 2012 00:00:00 +0000",
"sourceType" => "RAW",
- "preferredKernel" => "https://www.googleapis.com/compute/#{api_version}/projects/google/global/kernels/gce-v20120912",
"rawDisk" => {
"containerType" => "TAR",
"source" => ""
@@ -182,7 +184,6 @@ def self.data(api_version)
"name" => "centos-6-v20121106",
"description" => "SCSI-enabled CentOS 6; Created Tue, 06 Nov 2012 00:00:00 +0000",
"sourceType" => "RAW",
- "preferredKernel" => "https://www.googleapis.com/compute/#{api_version}/projects/google/global/kernels/gce-v20121106",
"rawDisk" => {
"containerType" => "TAR",
"source" => ""
@@ -202,7 +203,6 @@ def self.data(api_version)
"name" => "debian-6-squeeze-v20130816",
"description" => "Debian GNU/Linux 6.0.7 (squeeze) built on 2013-08-16",
"sourceType" => "RAW",
- "preferredKernel" => "https://www.googleapis.com/compute/#{api_version}/projects/google/global/kernels/gce-v20130813",
"rawDisk" => {
"containerType" => "TAR",
"source" => ""
@@ -217,7 +217,6 @@ def self.data(api_version)
"name" => "debian-7-wheezy-v20130816",
"description" => "Debian GNU/Linux 7.1 (wheezy) built on 2013-08-16",
"sourceType" => "RAW",
- "preferredKernel" => "https://www.googleapis.com/compute/#{api_version}/projects/google/global/kernels/gce-v20130813",
"rawDisk" => {
"containerType" => "TAR",
"source" => ""
@@ -232,12 +231,26 @@ def self.data(api_version)
"name" => "debian-7-wheezy-v20131014",
"description" => "Debian GNU/Linux 7.1 (wheezy) built on 2013-10-14",
"sourceType" => "RAW",
- "preferredKernel" => "https://www.googleapis.com/compute/#{api_version}/projects/google/global/kernels/gce-v20130813",
"rawDisk" => {
"containerType" => "TAR",
"source" => ""
},
"status" => "READY"
+ },
+ "debian-7-wheezy-v20131120" => {
+ "kind" => "compute#image",
+ "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/debian-cloud/global/images/debian-7-wheezy-v20131120",
+ "id" => "17312518942796567788",
+ "creationTimestamp" => "2013-11-25T15:17:00.436-08:00",
+ "name" => "debian-7-wheezy-v20131120",
+ "description" => "Debian GNU/Linux 7.2 (wheezy) built on 2013-11-20",
+ "sourceType" => "RAW",
+ "rawDisk" => {
+ "containerType" => "TAR",
+ "source" => ""
+ },
+ "status" => "READY",
+ "archiveSizeBytes" => "341857472"
}
}
}
@@ -252,7 +265,6 @@ def self.data(api_version)
"name" => "centos-6-v20130813",
"description" => "SCSI-enabled CentOS 6; Created Tue, 13 Aug 2013 00:00:00 +0000",
"sourceType" => "RAW",
- "preferredKernel" => "https://www.googleapis.com/compute/#{api_version}/projects/google/global/kernels/gce-v20130813",
"rawDisk" => {
"containerType" => "TAR",
"source" => ""
@@ -273,8 +285,6 @@ def self.data(api_version)
"name" => "fog-1380196541",
"tags" => { "fingerprint" => "42WmSpB8rSM=" },
"machineType" => "https://www.googleapis.com/compute/#{api_version}/projects/#{key}/zones/us-central1-a/machineTypes/n1-standard-1",
- "image" => "https://www.googleapis.com/compute/#{api_version}/projects/centos-cloud/global/images/centos-6-v20130813",
- "kernel" => "https://www.googleapis.com/compute/#{api_version}/projects/google/global/kernels/gce-v20130813",
"canIpForward" => false,
"networkInterfaces" => [
{
@@ -295,8 +305,11 @@ def self.data(api_version)
{
"kind" => "compute#attachedDisk",
"index" => 0,
- "type" => "SCRATCH",
- "mode" => "READ_WRITE"
+ "type" => "PERSISTENT",
+ "mode" => "READ_WRITE",
+ "source" => "https://www.googleapis.com/compute/#{api_version}/projects/#{key}/zones/us-central1-a/disks/fog-1",
+ "deviceName" => "persistent-disk-0",
+ "boot" => true
}
],
"metadata" => {
@@ -771,7 +784,30 @@ def self.data(api_version)
}
end,
:images => {},
- :disks => {},
+ :disks => {
+ "fog-1" => {
+ "kind" => "compute#disk",
+ "id" => "3338131294770784461",
+ "creationTimestamp" => "2013-12-18T19:47:10.583-08:00",
+ "zone" => "https://www.googleapis.com/compute/#{api_version}/projects/#{key}/zones/us-central1-a",
+ "status" => "READY",
+ "name" => "fog-1",
+ "sizeGb" => "10",
+ "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{key}/zones/us-central1-a/disks/fog-1",
+ "sourceImage" => "https://www.googleapis.com/compute/#{api_version}/projects/debian-cloud/global/images/debian-7-wheezy-v20131120",
+ "sourceImageId" => "17312518942796567788"
+ },
+ "fog-2" => {
+ "kind" => "compute#disk",
+ "id" => "3338131294770784462",
+ "creationTimestamp" => "2013-12-18T19:47:10.583-08:00",
+ "zone" => "https://www.googleapis.com/compute/#{api_version}/projects/#{key}/zones/us-central1-a",
+ "status" => "READY",
+ "name" => "fog-2",
+ "sizeGb" => "10",
+ "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{key}/zones/us-central1-a/disks/fog-1"
+ }
+ },
:operations => {}
}
end
View
13 lib/fog/google/examples/create.rb
@@ -1,9 +1,20 @@
def test
connection = Fog::Compute.new({ :provider => "Google" })
+ name = "fog-smoke-test-#{Time.now.to_i}"
+
+ disk = connection.disks.create({
+ :name => name,
+ :size_gb => 10,
+ :zone_name => 'us-central1-a',
+ :source_image => 'debian-7-wheezy-v20131120',
+ })
+
+ disk.wait_for { disk.ready? }
+
server = connection.servers.create(defaults = {
:name => "fog-smoke-test-#{Time.now.to_i}",
- :image_name => "debian-7-wheezy-v20130522",
+ :disks => [disk],
:machine_type => "n1-standard-1",
:zone_name => "us-central1-a",
:private_key_path => File.expand_path("~/.ssh/id_rsa"),
View
15 lib/fog/google/examples/eric-fail.rb
@@ -1,9 +1,20 @@
def test
connection = Fog::Compute.new({ :provider => "Google" })
+ name = "fog-smoke-test-#{Time.now.to_i}"
+
+ disk = connection.disks.create({
+ :name => name,
+ :size_gb => 10,
+ :zone_name => 'us-central1-a',
+ :source_image => 'debian-7-wheezy-v20131120',
+ })
+
+ disk.wait_for { disk.ready? }
+
server = connection.servers.create(defaults = {
- :name => "fog-smoke-test-#{Time.now.to_i}",
- :image_name => "debian-7-wheezy-v20130617",
+ :name => name,
+ :disks => [disk],
:machine_type => "n1-standard-1",
:zone_name => "us-central1-a",
:private_key_path => File.expand_path("~/.ssh/id_rsa"),
View
1  lib/fog/google/examples/image_create.rb
@@ -10,7 +10,6 @@ def test
return if rawdisk[:source].nil?
img = connection.image.create(:name => 'test-image',
- :preferred_kernel => 'gce-v20130603',
:description => 'Test image (via fog)',
:raw_disk => rawdisk)
View
3  lib/fog/google/examples/launch_micro_instance.rb
@@ -14,8 +14,7 @@ def test
:machine_type => "f1-micro",
:zone_name => "us-central1-a",
:disks => [ disk.get_as_boot_disk(true) ],
- :user => ENV['USER'],
- :kernel => 'gce-v20130522',
+ :user => ENV['USER']
}
server = connection.servers.bootstrap params
View
16 lib/fog/google/examples/metadata.rb
@@ -1,8 +1,20 @@
def test
connection = Fog::Compute.new({ :provider => "Google" })
+
+ name = "fog-smoke-test-#{Time.now.to_i}"
+
+ disk = connection.disks.create({
+ :name => name,
+ :size_gb => 10,
+ :zone_name => 'us-central1-a',
+ :source_image => 'debian-7-wheezy-v20131120',
+ })
+
+ disk.wait_for { disk.ready? }
+
server = connection.servers.create(defaults = {
- :name => "fog-#{Time.now.to_i}",
- :image_name => "debian-7-wheezy-v20130522",
+ :name => name,
+ :disks => [disk],
:machine_type => "n1-standard-1",
:zone_name => "us-central1-a",
:private_key_path => File.expand_path("~/.ssh/id_rsa"),
View
15 lib/fog/google/examples/network.rb
@@ -4,9 +4,20 @@ def test
# we create a new private network
connection.insert_network('my-private-network', '10.240.0.0/16')
+ name = "fog-smoke-test-#{Time.now.to_i}"
+
+ disk = connection.disks.create({
+ :name => name,
+ :size_gb => 10,
+ :zone_name => 'us-central1-a',
+ :source_image => 'debian-7-wheezy-v20131120',
+ })
+
+ disk.wait_for { disk.ready? }
+
server = connection.servers.create({
- :name => "fog-smoke-test-#{Time.now.to_i}",
- :image_name => "debian-7-wheezy-v20130522",
+ :name => name,
+ :disks => [disk],
:machine_type => "n1-standard-1",
:zone_name => "us-central1-a",
:private_key_path => File.expand_path("~/.ssh/id_rsa"),
View
21 lib/fog/google/models/compute/disk.rb
@@ -25,7 +25,7 @@ def save
requires :zone_name
options = {}
- if source_image.nil?
+ if source_image.nil? && !source_snapshot.nil?
options['sourceSnapshot'] = source_snapshot
end
@@ -57,20 +57,23 @@ def zone
end
end
- def get_as_boot_disk(writable=true)
+ def get_object(writable=true, boot=false, device_name=nil)
mode = writable ? 'READ_WRITE' : 'READ_ONLY'
return {
- 'name' => name,
- 'type' => 'PERSISTENT',
- 'boot' => true,
- 'source' => self_link,
- 'mode' => mode
- }
+ 'boot' => boot,
+ 'source' => self_link,
+ 'mode' => mode,
+ 'deviceName' => device_name,
+ 'type' => 'PERSISTENT'
+ }.select { |k, v| !v.nil? }
+ end
+
+ def get_as_boot_disk(writable=true)
+ get_object(writable, true)
end
def ready?
data = service.get_disk(self.name, self.zone_name).body
- data['zone_name'] = self.zone_name
self.merge_attributes(data)
self.status == RUNNING_STATE
end
View
1  lib/fog/google/models/compute/flavor.rb
@@ -16,6 +16,7 @@ class Flavor < Fog::Model
:aliases => 'maximumPersistentDisks'
attribute :maximum_persistent_disks_size,
:aliases => 'maximumPersistentDisksSizeGb'
+ attribute :self_link, :aliases => 'selfLink'
end
View
13 lib/fog/google/models/compute/image.rb
@@ -8,10 +8,11 @@ class Image < Fog::Model
identity :name
+ attribute :id
attribute :kind
+ attribute :self_link, :aliases => 'selfLink'
attribute :creation_timestamp, :aliases => 'creationTimestamp'
attribute :description
- attribute :preferred_kernel, :aliases => 'preferredKernel'
# This attribute is not available in the representation of an
# 'image' returned by the GCE servser (see GCE API). However,
@@ -30,6 +31,14 @@ class Image < Fog::Model
attribute :status
+ def preferred_kernel=(args)
+ Fog::Logger.deprecation("preferred_kernel= is no longer used [light_black](#{caller.first})[/]")
+ end
+ def preferred_kernel
+ Fog::Logger.deprecation("preferred_kernel is no longer used [light_black](#{caller.first})[/]")
+ nil
+ end
+
def reload
requires :name
@@ -41,11 +50,9 @@ def reload
def save
requires :name
- requires :preferred_kernel
requires :raw_disk
options = {
- 'preferredKernel' => preferred_kernel,
'rawDisk' => raw_disk,
'description' => description,
}
View
31 lib/fog/google/models/compute/server.rb
@@ -8,7 +8,7 @@ class Google
class Server < Fog::Compute::Server
identity :name
- attribute :image_name, :aliases => 'image'
+
attribute :network_interfaces, :aliases => 'networkInterfaces'
attribute :network, :aliases => 'network'
attribute :external_ip, :aliases => 'externalIP'
@@ -16,9 +16,31 @@ class Server < Fog::Compute::Server
attribute :zone_name, :aliases => 'zone'
attribute :machine_type, :aliases => 'machineType'
attribute :disks, :aliases => 'disks'
- attribute :kernel, :aliases => 'kernel'
attribute :metadata
attribute :tags, :squash => 'items'
+ attribute :self_link, :aliases => 'selfLink'
+
+ def image_name=(args)
+ Fog::Logger.deprecation("image_name= is no longer used [light_black](#{caller.first})[/]")
+ end
+
+ def image_name
+ boot_disk = disks.first
+ unless boot_disk.is_a?(Disk)
+ source = boot_disk['source']
+ match = source.match(%r{/zones/(.*)/disks/(.*)$})
+ boot_disk = service.disks.get match[2], match[1]
+ end
+ boot_disk.source_image.nil? ? nil : boot_disk.source_image
+ end
+
+ def kernel=(args)
+ Fog::Logger.deprecation("kernel= is no longer used [light_black](#{caller.first})[/]")
+ end
+ def kernel
+ Fog::Logger.deprecation("kernel is no longer used [light_black](#{caller.first})[/]")
+ nil
+ end
def flavor_id
machine_type
@@ -39,7 +61,9 @@ def destroy
operation
end
+ # not used since v1
def image
+ Fog::Logger.deprecation("Server.image is deprecated, get source_image from boot disk")
service.get_image(self.image_name.split('/')[-1])
end
@@ -112,6 +136,7 @@ def save
requires :name
requires :machine_type
requires :zone_name
+ requires :disks
if not service.zones.find{ |zone| zone.name == self.zone_name }
raise ArgumentError.new "#{self.zone_name.inspect} is either down or you don't have permission to use it."
@@ -120,13 +145,11 @@ def save
self.add_ssh_key(self.username, self.public_key) if self.public_key
options = {
- 'image' => image_name,
'machineType' => machine_type,
'networkInterfaces' => network_interfaces,
'network' => network,
'externalIp' => external_ip,
'disks' => disks,
- 'kernel' => kernel,
'metadata' => metadata,
'tags' => tags
}.delete_if {|key, value| value.nil?}
View
34 lib/fog/google/models/compute/servers.rb
@@ -45,22 +45,38 @@ def get(identity, zone=nil)
end
def bootstrap(new_attributes = {})
+ name = "fog-#{Time.now.to_i}"
+ zone = "us-central1-b"
+
+ disks = new_attributes[:disks]
+
+ if disks.nil? or disks.empty?
+ # create the persistent boot disk
+ disk_defaults = {
+ :name => name,
+ :size_gb => 10,
+ :zone_name => zone,
+ :source_image => "debian-7-wheezy-v20131120",
+ }
+
+ # backwards compatibility to pre-v1
+ new_attributes[:source_image] = new_attributes[:image_name] if new_attributes[:image_name]
+
+ disk = service.disks.create(disk_defaults.merge(new_attributes))
+ disk.wait_for { disk.ready? }
+ disks = [disk]
+ end
+
defaults = {
- :name => "fog-#{Time.now.to_i}",
- :image_name => "debian-7-wheezy-v20131014",
+ :name => name,
+ :disks => disks,
:machine_type => "n1-standard-1",
- :zone_name => "us-central1-b",
+ :zone_name => zone,
:private_key_path => File.expand_path("~/.ssh/id_rsa"),
:public_key_path => File.expand_path("~/.ssh/id_rsa.pub"),
:username => ENV['USER'],
}
- if new_attributes[:disks]
- new_attributes[:disks].each do |disk|
- defaults.delete :image_name if disk['boot']
- end
- end
-
server = create(defaults.merge(new_attributes))
server.wait_for { sshable? }
View
1  lib/fog/google/models/compute/zone.rb
@@ -14,6 +14,7 @@ class Zone < Fog::Model
attribute :end_time, :aliases => 'endTime'
attribute :quotas
attribute :region
+ attribute :self_link, :aliases => 'selfLink'
def up?
self.status == "UP"
View
58 lib/fog/google/requests/compute/insert_disk.rb
@@ -6,18 +6,15 @@ class Mock
def insert_disk(disk_name, zone_name, image_name=nil, options={})
# check that image and zone exist
- image_project = nil
- unless image_name.nil?
- ([ @project ] + Fog::Compute::Google::Images::GLOBAL_PROJECTS).each do |project|
- image_project = project
- break if data(project)[:images][options['image']]
- end
- get_image(image_name, image_project) # ok if image exists, will fail otherwise
+ image = nil
+ if image_name
+ image = images.get(image_name)
+ raise ArgumentError.new("Invalid image specified: #{image_name}") unless image
end
get_zone(zone_name)
id = Fog::Mock.random_numbers(19).to_s
- self.data[:disks][disk_name] = {
+ object = {
"kind" => "compute#disk",
"id" => id,
"creationTimestamp" => Time.now.iso8601,
@@ -27,22 +24,37 @@ def insert_disk(disk_name, zone_name, image_name=nil, options={})
"sizeGb" => options['sizeGb'] || "10",
"selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/disks/#{disk_name}"
}
+ if image
+ object.merge({
+ "sourceImage" => image.self_link,
+ "sourceImageId" => image.id
+ })
+ end
+ self.data[:disks][disk_name] = object
+
+ if image
+ object.merge!({
+ "sourceImage" => image.self_link,
+ "sourceImageId" => image.id
+ })
+ end
+ self.data[:disks][disk_name] = object
operation = self.random_operation
self.data[:operations][operation] = {
"kind" => "compute#operation",
"id" => Fog::Mock.random_numbers(19).to_s,
"name" => operation,
- "zone" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}",
+ "zone" => object["zone"],
"operationType" => "insert",
- "targetLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/disks/#{disk_name}",
+ "targetLink" => object["selfLink"],
"targetId" => id,
"status" => Fog::Compute::Google::Operation::PENDING_STATE,
"user" => "123456789012-qwertyuiopasdfghjkl1234567890qwe@developer.gserviceaccount.com",
"progress" => 0,
"insertTime" => Time.now.iso8601,
"startTime" => Time.now.iso8601,
- "selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/operations/#{operation}"
+ "selfLink" => "#{object["zone"]}/operations/#{operation}"
}
build_response(:body => self.data[:operations][operation])
@@ -60,26 +72,32 @@ def insert_disk(disk_name, zone_name, image_name=nil, opts={})
}
if image_name
+ # New disk from image
image = images.get(image_name)
- raise ArgumentError.new('Invalid image specified') unless image
+ raise ArgumentError.new("Invalid image specified: #{image_name}") unless image
@image_url = @api_url + image.resource_url
parameters['sourceImage'] = @image_url
end
body_object = { 'name' => disk_name }
- # These must be present if image_name is not specified
+ # According to Google docs, if image name is not present, only one of
+ # sizeGb or sourceSnapshot need to be present, one will create blank
+ # disk of desired size, other will create disk from snapshot
if image_name.nil?
- unless opts.has_key?('sourceSnapshot') and opts.has_key?('sizeGb')
- raise ArgumentError.new('Must specify image OR snapshot and '\
+ if opts.has_key?('sourceSnapshot')
+ # New disk from snapshot
+ snap = snapshots.get(opts.delete('sourceSnapshot'))
+ raise ArgumentError.new('Invalid source snapshot') unless snap
+ body_object['sourceSnapshot'] = @api_url + snap.resource_url
+ elsif opts.has_key?('sizeGb')
+ # New blank disk
+ body_object['sizeGb'] = opts.delete('sizeGb')
+ else
+ raise ArgumentError.new('Must specify image OR snapshot OR '\
'disk size when creating a disk.')
end
- body_object['sizeGb'] = opts.delete('sizeGb')
-
- snap = snapshots.get(opts.delete('sourceSnapshot'))
- raise ArgumentError.new('Invalid source snapshot') unless snap
- body_object['sourceSnapshot'] = @api_url + snap.resource_url
end
# Merge in any remaining options (only 'description' should remain)
View
6 lib/fog/google/requests/compute/insert_image.rb
@@ -19,14 +19,10 @@ def insert_image(image_name, options={})
'project' => @project,
}
- kernel_url = @api_url + 'google/global/kernels/' + \
- options.delete('preferredKernel').to_s
-
body_object = {
'sourceType' => 'RAW',
'name' => image_name,
- 'rawDisk' => options.delete('rawDisk'),
- 'preferredKernel' => kernel_url,
+ 'rawDisk' => options.delete('rawDisk')
}
# Merge in the remaining params (only 'description' should remain)
View
42 lib/fog/google/requests/compute/insert_server.rb
@@ -26,17 +26,13 @@ def handle_disks(options, zone_name)
def insert_server(server_name, zone_name, options={}, *deprecated_args)
- # check that image and zone exist
- image_project = nil
- if options.has_key? 'image'
- ([ @project ] + Fog::Compute::Google::Images::GLOBAL_PROJECTS).each do |project|
- image_project = project
- break if data(project)[:images][options['image']]
- end
- get_image(options['image'], image_project) # ok if image exists, will fail otherwise
- end
+ # check that zone exists
get_zone(zone_name)
+ if options['disks'].nil? or options['disks'].empty?
+ raise ArgumentError.new "Empty value for field 'disks'. Boot disk must be specified"
+ end
+
id = Fog::Mock.random_numbers(19).to_s
self.data[:servers][server_name] = {
"kind" => "compute#instance",
@@ -47,8 +43,6 @@ def insert_server(server_name, zone_name, options={}, *deprecated_args)
"name" => server_name,
"tags" => { "fingerprint" => "42WmSpB8rSM=" },
"machineType" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/zones/#{zone_name}/machineTypes/#{options['machineType']}",
- "image" => "https://www.googleapis.com/compute/#{api_version}/projects/#{image_project}/global/images/#{options['image']}",
- "kernel" => "https://www.googleapis.com/compute/#{api_version}/projects/google/global/kernels/gce-v20130813",
"canIpForward" => false,
"networkInterfaces" => [
{
@@ -65,14 +59,7 @@ def insert_server(server_name, zone_name, options={}, *deprecated_args)
]
}
],
- "disks" => options['disks'] ? handle_disks(options, zone_name) : [
- {
- "kind" => "compute#attachedDisk",
- "index" => 0,
- "type" => "SCRATCH",
- "mode" => "READ_WRITE"
- }
- ],
+ "disks" => handle_disks(options, zone_name),
"metadata" => {
"kind" => "compute#metadata",
"fingerprint" => "5_hasd_gC3E=",
@@ -113,6 +100,8 @@ class Real
def handle_disks(options)
disks = []
+ # An array of persistent disks. You must supply a boot disk as the first disk in
+ # this array and mark it as a boot disk using the disks[].boot property.
options.delete('disks').each do |disk|
if disk.is_a? Disk
disks << disk.get_object
@@ -120,6 +109,7 @@ def handle_disks(options)
disks << disk
end
end
+ disks.first['boot'] = true
disks
end
@@ -139,12 +129,6 @@ def insert_server(server_name, zone_name, options={}, *deprecated_args)
}
body_object = {:name => server_name}
- if options.has_key? 'image'
- image_name = options.delete 'image'
- image = images.get(image_name)
- @image_url = @api_url + image.resource_url
- body_object['image'] = @image_url
- end
body_object['machineType'] = @api_url + @project + "/zones/#{zone_name}/machineTypes/#{options.delete 'machineType'}"
network = nil
if options.has_key? 'network'
@@ -170,15 +154,15 @@ def insert_server(server_name, zone_name, options={}, *deprecated_args)
# TODO: add other networks
body_object['networkInterfaces'] = networkInterfaces
- body_object['disks'] = handle_disks(options) if options['disks']
+ if options['disks'].nil? or options['disks'].empty?
+ raise ArgumentError.new "Empty value for field 'disks'. Boot disk must be specified"
+ end
+ body_object['disks'] = handle_disks(options)
options['metadata'] = format_metadata options['metadata'] if options['metadata']
body_object['tags'] = { 'items' => options.delete('tags') } if options['tags']
- if options['kernel']
- body_object['kernel'] = @api_url + "google/global/kernels/#{options.delete 'kernel'}"
- end
body_object.merge!(options) # Adds in all remaining options that weren't explicitly handled.
result = self.build_result(api_method, parameters,
View
12 tests/google/helpers/disk_helper.rb
@@ -0,0 +1,12 @@
+# create a disk to be used in tests
+def create_test_disk(connection, zone)
+ zone = 'us-central1-a'
+ disk = connection.disks.create({
+ :name => "fogservername",
+ :size_gb => "2",
+ :zone_name => zone,
+ :source_image => "debian-7-wheezy-v20131120",
+ })
+ disk.wait_for { ready? }
+ disk
+end
View
5 tests/google/models/compute/server_tests.rb
@@ -1,6 +1,9 @@
Shindo.tests("Fog::Compute[:google] | server model", ['google']) do
- model_tests(Fog::Compute[:google].disks, {:name => 'fogservername', :zone_name => 'us-central1-a', :machine_type => 'n1-standard-1'})
+ @zone = 'us-central1-a'
+ @disk = create_test_disk(Fog::Compute[:google], @zone)
+
+ model_tests(Fog::Compute[:google].servers, {:name => 'fogservername', :zone_name => @zone, :machine_type => 'n1-standard-1', :disks => [@disk]})
tests('servers') do
@instance = nil
View
5 tests/google/models/compute/servers_tests.rb
@@ -1,5 +1,8 @@
Shindo.tests("Fog::Compute[:google] | servers", ['google']) do
- collection_tests(Fog::Compute[:google].servers, {:name => 'fogservername', :zone_name => 'us-central1-a', :machine_type => 'n1-standard-1'})
+ @zone = 'us-central1-a'
+ @disk = create_test_disk(Fog::Compute[:google], @zone)
+
+ collection_tests(Fog::Compute[:google].servers, {:name => 'fogservername', :zone_name => @zone, :machine_type => 'n1-standard-1', :disks => [@disk]})
end
View
1  tests/google/requests/compute/image_tests.rb
@@ -24,7 +24,6 @@
'name' => String,
'description' => String,
'sourceType' => String,
- 'preferredKernel' => String,
'rawDisk' => {
'containerType' => String,
'source' => String
View
3  tests/google/requests/compute/server_tests.rb
@@ -59,10 +59,11 @@
zone_name = "us-central1-a"
tests("#insert_server").formats(@insert_server_format) do
+ disk = create_test_disk(Fog::Compute[:google], zone_name)
@google.insert_server(
server_name,
zone_name,
- { 'image' => image_name, 'machineType' => machine_type }
+ { 'image' => image_name, 'machineType' => machine_type, 'disks' => [disk] }
).body
end
Something went wrong with that request. Please try again.