0

I try with following code but i am getting error,

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>'

I think i am missing some parameter which is required, can someone help me to solve this problem.

Vijay
  • 443
  • 4
  • 13

1 Answers1

4

First create a disk:

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

Next create the instance with that disk:

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

Note you can attach multiple disks at instance creation.

Paul Rossman
  • 171
  • 3
  • thanks a lot @Paul it is working. can you suggest any site where i can learn it. – Vijay Apr 30 '15 at 05:44
  • 1
    Take a look at the Fog repo https://github.com/fog/fog-google In particular https://github.com/fog/fog-google/blob/master/lib/fog/google/models/compute/disk.rb and https://github.com/fog/fog-google/blob/master/lib/fog/google/models/compute/server.rb – Paul Rossman Apr 30 '15 at 17:34