Search This Blog

Saturday, July 28, 2012

My python script buffers the output and it causes delays before the text appiers on the console

Linux bash is exelent tool for every day use. It allows you to combine tools and chain them toggethr to achieve remarkable results. As one of my favorite I use this one when testing:
$ python some_script.py | tee log.$(date +%s).txt 

Problem

The problem is that althoug I get all the output on the console it appers to be bufffered and I can't monitor the logs in live when my script runs. An example code can be seen below.
 
Solution

You have to tell python to stop buffering the data sent the the stream you are using (stdin, stdout, stderr). On on the way I found convenient is by using the command line '-u' options.

References

How long does a cloud API may return a cached results

I have been playing with the Rackspace first generation cloud API library/tool (python-cloudservers [1] ) and simulated API calls to create and destroy and list cloud servers.

Problem

At the time of this writing I haven't run into any issues with the create cloud API call. Although I have found some strange behavior when I tried to check status of the newly created cloud server after.

Playing with the tool I wrote [2] for testing I saw that the cloud API call to get a list of all cloud servers immensely relays on cached data that we often get.

GET /servers/detail  # List all servers (all details) [3]

Test

When testing and trying to determine how long it takes to create a cloud sever I got thes results:

# during a week 
$ python performance-single-cs.py -s 2 -u  user -k key  run 
[ 0] creating image: {'flavor': 1, 'image': 112, 'name': 'csperform1343469777'}
[ 0] cloud server build [csperform1343469777] created in 226.428314 seconds / 3.77380523333 minutes
[ 1] creating image: {'flavor': 1, 'image': 112, 'name': 'csperform1343470005'}
[ 1] cloud server build [csperform1343470005] created in 288.115938 seconds / 4.8019323 minutes
[ 2] creating image: {'flavor': 1, 'image': 112, 'name': 'csperform1343471011'}
[ 2] cloud server build [csperform1343471011] created in 1841.598305 seconds / 30.6933050833 minutes

# on Sunday 
$ python performance-single-cs.py -t 1 -s 13 -u hugoalmeidauk -k 391c77192480cbb9969d0514b3daebe1  run
[ 1][  ] starting test nr 1, creating 13 cloud server, please wait ...
[ 1][ 1] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582734'}
[ 1][ 2] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582738'}
[ 1][ 3] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582741'}
[ 1][ 4] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582744'}
[ 1][ 5] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582747'}
[ 1][ 6] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582751'}
[ 1][ 7] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582754'}
[ 1][ 8] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582758'}
[ 1][ 9] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582761'}
[ 1][10] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582835'}
[ 1][11] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582839'}
[ 1][12] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582843'}
[ 1][13] created image: {'flavor': 1, 'image': 112, 'name': 'csperform1343582847'}
[ 1][ 1] cloud server build [csperform1343582734] created in 149.491952 seconds / 2.49153253333 minutes
[ 1][ 2] cloud server build [csperform1343582738] created in 148.614413 seconds / 2.47690688333 minutes
[ 1][ 3] cloud server build [csperform1343582741] created in 147.810013 seconds / 2.46350021667 minutes
[ 1][ 4] cloud server build [csperform1343582744] created in 147.27588 seconds / 2.454598 minutes
[ 1][ 5] cloud server build [csperform1343582747] created in 145.799047 seconds / 2.42998411667 minutes
[ 1][ 6] cloud server build [csperform1343582751] created in 144.760795 seconds / 2.41267991667 minutes
[ 1][ 7] cloud server build [csperform1343582754] created in 143.3738 seconds / 2.38956333333 minutes
[ 1][ 8] cloud server build [csperform1343582758] created in 141.850991 seconds / 2.36418318333 minutes
[ 1][ 9] cloud server build [csperform1343582761] created in 140.177985 seconds / 2.33629975 minutes
[ 1][10] cloud server build [csperform1343582835] created in 157.222253 seconds / 2.62037088333 minutes
[ 1][11] cloud server build [csperform1343582839] created in 155.36349 seconds / 2.5893915 minutes
[ 1][12] cloud server build [csperform1343582843] created in 153.28229 seconds / 2.55470483333 minutes
[ 1][13] cloud server build [csperform1343582847] created in 151.02232 seconds / 2.51703866667 minutes
Results

In average the time between the library API call to create a cloud server and then multiple API calls to verify that this server is successfully built took about 3 to 4 minutes during the week and 2 to 3 min at the weekend. In the worst case when the cache was involved the cloud server API took up to 30min before the data were invalidated and refreshed.

