如何使用 Fog In Ruby 创建 Google 计算引擎实例

How To Create Google Compute Engine Instance Using Fog In Ruby

我尝试使用以下代码,但出现错误,

server = connection.servers.create({
:name => "instance-#{Time.now}",
:image_name => "debian-7-wheezy-v20150325",
      :machine_type => "f1-micro",
        :zone_name => "us-central1-a",         
})

/home/vijay/.rvm/gems/ruby-2.0.0-p598/gems/fog-core-1.30.0/lib/fog/core/attributes.rb:151:in `requires': disks is required for this operation (ArgumentError)
from /home/vijay/.rvm/gems/ruby-2.0.0-p598/gems/fog-1.29.0/lib/fog/google/models/compute/server.rb:218:in `save'
from /home/vijay/.rvm/gems/ruby-2.0.0-p598/gems/fog-core-1.30.0/lib/fog/core/collection.rb:51:in `create'
from google_compute_engine.rb:11:in `<main>'

我想我缺少一些必需的参数,谁能帮我解决这个问题。

首先创建一个磁盘:

disk = connection.disks.create({
  :name => "my-disk",
  :zone_name => "us-central1-a",
  :size_gb => 10,
  :source_image => "debian-7-wheezy-v20150325"})

接下来使用该磁盘创建实例:

server = connection.servers.create({
  :name => "my-server",
  :machine_type => "f1-micro",
  :zone_name => "us-central1-a",
  :disks => [disk.get_as_boot_disk]})

请注意,您可以在创建实例时附加多个磁盘。