Search This Blog

Showing posts with label nova. Show all posts
Showing posts with label nova. Show all posts

Sunday, May 19, 2013

How do I control vm placement in Openstack cluster

If you have built your owns Openstack cluster than it is up to you as well how do you tune and configure it to meet your requirements.

If you use your cluster primarily to spin up and spin down VM you need often some level of control where the VM are going to be built. In the latest Openstack release there are two options that can help: availability zones and host aggregate filter.

Host aggregates filter

It was introduced in Essex (Release Note, all Essex blueprints)
  • Host aggregates (direct link to blueprint
It was next modified and extended in Folsom as we can see this in the Folsom Release Notes and Folsom blueprints here:
  • General Host Aggregates were implemented, allowing metadata to be set dynamically for hosts and pased to the scheduler general-host-aggregates
  • Lots of improvements were made to the scheduler, Including filters for image architecture and scheduling based on capabilities from aggregates. See doc.
Going through the Grizzly Release note and the Grizzly blueprint I see only these blueprints that are relevant:
Availability zones

I didn't have a chance to investigate where this feature was introduced and how it was implemented fully. For these who are interested in more details this link should give a good starting point: Nova release notes and blueprints

Example

Below are some links to examples with nova commands to show how the two features work.

Controlling volume and instance placement in OpenStack (take 1)
Controlling volume and instance placement in OpenStack (take 2)
Controlling where instances run (Openstack compute administration guide - grizzly)
How do I group compute nodes to control workload placement? (ask openstack forum)
http://devstack.org/exercises/aggregates.sh.html

Friday, April 5, 2013

How to create two isolated Python environment to develop with Openstack nova

This is a natural choice to relay on the package mechanism that is available for you in Linux. You don't have to worry about dependencies, compilation, some basic configuration etc. You simply run rpm -i or apt-get install or pip install to install a package.

Problem

How to create two separate Python environment to to develop and test Python Openstack nova python-novaclient

Solution

We can use a Python package called virtualenv.

To create our two separate and isolated Python environments we need to execute these commands below (the logs are from powershell).
 
PS C:\Users\radoslaw\workspace> virtualenv.exe nova-git
New python executable in nova-git\Scripts\python.exe
Installing setuptools................done.
Installing pip...................done.

PS C:\Users\radoslaw\workspace> virtualenv.exe nova-stable
New python executable in nova-stable\Scripts\python.exe
Installing setuptools................done.
Installing pip...................done.

Once the env are created we have to enabled and switch to them. It is important to enable an environment before trying to run any pip commands. If you forget the requested changes are going to be performed on your default system configuration.

In every env we will install different version of the python-novaclient package. In first we are going to use the version from official Python PyPI repository. In seconds we use the latest source code from github.
 
PS C:\Users\radoslaw\workspace> cd .\nova-stable
PS C:\Users\radoslaw\workspace\nova-stable> cd .\Scripts
PS C:\Users\radoslaw\workspace\nova-stable\Scripts> .\activate.ps1
(nova-stable) PS C:\Users\radoslaw\workspace\nova-stable\Scripts>
(nova-stable) PS C:\Users\radoslaw\workspace\nova-stable\Scripts>
(nova-stable) PS C:\Users\radoslaw\workspace\nova-stable\Scripts> pip install  python-novaclient
Downloading/unpacking python-novaclient

To install the version directly from github under the second environment.
 
(nova-stable) PS C:\Users\radoslaw\workspace\nova-stable> deactivate
PS C:\Users\radoslaw\workspace> cd .\nova-git
PS C:\Users\radoslaw\workspace\nova-git> .\Scripts\activate.ps1
(nova-git) PS C:\Users\radoslaw\workspace\nova-git> pip install -e git+https://https://github.com/openstack/python-novaclient.git#egg=
python-novaclient

To list installed versions
 
(nova-stable) PS C:\Users\radoslaw\workspace\nova-stable> pip list
iso8601 (0.1.4)
prettytable (0.7.1)
python-novaclient (2.13.0)
requests (1.2.0)
simplejson (3.1.2)

(nova-git) PS C:\Users\radoslaw\workspace\nova-git> pip list
iso8601 (0.1.4)
prettytable (0.7.1)
python-novaclient (2.13.0.4.g0fc4e12, c:\users\radoslaw\workspace\nova-git\src\python-novaclient)
requests (1.2.0)
simplejson (3.1.2)

To upgrade the packages in the environments
 
(nova-stable) PS C:\Users\radoslaw\workspace\nova-stable> pip install -U python-novaclient
(nova-git) PS C:\Users\radoslaw\workspace\nova-git> pip install -U python-novaclient

References
  1. http://www.rackspace.com/knowledge_center/article/using-python-novaclient-with-the-rackspace-cloud
  2. https://github.com/openstack/python-novaclient
  3. http://www.virtualenv.org/en/latest/
  4. http://www.pip-installer.org/en/latest/usage.html#pip-install

Wednesday, October 24, 2012

How to check all metadata on your cloud servers

You can create a cloud server and attach a metadata to it. You can modify the settings through out the cloud server life.

Problem

How to check all metadata on all your cloud servers in a simple way.

root@server:~# nova list | tail -n +4 | tac | tail -n +2 | cut  -d'|' -f2 | while read i; do  nova show $i | egrep -i 'name|metadata'; done | sed 's/  */ /g'
| metadata | {} |
| name | test4 |

| metadata | {u'mykey2': u'value2 and 3', u'myke1': u'value1'} |
| name | test4 |

| metadata | {u'rado': u'my value2', u'rade2': u'value3'} |
| name | test3 |

| metadata | {u'rado': u'my value2'} |
| name | test2 |

| metadata | {} |
| name | test1 |

| metadata | {} |
| name | manage2 |

References
  1. http://stackoverflow.com/questions/8017456/output-file-lines-from-last-to-first-in-bash
  2. http://stackoverflow.com/questions/1411713/how-to-split-a-file-and-keep-the-first-line-in-each-of-the-pieces

Example of nova boot command

Problem

There is a lot of written about how the Cloud API works. What the request has to look like and what the correct successes is. But there aren't many practical tutorials or howtos on how to use the tools in practice.

Below is an example of how to create a cloud server using the nova tool.

Solution

This is a link that describe how to install the nova tool [1]. I'm not going to cover this here and I assume you already have it.

  1. Creaet a simple cloud server

  2. root@server:~# nova help | grep image
    root@server:~# nova help | grep flavor
    root@server:~# nova help | grep meta
    root@server:~# nova boot --flavor 2 --image 5cebb13a-f783-4f8c-8058-c4182c724ccd test4 
    +-------------------------+--------------------------------------+
    | Property                | Value                                |
    +-------------------------+--------------------------------------+
    | OS-DCF:diskConfig       | AUTO                                 |
    | OS-EXT-STS:power_state  | 0                                    |
    | OS-EXT-STS:task_state   | scheduling                           |
    | OS-EXT-STS:vm_state     | building                             |
    | accessIPv4              |                                      |
    | accessIPv6              |                                      |
    | adminPass               | 7777                                 |
    | created                 | 2012-10-23T23:11:46Z                 |
    | flavor                  | 512MB Standard Instance              |
    | hostId                  |                                      |
    | id                      | db16f2bc-0f75-4215-927b-c8a34e165dce |
    | image                   | Ubuntu 12.04 LTS (Precise Pangolin)  |
    | metadata                | {}                                   |
    | name                    | test4                                |
    | progress                | 0                                    |
    | rax-bandwidth:bandwidth | []                                   |
    | status                  | BUILD                                |
    | tenant_id               | 7777                                 |
    | updated                 | 2012-10-23T23:11:47Z                 |
    | user_id                 | 7777                                 |
    +-------------------------+--------------------------------------+
    


  3. Creaet a simple cloud server with metadata
root@server:~# nova boot --flavor 2 --image 5cebb13a-f783-4f8c-8058-c4182c724ccd test4 --meta myke1='value1' --meta mykey2='value2 and 3'
+-------------------------+---------------------------------------------------+
| Property                | Value                                             |
+-------------------------+---------------------------------------------------+
| OS-DCF:diskConfig       | AUTO                                              |
| OS-EXT-STS:power_state  | 0                                                 |
| OS-EXT-STS:task_state   | scheduling                                        |
| OS-EXT-STS:vm_state     | building                                          |
| accessIPv4              |                                                   |
| accessIPv6              |                                                   |
| adminPass               | 777                                               |
| created                 | 2012-10-23T23:15:18Z                              |
| flavor                  | 512MB Standard Instance                           |
| hostId                  |                                                   |
| id                      | 3f6be5ae-9c4e-4b0f-880f-c4928e426864              |
| image                   | Ubuntu 12.04 LTS (Precise Pangolin)               |
| metadata                | {u'mykey2': u'value2 and 3', u'myke1': u'value1'} |
| name                    | test4                                             |
| progress                | 0                                                 |
| rax-bandwidth:bandwidth | []                                                |
| status                  | BUILD                                             |
| tenant_id               | 7777                                              |
| updated                 | 2012-10-23T23:15:19Z                              |
| user_id                 | 777                                               |
+-------------------------+---------------------------------------------------+

References
  1. http://docs.rackspace.com/servers/api/v2/cs-gettingstarted/content/section_gs_install_nova.html
  2. http://docs.openstack.org/api/quick-start/content/
  3. http://devops.rackspace.com/13/getting-started-using-python-novaclient-to-manage-cloud-servers
  4. http://vexxhost.com/blog/2012/09/10/installing-cpanel-on-a-cloud-server/

Example of nova credential command



If your credential settings are correct you are going to see this output

root@server:~# set | grep OS_
OS_AUTH_SYSTEM=rackspace_uk
OS_AUTH_URL=https://lon.identity.api.rackspacecloud.com/v2.0/
OS_NO_CACHE=1
OS_PASSWORD=777
OS_REGION_NAME=LON
OS_TENANT_NAME=777
OS_USERNAME=777

root@server:~# nova credentials
+------------------------+---------------------------------------------------------------------------------------+       22:51:35
| User Credentials       | Value                                                                                 |
+------------------------+---------------------------------------------------------------------------------------+
| RAX-AUTH:defaultRegion |                                                                                       |
| id                     | 777                                                                                 |
| name                   | name                                                                       |
| roles                  | [{u'description': u'User Admin Role.', u'id': u'3', u'name': u'identity:user-admin'}] |
+------------------------+---------------------------------------------------------------------------------------+
+---------+--------------------------------------------+
| Token   | Value                                      |
+---------+--------------------------------------------+
| expires | 2012-10-24T13:21:47.000+01:00              |
| id      | f6e9c367-7777-7777-7777-777777777777       |
| tenant  | {u'id': u'777', u'name': u'777'} |
+---------+--------------------------------------------+


If your credentials are wrong you will see this one instead

root@server:~# nova credentials
ERROR: Invalid OpenStack Nova credentials.

root@server:~# nova --debug credentials

REQ: curl -i https://lon.identity.api.rackspacecloud.com/v2.0/tokens -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "User-Agent: python-novaclient" -d '{"auth": {"RAX-KSKEY:apiKeyCredentials": {"username": "777", "apiKey": "777", "tenantName": "777"}}}'

connect: (lon.identity.api.rackspacecloud.com, 443)
send: 'POST /v2.0/tokens HTTP/1.1\r\nHost: lon.identity.api.rackspacecloud.com\r\nContent-Length: 154\r\ncontent-type: application/json\r\naccept-encoding: gzip, deflate\r\naccept: application/json\r\nuser-agent: python-novaclient\r\n\r\n{"auth": {"RAX-KSKEY:apiKeyCredentials": {"username": "777", "apiKey": "777", "tenantName": "777"}}}'
reply: 'HTTP/1.1 401 Unauthorized\r\n'
header: Server: nginx/0.8.55
header: Date: Tue, 23 Oct 2012 22:55:15 GMT
header: Content-Type: application/json
header: Transfer-Encoding: chunked
header: Connection: keep-alive
header: Content-Encoding: gzip
header: response-source: cloud-auth
header: vary: Accept, Accept-Encoding, X-Auth-Token
header: VIA: 1.0 Repose (Repose/2.3.5)
RESP:{'status': '401', 'content-length': '73', 'via': '1.0 Repose (Repose/2.3.5)', 'response-source': 'cloud-auth', 'transfer-encoding': 'chunked', 'vary': 'Accept, Accept-Encoding, X-Auth-Token', 'server': 'nginx/0.8.55', 'connection': 'keep-alive', '-content-encoding': 'gzip', 'date': 'Tue, 23 Oct 2012 22:55:15 GMT', 'content-type': 'application/json'} {"unauthorized":{"code":401,"message":"Username or api key is invalid"}}

DEBUG (shell:534) Invalid OpenStack Nova credentials.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/novaclient/shell.py", line 531, in main
    OpenStackComputeShell().main(sys.argv[1:])
  File "/usr/local/lib/python2.7/dist-packages/novaclient/shell.py", line 463, in main
    raise exc.CommandError("Invalid OpenStack Nova credentials.")
CommandError: Invalid OpenStack Nova credentials.
ERROR: Invalid OpenStack Nova credentials.

Saturday, August 11, 2012

cloudserver script doesn't work anylonger after installing novaclient

I have played with the FirsGen Rackspace cloud on my box. It was working fine. Some info about how to start with it can be found here rackspace-cloudservers .

At some point I have started using the Openstack nova tool to interact with the Rackspace NextGen cloud to run some tests. Once I was done I returned to the openstack tool and discoved that it stopped to work.

Problem

For every comamnd I run i got alwasys the same error message. An example output.
$ /usr/bin/cloudservers --username user --apikey 123  list
Traceback (most recent call last):
  File "/usr/bin/cloudservers", line 9, in module
    load_entry_point('python-cloudservers==1.0a5', 'console_scripts', 'cloudservers')()
  File "/usr/lib/pymodules/python2.7/cloudservers/shell.py", line 413, in main
    CloudserversShell().main(sys.argv[1:])
  File "/usr/lib/pymodules/python2.7/cloudservers/shell.py", line 127, in main
    args.func(args)
  File "/usr/lib/pymodules/python2.7/cloudservers/shell.py", line 279, in do_list
    print_list(self.cs.servers.list(), ['ID', 'Name', 'Status', 'Public IP', 'Private IP'])
  File "/usr/lib/pymodules/python2.7/cloudservers/shell.py", line 402, in print_list
    pt.printt(sortby=fields[0])
  File "/usr/local/lib/python2.7/dist-packages/prettytable.py", line 163, in __getattr__
    raise AttributeError(name)
AttributeError: printt
Solution

After debugin the prettytable.py code it turned out that there is not such a function like printt. Further research confirmed this [1]. The fix this I have changed the code of cloudserver module on my PC. The new code after changes is listed below.

# vim +399 /usr/lib/pymodules/python2.7/cloudservers/shell.py

def print_list(objs, fields):
    pt = prettytable.PrettyTable([f for f in fields], caching=False)
    pt.aligns = ['l' for f in fields]
    for o in objs:
        pt.add_row([getattr(o, f.lower().replace(' ', '_'), '') for f in fields])

    # pt.printt(sortby=fields[0])
    print pt.get_string(sortby=fields[0])
References
  1. http://code.google.com/p/prettytable/issues/detail?id=14&q=printt
  2. https://answers.launchpad.net/nova/+question/198709

  3. Other examples where the code was broken as well
  4. https://github.com/calebgroom/clb/issues/24
  5. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=673790

Tuesday, August 7, 2012

Basic tutorial on how to use and debug Cloud API for the NextGene (Openstack based) or FirsGen (build by Mosso) Rackspace cloud infrastructure

Before we start writing code and play with API we have to install the necessary python libraries first. I used the Ubuntu 11.04 for my testing.

Tools installation
  • Openstack API library
There is a packet with the Openstack libraries in repositories unfortunately this is not the latest code that is compatible with the NextGen Rackspace cloud release. We have to install the tools manually as described here [1].

# don't do this i Ubuntu 11.04 because it is based on older version of the library 
# and will not work
aptitude install python-novaclient

aptitude install python-setuptools
easy_install pip
pip install python-novaclient
pip install --upgrade  python-novaclient

# To verify that the files were installed 
find /usr -name novaclient
/usr/share/pyshared/novaclient
/usr/local/lib/python2.7/dist-packages/novaclient
  • FirstGen
# to install the library
aptitude install python-rackspace-cloudservers

# to verify where the files were installed
find /usr -name cloudservers
/usr/share/pyshared/cloudservers
/usr/lib/pymodules/python2.7/cloudservers

Debugging Nova Openstack API

 As Rackspace lunched his cloud first in the USA and Europe is following a few weeks later the URL below is for a US base cloud account. More about the URLs can be found here [2].

nova_example.py

# cat nova_example.py 
import httplib2
httplib2.debuglevel = 1

OS_USERNAME="user"
OS_PASSWORD="api"
OS_AUTH_URL="https://identity.api.rackspacecloud.com/v2.0/"

from novaclient.v1_1 import client
nt=client.Client(OS_USERNAME,OS_PASSWORD,'',OS_AUTH_URL)
nt.flavors.list()

You can than run this like python -i nova_example.py or run python and copy the code into it like that:

$ python -u
>>> import httplib2
>>> httplib2.debuglevel = 1
>>> 
>>> OS_USERNAME="user"
>>> OS_PASSWORD="api"
>>> OS_AUTH_URL="https://identity.api.rackspacecloud.com/v2.0/"
>>> 
>>> from novaclient.v1_1 import client
>>> nt=client.Client(OS_USERNAME,OS_PASSWORD,'',OS_AUTH_URL)
>>> nt.flavors.list()
connect: (dfw.servers.api.rackspacecloud.com, 443)
send: 'GET /v2/672114/flavors/detail HTTP/1.1\r\nHost: dfw.servers.api.rackspacecloud.com\r\nx-auth-token: mytoken\r\naccept-encoding: gzip, deflate\r\naccept: application/json\r\nuser-agent: python-novaclient\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Tue, 07 Aug 2012 21:16:28 GMT
header: Content-Length: 2448
header: Content-Type: application/json
header: X-Compute-Request-Id: req-4e7dda9c-7eee-402f-acc8-b98dc08e21b5
header: Server: Jetty(8.0.y.z-SNAPSHOT)
[Flavor: 512MB Standard Instance, Flavor: 1GB Standard Instance, Flavor: 2GB Standard Instance, Flavor: 4GB Standard Instance, Flavor: 8GB Standard Instance, Flavor: 15GB Standard Instance, Flavor: 30GB Standard Instance]

Debugging FirstGen API

firstgen_example.py

# cat  firstgen_example.py
import httplib2
httplib2.debuglevel = 1

u='user'
k='api'

from cloudservers import CloudServers
cs=CloudServers(u,k)
cs.flavors.list()

An example output

$ python -u
>>> import httplib2
>>> httplib2.debuglevel = 1
>>>
>>> from cloudservers import CloudServers
>>> u='user'
>>> k='api'
>>> cs=CloudServers(u,k)
>>> cs.flavors.list()
connect: (lon.auth.api.rackspacecloud.com, 443)
send: 'GET /v1.0 HTTP/1.1\r\nHost: lon.auth.api.rackspacecloud.com\r\nx-auth-key: key\r\naccept-encoding: gzip, deflate\r\nx-auth-user: hugoalmeidauk\r\nuser-agent: python-cloudservers/1.0a1\r\n\r\n'
reply: 'HTTP/1.1 204 No Content\r\n'
header: Server: Apache/2.2.3 (Red Hat)
header: vary: X-Auth-User,X-Auth-Key,X-Storage-User,X-Storage-Pass
header: X-Storage-Url: https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_c99f3ebf-f27d-4933-94b7-9e9ebf2bc7cd
header: Cache-Control: s-maxage=60806
header: Content-Type: text/xml
header: Date: Tue, 07 Aug 2012 21:19:36 GMT
header: X-Auth-Token: token
header: X-Storage-Token: token2
header: X-Server-Management-Url: https://lon.servers.api.rackspacecloud.com/v1.0/10001641
header: Connection: Keep-Alive
header: X-CDN-Management-Url: https://cdn3.clouddrive.com/v1/MossoCloudFS_c99f3ebf-f27d-4933-94b7-9e9ebf2bc7cd
header: Content-Length: 0
connect: (lon.servers.api.rackspacecloud.com, 443)
send: 'GET /v1.0/10001641/flavors/detail?fresh HTTP/1.1\r\nHost: lon.servers.api.rackspacecloud.com\r\nx-auth-token: token\r\naccept-encoding: gzip, deflate\r\nuser-agent: python-cloudservers/1.0a1\r\n\r\n'
reply: 'HTTP/1.1 203 OK\r\n'
header: Server: Apache-Coyote/1.1
header: vary:  Accept, Accept-Encoding, X-Auth-Token
header: Content-Encoding: gzip
header: Vary: Accept-Encoding
header: Last-Modified: Tue, 21 Jun 2011 21:09:45 GMT
header: X-PURGE-KEY: /flavors
header: Cache-Control: s-maxage=1800
header: Content-Type: application/json
header: Content-Length: 175
header: Date: Tue, 07 Aug 2012 21:19:36 GMT
header: X-Varnish: 1664913388 1664913324
header: Age: 44
header: Via: 1.1 varnish
header: Connection: keep-alive
[Flavor: 256 server, Flavor: 512 server, Flavor: 1GB server, Flavor: 2GB server, Flavor: 4GB server, Flavor: 8GB server, Flavor: 15.5GB server, Flavor: 30GB server]

References
  1. http://docs.rackspace.com/servers/api/v2/cs-gettingstarted/content/section_gs_install_nova.html
  2. http://docs.rackspace.com/servers/api/v2/cs-gettingstarted/content/section_gs_auth.html
  3. http://pypi.python.org/pypi/python-novaclient
  4. https://github.com/openstack/python-novaclient
  5. http://www.rackspace.com/knowledge_center/article/cloud-servers-how-to-articles-other-resources