Skip to content

Instantly share code, notes, and snippets.

@krames
krames / print_response.rb
Last active December 15, 2015 07:29
Code snippet use to generate rdoc information from Excon::Response
def print_section(obj, i=2)
return if obj.nil?
obj.each_pair do |k, v|
klass = v.nil? ? String : v.class
print " " * i
puts "* '#{k}'<~#{klass}>: -"
print_section(v, i + 1) if v.is_a?(Hash)
print_section(v.first, i + 1) if v.is_a?(Array)
end
end
if Fog::VERSION == "1.10.1"
Fog::Logger.warning "PATCHING Fog::Compute::RackspaceV2::Server to allow networks to be created"
require 'rubygems'
require 'fog'
module Fog
module Compute
class RackspaceV2
class Server < Fog::Compute::Server
@krames
krames / ruby_getting_started.md
Last active December 17, 2015 10:28
Concise introduction to the Rackspace Ruby SDK

#Ruby SDK

Rather than reinvent the wheel, Rackspace choose to use the popular fog gem for its SDK. Fog provides both an ActiveRecord like model interface as well as a request interface for efficent access to cloud resources.

Installation

To install Fog via RubyGems run the following command:

gem install fog
@krames
krames / large_files.rb
Last active December 17, 2015 15:29
This gist contains a patch to allow uploaded large segmented files in memory efficient manner in the Rackspace Cloud. It also includes an example demonstrating it's use. This should only be used with Fog 1.11.1. I am currently working on a pull request to include this in fog proper.
#!/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
1.9.3:knife-rackspace [master]$ git config --add remote.upstream.fetch "+refs/pull/*/head:refs/remotes/upstream/pr/*"
1.9.3:knife-rackspace [master]$ git fetch upstream
remote: Counting objects: 481, done.
remote: Compressing objects: 100% (223/223), done.
remote: Total 393 (delta 191), reused 309 (delta 113)
Receiving objects: 100% (393/393), 45.29 KiB, done.
Resolving deltas: 100% (191/191), completed with 20 local objects.
From https://github.com/opscode/knife-rackspace
* [new ref] refs/pull/0/head -> upstream/pr/0
* [new ref] refs/pull/1/head -> upstream/pr/1
@krames
krames / bootstrap.cmd
Created June 10, 2013 18:27
When uploaded to C:\\cloud-automation\\bootstrap.cmd on a Cloud Server, this script will open up the WinRM port. Sample Usage: knife rackspace server create -I fc2448b4-da85-4893-b0e7-6c8794e608b4 --flavor 5 --file C:\\cloud-automation\\bootstrap.cmd=bootstrap.cmd --bootstrap-protocol winrm --server-create-timeout 2000 --template-file /Users/kyl…
netsh advfirewall firewall set rule group="remote administration" new enable=yes & netsh advfirewall firewall add rule name="WinRM Port" dir=in action=allow protocol=TCP localport=5985
@krames
krames / curl_rackspace.md
Last active May 28, 2016 20:16
This is a brief introduction on how to use CURL with the Rackspace Cloud. Any comments/suggestions are welcome!

#Curl and the Rackspace Cloud

This provides a quick introduction of how to use curl with the Rackspace Cloud.

Introduction

Before you can start issuing commands using curl you will need to authenticate to the Rackspace Cloud. The authentication process provides you with an authentication token and as well as a service catalog.

The authentication token is a temporary token that associates your account with your requests. The service catalog is a list of service endpoints for your account.

@krames
krames / upload.rb
Last active December 18, 2015 15:39
Cloud File Upload
#!/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
@krames
krames / load_balancer_access_rules.md
Created June 18, 2013 21:14
This gist explains how to use access rules with Cloud Load Balancers

#Cloud Load Balancers Access Rules

This document describes the access rules for cloud load balancers.

Create Service

Using a US-based account:

service = Fog::Rackspace::LoadBalancers.new({ :rackspace_username => RACKSPACE_USER_NAME, # Your Rackspace Username

@krames
krames / 01_cdn_patch.rb
Created June 19, 2013 20:36
This patch should address issue with the Rackspace CDN service not re-authenticating when the after the authentication token expires. This patch should be named 01_cdn_patch.rb and placed in the initializers directory to ensure that the patch is properly applied. This patch is only good for Fog 1.12.1.
if Fog::VERSION == "1.12.1"
Fog::Logger.warning "PATCHING Fog::CDN::Rackspace to re-authenticate after authentication token expires"
require 'rubygems'
require 'fog'
module Fog
module CDN
class Rackspace < Fog::Service