fog-rackspace-0.1.1/0000755000175000017500000000000012752304415013447 5ustar debiandebianfog-rackspace-0.1.1/.gitignore0000644000175000017500000000013512752304415015436 0ustar debiandebian/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ *.gem fog-rackspace-0.1.1/Gemfile0000644000175000017500000000014212752304415014737 0ustar debiandebiansource 'https://rubygems.org' # Specify your gem's dependencies in fog-rackspace.gemspec gemspec fog-rackspace-0.1.1/CODE_OF_CONDUCT.md0000644000175000017500000000453012752304415016250 0ustar debiandebian# Contributor Code of Conduct As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery * Personal attacks * Trolling or insulting/derogatory comments * Public or private harassment * Publishing other's private information, such as physical or electronic addresses, without explicit permission * Other unethical or unprofessional conduct Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer at matt.darby@rackspace.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident. This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.3.0, available at [http://contributor-covenant.org/version/1/3/0/][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/3/0/fog-rackspace-0.1.1/LICENSE.txt0000644000175000017500000000206512752304415015275 0ustar debiandebianThe MIT License (MIT) Copyright (c) 2016 Matt Darby Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fog-rackspace-0.1.1/Rakefile0000644000175000017500000000016512752304415015116 0ustar debiandebianrequire "bundler/gem_tasks" require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) task :default => :spec fog-rackspace-0.1.1/fog-rackspace.gemspec0000644000175000017500000000242012752304415017517 0ustar debiandebian# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'fog/rackspace/version' Gem::Specification.new do |spec| spec.name = "fog-rackspace" spec.version = Fog::Rackspace::VERSION spec.authors = ["Matt Darby"] spec.email = ["matt.darby@rackspace.com"] spec.summary = %q{Rackspace support for Fog} spec.description = %q{Rackspace provider gem for Fog} spec.homepage = "http://developer.rackspace.com" spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_development_dependency 'bundler', '~> 1.6' spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'shindo', '~> 0.3' spec.add_development_dependency 'rubyzip', '~> 0.9.9' spec.add_development_dependency "mime-types" spec.add_development_dependency "mime-types-data" spec.add_dependency 'fog-core', '>= 1.35' spec.add_dependency 'fog-json', '>= 1.0' spec.add_dependency 'fog-xml', '>= 0.1' spec.add_dependency 'ipaddress', '>= 0.8' end fog-rackspace-0.1.1/lib/0000755000175000017500000000000012752304415014215 5ustar debiandebianfog-rackspace-0.1.1/lib/fog/0000755000175000017500000000000012752304415014770 5ustar debiandebianfog-rackspace-0.1.1/lib/fog/rackspace.rb0000644000175000017500000000120612752304415017250 0ustar debiandebianrequire "fog/rackspace/version" module Fog module Rackspace # Your code goes here... end end require 'fog/rackspace/auto_scale' require 'fog/rackspace/block_storage' require 'fog/rackspace/cdn' require 'fog/rackspace/cdn_v2' require 'fog/rackspace/compute' require 'fog/rackspace/compute_v2' require 'fog/rackspace/databases' require 'fog/rackspace/dns' require 'fog/rackspace/identity' require 'fog/rackspace/load_balancers' require 'fog/rackspace/monitoring' require 'fog/rackspace/queues' require 'fog/rackspace/storage' require 'fog/rackspace/networking' require 'fog/rackspace/orchestration' require 'fog/rackspace/networking_v2' fog-rackspace-0.1.1/lib/fog/rackspace/0000755000175000017500000000000012752304415016724 5ustar debiandebianfog-rackspace-0.1.1/lib/fog/rackspace/storage.rb0000644000175000017500000003755712752304415020736 0ustar debiandebianrequire 'fog/rackspace/core' module Fog module Storage class Rackspace < Fog::Service include Fog::Rackspace::Errors class ServiceError < Fog::Rackspace::Errors::ServiceError; end class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end class BadRequest < Fog::Rackspace::Errors::BadRequest; end requires :rackspace_api_key, :rackspace_username recognizes :rackspace_auth_url, :rackspace_servicenet, :rackspace_cdn_ssl, :persistent, :rackspace_region recognizes :rackspace_temp_url_key, :rackspace_storage_url, :rackspace_cdn_url model_path 'fog/rackspace/models/storage' model :directory collection :directories model :file collection :files model :account request_path 'fog/rackspace/requests/storage' request :copy_object request :delete_container request :delete_object request :delete_static_large_object request :delete_multiple_objects request :get_container request :get_containers request :get_object request :get_object_https_url request :get_object_http_url request :head_container request :head_containers request :head_object request :put_container request :put_object request :put_object_manifest request :put_dynamic_obj_manifest request :put_static_obj_manifest request :post_set_meta_temp_url_key request :extract_archive module Common def apply_options(options) @rackspace_api_key = options[:rackspace_api_key] @rackspace_username = options[:rackspace_username] @rackspace_cdn_ssl = options[:rackspace_cdn_ssl] @rackspace_auth_url = options[:rackspace_auth_url] @rackspace_servicenet = options[:rackspace_servicenet] @rackspace_auth_token = options[:rackspace_auth_token] @rackspace_storage_url = options[:rackspace_storage_url] @rackspace_cdn_url = options[:rackspace_cdn_url] @rackspace_region = options[:rackspace_region] @rackspace_temp_url_key = options[:rackspace_temp_url_key] @rackspace_must_reauthenticate = false @connection_options = options[:connection_options] || {} unless @rackspace_region || (@rackspace_storage_url && @rackspace_cdn_url) Fog::Logger.deprecation("Default region support will be removed in an upcoming release. Please switch to manually setting your endpoint. This requires settng the :rackspace_region option.") end @rackspace_region ||= :dfw end def cdn @cdn ||= Fog::CDN.new( :provider => 'Rackspace', :rackspace_api_key => @rackspace_api_key, :rackspace_auth_url => @rackspace_auth_url, :rackspace_cdn_url => @rackspace_cdn_url, :rackspace_username => @rackspace_username, :rackspace_region => @rackspace_region, :rackspace_cdn_ssl => @rackspace_cdn_ssl ) if @cdn.enabled? @cdn end end def service_net? @rackspace_servicenet == true end def authenticate if @rackspace_must_reauthenticate || @rackspace_auth_token.nil? options = { :rackspace_api_key => @rackspace_api_key, :rackspace_username => @rackspace_username, :rackspace_auth_url => @rackspace_auth_url, :connection_options => @connection_options } super(options) else @auth_token = @rackspace_auth_token @uri = URI.parse(@rackspace_storage_url) end end def service_name :cloudFiles end def request_id_header "X-Trans-Id" end def region @rackspace_region end def endpoint_uri(service_endpoint_url=nil) return @uri if @uri super(@rackspace_storage_url || service_endpoint_url, :rackspace_storage_url) end # Return Account Details # @return [Fog::Storage::Rackspace::Account] account details object def account account = Fog::Storage::Rackspace::Account.new(:service => self) account.reload end end class Mock < Fog::Rackspace::Service include Common # An in-memory container for use with Rackspace storage mocks. Includes # many `objects` mapped by (escaped) object name. Tracks container # metadata. class MockContainer attr_reader :objects, :meta, :service # Create a new container. Generally, you should call # {Fog::Rackspace::Storage#add_container} instead. def initialize(service) @service = service @objects, @meta = {}, {} end # Determine if this container contains any MockObjects or not. # # @return [Boolean] def empty? @objects.empty? end # Total sizes of all objects added to this container. # # @return [Integer] The number of bytes occupied by each contained # object. def bytes_used @objects.values.map { |o| o.bytes_used }.reduce(0) { |a, b| a + b } end # Render the HTTP headers that would be associated with this # container. # # @return [Hash] Any metadata supplied to this # container, plus additional headers indicating the container's # size. def to_headers @meta.merge({ 'X-Container-Object-Count' => @objects.size, 'X-Container-Bytes-Used' => bytes_used }) end # Access a MockObject within this container by (unescaped) name. # # @return [MockObject, nil] Return the MockObject at this name if # one exists; otherwise, `nil`. def mock_object(name) @objects[Fog::Rackspace.escape(name)] end # Access a MockObject with a specific name, raising a # `Fog::Storage::Rackspace::NotFound` exception if none are present. # # @param name [String] (Unescaped) object name. # @return [MockObject] The object within this container with the # specified name. def mock_object!(name) mock_object(name) or raise Fog::Storage::Rackspace::NotFound.new end # Add a new MockObject to this container. An existing object with # the same name will be overwritten. # # @param name [String] The object's name, unescaped. # @param data [String, #read] The contents of the object. def add_object(name, data) @objects[Fog::Rackspace.escape(name)] = MockObject.new(data, service) end # Remove a MockObject from the container by name. No effect if the # object is not present beforehand. # # @param name [String] The (unescaped) object name to remove. def remove_object(name) @objects.delete Fog::Rackspace.escape(name) end end # An in-memory Swift object. class MockObject attr_reader :hash, :bytes_used, :content_type, :last_modified attr_reader :body, :meta, :service attr_accessor :static_manifest # Construct a new object. Generally, you should call # {MockContainer#add_object} instead of instantiating these directly. def initialize(data, service) data = Fog::Storage.parse_data(data) @service = service @bytes_used = data[:headers]['Content-Length'] @content_type = data[:headers]['Content-Type'] if data[:body].respond_to? :read @body = data[:body].read else @body = data[:body] end @last_modified = Time.now.utc @hash = Digest::MD5.hexdigest(@body) @meta = {} @static_manifest = false end # Determine if this object was created as a static large object # manifest. # # @return [Boolean] def static_manifest? @static_manifest end # Determine if this object has the metadata header that marks it as a # dynamic large object manifest. # # @return [Boolean] def dynamic_manifest? ! large_object_prefix.nil? end # Iterate through each MockObject that contains a part of the data for # this logical object. In the normal case, this will only yield the # receiver directly. For dynamic and static large object manifests, # however, this call will yield each MockObject that contains a part # of the whole, in sequence. # # Manifests that refer to containers or objects that don't exist will # skip those sections and log a warning, instead. # # @yield [MockObject] Each object that holds a part of this logical # object. def each_part case when dynamic_manifest? # Concatenate the contents and sizes of each matching object. # Note that cname and oprefix are already escaped. cname, oprefix = large_object_prefix.split('/', 2) target_container = service.data[cname] if target_container all = target_container.objects.keys matching = all.select { |name| name.start_with? oprefix } keys = matching.sort keys.each do |name| yield target_container.objects[name] end else Fog::Logger.warning "Invalid container in dynamic object manifest: #{cname}" yield self end when static_manifest? Fog::JSON.decode(body).each do |segment| cname, oname = segment['path'].split('/', 2) cont = service.mock_container cname unless cont Fog::Logger.warning "Invalid container in static object manifest: #{cname}" next end obj = cont.mock_object oname unless obj Fog::Logger.warning "Invalid object in static object manifest: #{oname}" next end yield obj end else yield self end end # Access the object name prefix that controls which other objects # comprise a dynamic large object. # # @return [String, nil] The object name prefix, or `nil` if none is # present. def large_object_prefix @meta['X-Object-Manifest'] end # Construct the fake HTTP headers that should be returned on requests # targetting this object. Includes computed `Content-Type`, # `Content-Length`, `Last-Modified` and `ETag` headers in addition to # whatever metadata has been associated with this object manually. # # @return [Hash] Header values stored in a Hash. def to_headers { 'Content-Type' => @content_type, 'Content-Length' => @bytes_used, 'Last-Modified' => @last_modified.strftime('%a, %b %d %Y %H:%M:%S %Z'), 'ETag' => @hash }.merge(@meta) end end def self.data @data ||= Hash.new do |hash, key| hash[key] = {} end end # Access or create account-wide metadata. # # @return [Hash] A metadata hash pre-populated with # a (fake) temp URL key. def self.account_meta @account_meta ||= Hash.new do |hash, key| hash[key] = { 'X-Account-Meta-Temp-Url-Key' => Fog::Mock.random_hex(32) } end end def self.reset @data = nil @account_meta = nil end def initialize(options={}) apply_options(options) authenticate endpoint_uri end def data self.class.data[@rackspace_username] end def account_meta self.class.account_meta[@rackspace_username] end def reset_data self.class.data.delete(@rackspace_username) end # Access a MockContainer with the specified name, if one exists. # # @param cname [String] The (unescaped) container name. # @return [MockContainer, nil] The named MockContainer, or `nil` if # none exist. def mock_container(cname) data[Fog::Rackspace.escape(cname)] end # Access a MockContainer with the specified name, raising a # {Fog::Storage::Rackspace::NotFound} exception if none exist. # # @param cname [String] The (unescaped) container name. # @throws [Fog::Storage::Rackspace::NotFound] If no container with the # given name exists. # @return [MockContainer] The existing MockContainer. def mock_container!(cname) mock_container(cname) or raise Fog::Storage::Rackspace::NotFound.new end # Create and add a new, empty MockContainer with the given name. An # existing container with the same name will be replaced. # # @param cname [String] The (unescaped) container name. # @return [MockContainer] The container that was added. def add_container(cname) data[Fog::Rackspace.escape(cname)] = MockContainer.new(self) end # Remove a MockContainer with the specified name. No-op if the # container does not exist. # # @param cname [String] The (unescaped) container name. def remove_container(cname) data.delete Fog::Rackspace.escape(cname) end def ssl? !!@rackspace_cdn_ssl end private def authenticate_v1(options) uuid = Fog::Rackspace::MockData.uuid endpoint_uri "https://storage101.#{region}1.clouddrive.com/v1/MockCloudFS_#{uuid}" @auth_token = Fog::Mock.random_hex(32) end end class Real < Fog::Rackspace::Service include Common attr_reader :rackspace_cdn_ssl def initialize(options={}) apply_options(options) authenticate @persistent = options[:persistent] || false Excon.defaults[:ssl_verify_peer] = false if service_net? @connection = Fog::Core::Connection.new(endpoint_uri.to_s, @persistent, @connection_options) end # Using SSL? # @return [Boolean] return true if service is returning SSL-Secured URLs in public_url methods # @see Directory#public_url def ssl? !!rackspace_cdn_ssl end # Resets presistent service connections def reload @connection.reset end def request(params, parse_json = true) super rescue Excon::Errors::NotFound => error raise NotFound.slurp(error, self) rescue Excon::Errors::BadRequest => error raise BadRequest.slurp(error, self) rescue Excon::Errors::InternalServerError => error raise InternalServerError.slurp(error, self) rescue Excon::Errors::HTTPStatusError => error raise ServiceError.slurp(error, self) end private def authenticate_v1(options) credentials = Fog::Rackspace.authenticate(options, @connection_options) endpoint_uri credentials['X-Storage-Url'] @auth_token = credentials['X-Auth-Token'] end end end end end fog-rackspace-0.1.1/lib/fog/rackspace/examples/0000755000175000017500000000000012752304415020542 5ustar debiandebianfog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/0000755000175000017500000000000012752304415022625 5ustar debiandebianfog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/create_server.rb0000644000175000017500000000566612752304415026020 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates creating a server with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' require "base64" #required to encode files for personality functionality def get_user_input(prompt) print "#{prompt}: " gets.chomp end # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Next Generation Cloud Server service service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) # pick the first flavor flavor = service.flavors.first # pick the first Ubuntu image we can find image = service.images.find {|image| image.name =~ /Ubuntu/} # prompt for server name server_name = get_user_input "\nEnter Server Name" # create server server = service.servers.create :name => server_name, :flavor_id => flavor.id, :image_id => image.id, :metadata => { 'fog_sample' => 'true'}, :personality => [{ :path => '/root/fog.txt', :contents => Base64.encode64('Fog was here!') }] # reload flavor in order to retrieve all of its attributes flavor.reload puts "\nNow creating server '#{server.name}' the following with specifications:\n" puts "\t* #{flavor.ram} MB RAM" puts "\t* #{flavor.disk} GB" puts "\t* #{flavor.vcpus} CPU(s)" puts "\t* #{image.name}" puts "\n" begin # Check every 5 seconds to see if server is in the active state (ready?). # If the server has not been built in 5 minutes (600 seconds) an exception will be raised. server.wait_for(600, 5) do print "." STDOUT.flush ready? end puts "[DONE]\n\n" puts "The server has been successfully created, to login onto the server:\n\n" puts "\t ssh #{server.username}@#{server.public_ip_address}\n\n" rescue Fog::Errors::TimeoutError puts "[TIMEOUT]\n\n" puts "This server is currently #{server.progress}% into the build process and is taking longer to complete than expected." puts "You can continute to monitor the build process through the web console at https://mycloud.rackspace.com/\n\n" end puts "The #{server.username} password is #{server.password}\n\n" puts "To delete the server please execute the delete_server.rb script\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/create_network.rb0000644000175000017500000000567612752304415026204 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates creating a private network and attaching it to a new server with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' # UUID for INTERNET INTERNET = '00000000-0000-0000-0000-000000000000' # UUID for Rackspace's service net SERVICE_NET = '11111111-1111-1111-1111-111111111111' def get_user_input(prompt) print "#{prompt}: " gets.chomp end # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Next Generation Cloud Server service service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) #create private network called my_private_net with an ip range between 192.168.0.1 - 192.168.0.255 (Note this will accept IPv6 CIDRs as well) net = service.networks.create :label => 'my_private_net', :cidr => '192.168.0.0/24' puts "\nCreating #{net.label} Network with CIDR #{net.cidr}" # pick the first flavor flavor = service.flavors.first # pick the first Ubuntu image we can find image = service.images.find {|image| image.name =~ /Ubuntu/} # Create a server called alphabits connected our private network as well as the internet server = service.servers.create :name => 'alphabits', :flavor_id => flavor.id, :image_id => image.id, :networks => [net.id, INTERNET] puts "\nNow creating server '#{server.name}' connected the the Internet and '#{net.label}'\n" begin # Check every 5 seconds to see if server is in the active state (ready?). # If the server has not been built in 10 minutes (600 seconds) an exception will be raised. server.wait_for(600, 5) do print "." STDOUT.flush ready? end puts "[DONE]\n\n" puts "The server has been successfully created, to login onto the server:\n\n" puts "\t ssh #{server.username}@#{server.public_ip_address}\n\n" rescue Fog::Errors::TimeoutError puts "[TIMEOUT]\n\n" puts "This server is currently #{server.progress}% into the build process and is taking longer to complete than expected." puts "You can continute to monitor the build process through the web console at https://mycloud.rackspace.com/\n\n" end puts "The #{server.username} password is #{server.password}\n\n" puts "To delete the server and private network please execute the delete_network.rb script\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/resize_server.rb0000644000175000017500000000605312752304415026045 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates how to resize servers with Fog and the Rackspace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end 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 def select_server(servers) abort "\nThere are not any servers to resize in the Chicago region. Try running create_server.rb\n\n" if servers.empty? puts "\nSelect Server Resize:\n\n" servers.each_with_index do |server, i| puts "\t #{i}. #{server.name} [#{server.public_ip_address}]" end selected_str = get_user_input "\nEnter Server Number" servers[selected_str.to_i] end # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end #create Next Generation Cloud Server service service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) #retrieve list of servers servers = service.servers #prompt user for server server = select_server(servers) # retrieve list of avaliable flavors flavors = service.flavors # prompt user for flavor selected_flavor = select_flavor(flavors, server) # resize server server.resize selected_flavor.id puts "\n" # wait for the resize process to start server.wait_for { ready?('RESIZE') } begin # Check every 5 seconds to see if server is in the VERIFY_RESIZE state. # If the server has not been built in 5 minutes (600 seconds) an exception will be raised. server.wait_for(1200, 5) do print "." STDOUT.flush ready?('VERIFY_RESIZE', ['ACTIVE', 'ERROR']) end puts "[DONE]\n\n" puts "Server Has Been Successfully Resized!" action = get_user_input "Press 'C' To Confirm Or 'R' to Revert Resize (R/C)" case action.upcase when 'C' puts "\nConfirming Resize Operation" server.confirm_resize when 'R' puts "\nReverting Resize Operation" server.revert_resize else puts "\nUnrecognized Input. Exiting." end rescue Fog::Errors::TimeoutError puts "[TIMEOUT]\n\n" puts "This server is currently #{server.progress}% into the resize process and is taking longer to complete than expected." puts "You can continute to monitor the build process through the web console at https://mycloud.rackspace.com/\n\n" end fog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/server_metadata.rb0000644000175000017500000000440112752304415026317 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates working with server metadata on the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require './lib/fog' # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end def print_metadata(server) server.metadata.each do |metadatum| puts "\t#{metadatum.key}: #{metadatum.value}" end puts "\n" end #create Next Generation Cloud Server service service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) # Pick the first flavor flavor = service.flavors.first # Pick the first Ubuntu image we can find image = service.images.find {|image| image.name =~ /Ubuntu/} #create server server = service.servers.create :name => 'meta-cumulus', :flavor_id => flavor.id, :image_id => image.id, :metadata => { 'color' => 'red'} puts "Waiting for server to be created\n" server.wait_for(600, 5) do print "." STDOUT.flush ready? end puts "[DONE]\n\n" puts "Initial Metadata\n" print_metadata(server) puts "Adding New Metadata\n" server.metadata["environment"] = "demo" print_metadata(server) puts "Updating Existing Metadata\n" server.metadata["color"] = "blue" print_metadata(server) puts "Saving Metadata Changes\n" server.metadata.save puts "Reload Metadata\n" server.metadata.reload print_metadata(server) puts "Delete Metadata" metadatum = server.metadata.find {|metadataum| metadataum.key == 'environment'} metadatum.destroy puts "Reload Metadata" server.metadata.reload print_metadata(server) puts "To delete the server please execute the delete_server.rb script\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/bootstrap_server.rb0000644000175000017500000000642312752304415026562 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates creating a server with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' require 'base64' #required to encode files for personality functionality require 'sshkey' #required to generate ssh keys. 'gem install sshkey' def get_user_input(prompt) print "#{prompt}: " gets.chomp end # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") 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' def generate_ssh_key SSHKey.generate end # create Next Generation Cloud Server service service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) # pick the first flavor flavor = service.flavors.first # pick the first Ubuntu image we can find image = service.images.find {|image| image.name =~ /Ubuntu/} # prompt for server name server_name = get_user_input "\nEnter Server Name" # generate the ssh key ssh_key = generate_ssh_key # reload flavor in order to retrieve all of its attributes flavor.reload puts "\nNow creating server '#{server_name}' the following with specifications:\n" puts "\t* #{flavor.ram} MB RAM" puts "\t* #{flavor.disk} GB" puts "\t* #{flavor.vcpus} CPU(s)" puts "\t* #{image.name}" puts "\n" begin # bootstrap server server = service.servers.bootstrap :name => server_name, :flavor_id => flavor.id, :image_id => image.id, :private_key => ssh_key.private_key, :public_key => ssh_key.ssh_public_key if server.ready? puts "[DONE]\n\n" puts "The server has been successfully created.\n" puts "Write the following ssh keys to you ~/.ssh directory in order to log in\n\n" puts "+++++++++++PRIVATE_KEY (~/.ssh/fog_key)++++++++++++" puts ssh_key.private_key puts "++++++++++PUBLIC_KEY (~/.ssh/fog_key.pub)++++++++++" puts ssh_key.ssh_public_key puts "+++++++++++++++++++++++++++++++++++++++++++++++++++i\n\n" puts "You can then log into the server using the following command\n" puts "ssh #{server.username}@#{server.public_ip_address}\n\n" else puts "An error occured, please try again" end rescue Fog::Errors::TimeoutError puts "[TIMEOUT]\n\n" puts "This server is currently #{server.progress}% into the build process and is taking longer to complete than expected." puts "You can continute to monitor the build process through the web console at https://mycloud.rackspace.com/\n\n" end puts "To delete the server please execute the delete_server.rb script\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/delete_server.rb0000644000175000017500000000315512752304415026006 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates how to delete servers with Fog and the Rackspace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end def select_server(servers) abort "\nThere are not any servers to delete in the Chicago region. Try running create_server.rb\n\n" if servers.empty? puts "\nSelect Server To Delete:\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 # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end #create Next Generation Cloud Server service service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) #retrieve list of servers servers = service.servers #prompt user for server server = select_server(servers) #destroy server server.destroy puts "\nServer #{server.name} has been destroyed\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/delete_network.rb0000644000175000017500000000424412752304415026171 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates deletes a private network and attaching it to a new server with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def wait_for_server_deletion(server) begin server.wait_for { state = 'DELETED' } rescue Fog::Compute::RackspaceV2::NotFound => e # do nothing end end # I have notice that cloud networks is slow to acknowledge deleted servers. This method tries to mitigate this. 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 def get_user_input(prompt) print "#{prompt}: " gets.chomp end # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Next Generation Cloud Server service service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) # NOTE: The network must not be connected to any servers before deletion # Find alpha bits server server = service.servers.find {|s| s.name == 'alphabits'} puts "\n" if server puts "Deleting alphabits server..." server.destroy else puts "Unable to find server alphabits" end wait_for_server_deletion(server) network = service.networks.find {|n| n.label == 'my_private_net'} delete_network(network) puts "The network '#{network.label}' has been successfully deleted" fog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/server_attachments.rb0000644000175000017500000000422512752304415027056 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates working with server and volumes on the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end 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 Attachment:\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 # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end #create Next Generation Cloud Server service compute_service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) cbs_service = Fog::Rackspace::BlockStorage.new({ :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # retrieve list of servers servers = compute_service.servers # prompt user for server server = select_server(servers) # prompt for volume name volume_name = get_user_input "Enter Volume Name" puts "\nCreating Volume\n" volume = cbs_service.volumes.create(:size => 100, :display_name => volume_name) puts "\nAttaching volume\n" attachment = server.attach_volume volume puts "\nVolume #{volume.display_name} has been attached to #{server.name} on device #{attachment.device}\n\n" puts "To detach volume please execute the detach_volume.rb script\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/delete_image.rb0000644000175000017500000000342212752304415025557 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates deleting a server image with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end 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 # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Next Generation Cloud Server service service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) # retrieve list of images images = service.images # select all of the snapshot type images. base images are not user deletable snapshot_images = images.select do |image| image.metadata["image_type"] == "snapshot" end # prompt user for image to delete image = select_image(snapshot_images) # delete image image.destroy puts "\n#{image.name} has been destroyed\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/create_image.rb0000644000175000017500000000347712752304415025572 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates creating a server image with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end def select_server(servers) abort "\nThere are not any servers available to image in the Chicago region. Try running create_server.rb\n\n" if servers.empty? puts "\nSelect Server To Image:\n\n" servers.each_with_index do |server, i| puts "\t #{i}. #{server.name} [#{server.public_ip_address}]" end selected_str = get_user_input "\nEnter Server Number" servers[selected_str.to_i] end # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Next Generation Cloud Server service service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) # retrieve list of servers servers = service.servers # prompt user for server server = select_server(servers) # prompt user for image name image_name = get_user_input "Enter Image Name" # creates image for server server.create_image image_name puts "\nImage #{image_name} is being created for server #{server.name}.\n\n" puts "To delete the image please execute the delete_image.rb script\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/compute_v2/detach_volume.rb0000644000175000017500000000544412752304415026000 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates working with server and volumes on the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end 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 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 # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end #create Next Generation Cloud Server service compute_service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) cbs_service = Fog::Rackspace::BlockStorage.new({ :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # retrieve list of servers servers = compute_service.servers # prompt user for server server = select_server(servers) # get attached volumes --also know as attachments attachments = server.attachments # prompt user for volume to detach attachment = select_attachment(attachments) volume = cbs_service.volumes.get attachment.volume_id puts "Detaching Volume #{volume.display_name} From Server #{server.name}" attachment.detach puts "\n" delete_confirm = get_user_input "Would You Like To Destroy Volume #{volume.display_name} (y/n)" if delete_confirm.downcase == 'y' # wait for server to finish detaching before attempting to delete volume.wait_for(600) do print "." STDOUT.flush ready? && attachments.empty? end volume.destroy puts "\n\nThe Volume Has been Destroyed" end fog-rackspace-0.1.1/lib/fog/rackspace/examples/storage/0000755000175000017500000000000012752304415022206 5ustar debiandebianfog-rackspace-0.1.1/lib/fog/rackspace/examples/storage/delete_directory.rb0000644000175000017500000000327312752304415026066 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates deleting a container with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end 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 # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Cloud Files service service = Fog::Storage.new({ :provider => 'Rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # retrieve directories directories = service.directories # prompt for directory directory = select_directory(directories) puts "\nNow deleting #{directory.key}" # delete files if necessary directory.files.each do |f| puts "\tDeleting file #{f.key}" f.destroy end # delete directory directory.destroy puts "\tDone\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/storage/lorem.txt0000644000175000017500000000067712752304415024077 0ustar debiandebianLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. fog-rackspace-0.1.1/lib/fog/rackspace/examples/storage/download_file.rb0000644000175000017500000000415112752304415025342 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates downloading a file with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end def select_directory(directories) abort "\nThere are not any directories with files 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 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 # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Cloud Files service service = Fog::Storage.new({ :provider => 'Rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # retrieve directories with files directories = service.directories.select {|s| s.count > 0} # prompt for directory directory = select_directory(directories) # list of files for directory files = directory.files # prompt for file to download file = select_file(files) # download file filename = File.join(File.dirname(__FILE__), "downloaded-#{file.key}") File.open(filename, 'w') do | f | directory.files.get(file.key) do | data, remaining, content_length | f.syswrite data end end puts "\nFile #{file.key} was successfully downloaded to #{filename}" fog-rackspace-0.1.1/lib/fog/rackspace/examples/storage/create_cdn_directory.rb0000644000175000017500000000255012752304415026710 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates creating a container with CDN on the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Cloud Files service service = Fog::Storage.new({ :provider => 'Rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # prompt for directory name directory_name = get_user_input "\nEnter name of directory to create" # create directory directory = service.directories.create :key => directory_name, :public => true # reload directory to refresh information directory.reload puts "\nDirectory #{directory.key} was created." puts "To delete the container please execute the delete_directory.rb script\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/storage/upload_large_files.rb0000644000175000017500000000633512752304415026362 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates uploading large files in segments require 'rubygems' #required for Ruby 1.8.x require 'fog' # Size of segment. The Rackspace cloud currently requires files larger than 5GB to be segmented so we will choose 5GB -1 for a size # http://docs.rackspace.com/files/api/v1/cf-devguide/content/Large_Object_Creation-d1e2019.html SEGMENT_LIMIT = 5368709119.0 # 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 BUFFER_SIZE = Excon.defaults[:chunk_size] || 1024 * 1024 def get_user_input(prompt) print "\n#{prompt}: " gets.chomp end def select_directory(directories) abort "\nThere are not any directories in the Chicago region. Try running create_private_directory.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 select_str = get_user_input "Enter Directory Number" directories[select_str.to_i] end # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Cloud Files service service = Fog::Storage.new({ :provider => 'Rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord }) # retrieve directories with files directories = service.directories # prompt for directory directory = select_directory(directories) # prompt for file name file_name = get_user_input "Enter full path of file to upload" segment_name = File.basename(file_name) File.open(file_name) do |f| num_segments = (f.stat.size / SEGMENT_LIMIT).round + 1 puts "\nThis upload of '#{file_name}' will require #{num_segments} segment(s) and 1 manifest file\n" segment = 0 until f.eof? segment += 1 offset = 0 # upload segment to cloud files segment_suffix = segment.to_s.rjust(10, '0') print "\n\tUploading segment #{segment_suffix} " service.put_object(directory.key, "#{segment_name}/#{segment_suffix}", nil) do if offset <= SEGMENT_LIMIT - BUFFER_SIZE print "." buf = f.read(BUFFER_SIZE).to_s offset += buf.size buf else '' end end end end puts "\n\n\tWriting manifest #{segment_name}\n\n" service.put_object_manifest(directory.key, segment_name, 'X-Object-Manifest' => "#{directory.key}/#{segment_name}/" ) puts <<-NOTE You should now be able to download #{segment_name} from the cloud control panel or using the following code: directory = service.directories.get('#{directory.key}') File.open('downloaded_#{segment_name}', 'w') do | f | directory.files.get('#{segment_name}') do | data, remaining, content_length | print "." f.write data end end NOTE fog-rackspace-0.1.1/lib/fog/rackspace/examples/storage/upload_file.rb0000644000175000017500000000302612752304415025017 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates creating a file on the CDN network with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Cloud Files service service = Fog::Storage.new({ :provider => 'Rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # prompt for directory name directory_name = get_user_input "\nEnter name of directory to create" # create directory with CDN service directory = service.directories.create :key => directory_name, :public => true # upload file upload_file = File.join(File.dirname(__FILE__), "lorem.txt") file = directory.files.create :key => 'sample.txt', :body => File.open(upload_file, "r") puts "You should be able to view this file via CDN at #{file.public_url}" puts "To delete the container and associated file please execute the delete_directory.rb script\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/storage/create_private_directory.rb0000644000175000017500000000252112752304415027614 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates creating a container with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Cloud Files service service = Fog::Storage.new({ :provider => 'Rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # prompt for directory name directory_name = get_user_input "\nEnter name of directory to create" # create directory directory = service.directories.create :key => directory_name # reload directory to refresh information directory.reload puts "\n Directory #{directory.key} was created." puts "To delete the container please execute the delete_directory.rb script\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/storage/storage_metadata.rb0000644000175000017500000000410312752304415026035 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates creating a file on the CDN network with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end def print_metadata(object) object.metadata.each_pair do |key, value| puts "\t#{key}: #{value}" end puts "\n" end # create Cloud Files service service = Fog::Storage.new({ :provider => 'Rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # create directory puts "Creating directory 'metadata-tester'" directory = service.directories.create :key => "metadata-tester" # initial metadata puts "Initial Container Metadata\n" print_metadata directory # adding metadata puts "Adding Container Metadata" directory.metadata["environment"] = "demo" directory.save print_metadata directory # update metadata puts "Updating Container Metadata" directory.metadata["environment"] = "test" directory.save print_metadata directory # upload file puts "Uploading file" upload_file = File.join(File.dirname(__FILE__), "lorem.txt") file = directory.files.create :key => 'sample.txt', :body => File.open(upload_file, "r") # initial metadata puts "Initial File Metadata\n" print_metadata file # adding metadata puts "Adding File Metadata" file.metadata["preview"] = "true" file.save print_metadata file # update metadata puts "Updating File Metadata" file.metadata["preview"] = "false" file.save print_metadata file puts "To delete the directory and file please execute the delete_directory.rb script\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/storage/delete_file.rb0000644000175000017500000000365212752304415025002 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates deleting a file from a container with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "#{prompt}: " gets.chomp end 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 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 # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Cloud Files service service = Fog::Storage.new({ :provider => 'Rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # retrieve directories with files directories = service.directories.select {|s| s.count > 0} # prompt for directory directory = select_directory(directories) # list of files for directory files = directory.files # prompt for file to delete file = select_file(files) # delete file file.destroy puts "\nFile #{file.key} was successfully deleted" fog-rackspace-0.1.1/lib/fog/rackspace/examples/block_storage/0000755000175000017500000000000012752304415023360 5ustar debiandebianfog-rackspace-0.1.1/lib/fog/rackspace/examples/block_storage/create_volume.rb0000644000175000017500000000346112752304415026543 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates creating Cloud Block Storage volume with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "\n#{prompt}: " gets.chomp end 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 # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Cloud Block Storage service service = Fog::Rackspace::BlockStorage.new({ :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # retrieve list of volume types volume_types = service.volume_types #prompt user for volume type volume_type = select_volume_type(volume_types) # prompt for volume size volume_size = get_user_input "Enter Size of Volume (100 GB Minimum)" # prompt for name of volume volume_name = get_user_input "Enter Name for Volume" #create volume volume = service.volumes.create(:size => volume_size, :display_name => volume_name, :volume_type => volume_type.name) puts "\nVolume #{volume_name} is being created.\n\n" puts "To delete the volume please execute the delete_volume.rb script\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/block_storage/create_snapshot.rb0000644000175000017500000000745112752304415027076 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates creating a snapshot from a Cloud Block Storage volume with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "\n#{prompt}: " gets.chomp end 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 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 # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end #create Next Generation Cloud Server service compute_service = Fog::Compute.new({ :provider => 'rackspace', :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :version => :v2, # Use Next Gen Cloud Servers :rackspace_region => :ord #Use Chicago Region }) #create Cloud Block Storage service cbs_service = Fog::Rackspace::BlockStorage.new({ :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # retrieve list of servers servers = compute_service.servers # prompt user for server server = select_server(servers) # get attached volumes --also know as attachments attachments = server.attachments # prompt user for volume to detach attachment = select_attachment(attachments) # prompt for snapshot name snapshot_name = get_user_input "Enter Snapshot Name" puts "\n\n" puts "******************** NOTE ******************************************" puts "* Volume must be unmounted from operating system before detaching. *" puts "* This script assumes volume has been unmounted. *" puts "********************************************************************\n\n" volume = cbs_service.volumes.get attachment.volume_id # The snapshot process requires all writes to be flushed to disk. This requires unmounting the file systems or detaching the volume. puts "Detaching Volume #{volume.display_name}" attachment.detach volume.wait_for { ready? } puts "Now Creating Snapshot #{snapshot_name}" snapshot = cbs_service.snapshots.create :display_name => snapshot_name, :volume_id => attachment.volume_id begin # Check every 5 seconds to see if snapshot is in the available state (ready?). # If the available has not been built in 5 minutes (600 seconds) an exception will be raised. snapshot.wait_for(600, 5) do print "." STDOUT.flush ready? end puts "[DONE]\n\n" puts "Re-attaching Volume #{volume.display_name}" attachment.save rescue Fog::Errors::TimeoutError puts "[TIMEOUT]\n\n" puts "The snapshot #{snapshot.display_name} is still being preformed and is taking longer to complete than expected." puts "You can continute to monitor the process through the web console at https://mycloud.rackspace.com/\n\n" end fog-rackspace-0.1.1/lib/fog/rackspace/examples/block_storage/delete_volume.rb0000644000175000017500000000302312752304415026534 0ustar debiandebian#!/usr/bin/env ruby # This example demonstrates deleting Cloud Block Storage volume with the Rackpace Open Cloud require 'rubygems' #required for Ruby 1.8.x require 'fog' def get_user_input(prompt) print "\n#{prompt}: " gets.chomp end 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 # Use username defined in ~/.fog file, if absent prompt for username. # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_username Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") end # Use api key defined in ~/.fog file, if absent prompt for api key # For more details on ~/.fog refer to http://fog.io/about/getting_started.html def rackspace_api_key Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") end # create Cloud Block Storage service service = Fog::Rackspace::BlockStorage.new({ :rackspace_username => rackspace_username, :rackspace_api_key => rackspace_api_key, :rackspace_region => :ord #Use Chicago Region }) # retrieve list of volumes volumes = service.volumes # prompt user for volume volume = select_volume(volumes) # delete volume volume.destroy puts "\nVolume #{volume.display_name} is being destroyed.\n\n" fog-rackspace-0.1.1/lib/fog/rackspace/examples/README.md0000644000175000017500000000303112752304415022016 0ustar debiandebian# Getting Started Examples ## Download Examples using the Rackspace Open Cloud and Fog can be found in the [fog repository](https://github.com/fog/fog) under the directory `fog/lib/fog/rackspace/examples`. This repository can be downloaded via `git` by executing the following: git clone git://github.com/fog/fog.git Optionally you can download a zip by clicking on this [link](https://github.com/fog/fog/archive/master.zip). ## Requirements Examples require the following: * Rackspace Open Cloud account * Ruby 1.8.x or 1.9.x * `fog` gem For more information please refer to the [Getting Started with Fog and the Rackspace Open Cloud](https://github.com/fog/fog/blob/master/lib/fog/rackspace/docs/getting_started.md) document. ## Credentials Examples will prompt for Rackspace Open Cloud credentials. Prompts can be skipped by creating a `.fog` file in the user's home directory. This is an example of a `.fog` file for the Rackspace Open Cloud: default: rackspace_username: RACKSPACE_USERNAME rackspace_api_key: RACKSPACE_API_KEY **Note:** Replace capitalized values with the appropriate credential information. ## Executing To execute scripts using `bundler`: bundle exec ruby