Size of buffer to use for transfers. Use Excon's default chunk size and if that's not avaliable we will default to 1 MB
UUID for INTERNET
if !ONE_LOCATION
Size of segment. The Rackspace cloud currently requires files larger than 5GB to be segmented so we will choose 5GB -1 for a size docs.rackspace.com/files/api/v1/cf-devguide/content/Large_Object_Creation-d1e2019.html
UUID for Rackspace's service net
else
NOVNC_LOCK_FILE= ONE_LOCATION + "/var/.novnc.lock"
end
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
I have notice that cloud networks is slow to acknowledge deleted servers. This method tries to mitigate this.
# File lib/fog/rackspace/examples/compute_v2/delete_network.rb, line 17 def delete_network(network) attempt = 0 begin network.destroy rescue Fog::Compute::RackspaceV2::ServiceError => e if attempt == 3 puts "Unable to delete #{network.label}" return false end puts "Network #{network.label} Delete Fail Attempt #{attempt}- #{e.inspect}" attempt += 1 sleep 60 retry end return true end
Generates a ssh key using the SSHKey library. The private key is avaialble via the '.private_key' and the public key is avaialble via '.ssh_public_key'
# File lib/fog/rackspace/examples/compute_v2/bootstrap_server.rb, line 29 def generate_ssh_key SSHKey.generate end
# File lib/fog/rackspace/examples/queues/list_messages.rb, line 13 def get_user_boolean(prompt) str = get_user_input(prompt) return false unless str str.match(/y(es)?/) ? true : false end
# File lib/fog/rackspace/examples/auto_scale/add_policy.rb, line 7 def get_user_input(prompt) print "#{prompt}: " gets.chomp end
# File lib/fog/rackspace/examples/auto_scale/add_policy.rb, line 12 def get_user_input_as_int(prompt) str = get_user_input(prompt) str.to_i 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/auto_scale/add_policy.rb, line 25 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/auto_scale/add_policy.rb, line 19 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_directory.rb, line 13 def select_directory(directories) abort "\nThere are not any directories to delete in the Chicago region. Try running create_directory.rb\n\n" if directories.empty? puts "\nSelect Directory To Delete:\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/auto_scale/add_policy.rb, line 29 def select_group(groups) abort "\nThere are not any scaling groups in the Chicago region. Try running create_scaling_group.rb\n\n" if groups.empty? puts "\nSelect Group For New Policy:\n\n" groups.each_with_index do |group, i| config = group.group_config puts "\t #{i}. #{config.name}" end select_str = get_user_input "\nEnter Group Number" groups[select_str.to_i] end
# File lib/fog/rackspace/examples/auto_scale/create_scaling_group.rb, line 36 def select_image(images) puts "\nSelect Image For Server:\n\n" images.each_with_index do |image, i| puts "\t #{i}. #{image.name}" end select_str = get_user_input "\nEnter Image Number" images[select_str.to_i] end
# File lib/fog/rackspace/examples/queues/delete_message.rb, line 25 def select_message(messages) abort "\nThere are not any messages in the Chicago region. Try running post_message.rb\n\n" if messages.empty? puts "\nSelect Message To Delete:\n\n" messages.each_with_index do |message, i| puts "\t #{i}. [#{message.id}] #{message.body[0..50]}" end delete_str = get_user_input "\nEnter Message Number" messages[delete_str.to_i] end
# File lib/fog/rackspace/examples/auto_scale/add_webhook.rb, line 37 def select_policy(policies) abort "\nThere are no policies for this scaling group. Try running add_policy.rb\n\n" if policies.empty? puts "\nSelect Policy Triggered By Webhook:\n\n" policies.each_with_index do |policy, i| puts "\t #{i}. #{policy.name}" end select_str = get_user_input "\nEnter Policy Number" policies[select_str.to_i] end
# File lib/fog/rackspace/examples/queues/claim_messages.rb, line 13 def select_queue(queues) abort "\nThere are not any queues the Chicago region. Try running create_queue.rb\n\n" if queues.empty? puts "\nSelect Queue To Delete:\n\n" queues.each_with_index do |queue, i| puts "\t #{i}. #{queue.name}" end delete_str = get_user_input "\nEnter Queue Number" queues[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
# File lib/fog/rackspace/examples/auto_scale/delete_webhook.rb, line 49 def select_webhook(webhooks) abort "\nThere are no webhooks for this policy. Try running add_webhook.rb\n\n" if webhooks.empty? puts "\nSelect Webhook:\n\n" webhooks.each_with_index do |webhook, i| puts "\t #{i}. #{webhook.name}" end select_str = get_user_input "\nEnter Webhook Number" webhooks[select_str.to_i] end
# File lib/fog/google/examples/bootstrap.rb, line 1 def test connection = Fog::Compute.new({ :provider => "Google" }) server = connection.servers.bootstrap server.wait_for { sshable? } raise "Could not bootstrap sshable server." unless server.ssh("whoami") raise "Could not delete server." unless server.destroy end
# File lib/fog/rackspace/examples/compute_v2/delete_network.rb, line 8 def wait_for_server_deletion(server) begin server.wait_for { state = 'DELETED' } rescue Fog::Compute::RackspaceV2::NotFound => e # do nothing end end