BasicObject
Quantum demo
Create some routers, networks and subnets for a couple of tenants.
Needs Fog >= 1.11.0 Needs OpenStack credentials in ~/.fog
# File lib/fog/openstack/examples/network/network_subnets_routers.rb, line 13 def create_tenant_network( tenant_name, external_net, router_name = 'router1', subnet_range = '10.0.0.0/21', subnet_gateway = '10.0.0.1', private_network_name = 'private' ) network = Fog::Network[:openstack] id = Fog::Identity[:openstack] tenant = id.tenants.find { |t| t.name == tenant_name } # Create a router for the tenant router = network.routers.create :name => router_name, :tenant_id => tenant.id, :external_gateway_info => { 'network_id' => external_net.id } # Create a private network for the tenant net = network.networks.create :name => private_network_name, :tenant_id => tenant.id # Create a subnet for the previous network and associate it # with the tenant subnet = network.subnets.create :name => 'net_10', :network_id => net.id, :ip_version => 4, :gateway_ip => subnet_gateway, :cidr => subnet_range, :tenant_id => tenant.id, :enable_dhcp => true network.add_router_interface router.id, subnet.id end
# File lib/fog/rackspace/examples/block_storage/create_volume.rb, line 8 def get_user_input(prompt) print "\n#{prompt}: " gets.chomp end
# File lib/fog/rackspace/examples/compute_v2/server_metadata.rb, line 20 def print_metadata(server) server.metadata.each do |metadatum| puts "\t#{metadatum.key}: #{metadatum.value}" end puts "\n" end
Use api key defined in ~/.fog file, if absent prompt for api key For more details on ~/.fog refer to fog.io/about/getting_started.html
# File lib/fog/rackspace/examples/block_storage/create_volume.rb, line 31 def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end
Use username defined in ~/.fog file, if absent prompt for username. For more details on ~/.fog refer to fog.io/about/getting_started.html
# File lib/fog/rackspace/examples/block_storage/create_volume.rb, line 25 def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end
# File lib/fog/rackspace/examples/block_storage/create_snapshot.rb, line 25 def select_attachment(attachments) abort "\nThis server does not contain any volumes in the Chicago region. Try running server_attachments.rb\n\n" if attachments.empty? puts "\nSelect Volume To Detach:\n\n" attachments.each_with_index do |attachment, i| puts "\t #{i}. #{attachment.device}" end delete_str = get_user_input "\nEnter Volume Number" attachments[delete_str.to_i] end
# File lib/fog/rackspace/examples/storage/delete_file.rb, line 13 def select_directory(directories) abort "\nThere are not any directories with files to delete in the Chicago region. Try running create_file.rb\n\n" if directories.empty? puts "\nSelect Directory:\n\n" directories.each_with_index do |dir, i| puts "\t #{i}. #{dir.key} [#{dir.count} objects]" end delete_str = get_user_input "\nEnter Directory Number" directories[delete_str.to_i] end
# File lib/fog/rackspace/examples/storage/delete_file.rb, line 25 def select_file(files) puts "\nSelect File:\n\n" files.each_with_index do |file, i| puts "\t #{i}. #{file.key}" end delete_str = get_user_input "\nEnter File Number" files[delete_str.to_i] end
# File lib/fog/rackspace/examples/compute_v2/resize_server.rb, line 13 def select_flavor(flavors, server) puts "\nSelect New Flavor Size:\n\n" flavors.each_with_index do |flavor, i| next if server.flavor_id == flavor.id puts "\t #{i}. #{flavor.name}" end selected_flavor_str = get_user_input "\nEnter Flavor Number" flavors[selected_flavor_str.to_i] end
# File lib/fog/rackspace/examples/compute_v2/delete_image.rb, line 13 def select_image(snapshot_images) abort "\nThere are not any images to delete in the Chicago region. Try running create_image.rb\n\n" if snapshot_images.empty? puts "\nSelect Image To Delete:\n\n" snapshot_images.each_with_index do |image, i| puts "\t #{i}. #{image.name}" end delete_str = get_user_input "\nEnter Image Number" snapshot_images[delete_str.to_i] end
# File lib/fog/rackspace/examples/block_storage/create_snapshot.rb, line 13 def select_server(servers) abort "\nThere are not any servers in the Chicago region. Try running create_server.rb\n\n" if servers.empty? puts "\nSelect Server For Volume Detachment:\n\n" servers.each_with_index do |server, i| puts "\t #{i}. #{server.name} [#{server.public_ip_address}]" end delete_str = get_user_input "\nEnter Server Number" servers[delete_str.to_i] end
# File lib/fog/rackspace/examples/block_storage/delete_volume.rb, line 13 def select_volume(volumes) abort "\nThere are not any volumes to delete in the Chicago region. Try running create_volume.rb\n\n" if volumes.empty? puts "\nSelect Volume:\n\n" volumes.each_with_index do |volume, i| puts "\t #{i}. #{volume.display_name}" end selected_str = get_user_input "Enter Volume Type Number" volumes[selected_str.to_i] end
# File lib/fog/rackspace/examples/block_storage/create_volume.rb, line 13 def select_volume_type(volume_types) puts "\nSelect Volume Type:\n\n" volume_types.each_with_index do |volume_type, i| puts "\t #{i}. #{volume_type.name}" end selected_str = get_user_input "Enter Volume Type Number" volume_types[selected_str.to_i] end
Generated with the Darkfish Rdoc Generator 2.