Custom Search

Friday, February 20, 2015

How to Install OpenStack and OpenContrail in Separate Machines for Development

1)
Install OpenStack using devstack
========================


a)
* Set Static IP for your VirtualBox OpenStack VM


#vim /etc/network/interfaces

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0

b)
* Clone devstack


#git clone https://github.com/openstack-dev/devstack.git -b stable/icehouse
#cd devstack


c)
* Settings


#vim localrc

SERVICE_HOST=192.168.56.101
DATABASE_PASSWORD=nova
RABBIT_PASSWORD=nova
SERVICE_TOKEN=nova
SERVICE_PASSWORD=nova
ADMIN_PASSWORD=nova
#OFFLINE=True
#RECLONE=no


d)
* Install


./stack.sh


2)
Install OpenContrail from source code using contrail-installer
============================================

1)
* Set Static IP for your VirtualBox OpenContrail VM

#vim /etc/network/interfaces

auto eth0
iface eth0 inet static
address 10.0.2.15
netmask 255.255.255.0
gateway 10.0.2.2

auto eth1
iface eth1 inet static
address 192.168.56.102
netmask 255.255.255.0


2)
* Clone contrail-installer (master branch)

#git clone https://github.com/Juniper/contrail-installer.git
#cd contrail-installer
#cp samples/localrc-all localrc

3)
* Settings

#vim localrc

CONTRAIL_BRANCH=R2.1
CONTRAIL_DEFAULT_INSTALL=False
INSTALL_PROFILE=ALL
NB_JOBS=1
#IP of OpenContrail Service Host
SERVICE_HOST=192.168.56.102
PHYSICAL_INTERFACE=eth1
CONTRAIL_REPO_PROTO=https
#IP of OpenStack Keystone Service Endpoint
OPENSTACK_IP=192.168.56.101

4)
* Settings

#vim contrail-installer/contrail.sh
sudo -E add-apt-repository -y cloud-archive:icehouse

* Change "icehouse" to any branch which you want.

5)
* Build, Install, Configure and Start the OPenContrail Services

#./contrail.sh build
#./contrail.sh install
#./contrail.sh configure
#./contrail.sh start

* Open the Screen
#screen -ls
#screen -x

6)
* Check whether OpenStack Keystone configurations are correct in OpenContrail config files.

* I have written a script reconfigure keystone settings in OpenContrail config files.

https://raw.githubusercontent.com/sajuptpm/mytools/master/opencontrail/contrail_installer_setup_re_config.sh


a)
#vim /etc/contrail/ContrailPlugin.ini

[KEYSTONE]
auth_url = http://192.168.56.101:5000/v2.0
auth_host = 192.168.56.101
admin_tenant_name = admin
admin_password = nova
admin_user = admin

b)
#vim /etc/contrail/contrail_plugin.ini

[KEYSTONE]
auth_url = http://192.168.56.101:5000/v2.0
admin_tenant_name = admin
admin_password = nova
admin_user = admin

c)
#vim /etc/contrail/contrail-api.conf

[KEYSTONE]
auth_protocol = http
auth_port = 5000
admin_tenant_name = admin
admin_password = nova
admin_user = admin
auth_host = 192.168.56.101

d)
#vim /etc/contrail/contrail-schema.conf

[KEYSTONE]
admin_tenant_name = admin
admin_password = nova
admin_user = admin

e)
#vim /etc/contrail/svc-monitor.conf

[KEYSTONE]
admin_tenant_name = admin
admin_password = nova
admin_user = admin

f)
#vim /etc/contrail/contrail-snmp-collector.conf

[KEYSTONE]
admin_user=admin
admin_password=nova
admin_tenant_name=admin

g)
#sudo vim /opt/stack/contrail/contrail-web-core/config/config.global.js

config.identityManager.ip = '192.168.56.101';
config.featurePkg.webController.path = '/opt/stack/contrail/contrail-web-controller';

7)
* How to restart services after configuration change

#screen -ls
#screen -x
#Then goto the Tab of service which you want to restart and press "Ctrl + c", the press "UP" arrow and press Enter.

OR

#cd contrail-installer
#./contrail.sh stop
#./contrail.sh start

8)

a)
* OpenContrail Web UI endpoint

http://192.168.56.102:8080/
https://192.168.56.102:8143/

Login with keystone credentials
username :admin
password: nova

Known Issue: http://fosshelp.blogspot.in/2015/02/opencontrail-ui-error-install-feature.html

b)
* OpenContrail API Server endpoint

http://192.168.56.102:8082/
http://192.168.56.102:8084/

