Sha256: 352055d9663fe0730511bf20e83f77a07d6671bf7b62a26b04102a3a8c3d9f08

Contents?: true

Size: 1.7 KB

Versions: 17

Compression:

Stored size: 1.7 KB

Contents

# All examples presume that you have a ~/.fog credentials file set up.
# More info on it can be found here: http://fog.io/about/getting_started.html

require "bundler"
Bundler.require(:default, :development)

def example
  p "Connecting to Google API"
  connection = Fog::Compute.new(:provider => "Google")

  p "Creating disk"
  disk = connection.disks.create(
    :name => "fog-smoke-test-#{Time.now.to_i}",
    :size_gb => 10,
    :zone => "us-central1-f",
    :source_image => "debian-9-stretch-v20180611"
  )

  p "Creating a second disk"
  attached_disk = connection.disks.create(
    :name => "fog-smoke-test-#{Time.now.to_i}",
    :size_gb => 10,
    :zone => "us-central1-f"
  )

  p "Waiting for disks to be ready"
  disk.wait_for { ready? }
  attached_disk.wait_for { ready? }

  p "Creating a server"
  server = connection.servers.create(
    :name => "fog-smoke-test-#{Time.now.to_i}",
    :disks => [disk.attached_disk_obj(boot: true),
               attached_disk.attached_disk_obj(boot: false,
                                               auto_delete: true)],
    :machine_type => "n1-standard-1",
    :private_key_path => File.expand_path("~/.ssh/id_rsa"),
    :public_key_path => File.expand_path("~/.ssh/id_rsa.pub"),
    :zone => "us-central1-f",
    # Will be simplified, see https://github.com/fog/fog-google/issues/360
    :network_interfaces => [{ :network => "global/networks/default",
                              :access_configs => [{
                                :name => "External NAT",
                                :type => "ONE_TO_ONE_NAT"
                              }] }],
    :username => ENV["USER"]
  )

  p "Deleting server"
  raise "Could not delete server." unless server.destroy
end

example

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
fog-google-1.19.0 examples/create_instance_with_attached_disk.rb
fog-google-1.18.0 examples/create_instance_with_attached_disk.rb
fog-google-1.17.0 examples/create_instance_with_attached_disk.rb
fog-google-1.16.1 examples/create_instance_with_attached_disk.rb
fog-google-1.16.0 examples/create_instance_with_attached_disk.rb
fog-google-1.15.0 examples/create_instance_with_attached_disk.rb
fog-google-1.14.0 examples/create_instance_with_attached_disk.rb
gitlab-fog-google-1.14.0 examples/create_instance_with_attached_disk.rb
fog-google-1.13.0 examples/create_instance_with_attached_disk.rb
gitlab-fog-google-1.13.0 examples/create_instance_with_attached_disk.rb
fog-google-1.12.1 examples/create_instance_with_attached_disk.rb
fog-google-1.12.0 examples/create_instance_with_attached_disk.rb
fog-google-1.11.0 examples/create_instance_with_attached_disk.rb
fog-google-1.10.0 examples/create_instance_with_attached_disk.rb
fog-google-1.9.1 examples/create_instance_with_attached_disk.rb
fog-google-1.9.0 examples/create_instance_with_attached_disk.rb
fog-google-1.8.2 examples/create_instance_with_attached_disk.rb