-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script for enabling root access on a Rackspace DB instance
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/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.fetch(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}" |