c)
* OpenContrail Analytics API Server endpoint

http://192.168.56.102:8081/
http://192.168.56.102:8090/




[Solved] OpenContrail Web UI login error "Install feature package"

Try following steps if you are installing from source code using contrail-installer.

I found this issue with CONTRAIL_BRANCH R2.1, Ubuntu 12.04.4, contrail-installer master branch (commit id:600d4db0ef99f570b475e5e5241ff3c746987acd)
and resolved by steps below.

1)
Goto
#cd /opt/stack/contrail/contrail-web-core

2)
Run

#make dev-env REPO=webController

3)
Restart the servers


#screen -x
Goto "ui-jobs" and "ui-webs" screen tabs and restart the servers (node webServerStart.js and node jobServerStart.js)

OR

#cd /home/saju/contrail-installer
#./contrail.sh stop
#./contrail.sh start


4)
Open Web UI
https://192.168.56.102:8143




Thursday, February 12, 2015

How to Setup Static IP Address VirtualBox Ubuntu VM

How to Setup Static IP Address VirtualBox Ubuntu VM

1)
Set Static IP Address

#sudo vim /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 10.0.2.15
netmask 255.255.255.0
gateway 10.0.2.2


auto eth1
iface eth1 inet static
address 192.168.56.102
netmask 255.255.255.0


2)
Set nameserver

#sudo vim /etc/resolv.conf
nameserver 8.8.8.8

3)
Reoot

#sudo reboot

4)
Check route

#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.2.2        0.0.0.0         UG    100    0        0 eth0
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.56.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1


5)
Try ping

#ping www.google.com



Python gevent Greenlet Tutorial

Wednesday, February 11, 2015

Get all Open Patchset of particular Project from review.openstack.org

OpenStack what is the difference between driver and plugin


a)
Driver is a minimal implementation and Plugin is a complete specific implementation.

b)
Every driver will have a plugin, right ?

yeah, pretty much, although there are a couple of drivers / agents that use the ML2 plugin. So, it's not a 1-to-1 link

c)
Driver - Example ML2 Drivers . - ML2 is a plugin with the core implementation. All the Driver use a the results of core implementation.

Plugin - Example vmware, ml2, cisco, mlnx etc .. - Refer to individual specific implementation of a core abstract.

How To Customize Django QuerySet values() Method

from mypro.models import Building
from pprint import pprint

a)
Query all the fields of the model class 'Building'

b = Building.objects.filter(id='1015445')
pprint (b.values()[0])


b)
Get selected fields of the model class 'Building'

fields=[f.attname for f in Building._meta.fields]
b = Building.objects.filter(id='1015445')

pprint (b.values(*fields)[0])
len(b.values(*fields)[0])


c)

Include fields from another model class via Foreignkey relation

cust_fields = [f.attname for f in Building._meta.fields]
cust_fields.append('nonuse__description') <--- b="">
b = Building.objects.filter(id='1015445')

pprint (b.values(*cust_fields)[0])
len(b.values(*cust_fields)[0])






Monday, February 9, 2015

Download Ext JS API Docs and use it Offline Locally

1)
Download the Ext JS API Library.

2)
Extract the downloaded file

3)
Goto "docs" directory and run following command
#python -m SimpleHTTPServer 8003

4)
Open the browser and enter following url
http://127.0.0.1:8003/



Saturday, February 7, 2015

How to boot from USB using qemu-system-x86_64

1)
Create a Bootable USB

2)
Run following command and find USB device
#sudo fdisk -l

3)
Then,  Boot from USB using qemu-system-x86_64

#sudo qemu-system-x86_64 -machine accel=kvm:tcg -m 512 -hda /dev/sdc

Here "/dev/sdc" is the usb device



Wednesday, February 4, 2015

How to manually start and stop nova-api service and debug

1)
List "nova-api" service and copy the command
#ps -aux | grep nova-api

2)

Command used to start "nova-api" service
#/usr/bin/python /usr/bin/nova-api --config-file=/etc/nova/nova.conf

3)
Stop "nova-api" service
#sudo /etc/init.d/nova-api stop

4)
Start "nova-api" service manually
#sudo /usr/bin/python /usr/bin/nova-api --config-file=/etc/nova/nova.conf

5)
Find the path of nova package
#find /usr -name nova
#cd /usr/lib/python2.7/dist-packages/nova
#ls


6)
Goto "api" directory, open a *.py file anf add debug statement.
Example:
#import pdb; pdb.set_trace()

7)
Restart "nova-api" service manually
#sudo /usr/bin/python /usr/bin/nova-api --config-file=/etc/nova/nova.conf

