Skip to content

Instantly share code, notes, and snippets.

@robmiller
Created February 4, 2016 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robmiller/3f78a1cf4e945e60c5f3 to your computer and use it in GitHub Desktop.
Save robmiller/3f78a1cf4e945e60c5f3 to your computer and use it in GitHub Desktop.
A script for easily enabling the root account on a Rackspace cloud database instance, something that's inexplicably impossible to do via the GUI
#!/usr/bin/env ruby
#
# enable-rs-db-root
#
# Enables the root account on a Rackspace cloud database instance.
#
# Usage:
#
# enable-rs-db-root name.of.your.instance.example.com
#
# Rackspace cloud databases disable the root account by default, meaning
# that you have to create databases etc. through the GUI or over the API
# rather than through standard mySQL tools. The root account can't be
# enabled through the GUI, but it can be enabled over the API; this
# script does that.
#
# Requires Ruby and the fog gem (`gem install fog`).
#
# Assumes your Rackspace credentials are in environment variables called
# `RACKSPACE_USERNAME` and `RACKSPACE_API_KEY`.
require "fog"
instance_name = ARGV[0]
@databases = Fog::Rackspace::Databases.new(
rackspace_username: ENV.fetch("RACKSPACE_USERNAME"),
rackspace_api_key: ENV.fetch("RACKSPACE_API_KEY"),
rackspace_region: :lon,
)
instance = @databases.instances.find { |i| i.name == instance_name }
unless instance
$stderr.puts "Couldn't find an instance with the name #{instance_name}"
exit 1
end
puts "Found a matching database instance (name: #{instance.name}; hostname: #{instance.hostname})"
puts
puts "Enabling root user..."
puts
instance.enable_root_user
puts "Root username: #{instance.root_user}"
puts "Root password: #{instance.root_password}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment