Search This Blog

Tuesday, April 23, 2013

Challenge 5 script

The full summary of all posts for API Rackspace challenge can be found here:
Rackspace api-challenge summary

Challenge 5 script

Below is the output and results from script #5 from the api-challenge.
The script first do some verification if the provided or the default options are correct.
It verifies if a data base instance exists and if run with option '-i' deletes it.
If there is no db instance it will create a new one.
Before proceeding it waits for the instance to be built. It can take some minutes (on average about 2 min).
Once the instance is created it connects to it and creates databases.
Once the data base(s) are created it creates user(s) that can connect to them.
At the end the script is not deleting the created db instance, databases or users. It has to be deleted manually.
$ python -h

    usage: [-h] [-v] [ -i | -d ] [ -u db-user ] [ instance-name ] [ db-name1 [db-name2] ]
        -h - usage help
        -v - verbose / debug output
        -i - if instance exists delete it and all its databases before proceeding
        -d - delete database(s) from under the instance

        instance-name - create instance with this name
        db-nameX - name of the database
        db-user - create user that can access the database; by default a user name is equal to db-name

$ python -i
[12:12:30] Found existing db instance challenge5-inst1, deleting it ...
[12:12:35] Creating instance challenge5-inst1
[12:12:36] Waiting for the instance to be built ...
[12:14:38] Instance is created on host
[12:14:39] Creating databases ['challenge5-db1', 'challenge5-db2'] under the instance challenge5-inst1
[12:14:39] creating db: challenge5-db1
[12:14:40] creating db: challenge5-db2
[12:14:40] Creating users ['challenge5-user1', 'challenge5-user2']
[12:14:41] Created user challenge5-user1 pass pass123@ in db ['challenge5-db1', 'challenge5-db2']
[12:14:42] Created user challenge5-user2 pass pass123@ in db ['challenge5-db1', 'challenge5-db2']

Once the database is created we can connect to it from any existing cloud servers.
root@server:~/# mysql -h --user=challenge5-user1 --password=pass123@ challenge5-db1
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 52
Server version: 5.1.66-0+squeeze1 (Debian)

mysql> show databases;
| Database           |
| information_schema |
| challenge5-db1     |
| challenge5-db2     |
3 rows in set (0.00 sec)


No comments:

Post a Comment