8)
Fire OpenStack nova CLI commands
Examples:
#nova server-list
#nova image-list



How to Install Python Object Graphs objgrap

1)
Installation

#sudo apt-get install python-gtk2 graphviz
#pip install objgraph


2) 
Goto python console and draw the graph of a python object in the memory

#python
import objgraph
my_data = [1, 'saju', True, [3], (4,), {'5':5}]
objgraph.show_refs([my_data], filename='sample-graph.png')


3)
Open the graph image "sample-graph.png"

Sunday, February 1, 2015

OpenStack Oslo messaging RPC API Example Call, Cast and Fanout

1) RPC Server
===========




from pprint import pprint
from oslo.config import cfg
import oslo.messaging as om


##Invoke "get_transport". This call will set default Configurations required to Create Messaging Transport
transport = om.get_transport(cfg.CONF)

##Set/Override Configurations required to Create Messaging Transport
cfg.CONF.set_override('rabbit_host', '192.168.56.101')
cfg.CONF.set_override('rabbit_port', 5672)
cfg.CONF.set_override('rabbit_userid', 'guest')
cfg.CONF.set_override('rabbit_password', 'cloud')

cfg.CONF.set_override('rabbit_login_method', 'AMQPLAIN')
cfg.CONF.set_override('rabbit_virtual_host', '/')
cfg.CONF.set_override('rpc_backend', 'rabbit')

##Check Configurations
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)


##Create Messaging Transport
transport = om.get_transport(cfg.CONF)

##Create Target (Exchange, Topic and Server to listen on)
target = om.Target(topic='testme', server='192.168.56.102')

##Create EndPoint
class TestEndpoint(object):
    def test_method1(self, ctx, arg):
        res = "Result from test_method1 " + str(arg)
        print res
        return res
    def test_method2(self, ctx, arg):
        res = "Result from test_method2 " + str(arg)
        print res
        return res


##Create EndPoint List
endpoints = [TestEndpoint(),]

##Create RPC Server
server = om.get_rpc_server(transport, target, endpoints, executor='blocking')

##Start RPC Server
server.start()

2) RPC Client
===========




from pprint import pprint
from oslo.config import cfg
import oslo.messaging as om


##Invoke "get_transport". This call will set default Configurations required to Create Messaging Transport
transport = om.get_transport(cfg.CONF)

##Set Configurations required to Create Messaging Transport
cfg.CONF.set_override('rabbit_host', '192.168.56.101')
cfg.CONF.set_override('rabbit_port', 5672)
cfg.CONF.set_override('rabbit_userid', 'guest')
cfg.CONF.set_override('rabbit_password', 'cloud')

cfg.CONF.set_override('rabbit_login_method', 'AMQPLAIN')
cfg.CONF.set_override('rabbit_virtual_host', '/')
cfg.CONF.set_override('rpc_backend', 'rabbit')

##Check Configurations
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)


##Create Messaging Transport
transport = om.get_transport(cfg.CONF)

##Create Target
target = om.Target(topic='testme')

##Create RPC Client
client = om.RPCClient(transport, target)

##Invoke remote method and wait for a reply.
arg = "Saju"
ctxt = {}
client.call(ctxt, 'test_method1', arg=arg)


##Invoke remote method and return immediately.
arg = "Saju"
ctxt = {}
client.cast(ctxt, 'test_method1', arg=arg)


3)
RPC Client Options
===============

a) 
RPC Client Call and Cast
----------------------------------------------

##Create Target
target = om.Target(topic='testme')

##Create RPC Client
client = om.RPCClient(transport, target)

##RPC Call
ctxt = {}
for x in range(10):
    client.call(ctxt, 'test_method1', arg=x)


##RPC Cast
ctxt ={}
for x in range(10):
    client.cast(ctxt, 'test_method1', arg=x)


b)
Client send request to Specific Server
--------------------------------------------------------------------

##Create Target and specify the server where you want to send the request
target = om.Target(topic='testme', server='192.168.56.102')

##Create RPC Client
client = om.RPCClient(transport, target)

##RPC call
ctxt = {}
for x in range(10):
    client.call(ctxt, 'test_method1', arg=x)


##RPC cast
ctxt = {}
for x in range(10):
    client.cast(ctxt, 'test_method1', arg=x)


c)
Client send request to one of the servers in a round-robin fashion
--------------------------------------------------------------------

##Create Target without any specific server
target = om.Target(topic='testme')

##Create RPC Client
client = om.RPCClient(transport, target)