Analysis  

I don't think it is cache problem only. When looking at the python-cloudservers [1] library we can notice that:
  • The documentation has a warning [4]
find(**kwargs) Find a single item with attributes matching **kwargs.
This isn’t very efficient: it loads the entire list then filters on the Python side.
  • The python-cloudservers code shows that it uses only the 'GET /servers/detail' API call instead of  'GET /servers/id' [5]
A code analyses will not be provided but for interested readers they can take a lock at these files to confirm:
/usr/lib/pymodules/python2.7/cloudservers/__init__.py
/usr/lib/pymodules/python2.7/cloudservers/base.py
/usr/lib/pymodules/python2.7/cloudservers/servers.py


References
[1] https://github.com/rackspace/python-cloudservers
[2] https://github.com/rtomaszewski/cloud-performance
[3] http://docs.rackspace.com/servers/api/v1.0/cs-devguide/content/List_Servers-d1e1730.html
[4] http://packages.python.org/python-cloudservers/ref/servers.html#classes
[5] http://docs.rackspace.com/servers/api/v1.0/cs-devguide/content/Get_Server_Details-d1e2143.html

Friday, July 27, 2012

Stale data and caching problem when dealing with cloud API responses

Because the Rackspace cloud API is using caching extensively you have to write a code that is able to handle a stale HTTP data and be able to resent the request if needed.

Example 

A simple example that sometimes works and another time may not work because the API HTTP response contains 404 status code.

from cloudservers import CloudServers
cs=CloudServers(user, key)
cs.authenticate()
sm=cs.servers
server=sm.create(name, image, flavor)
sm.find( name=_server.name )

The cloud 'find' function [1] raises exception NotFound even though we know that the server is there and it shouldn't. 

Traceback (most recent call last):
  File "performance-single-cs.py", line 175, in module
    Main().run()
  File "performance-single-cs.py", line 172, in run
    self.test_performance(user,key)
  File "performance-single-cs.py", line 134, in test_performance
    t.test_perf_single_cs(1)
  File "performance-single-cs.py", line 105, in test_perf_single_cs
    status=self.check_cs_status(server)
  File "performance-single-cs.py", line 45, in check_cs_status
    server=sm.find( name=_server.name )
  File "/usr/lib/pymodules/python2.7/cloudservers/base.py", line 50, in find
    raise NotFound(404, "No %s matching %s." % (self.resource_class.__name__, kwargs))


References

[1] http://packages.python.org/python-cloudservers/ref/servers.html#classes

Tuesday, July 24, 2012

Rackspace python-cloudservers debugging

For the first generation of Rackspace cloud there is a cli tool and a python library [1].
The source code can the tool can be found on github [2].

Problem description

After successful installation of this tool I run into the follow error below.
 
# cat /etc/issue
Ubuntu 11.04 \n \l
# aptitude install python-rackspace-cloudservers

$ cloudservers --username user --apikey 391c7...be1  show 10197279
Traceback (most recent call last):
  File "/usr/bin/cloudservers", line 9, in 
    load_entry_point('python-cloudservers==1.0a5', 'console_scripts', 'cloudservers')()
  File "/usr/lib/pymodules/python2.7/cloudservers/shell.py", line 409, in main
    CloudserversShell().main(sys.argv[1:])
  File "/usr/lib/pymodules/python2.7/cloudservers/shell.py", line 123, in main
    self.cs.authenticate()
  File "/usr/lib/pymodules/python2.7/cloudservers/__init__.py", line 60, in authenticate
    self.client.authenticate()
  File "/usr/lib/pymodules/python2.7/cloudservers/client.py", line 79, in authenticate
    resp, body = self.request(self.AUTH_URL, 'GET', headers=headers)
  File "/usr/lib/pymodules/python2.7/cloudservers/client.py", line 34, in request
    body = json.loads(body) if body else None
  File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 360, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 378, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Troubleshooting


Investigating the stacktrace we see that there are various method called before the error was reported. Looking at the stack from bottom up we see that the the code gets interested around lines 12 and 13.

$ sed -n 79p  /usr/lib/pymodules/python2.7/cloudservers/client.py
        resp, body = self.request(self.AUTH_URL, 'GET', headers=headers)

$ grep AUTH_URL /usr/lib/pymodules/python2.7/cloudservers/client.py 
    AUTH_URL = 'https://auth.api.rackspacecloud.com/v1.0'
        resp, body = self.request(self.AUTH_URL, 'GET', headers=headers)

