SHARE
TWEET

Untitled

a guest Feb 4th, 2016 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env ruby
  2. #
  3. # enable-rs-db-root
  4. #
  5. # Enables the root account on a Rackspace cloud database instance.
  6. #
  7. # Usage:
  8. #
  9. #   enable-rs-db-root name.of.your.instance.example.com
  10. #
  11. # Rackspace cloud databases disable the root account by default, meaning
  12. # that you have to create databases etc. through the GUI or over the API
  13. # rather than through standard mySQL tools. The root account can't be
  14. # enabled through the GUI, but it can be enabled over the API; this
  15. # script does that.
  16. #
  17. # Requires Ruby and the fog gem (`gem install fog`).
  18. #
  19. # Assumes your Rackspace credentials are in environment variables called
  20. # `RACKSPACE_USERNAME` and `RACKSPACE_API_KEY`.
  21.  
  22. require "fog"
  23.  
  24. instance_name = ARGV[0]
  25.  
  26. @databases = Fog::Rackspace::Databases.new(
  27.   rackspace_username: ENV.fetch("RACKSPACE_USERNAME"),
  28.   rackspace_api_key:  ENV.fetch("RACKSPACE_API_KEY"),
  29.   rackspace_region:  :lon,
  30. )
  31.  
  32. instance = @databases.instances.find { |i| i.name == instance_name }
  33.  
  34. unless instance
  35.   $stderr.puts "Couldn't find an instance with the name #{instance_name}"
  36.   exit 1
  37. end
  38.  
  39. puts "Found a matching database instance (name: #{instance.name}; hostname: #{instance.hostname})"
  40. puts
  41. puts "Enabling root user..."
  42. puts
  43.  
  44. instance.enable_root_user
  45.  
  46. puts "Root username: #{instance.root_user}"
  47. puts "Root password: #{instance.root_password}"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top