##RPC Call
ctxt = {}
for x in range(10):
    client.call(ctxt, 'test_method1', arg=x)


##RPC Cast
ctxt = {}
for x in range(10):
    client.cast(ctxt, 'test_method1', arg=x)ctxt = {}


d)
Client send request to all the servers. (fanout)
----------------------------------------------------------------------

##Create Target and set fanout = True
target = om.Target(topic='testme', fanout=True)

##Create RPC Client
client = om.RPCClient(transport, target)

##RPC Call (Will not Support)
ctxt = {}
for x in range(10):
    client.call(ctxt, 'test_method1', arg=x)


##RPC Cast.Fanout works with only RPC Cast.
ctxt = {}
for x in range(10):
    client.cast(ctxt, 'test_method1', arg=x)



Ref: http://docs.openstack.org/developer/oslo.messaging/


How to use OpenStack oslo.config

An OpenStack library for parsing configuration options from the command line and configuration files

1)
How to print configuration using oslo.config


from pprint import pprint
from oslo.config import cfg

res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)




2)
How to Register, Unregister and Override an option in the configuration using oslo.config


from pprint import pprint
from oslo.config import cfg


##Register
opts = [cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""),]

cfg.CONF.register_opts(opts)


OR
cfg.CONF.register_opt(cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""))


##Unregister
opts = [cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""),]

cfg.CONF.unregister_opts(opts)
 

OR
cfg.CONF.unregister_opt(cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""))

##Override
cfg.CONF.set_override('transport_url', None)

##Print all config options
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)


OpenStack oslo messaging and config examples

* How to print configuration using oslo.config

from pprint import pprint
from oslo.config import cfg

res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)


==============

* How to register/unregister/override an option in configuration using oslo.config


from pprint import pprint
from oslo.config import cfg

##Register
opts = [cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""),]
cfg.CONF.register_opts(opts)
OR
cfg.CONF.register_opt(cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""))

##Unregister
opts = [cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""),]
cfg.CONF.unregister_opts(opts)
OR
cfg.CONF.unregister_opt(cfg.StrOpt('api_server_ip', default='127.0.0.1', help=""))

##Override
cfg.CONF.set_override('transport_url', None)

##Print
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)






==============

* RPC Server
--------------------


#vim /usr/local/lib/python2.7/dist-packages/oslo.messaging-1.4.1.dist-info/entry_points.txt

from pprint import pprint
from oslo.config import cfg
import oslo.messaging as om

##Invoke "get_transport". This call will set default Configurations required to Create Messaging Transport
>>> transport = om.get_transport(cfg.CONF)

##Set/Override Configurations required to Create Messaging Transport
cfg.CONF.set_override('rabbit_host', '127.0.0.1')
cfg.CONF.set_override('rabbit_port', 5672)
cfg.CONF.set_override('rabbit_userid', 'guest')
cfg.CONF.set_override('rabbit_password', 'cloud')
cfg.CONF.set_override('rabbit_login_method', 'AMQPLAIN')
cfg.CONF.set_override('rabbit_virtual_host', '/')
cfg.CONF.set_override('rpc_backend', 'rabbit')

##Check Configurations
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)

##Create Messaging Transport
>>> transport = om.get_transport(cfg.CONF)

##Set/Override Configurations required to Create Target (Exchange, Topic and Server to listen on)
>>> cfg.CONF.set_override('control_exchange', 'openstack')

##Create Target (Exchange, Topic and Server to listen on)
>>> target = om.Target(topic='testme', server='127.0.0.1')

>>> target.namespace
>>> target.topic
'testme'
>>> target.version
>>> target.fanout
>>> target.server
'127.0.0.1'
>>> target.exchange

##Create End Points
class TestEndpoint(object):
    def test(self, ctx, arg):
        return arg

endpoints = [TestEndpoint(),]

##Create RPC Server
server = om.get_rpc_server(transport, target, endpoints, executor='blocking')

>>> server.dispatcher

>>> server.transport

>>> server.executor
'blocking'
>>> server.start
>
>>>

##Check rabbitmq queue
#sudo rabbitmqctl list_queues | grep testme
testme    0
testme.127.0.0.1    0
testme_fanout_ba1e644ad10e40fc881793445b5e42bf    0

##Debug RPC server
#vim /usr/local/lib/python2.7/dist-packages/oslo/messaging/server.py
Add debug statement "import pdb; pdb.set_trace()" in method "start".
   

* RPC Client
------------------


from pprint import pprint
from oslo.config import cfg
import oslo.messaging as om