We see that the URL is hard coded in python code. Because my cloud account is base in London (my cloud files and cloud server provisioning regions are in London ) this URL is wrong. More info about the authentication point can be found in the official doc [3].

An easy fix for this requires to change the URL to a new one:

https://lon.auth.api.rackspacecloud.com/v1.0

References

[1] http://packages.python.org/python-cloudservers/index.html
[2] https://github.com/rackspace/python-cloudservers
[3]
http://docs.rackspace.com/api/
http://docs.rackspace.com/servers/api/v1.0/cs-devguide/content/Overview-d1e70.html

[4] http://www.dimitrioskouzisloukas.com/blog/index.php?blog=2&title=authenticate_with_cloudservers_to_the_lo&more=1&c=1&tb=1&pb=1

Monday, July 23, 2012

How to create a Cloud Server using Rackspace API

Problem description

How to create a cloud server using cloud API.

Solution

A small script available at gitub [1] that uses available cloud API to login to the Rackspace cloud infrastructure. After login it issues necessary create request and creates a new cloud server. At the end prints the result on stdout.

Demonstration
  • Standard output
# python rackspace_cloudserver.py -u user -k key run
creating new cloud server with a name: cstest1343077883
{
 "server": {
  "status": "BUILD", 
  "hostId": "50a21504e046275fa53877dc937ceab6", 
  "name": "cstest1343077883", 
  "adminPass": "KnB1Cu7t4cstest1343077883", 
  "metadata": {}, 
  "imageId": 112, 
  "progress": 0, 
  "flavorId": 1, 
  "id": 10196007, 
  "addresses": {
   "public": [
    "5.79.1.17"
   ], 
   "private": [
    "10.178.4.241"
   ]
  }
 }
}
  • Verbose output 
# python rackspace_cloudserver.py -u user -k key -v run
debug[ 1]: user:  key: key;
debug[ 1]: http request
  lon.auth.api.rackspacecloud.com GET /v1.0
  headers: 
    X-Auth-Key: 391....aebe1
    X-Auth-User: user
debug[ 1]: http response
  204 No Content
  headers
    content-length: 0
    x-server-management-url: https://lon.servers.api.rackspacecloud.com/v1.0/10001641
    x-storage-token: 7e901...67a
    vary: X-Auth-Token,X-Auth-Key,X-Storage-User,X-Storage-Pass
    x-cdn-management-url: https://cdn3.clouddrive.com/v1/MossoCloudFS_c99f3ebf-f27d-4933-94b7-9e9ebf2bc7cd
    server: Apache/2.2.3 (Red Hat)
    connection: Keep-Alive
    cache-control: s-maxage=85050
    date: Mon, 23 Jul 2012 20:59:40 GMT
    x-storage-url: https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_c99f3ebf-f27d-4933-94b7-9e9ebf2bc7cd
    x-auth-token: 7e90....1bc67a
    content-type: text/xml
debug[ 1]: read 0 from the server:
creating new cloud server with a name: cstest1343077180
debug[ 1]: http request
  lon.servers.api.rackspacecloud.com POST /v1.0/10001641/servers
  headers: 
    Content-Type: application/json
    X-Auth-Token: 7e901...bc67a
body:
   {"server": {"flavorId": 1, "name": "cstest1343077180", "imageId": 112}}
debug[ 1]: http response
  202 Accepted
  headers
    content-length: 272
    x-varnish: 1662239131
    age: 0
    vary: Accept, Accept-Encoding, X-Auth-Token
    server: Apache-Coyote/1.1
    connection: keep-alive
    via: 1.1 varnish
    cache-control: no-cache
    date: Mon, 23 Jul 2012 20:59:45 GMT
    content-type: application/json
debug[ 1]: read 272 from the server:
{
 "server": {
  "status": "BUILD", 
  "hostId": "155a42778c64cf881c41ae5dc8a8bd0c", 
  "name": "cstest1343077180", 
  "adminPass": "4KUt5u3oXcstest1343077180", 
  "metadata": {}, 
  "imageId": 112, 
  "progress": 0, 
  "flavorId": 1, 
  "id": 10195995, 
  "addresses": {
   "public": [
    "5.79.1.129"
   ], 
   "private": [
    "10.178.18.97"
   ]
  }
 }
}

References
[1]  https://github.com/rtomaszewski/experiments/blob/master/rackspace_cloudserver.py  

Sunday, July 22, 2012

How to use the first generation of Rackspace Cloud Server API



Problem description

