|
| 1 | +# All examples presume that you have a ~/.fog credentials file set up. |
| 2 | +# More info on it can be found here: http://fog.io/about/getting_started.html |
| 3 | + |
| 4 | +require "bundler" |
| 5 | +Bundler.require(:default, :development) |
| 6 | + |
| 7 | +def example |
| 8 | + p "Connecting to Google API" |
| 9 | + connection = Fog::Compute.new(:provider => "Google") |
| 10 | + |
| 11 | + p "Creating disk" |
| 12 | + disk = connection.disks.create( |
| 13 | + :name => "fog-smoke-test-#{Time.now.to_i}", |
| 14 | + :size_gb => 10, |
| 15 | + :zone => "us-central1-f", |
| 16 | + :source_image => "debian-9-stretch-v20180611" |
| 17 | + ) |
| 18 | + |
| 19 | + p "Creating a second disk" |
| 20 | + attached_disk = connection.disks.create( |
| 21 | + :name => "fog-smoke-test-#{Time.now.to_i}", |
| 22 | + :size_gb => 10, |
| 23 | + :zone => "us-central1-f" |
| 24 | + ) |
| 25 | + |
| 26 | + p "Waiting for disks to be ready" |
| 27 | + disk.wait_for { ready? } |
| 28 | + attached_disk.wait_for { ready? } |
| 29 | + |
| 30 | + p "Creating a server" |
| 31 | + server = connection.servers.create( |
| 32 | + :name => "fog-smoke-test-#{Time.now.to_i}", |
| 33 | + :disks => [disk.attached_disk_obj(boot: true), |
| 34 | + attached_disk.attached_disk_obj(boot: false, |
| 35 | + auto_delete: true)], |
| 36 | + :machine_type => "n1-standard-1", |
| 37 | + :private_key_path => File.expand_path("~/.ssh/id_rsa"), |
| 38 | + :public_key_path => File.expand_path("~/.ssh/id_rsa.pub"), |
| 39 | + :zone => "us-central1-f", |
| 40 | + # Will be simplified, see https://github.com/fog/fog-google/issues/360 |
| 41 | + :network_interfaces => [{ :network => "global/networks/default", |
| 42 | + :access_configs => [{ |
| 43 | + :name => "External NAT", |
| 44 | + :type => "ONE_TO_ONE_NAT" |
| 45 | + }] }], |
| 46 | + :username => ENV["USER"] |
| 47 | + ) |
| 48 | + |
| 49 | + p "Deleting server" |
| 50 | + raise "Could not delete server." unless server.destroy |
| 51 | +end |
| 52 | + |
| 53 | +example |
0 commit comments