##Invoke "get_transport". This call will set default Configurations required to Create Messaging Transport
>>> transport = om.get_transport(cfg.CONF)

##Set Configurations required to Create Messaging Transport

cfg.CONF.set_override('rabbit_host', '127.0.0.1')
cfg.CONF.set_override('rabbit_port', 5672)
cfg.CONF.set_override('rabbit_userid', 'guest')
cfg.CONF.set_override('rabbit_password', 'cloud')
cfg.CONF.set_override('rabbit_login_method', 'AMQPLAIN')
cfg.CONF.set_override('rabbit_virtual_host', '/')
cfg.CONF.set_override('rpc_backend', 'rabbit')

##Check Configurations
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)

##Create Messaging Transport
>>> transport = om.get_transport(cfg.CONF)

##Create Target
>>> target = om.Target(topic='testme')

##Create RPC Client
>>> client = om.RPCClient(transport, target)

##Invoke remote method named "test"

ctxt={}
arg="blabla"
client.call(ctxt, 'test', arg=arg)

==============

RPC Server Code
-----------------------


from pprint import pprint
from oslo.config import cfg
import oslo.messaging as om

##Invoke "get_transport". This call will set default Configurations required to Create Messaging Transport
transport = om.get_transport(cfg.CONF)

##Set/Override Configurations required to Create Messaging Transport
cfg.CONF.set_override('rabbit_host', '127.0.0.1')
cfg.CONF.set_override('rabbit_port', 5672)
cfg.CONF.set_override('rabbit_userid', 'guest')
cfg.CONF.set_override('rabbit_password', 'cloud')
cfg.CONF.set_override('rabbit_login_method', 'AMQPLAIN')
cfg.CONF.set_override('rabbit_virtual_host', '/')
cfg.CONF.set_override('rpc_backend', 'rabbit')

##Check Configurations
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)

##Create Messaging Transport
transport = om.get_transport(cfg.CONF)

##Create Target (Exchange, Topic and Server to listen on)
target = om.Target(topic='testme', server='10.0.2.15')

##Create End Points
class TestEndpoint(object):
    def test_method1(self, ctx, arg):
        res = "Result from test_method1 " + str(arg)
        print res
        return res
    def test_method2(self, ctx, arg):
        res = "Result from test_method2 " + str(arg)
        print res
        return res

endpoints = [TestEndpoint(),]


##Create RPC Server
server = om.get_rpc_server(transport, target, endpoints, executor='blocking')

##Start RPC Server
server.start()

RPC Client Code
-----------------------


from pprint import pprint
from oslo.config import cfg
import oslo.messaging as om

##Invoke "get_transport". This call will set default Configurations required to Create Messaging Transport
transport = om.get_transport(cfg.CONF)

##Set Configurations required to Create Messaging Transport
cfg.CONF.set_override('rabbit_host', '127.0.0.1')
cfg.CONF.set_override('rabbit_port', 5672)
cfg.CONF.set_override('rabbit_userid', 'guest')
cfg.CONF.set_override('rabbit_password', 'cloud')
cfg.CONF.set_override('rabbit_login_method', 'AMQPLAIN')
cfg.CONF.set_override('rabbit_virtual_host', '/')
cfg.CONF.set_override('rpc_backend', 'rabbit')

##Check Configurations
res = [{k:v} for k, v in cfg.CONF.iteritems()]
pprint(res)

##Create Messaging Transport
transport = om.get_transport(cfg.CONF)

##Create Target
target = om.Target(topic='testme', server='10.0.2.15')

##Create RPC Client
client = om.RPCClient(transport, target)

##Invoke remote method and wait for a reply.
arg = "Saju"
ctxt = {}
client.call(ctxt, 'test_method1', arg=arg)

##Invoke remote method and return immediately.
arg = "Saju"
ctxt = {}
client.cast(ctxt, 'test_method1', arg=arg)

==============

a)
Client Request to Specific Server

##Create Target
target = om.Target(topic='testme', server='127.0.0.1')
##Create RPC Client
client = om.RPCClient(transport, target)
for x in range(10):
    client.call(ctxt, 'test_method1', arg=x)

b)
Client Request to one of the servers in a round-robin fashion.

##Create Target
target = om.Target(topic='testme')
##Create RPC Client
client = om.RPCClient(transport, target)
for x in range(10):
    client.call(ctxt, 'test_method1', arg=x)

b)
Client Request to all the servers. (fanout)

##Create Target
target = om.Target(topic='testme')
##Create RPC Client
client = om.RPCClient(transport, target, fanout=True)
for x in range(10):
    client.call(ctxt, 'test_method1', arg=x)