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 challenge5.py -h

    usage: challenge5.py [-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 challenge5.py -i
[12:12:30] Found existing db instance challenge5-inst1, deleting it ...
challenge5-user2']
[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 ad5e20f3ed07b5ab7592ede01f15316ef05fb0e2.rackspaceclouddb.com
[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 71b4042b25136f6337ca013bb8525afae87a75a0.rackspaceclouddb.com --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)

References
  1. https://github.com/rtomaszewski/api-challenge/tree/challenge5
  2. https://github.com/rackspace/pyrax/tree/master/samples/cloud_databases
  3. http://www.rackspace.com/knowledge_center/article/cloud-databases-how-to-articles-other-resources
  4. http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/POST_createInstance__version___accountId__instances_.html
  5. http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/POST_createDatabase__version___accountId__instances__instanceId__databases_.html
  6. http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/POST_createUser__version___accountId__instances__instanceId__users_.html

No comments:

Post a Comment