Using the Rackspace Cloud API [1] for the Cloud Servers how to authenticate yourself.
Being authenticated how to execute and test the various API calls that are listed in the API specification [2]

Solution

  • Authentication

To authenticate you need the user name and the API key. You can find these on your cloud control (CC) portal [3] under the "Your Accout" -> "API Access" section.

If you use the new CC Panel you will find it under the user name on the top - right section of the screen. Once clicked you will see the "API Keys" menu that lists the key and the user name again.

Example output:

curl --verbose -H "X-Auth-User: user" -H "X-Auth-Key: key"  https://lon.auth.api.rackspacecloud.com/v1.0
* About to connect() to lon.auth.api.rackspacecloud.com port 443 (#0)
*   Trying 94.236.107.224... connected
* successfully set certificate verify locations:
*   CAfile: /usr/ssl/certs/ca-bundle.crt
  CApath: none
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using RC4-SHA
* Server certificate:
*        subject: C=US; ST=Texas; L=San Antonio; O=Rackspace Managed Hosting; OU=The Rackspace Cloud; OU=Terms of use at www.verisign.com/rpa (c)05; CN=lon.auth.api.rackspacecloud.com
*        start date: 2010-11-02 00:00:00 GMT
*        expire date: 2015-11-01 23:59:59 GMT
*        common name: lon.auth.api.rackspacecloud.com (matched)
*        issuer: C=US; O=VeriSign, Inc.; OU=VeriSign Trust Network; OU=Terms of use at https://www.verisign.com/rpa (c)10; CN=VeriSign Class 3 Secure Server CA - G3
*        SSL certificate verify ok.
> GET /v1.0 HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-cygwin) libcurl/7.22.0 OpenSSL/0.9.8r zlib/1.2.5 libidn/1.22 libssh2/1.2.7
> Host: lon.auth.api.rackspacecloud.com
> Accept: */*
> X-Auth-User: user
> X-Auth-Key: key
>
< HTTP/1.1 204 No Content
< Server: Apache/2.2.3 (Red Hat)
< vary: X-Auth-Token,X-Auth-Key,X-Storage-User,X-Storage-Pass
< X-Storage-Url: https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_c99f3ebf-f27d-4933-94b7-9e9ebf2bc7cd
< Cache-Control: s-maxage=79412
< Content-Type: text/xml
< Date: Sun, 22 Jul 2012 20:33:45 GMT
< X-Auth-Token: a27...e
< X-Server-Management-Url: https://lon.servers.api.rackspacecloud.com/v1.0/10001641
< X-Storage-Token: a27...9de
< Connection: Keep-Alive
< X-CDN-Management-Url: https://cdn3.clouddrive.com/v1/MossoCloudFS_c99f3ebf-f27d-4933-94b7-9e9ebf2bc7cd
< Content-Length: 0
<
* Connection #0 to host lon.auth.api.rackspacecloud.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):

The most important values we have to copy from the output for further work are:

X-Auth-Token: a27....b9de
X-Server-Management-Url: https://lon.servers.api.rackspacecloud.com/v1.0/10001641

  • Issuing more requests, example of how to list available cloud flavors

curl --verbose -H "X-Auth-Token: a27....9de"  https://lon.servers.api.rackspacecloud.com/v1.0/10001641/flavors
* About to connect() to lon.servers.api.rackspacecloud.com port 443 (#0)
*   Trying 212.64.148.15... connected
* successfully set certificate verify locations:
*   CAfile: /usr/ssl/certs/ca-bundle.crt
  CApath: none
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES256-SHA
* Server certificate:
*        subject: C=US; ST=Texas; L=San Antonio; O=Rackspace Managed Hosting; OU=The Rackspace Cloud; OU=Terms of use at www.verisign.com/rpa (c)05; CN=lon.servers.api.rackspacecloud.com
*        start date: 2010-11-02 00:00:00 GMT
*        expire date: 2015-11-01 23:59:59 GMT
*        common name: lon.servers.api.rackspacecloud.com (matched)
*        issuer: C=US; O=VeriSign, Inc.; OU=VeriSign Trust Network; OU=Terms of use at https://www.verisign.com/rpa (c)10; CN=VeriSign Class 3 Secure Server CA - G3
*        SSL certificate verify ok.
> GET /v1.0/10001641/flavors HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-cygwin) libcurl/7.22.0 OpenSSL/0.9.8r zlib/1.2.5 libidn/1.22 libssh2/1.2.7
> Host: lon.servers.api.rackspacecloud.com
> Accept: */*
> X-Auth-Token: a277...9de
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< vary:  Accept, Accept-Encoding, X-Auth-Token
< Last-Modified: Tue, 21 Jun 2011 21:09:45 GMT
< X-PURGE-KEY: /flavors
< Cache-Control: s-maxage=1800
< Content-Type: application/json
< Content-Length: 249
< Date: Sun, 22 Jul 2012 20:34:35 GMT
< X-Varnish: 1603286324
< Age: 0
< Via: 1.1 varnish
< Connection: keep-alive
<
* Connection #0 to host lon.servers.api.rackspacecloud.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
{
  flavors => [
    { id => 1, name => "256 server" },
    { id => 2, name => "512 server" },
    { id => 3, name => "1GB server" },
    { id => 4, name => "2GB server" },
    { id => 5, name => "4GB server" },
    { id => 6, name => "8GB server" },
    { id => 7, name => "15.5GB server" },
    { id => 8, name => "30GB server" },
  ],
}

  • Example of how to list available image types (type of operating systems/Linux distributions)

curl -H "X-Auth-Token: a2772b...b9de" https://lon.servers.api.rackspacecloud.com/v1.0/10001641/images | json_xs -t dump 
{
  images => [
    { id => 24,  name => "Windows Server 2008 SP2 x64" },
    { id => 31,  name => "Windows Server 2008 SP2 x86" },
    { id => 56,  name => "Windows Server 2008 SP2 x86 + SQL Server 2008 R2 Standard" },
    { id => 57,  name => "Windows Server 2008 SP2 x64 + SQL Server 2008 R2 Standard"},
    { id => 85,  name => "Windows Server 2008 R2 x64" },
    { id => 86,  name => "Windows Server 2008 R2 x64 + SQL Server 2008 R2 Standard" },
    { id => 89,  name => "Windows Server 2008 R2 x64 + SQL Server 2008 R2 Web"},
    { id => 91,  name => "Windows Server 2008 R2 x64 + SQL Server 2012 Standard" },
    { id => 92,  name => "Windows Server 2008 R2 x64 + SQL Server 2012 Web" },
    { id => 100, name => "Arch 2011.10" },
    { id => 103, name => "Debian 5 (Lenny)" },
    { id => 104, name => "Debian 6 (Squeeze)" },
    { id => 108, name => "Gentoo 11.0" },
    { id => 109, name => "openSUSE 12" },
    { id => 110, name => "Red Hat Enterprise Linux 5.5" },
    { id => 111, name => "Red Hat Enterprise Linux 6" },
    { id => 112, name => "Ubuntu 10.04 LTS" },
    { id => 114, name => "CentOS 5.6" },
    { id => 115, name => "Ubuntu 11.04" },
    { id => 116, name => "Fedora 15" },
    { id => 118, name => "CentOS 6.0" },
    { id => 119, name => "Ubuntu 11.10" },
    { id => 120, name => "Fedora 16" },
    { id => 121, name => "CentOS 5.8" },
    { id => 122, name => "CentOS 6.2" },
    { id => 125, name => "Ubuntu 12.04 LTS" },
    { id => 126, name => "Fedora 17" },
    { id => 10776442, name => "test3" },
    { id => 10992583, name => "test2" },
    { id => 11019155, name => "Mytest1" },
    { id => 11208053, name => "windows2008R2x64Image" },
    { id => 11236707, name => "w2k8x86sp2-090712-IIS" },
  ],
}

The above outputs has been changed a little bit to include the HTTP headers as well as nice formatted server payload. The payload was generated using this command:

curl -H "X-Auth-Token: a27...de" https://lon.servers.api.rackspacecloud.com/v1.0/10001641/flavors | json_xs -t dump

  • Issuing a request to create a cloud server

And our important request to create a cloud server with a help of the API request.

cat create-cloud.txt 
{
    "server" : {
        "name" : "rc-test1",
        "imageId" : 112,
        "flavorId" : 1,
        "metadata" : {
            "key1" : "value1"
        }
    }
}

curl --verbose -d @create-cloud.txt -H "Content-Type: application/json" -H "X-Auth-Token: a2772b...9de" https://lon.servers.api.rackspacecloud.com/v1.0/10001641/servers | json_xs -t dump 
* About to connect() to lon.servers.api.rackspacecloud.com port 443 (#0)
*   Trying 212.64.148.15...   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0connected
* Connected to lon.servers.api.rackspacecloud.com (212.64.148.15) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Server hello (2):
{ [data not shown]
* SSLv3, TLS handshake, CERT (11):
{ [data not shown]
* SSLv3, TLS handshake, Server finished (14):
{ [data not shown]
* SSLv3, TLS handshake, Client key exchange (16):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Finished (20):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
{ [data not shown]
* SSLv3, TLS handshake, Finished (20):
{ [data not shown]
* SSL connection using AES256-SHA
* Server certificate:
*   subject: C=US; ST=Texas; L=San Antonio; O=Rackspace Managed Hosting; OU=The Rackspace Cloud; OU=Terms of use at www.verisign.com/rpa (c)05; CN=lon.servers.api.rackspacecloud.com
*   start date: 2010-11-02 00:00:00 GMT
*   expire date: 2015-11-01 23:59:59 GMT
*   common name: lon.servers.api.rackspacecloud.com (matched)
*   issuer: C=US; O=VeriSign, Inc.; OU=VeriSign Trust Network; OU=Terms of use at https://www.verisign.com/rpa (c)10; CN=VeriSign Class 3 Secure Server CA - G3
*   SSL certificate verify ok.
> POST /v1.0/10001641/servers HTTP/1.1
> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: lon.servers.api.rackspacecloud.com
> Accept: */*
> Content-Type: application/json
> X-Auth-Token: a2772b...
> Content-Length: 158
> 
} [data not shown]
100   158    0     0  100   158      0     49  0:00:03  0:00:03 --:--:--    50< HTTP/1.1 202 Accepted
< Server: Apache-Coyote/1.1
< vary:  Accept, Accept-Encoding, X-Auth-Token
< Cache-Control: no-cache
< Content-Type: application/json
< Content-Length: 272
< Date: Sun, 22 Jul 2012 21:33:26 GMT
< X-Varnish: 1603293323
< Age: 0
< Via: 1.1 varnish
< Connection: keep-alive
< 
 36   430    0     0  100   158      0     43  0:00:03  0:00:03 --:--:--    44{ [data not shown]
100   430  100   272  100   158     74     42  0:00:03  0:00:03 --:--:--    75* Connection #0 to host lon.servers.api.rackspacecloud.com left intact

* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
} [data not shown]
{
  server => {
    addresses => { private => ["10.178.14.178"], public => ["5.79.0.178"] },
    adminPass => "vS2Ec60xDrc-test1",
    flavorId => 1,
    hostId => "0fa7e40134ef21228895618b21e7090b",
    id => 10195258,
    imageId => 112,
    metadata => { key1 => "value1" },
    name => "rc-test1",
    progress => 0,
    status => "BUILD",
  },
}

References
http://docs.rackspace.com/api/
[2] http://docs.rackspace.com/servers/api/v1.0/cs-devguide/content/Overview-d1e70.html
[3] https://lon.manage.rackspacecloud.com
[4] http://docs.rackspace.com/servers/api/v1.0/cs-devguide/content/Auth-Request.html

Saturday, July 21, 2012

Python IDE using Eclipse and PyDev/Aptana

There are numbers of options when you want to code in Python or other languages and you expect some level of support from your editor and IDE. The environment I use is definitely not the simplest and easy to set up but if you like using one single tool to code in various languages it works than relatively well.

Problem description

How to use a modern IDE to develop programs in Python and potentially use it with other languages like Java and C.

Solution


Eclipse as a single IDE with a support for multiple languages.
PyDev as an Eclipse plugin to support programming in Python. But instead of installing it manualy I decide to use the Aptana Studio 3.x

Installation
  1. We need java first http://java.com/en/download/faq/java_6.xml
  2. Nest install the Eclipse http://www.eclipse.org/downloads/. I used the most popular branch Eclipse IDE for Java EE Developers. It comes with a number of preinstalled modules.
  3. Install Python http://www.python.org/getit/. I needed 2.7.x.
  4. Every one uses some source of software version control tools. I've started to use   http://msysgit.github.com/
  5. This is optional, but because I wanted to have a working Ruby environment as well i installed
    1. Ruby from  http://rubyinstaller.org/downloads/
    2. From the some link than ' RubyInstaller Development Kit (DevKit)'  DevKit
  6. The ruby comes with a powerful Rails application framework  http://rubyonrails.org/download/
  7. At the end we installed our Python plugin from  http://aptana.com/products/studio3/download using the option 'Eclipse Plug-in Version'. The installation is described here:  http://aptana.com/downloads/start
After all the steps the hello world looks like this :)