Skip to content

Instantly share code, notes, and snippets.

@jeremyd
Created January 28, 2009 21:25
Show Gist options
  • Save jeremyd/54201 to your computer and use it in GitHub Desktop.
Save jeremyd/54201 to your computer and use it in GitHub Desktop.
rightscript example get and put, to and from a local file
---
:pass: yourSecurePassword
:user: youremail@test.com
:rs_api_url: https://my.rightscale.com/api/acct/999999999999
#!/usr/bin/ruby
require 'rubygems'
require 'rest_client'
require 'xmlsimple'
require 'yaml'
id = ARGV[0]
config = YAML::load(IO.read('rs_api_config.yaml'))
res = RestClient::Resource.new(config[:rs_api_url], config[:user], config[:pass])
script = res["right_scripts/#{id}"].get('X-API-VERSION' => '1.0')
sc_hash = XmlSimple.xml_in(script)
File.open(id, "w") do |f|
f.write(sc_hash['script'])
end
#!/usr/bin/ruby
require 'rubygems'
require 'rest_client'
require 'yaml'
id = ARGV[0]
pkgfile = "#{id}.packages"
inputfile = "#{id}.inputs"
unless id && File.exists?(id) && File.exists?(pkgfile) && File.exists?(inputfile)
raise "file not found found\nsyntax: rs_put.rb <script id>"
end
config = YAML::load(IO.read('rs_api_config.yaml'))
res = RestClient::Resource.new(config[:rs_api_url], config[:user], config[:pass])
# expecting simple string format here, space separated
packages = IO.read(pkgfile)
inputs = IO.read(inputfile)
# inputs are in hacky hash format, need better api support
input_hash = {}
i = inputs.split(/\s/)
i.each do |convert|
input_hash[convert] = "TRASHVAL"
end
res["right_scripts/#{id}"].put(:right_script => { :packages => packages,
:inputs => input_hash,
:script => IO.read(id) },
:api_version => '1.0')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment