Sha256: 25dbe4ec8be3cfece38ee6144811ad7ce63504507baebe32c540877b55413760

Contents?: true

Size: 1.61 KB

Versions: 67

Compression:

Stored size: 1.61 KB

Contents

# OpenStack Compute (Nova) Example

require 'fog/openstack'

auth_url = "https://example.net/v2.0/tokens"
username = 'admin@example.net'
password = 'secret'
tenant   = 'My Compute Tenant' # String

compute_client ||= ::Fog::Compute.new(:provider           => :openstack,
                                      :openstack_api_key  => password  ,
                                      :openstack_username => username  ,
                                      :openstack_auth_url => auth_url  ,
                                      :openstack_tenant   => tenant)

# Create VM
# Options include metadata, availability zone, etc...

begin
  vm = compute_client.servers.create(:name => 'lucky',
                                     :image_ref => 'fcd8f8a9',
                                     :flavor_ref => 4)
rescue => e
  puts JSON.parse(e.response.body)['badRequest']['message']
end

# Destroy VM

vm = compute_client.servers.get(vm.id) # Retrieve previously created vm by UUID
floating_ips = vm.all_addresses # fetch and release its floating IPs
floating_ips.each do |address|
  compute_client.disassociate_address(uuid, address['ip'])
  compute_client.release_address(address['id'])
end
vm.destroy

# Images available at tenant
image_names = compute_client.images.map { |image| image['name'] }

# Floating IP address pools available at tenant
compute_client.addresses.get_address_pools
# response.body #=> { 'name' => 'pool1' }, { 'name' => 'pool2' }

# VNC console
vm.console.body # returns VNC url

# "console" => {
#                "url"  => "http://vmvncserver:6080/vnc_auto.html?token=231",
#                "type" => "novnc"
#              }

Version data entries

67 entries across 65 versions & 5 rubygems

Version Path
fog-openstack-0.1.27 examples/compute/basics.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-openstack-0.1.26/examples/compute/basics.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-openstack-0.1.26/examples/compute/basics.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-openstack-0.1.26/examples/compute/basics.rb
fog-openstack-0.1.26 examples/compute/basics.rb
fog-openstack-0.1.25 examples/compute/basics.rb
fog-openstack-0.1.24 examples/compute/basics.rb
fog-openstack-0.1.23 examples/compute/basics.rb
fog-openstack-0.1.22 examples/compute/basics.rb
fog-openstack-0.1.21 examples/compute/basics.rb
fog-openstack-0.1.20 examples/compute/basics.rb
fog-openstack-0.1.19 examples/compute/basics.rb
fog-openstack-0.1.18 examples/compute/basics.rb
fog-openstack-0.1.17 examples/compute/basics.rb
fog-openstack-0.1.15 examples/compute/basics.rb
fog-openstack-0.1.14 examples/compute/basics.rb
fog-openstack-0.1.13 examples/compute/basics.rb
fog-openstack-0.1.12 examples/compute/basics.rb
fog-openstack-0.1.11 examples/compute/basics.rb
fog-openstack-0.1.10 examples/compute/basics.rb