Skip to content

Instantly share code, notes, and snippets.

@krames
krames / invalid_token
Created June 20, 2013 18:07
Hitting Cloud Block Storage with invalid authentication token. I expected a HTTP 401 instead of a 503. I was also wondering why the body of the response comes back as html rather than JSON.
excon.request {:chunk_size=>1048576, :connect_timeout=>60, :debug_request=>true, :debug_response=>true, :headers=>{"User-Agent"=>"fog/1.12.1", "Content-Type"=>"application/json", "Accept"=>"application/json",
"X-Auth-Token"=>"bad token", "Host"=>"ord.blockstorage.api.rackspacecloud.com:443"}, :idempotent=>false, :instrumentor_name=>"excon", :middlewares=>[Excon::Middleware::Expects, Excon::Middleware::Idempotent,
Excon::Middleware::Instrumentor, Excon::Middleware::Mock], :mock=>false, :nonblock=>true, :omit_default_port=>false, :read_timeout=>60, :retry_limit=>4,
:ssl_ca_file=>"/Users/kyle.rames/.rvm/gems/ruby-1.9.3-p392@fog_dev/gems/excon-0.24.0/data/cacert.pem", :ssl_verify_peer=>true, :tcp_nodelay=>false, :uri_parser=>URI, :write_timeout=>60,
:host=>"ord.blockstorage.api.rackspacecloud.com", :path=>"/v1/772045/volumes", :port=>"443", :query=>nil, :scheme=>"https", :user=>nil, :password=>"REDACTED", :instrumentor=>Excon::StandardInstrumentor, :expects=>[200],
:method=>"GET", :retries_remaining=>4, :connecti
@krames
krames / delete_network_error
Created June 25, 2013 13:36
I am attempting to delete a cloud network that is attached to a server. I am expecting to see an error come back in json, but it is coming back in HTML. I am using our Ruby SDK (fog). A dump of the output is given below.
1.9.3p392 :003 > service.delete_network net.id
excon.request {:chunk_size=>1048576, :connect_timeout=>60, :debug_request=>false, :debug_response=>true, :headers=>{"User-Agent"=>"fog/1.12.1", "Content-Type"=>"application/json", "Accept"=>"application/json", "X-Auth-Token"=>"6ff9abe98db0415f99a12317e59e0cc0", "Host"=>"dfw.servers.api.rackspacecloud.com:443"}, :idempotent=>false, :instrumentor_name=>"excon", :middlewares=>[Excon::Middleware::Expects, Excon::Middleware::Idempotent, Excon::Middleware::Instrumentor, Excon::Middleware::Mock], :mock=>false, :nonblock=>true, :omit_default_port=>false, :read_timeout=>60, :retry_limit=>4, :ssl_ca_file=>"/Users/kyle.rames/.rvm/gems/ruby-1.9.3-p392@fog_dev/gems/excon-0.24.0/data/cacert.pem", :ssl_verify_peer=>true, :tcp_nodelay=>false, :uri_parser=>URI, :write_timeout=>60, :host=>"dfw.servers.api.rackspacecloud.com", :path=>"/v2/772045/os-networksv2/ef03eac3-e07e-4001-b151-d0af2231e6de.json", :port=>"443", :query=>nil, :scheme=>"https", :user=>nil, :password=>"REDACTED",
service = Fog::Rackspace::LoadBalancers.new
#create load balancer
lb = service.load_balancers.create :name => 'bob-the-balancer',
:protocol => 'HTTP',
:port => 80,
:virtual_ips => [{:type => 'PUBLIC'}],
:nodes => [{:address => '1.1.1.1',
:port => 80,
:condition => 'ENABLED'
@krames
krames / cloud_files_publish.rb
Created July 5, 2013 13:13
This script will create a CDN backed container named "demo-container" containing a file called demo-file" To run this install fog using `gem install fog` and the script can be run as follows: ```ruby cloud_files_publish <username> <api key>```
require 'fog'
require 'tempfile'
# Note: Only Rackspace, HP, and Amazon have CDN support. This example only demonstrates creating a CDN backed container with Rackspace and HP. (Amazon does something else.)
begin
# :provider is the only standard key all others are provider specific
service = Fog::Storage.new :provider => 'rackspace',
:rackspace_username => ARGV[0],
:rackspace_api_key => ARGV[1]
require 'fog'
SEGMENT_LIMIT = 1024 * 1024 * 10
BUFFER_SIZE = Excon.defaults[:chunk_size] || 1024 * 1024
Excon.defaults[:retry_limit] = 0
service = Fog::Storage.new({
:provider => 'Rackspace',
:rackspace_region => :dfw
@krames
krames / segment_upload_fail.txt
Created July 16, 2013 14:52
This gist is a sample of uploading a large segmented file with etags. The first segment is successfully uploaded with a valid segment. The second segment contains a bad etag. My ruby code receives a 422 and then tries to reload the same segment with a valid tag. Cloud Files continues to send back a 422. I have attempted to hunt down the phrase "…
excon.request {:chunk_size=>1048576, :connect_timeout=>60, :debug_request=>false, :debug_response=>true, :headers=>{"User-Agent"=>"fog/1.12.1", "Content-Type"=>nil, "Accept"=>"application/json", "X-Auth-Token"=>"6fba6c5b4817446cbec0286f5e1fb5f4", "Content-Length"=>0, "ETag"=>"6bca3dcbd6eb0a7044e90e0297447faa", "Host"=>"storage101.dfw1.clouddrive.com:443"}, :idempotent=>true, :instrumentor_name=>"excon", :middlewares=>[Excon::Middleware::Expects, Excon::Middleware::Idempotent, Excon::Middleware::Instrumentor, Excon::Middleware::Mock], :mock=>false, :nonblock=>true, :omit_default_port=>false, :read_timeout=>60, :retry_limit=>0, :ssl_ca_file=>"/Users/kyle.rames/.rvm/gems/ruby-1.9.3-p286@fog/gems/excon-0.23.0/data/cacert.pem", :ssl_verify_peer=>true, :tcp_nodelay=>false, :uri_parser=>URI, :write_timeout=>60, :host=>"storage101.dfw1.clouddrive.com", :path=>"/v1/MossoCloudFS_5d0bc756-9753-4681-bdc3-570aa8ba86c3/bucket/frank.jpg%2F0000000001", :port=>"443", :query=>nil, :scheme=>"https", :user=>nil, :password=>"RED
@krames
krames / vcr_filter.rb
Created July 25, 2013 17:50
This is my attempt at creating dynamic filters for VCR.
class FilterProcessor
#install in VCR config
# VCR.config do |c|
# FilterProcessor.new(config)
# end
def initialize(config)
@filters = []
config.before_record {|i| self.process_before_record(i) }
config.before_playback {|i| self.process_before_playback(i) }
curl --include --header "Accept: application/json" --header "X-Auth-token: MY_SECRET_TOKEN --request PUT --data-binary '{
"name": "workers",
"cooldown": 60,
"minEntities": 0,
"maxEntities": 0,
"metadata": {
"firstkey": "this is a string",
"secondkey": "1"
}
}' "https://dfw.autoscale.api.rackspacecloud.com/v1.0/772045/groups/2066dd25-c590-4f0d-b94a-5f59887888b4/config"
@krames
krames / rackspace-images.txt
Created August 6, 2013 14:54
List of Rackspace Images as of 8/6/2013
Windows Server 2012 + SQL Server 2012 Web SP1
Windows Server 2012 + SQL Server 2012 Standard SP1
Windows Server 2012 (with updates)
Windows Server 2012
Windows Server 2008 x64 SP2
Windows Server 2008 R2 SP1 + SQL Server 2012 Web SP1
Windows Server 2008 R2 SP1 + SQL Server 2012 Standard SP1
Windows Server 2008 R2 SP1 + SQL Server 2008 R2 Web SP2
Windows Server 2008 R2 SP1 + SQL Server 2008 R2 Standard SP2
Windows Server 2008 R2 SP1 (with updates) + SQL Server 2012 Standard SP1
@krames
krames / set_temp_key.rb
Created August 13, 2013 18:48
This script file will update X-Account-Meta-Temp-Url-Key which is required to use TempURL. This script assumes that you have the fog gem installed. It can be installed by executing "gem install fog"
require 'fog'
# Please replace these with the approprate values
RACKSPACE_USERNAME = "YOUR USERNAME"
RACKSPACE_API_KEY = "YOUR API KEY"
RACKSPACE_TEMP_URL_KEY = "#192!29jd!23990192DSAF"
puts "Creating Storage Service"
begin