Custom Search

Monday, April 28, 2014

Git How to merge a branch into master branch (Move all new commits one by one from our branch to master branch)

1)
#git clone https://github.com/myrepo/horizon.git

2)
#cd horizon
*Now you are in master branch

3)
*Checkput new feature branch
#git checkout new_feature

4)
*Go back to master branch
#git checkout master

5)
*Check log
#git log -n 3

6)
*Merge the branch "new_feature" into "master"
#git merge new_feature

7)
*Check log
#git log -n 3
8)
#Push master to remote repo (https://github.com/blabla)
#git push remote master

Saturday, April 26, 2014

OpenStack Keystone Database ER Diagram






How to Generate ER Diagram from existing database

1)
Install mysql-workbench
#sudo apt-get install mysql-workbench

2)
Goto to mysql-workbench




ubuntu 14.04 lts server eth0 and eth1 are missing virtualbox

1)
Goto following file and add eth0 and eth1
sudo vim /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback


# The primary network interface
auto eth0
iface eth0 inet dhcp


auto eth1
iface eth1 inet dhcp




2)
Reboot
#sudo reboot

3)
#ifconfig



Solved: How to Enable SSH in Ubuntu 14.04 Trusty Tahr

1)
sudo apt-get update

2)
sudo apt-get install ssh

How To Install Stable OpenStack with Neutron and Swift In Ubuntu Using Devstack

1)
git clone https://github.com/openstack-dev/devstack.git -b stable/icehouse

2)
cd devstack



3)
Create a "localrc" file and add following lines
vim localrc

#Neutron
disable_service n-net
enable_service q-svc
enable_service q-agt
enable_service q-dhcp
enable_service q-l3
enable_service q-meta
enable_service q-metering


#Swift
enable_service s-proxy s-object s-container s-account

4)
./unstack
./stack

Wednesday, April 23, 2014

How to upgrade Ubuntu 12.04 to 14.04

How to Install Ubuntu 14.04 LTS Server Trusty Tahr


How to Install Ubuntu 14.04 LTS Desktop Trusty Tahr



*** missing separator (did you mean TAB instead of 8 spaces?). Stop.

Fix
===
Substitute 8 space with tab via "vim" editor using following command
:%s/^ \{8}/^I/

If it not replacing 8 space with tab, then edit :%s/^ \{8}/^I/ and remove "^I" and press "Tab", so we can see "^I" again there. Then run it again.

How to Horizon packaging copy /etc/apache2/openstack-dashboard.conf

1)
#ls debian/

changelog  openstack-dashboard.conf      openstack-dashboard.preinst                patches                                  source
compat     openstack-dashboard.dirs      openstack-dashboard-ubuntu-theme.dirs      pydist-overrides                         static
conffile   openstack-dashboard.install   openstack-dashboard-ubuntu-theme.install   python-django-horizon.install            theme
control    openstack-dashboard.links     openstack-dashboard-ubuntu-theme.links     python-django-horizon.lintian-overrides  watch
copyright  openstack-dashboard.postinst  openstack-dashboard-ubuntu-theme.postinst  README.compression
gbp.conf   openstack-dashboard.postrm    openstack-dashboard-ubuntu-theme.postrm    rules

2)
#vim ./debian/openstack-dashboard.install

debian/openstack-dashboard.conf etc/apache2/conf-available <===
etc/openstack-dashboard
usr/share/openstack-dashboard
horizon usr/share/openstack-dashboard
horizon_mycloud usr/share/openstack-dashboard
horizon_mycloud/static/* usr/share/openstack-dashboard/openstack_dashboard/static/
debian/static/openstack-dashboard/manifest.json usr/share/openstack-dashboard/openstack_dashboard/static/dashboard
debian/static/openstack-dashboard/css/* usr/share/openstack-dashboard/openstack_dashboard/static/dashboard/css
debian/static/openstack-dashboard/js/* usr/share/openstack-dashboard/openstack_dashboard/static/dashboard/js

3)
#vim ./debian/openstack-dashboard.preinst

#!/bin/sh
# vim: set ts=2 et:

set -e

# /etc/apache2/conf.d/dashboard.conf -> /etc/apache2/conf.d/openstack-dashboard.conf
dpkg-maintscript-helper mv_conffile \
  /etc/apache2/conf.d/dashboard.conf /etc/apache2/conf.d/openstack-dashboard.conf \
  2012.1~rc1-0ubuntu1 -- "$@"


# Transition config to apache 2.4 compatable location.
dpkg-maintscript-helper mv_conffile \
  /etc/apache2/conf.d/openstack-dashboard.conf \
  /etc/apache2/conf-available/openstack-dashboard.conf \
  1:2013.2~b2-0ubuntu3 -- "$@"


4)
vim ./debian/openstack-dashboard.postinst

#!/bin/sh
# vim: set ts=2 et:

set -e

CONF="openstack-dashboard.conf"

if [ "$1" = "configure" ]; then
  # /etc/apache2/conf.d/dashboard.conf -> /etc/apache2/conf-available/openstack-dashboard.conf
  dpkg-maintscript-helper mv_conffile \
    /etc/apache2/conf.d/dashboard.conf /etc/apache2/conf-available/$CONF \
    2012.1~rc1-0ubuntu1 -- "$@"


  # Transition config to apache 2.4 compatable location.
  dpkg-maintscript-helper mv_conffile \
    /etc/apache2/conf.d/$CONF \
    /etc/apache2/conf-available/$CONF \
    1:2013.2~b2-0ubuntu3 -- "$@"


        if ! getent group horizon > /dev/null 2>&1
        then
                addgroup --system horizon >/dev/null
        fi
        if ! getent passwd horizon > /dev/null 2>&1
        then
    adduser --system --home /usr/share/openstack-dashboard/ --ingroup horizon \
            --no-create-home --shell /bin/false horizon
        fi

  if [ -e /usr/share/openstack-dashboard/openstack_dashboard/static ] ; then
    chown -R horizon:horizon \
      /usr/share/openstack-dashboard/openstack_dashboard/static
  fi

  if [ -d /etc/openstack-dashboard/ ] ; then
   chown horizon:horizon /etc/openstack-dashboard/
  fi

  A22_STATE=$(dpkg-query -f '${Status}' -W 'apache2.2-common' 2>/dev/null | awk '{print $3}' || true)

  if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
    # apache 2.4
    . /usr/share/apache2/apache2-maintscript-helper
    apache2_invoke enconf $CONF || exit $?
  elif [ "$A22_STATE" = "installed" ] || [ "$A22_STATE" = "unpacked" ] ; then
    # apache 2.2
    [ -d /etc/apache2/conf.d/ ] && [ ! -L /etc/apache2/conf.d/$CONF ] &&
      ln -s ../conf-available/$CONF /etc/apache2/conf.d/$CONF
    [ -x /etc/init.d/apache2 ] && invoke-rc.d --quiet apache2 reload
  fi

  if [ -d /var/lib/openstack-dashboard ] ; then
    # Generated secret storage for single node use - see local_settings.py
    # for more details of SECRET_KEY
    chmod 0700 /var/lib/openstack-dashboard
    if [ -f /etc/openstack-dashboard/secret_key ]; then
      mv /etc/openstack-dashboard/secret_key /var/lib/openstack-dashboard
    fi
    chown -R horizon:horizon /var/lib/openstack-dashboard
  fi
fi

ubuntu 12.04 lts server eth0 and eth1 are missing

1)
Goto following file and add eth0 and eth1
sudo vim /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback


# The primary network interface
auto eth0
iface eth0 inet dhcp


auto eth1
iface eth1 inet dhcp


2)
Remove following line
sudo rm /etc/udev/rules.d/70-persistent-net.rules

3)
Restart networking
#sudo reboot
sudo /etc/init.d/networking restart






Tuesday, April 22, 2014

How to Upgrade Ubuntu 13.04 LTS or 13.10 to Ubuntu 14.04 LTS

1)
#sudo update-manager -d
#sudo do-release-upgrade -d

How to Upgrade Ubuntu 12.04 LTS to Ubuntu 14.04 LTS

1)
First, you need to remove all 3rd party binary drivers such as NVIDIA or AMD graphics card driver.
http://askubuntu.com/questions/25528/uninstalling-atis-drivers-and-installing-nvidias

sudo apt-get remove --purge nvidia-185-*
sudo apt-get remove --purge nvidia-current-*
sudo apt-get remove --purge nvidia-glx-185



2)
Then run
#sudo update-manager -d

3)
Reboot the system
#sudo reboot

How to Git create a new branch and push to github.com

1)
Create a branch "new_branch"
#git branch new_branch

2)
Switch to the branch "new_branch"
#git checkout new_branch

3)
Find name of the remote
#git remote -v

4)
Push the branch "new_branch" to remote "origin"
#git push origin new_branch

Friday, April 18, 2014

devstack ++ failed ++ kill ++ set +o xtrace curl -O https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz

Error
=====
+ uninstall_package python-pip
+ is_ubuntu
+ [[ -z deb ]]
+ '[' deb = deb ']'
+ apt_get purge python-pip
+ [[ '' = \T\r\u\e ]]
+ [[ -z purge python-pip ]]
+ local sudo=sudo
++ id -u
+ [[ 1005 = \0 ]]
+ sudo DEBIAN_FRONTEND=noninteractive http_proxy= https_proxy= no_proxy= apt-get --option Dpkg::Options::=--force-confold --assume-yes purge python-pip
Reading package lists... Done
Building dependency tree      
Reading state information... Done
Package python-pip is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 24 not upgraded.
+ [[ -n '' ]]
+ install_pip_tarball
+ cd /home/stackuser/openstack/devstack/files
+ curl -O https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) couldn't connect to host
++ failed
++ local r=1
+++ jobs -p
++ kill
++ set +o xtrace

Fix:
===
a) Check yout internet connectivity
b) Check http and https access



SOLVED: heat.engine.resource Error: Creation of server my-wordpress-stack-WikiDatabase-wkamhzaov7z3 failed: No valid host was f ound. (500)

Error
=====
2014-04-18 10:59:10.500 ERROR heat.engine.resource [-] CREATE : Instance "WikiDatabase"
2014-04-18 10:59:10.500 TRACE heat.engine.resource Traceback (most recent call last):
2014-04-18 10:59:10.500 TRACE heat.engine.resource   File "/opt/stack/heat/heat/engine/resource.py", line 371, in _do_action
2014-04-18 10:59:10.500 TRACE heat.engine.resource     while not check(handle_data):
2014-04-18 10:59:10.500 TRACE heat.engine.resource   File "/opt/stack/heat/heat/engine/resources/instance.py", line 372, in check_create_complete
2014-04-18 10:59:10.500 TRACE heat.engine.resource     return self._check_active(cookie)
2014-04-18 10:59:10.500 TRACE heat.engine.resource   File "/opt/stack/heat/heat/engine/resources/instance.py", line 398, in _check_active
2014-04-18 10:59:10.500 TRACE heat.engine.resource     raise exc
2014-04-18 10:59:10.500 TRACE heat.engine.resource Error: Creation of server my-wordpress-stack-WikiDatabase-wkamhzaov7z3 failed: No valid host was f
ound.  (500)
2014-04-18 10:59:10.500 TRACE heat.engine.resource

Fix

===
* Try again with higher flavor/instancetype.
* Use Following command to find flavors
#nova flavor-list





SOLVED:nova.virt.driver ImportError: libvirt.so.0: cannot open shared object file: No such file or directory

Error
=====

2014-04-18 09:13:46.503 ERROR nova.virt.driver [-] Unable to load the virtualization driver
2014-04-18 09:13:46.503 TRACE nova.virt.driver Traceback (most recent call last):
2014-04-18 09:13:46.503 TRACE nova.virt.driver   File "/opt/stack/nova/nova/virt/driver.py", line 1115, in load_compute_driver
2014-04-18 09:13:46.503 TRACE nova.virt.driver     virtapi)
2014-04-18 09:13:46.503 TRACE nova.virt.driver   File "/opt/stack/nova/nova/openstack/common/importutils.py", line 54, in import_object_ns
2014-04-18 09:13:46.503 TRACE nova.virt.driver     return import_class(import_str)(*args, **kwargs)
2014-04-18 09:13:46.503 TRACE nova.virt.driver   File "/opt/stack/nova/nova/openstack/common/importutils.py", line 30, in import_class
2014-04-18 09:13:46.503 TRACE nova.virt.driver     __import__(mod_str)
2014-04-18 09:13:46.503 TRACE nova.virt.driver   File "/usr/lib/python2.7/dist-packages/libvirt.py", line 25, in
2014-04-18 09:13:46.503 TRACE nova.virt.driver     raise lib_e
2014-04-18 09:13:46.503 TRACE nova.virt.driver ImportError: libvirt.so.0: cannot open shared object file: No such file or directory
2014-04-18 09:13:46.503 TRACE nova.virt.driver
n-cpu failed to start

Fix
======

a)
I had libvirt0.9.8 by default on my ubuntu 12.04.  Later i installed libvirt1.2 from source. And later i removed that using the command#make uninstall. Then now, I am trying to install default libvirt 0.9 back using #sudo apt-get install libvirt-bin.  That got installed. But getting error when running my application which using libvir Error:nova.virt.driver ImportError: libvirt.so.0: cannot open shared object file: No such file or directory

b)

jitsusama> It's not loading up the dynamic library file.
jitsusama> curious. Try find / -name "*libvirt*" -print
jitsusama> Look for any .a or .so files.
jitsusama> I'm thinking you have conflicting library files installed. make uninstall might not have done its job.

stackuser@mypc:~$ sudo find / -name "*libvirt*" -print | grep .so
/usr/lib/python2.7/dist-packages/libvirtmod.so
/usr/lib/python2.7/dist-packages/libvirtmod_qemu.so
/usr/lib/libvirt.so.0.9.8
/usr/lib/libvirt-qemu.so.0.9.8
/usr/lib/pyshared/python2.7/libvirtmod.so
/usr/lib/pyshared/python2.7/libvirtmod_qemu.so
/home/stackuser/openstack/devstack/lib/nova_plugins/hypervisor-libvirt
/opt/libvirt/libvirt/src/qemu/.deps/libvirt_driver_qemu_impl_la-qemu_monitor_json.Plo
/opt/libvirt/libvirt/src/qemu/libvirt_driver_qemu_impl_la-qemu_monitor_json.lo
/opt/libvirt/libvirt/src/qemu/.libs/libvirt_driver_qemu_impl_la-qemu_monitor_json.o
/opt/libvirt/libvirt/src/rpc/libvirt_net_rpc_la-virnetsocket.lo
/opt/libvirt/libvirt/src/rpc/.deps/libvirt_net_rpc_la-virnetsocket.Plo
/opt/libvirt/libvirt/src/rpc/.deps/libvirt_setuid_rpc_client_la-virnetsocket.Plo
/opt/libvirt/libvirt/src/rpc/libvirt_setuid_rpc_client_la-virnetsocket.lo
/opt/libvirt/libvirt/src/rpc/.libs/libvirt_setuid_rpc_client_la-virnetsocket.o
/opt/libvirt/libvirt/src/rpc/.libs/libvirt_net_rpc_la-virnetsocket.o
/opt/libvirt/libvirt/src/util/libvirt_util_la-virjson.lo
/opt/libvirt/libvirt/src/util/.deps/libvirt_util_la-virjson.Plo
/opt/libvirt/libvirt/src/util/.deps/libvirt_setuid_rpc_client_la-virjson.Plo
/opt/libvirt/libvirt/src/util/.deps/libvirt_setuid_rpc_client_la-virsocketaddr.Plo
/opt/libvirt/libvirt/src/util/.deps/libvirt_util_la-virsocketaddr.Plo
/opt/libvirt/libvirt/src/util/libvirt_setuid_rpc_client_la-virsocketaddr.lo
/opt/libvirt/libvirt/src/util/libvirt_util_la-virsocketaddr.lo
/opt/libvirt/libvirt/src/util/libvirt_setuid_rpc_client_la-virjson.lo
/opt/libvirt/libvirt/src/util/.libs/libvirt_setuid_rpc_client_la-virsocketaddr.o
/opt/libvirt/libvirt/src/util/.libs/libvirt_util_la-virsocketaddr.o
/opt/libvirt/libvirt/src/util/.libs/libvirt_setuid_rpc_client_la-virjson.o
/opt/libvirt/libvirt/src/util/.libs/libvirt_util_la-virjson.o
/opt/libvirt/libvirt/src/xen/.deps/libvirt_driver_xen_impl_la-xen_hypervisor.Plo
/opt/libvirt/libvirt/src/.libs/libvirt.so.0.1002.3
/opt/libvirt/libvirt/src/.libs/libvirt_driver_network.so
/opt/libvirt/libvirt/src/.libs/libvirt-lxc.so.0
/opt/libvirt/libvirt/src/.libs/libvirt_driver_vbox.so
/opt/libvirt/libvirt/src/.libs/libvirt_driver_nwfilter.so
/opt/libvirt/libvirt/src/.libs/libvirt-lxc.so.0.1002.3
/opt/libvirt/libvirt/src/.libs/libvirt-lxc.so.0.1002.3T
/opt/libvirt/libvirt/src/.libs/libvirt-qemu.so.0
/opt/libvirt/libvirt/src/.libs/libvirt-lxc.so
/opt/libvirt/libvirt/src/.libs/libvirt_driver_qemu.so
/opt/libvirt/libvirt/src/.libs/libvirt_driver_nodedev.so
/opt/libvirt/libvirt/src/.libs/libvirt-qemu.so.0.1002.3T
/opt/libvirt/libvirt/src/.libs/libvirt_driver_secret.so
/opt/libvirt/libvirt/src/.libs/libvirt-qemu.so.0.1002.3
/opt/libvirt/libvirt/src/.libs/libvirt-qemu.so
/opt/libvirt/libvirt/src/.libs/libvirt.so.0
/opt/libvirt/libvirt/src/.libs/libvirt_driver_interface.so
/opt/libvirt/libvirt/src/.libs/libvirt_driver_lxc.so
/opt/libvirt/libvirt/src/.libs/libvirt.so
/opt/libvirt/libvirt/src/.libs/libvirt_driver_uml.so
/opt/libvirt/libvirt/src/.libs/libvirt_driver_storage.so

c)
saju_m: sudo ldconfig -v | grep libvirt

stackuser@mypc:~$ sudo ldconfig -v | grep libvirt
/sbin/ldconfig.real: Path `/lib/x86_64-linux-gnu' given more than once
/sbin/ldconfig.real: Path `/usr/lib/x86_64-linux-gnu' given more than once
    libvirt-qemu.so.0 -> libvirt-qemu.so.0.9.8 (changed)
    libvirt.so.0 -> libvirt.so.0.9.8 (changed)
stackuser@mypc:~$

jitsusama> Ah ha, changed.
jitsusama> That might've fixed ya.
jitsusama> Try loading it again.
jitsusama> Do you still have libvirt-bin installed btw?
jitsusama> If not, you might want to load that first.
jitsusama> Try the command sysinfo and see if you get a response.
jitsusama> saju_m: You'd want to run that command from virsh.

d)
stackuser@mypc:~$ sudo service libvirt-bin restart
libvirt-bin stop/waiting
libvirt-bin start/running, process 54833
stackuser@mypc:~$
stackuser@mypc:~$
stackuser@mypc:~$
stackuser@mypc:~$ sudo ldconfig -v | grep libvirt
/sbin/ldconfig.real: Path `/lib/x86_64-linux-gnu' given more than once
/sbin/ldconfig.real: Path `/usr/lib/x86_64-linux-gnu' given more than once
    libvirt.so.0 -> libvirt.so.0.9.8
    libvirt-qemu.so.0 -> libvirt-qemu.so.0.9.8
stackuser@mypc:~$
stackuser@mypc:~$
stackuser@mypc:~$
stackuser@mypc:~$ sudo virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh #
virsh # sysinfo
virsh #

e)
saju_m> jitsusama: which command got fixed this issue ?

jitsusama> You compiled and installed from source.
jitsusama> At some time your library file cache was rebuilt.
jitsusama> You did a make uninstall, then installed the binary.

jitsusama> Your library file cache didn't get rebuilt.
jitsusama> So, when the libvirt daemon tried to load, Linux didn't have a cache of the proper library file loaded.

jitsusama> So, it couldn't dynamically link it with the binary.
jitsusama> This caused the failure.
jitsusama> Running ldconfig recreated the library file cache.

jitsusama> Whenever you muck around with .so files, you want to run ldconfig to "refresh" your library file cache.
jitsusama> Otherwise, binaries won't know where to find their library files.

jitsusama:thanks, Let me try to create a VM

SOLVED:ERROR nova.virt.libvirt.driver [-] Connection to libvirt failed: Failed to connect socket to '/var/run/libvirt/libvirt-sock' No such file or directory

Fix:
====
a)
Find libvirt group
$ cat /etc/group | grep lib
libuuid:x:101:
libvirtd:x:113:stackuser,saju

b)
Edit  /etc/libvirt/libvirtd.conf
sudo vim /etc/libvirt/libvirtd.conf
unix_sock_group = "libvirtd"

c)
$ cat /etc/libvirt/libvirtd.conf | grep ^[^#]
unix_sock_group = "libvirtd"
unix_sock_rw_perms = "0770"
auth_unix_ro = "none"
auth_unix_rw = "none"

d)
Restart
sudo service libvirt-bin restart
 
Error
======

2014-04-18 01:24:15.803 ERROR nova.virt.libvirt.driver [-] Connection to libvirt failed: Failed to connect socket to '/var/run/libvirt/libvirt-sock'
: No such file or directory
2014-04-18 01:24:15.803 TRACE nova.virt.libvirt.driver Traceback (most recent call last):
2014-04-18 01:24:15.803 TRACE nova.virt.libvirt.driver   File "/opt/stack/nova/nova/virt/libvirt/driver.py", line 677, in _connect
2014-04-18 01:24:15.803 TRACE nova.virt.libvirt.driver     return libvirt.openAuth(uri, auth, flags)
2014-04-18 01:24:15.803 TRACE nova.virt.libvirt.driver   File "/usr/lib/python2.7/dist-packages/libvirt.py", line 102, in openAuth
2014-04-18 01:24:15.803 TRACE nova.virt.libvirt.driver     if ret is None:raise libvirtError('virConnectOpenAuth() failed')
2014-04-18 01:24:15.803 TRACE nova.virt.libvirt.driver libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory

Error
=====

2014-04-17 20:14:50.100+0000: 57679: info : libvirt version: 1.2.3
2014-04-17 20:14:50.100+0000: 57679: error : virGetGroupID:994 : invalid argument: Failed to parse group 'libvirt'
                       

SOLVED:ERROR nova.virt.libvirt.driver [-] Connection to libvirt failed: Failed to connect socket to '/var/run/libvirt/libvirt-sock' Permission denied

Fix
====
http://wiki.libvirt.org/page/Failed_to_connect_to_the_hypervisor

a)
sudo vim /etc/libvirt/libvirtd.conf

unix_sock_group = "libvirtd"
unix_sock_rw_perms = "0770"


b)
sudo service libvirt-bin restart

Error:
======
2014-04-18 01:09:15.254 ERROR nova.virt.libvirt.driver [-] Connection to libvirt failed: Failed to connect socket to '/var/run/libvirt/libvirt-sock'
: Permission denied
2014-04-18 01:09:15.254 TRACE nova.virt.libvirt.driver Traceback (most recent call last):
2014-04-18 01:09:15.254 TRACE nova.virt.libvirt.driver   File "/opt/stack/nova/nova/virt/libvirt/driver.py", line 677, in _connect
2014-04-18 01:09:15.254 TRACE nova.virt.libvirt.driver     return libvirt.openAuth(uri, auth, flags)
2014-04-18 01:09:15.254 TRACE nova.virt.libvirt.driver   File "/usr/lib/python2.7/dist-packages/libvirt.py", line 102, in openAuth
2014-04-18 01:09:15.254 TRACE nova.virt.libvirt.driver     if ret is None:raise libvirtError('virConnectOpenAuth() failed')
2014-04-18 01:09:15.254 TRACE nova.virt.libvirt.driver libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied
2014-04-18 01:09:15.254 TRACE nova.virt.libvirt.driver

SOLVED:ERROR nova.openstack.common.threadgroup [-] internal error Cannot find suitable emulator for x86_64

Error:
====
https://bugs.launchpad.net/heat/+bug/1308959/comments/3

I can see following error in nova-compute (n-cpu*) and its not running. I am using libvirtd (libvirt) 0.9.8 + Ubuntu 12,04 lts
=========================
2014-04-17 19:43:34.497 ERROR nova.openstack.common.threadgroup [-] internal error Cannot find suitable emulator for x86_64
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup Traceback (most recent call last):
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/opt/stack/nova/nova/openstack/common/threadgroup.py", line 117, in wait
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup x.wait()
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/opt/stack/nova/nova/openstack/common/threadgroup.py", line 49, in wait
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup return self.thread.wait()
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/usr/lib/python2.7/dist-packages/eventlet/greenthread.py", line 168, in wait
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup return self._exit_event.wait()
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/usr/lib/python2.7/dist-packages/eventlet/event.py", line 116, in wait
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup return hubs.get_hub().switch()
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/usr/lib/python2.7/dist-packages/eventlet/hubs/hub.py", line 187, in switch
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup return self.greenlet.switch()
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/usr/lib/python2.7/dist-packages/eventlet/greenthread.py", line 194, in main
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup result = function(*args, **kwargs)
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/opt/stack/nova/nova/openstack/common/service.py", line 65, in run_service
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup service.start()
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/opt/stack/nova/nova/service.py", line 164, in start
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup self.manager.pre_start_hook()
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/opt/stack/nova/nova/compute/manager.py", line 803, in pre_start_hook
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup self.update_available_resource(nova.context.get_admin_context())
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/opt/stack/nova/nova/compute/manager.py", line 4893, in update_available_resource
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup nodenames = set(self.driver.get_available_nodes())
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/opt/stack/nova/nova/virt/driver.py", line 963, in get_available_nodes
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup stats = self.get_host_stats(refresh=refresh)
2014-04-17 19:43:34.497 TRACE nova.openstack.common.threadgroup File "/opt/stack/nova/nova/virt/libvirt/driver.py"...

Fix: 
====
#sudo apt-get install qemu-system
 

#sudo apt-get install qemu-kvm
 

#sudo service libvirt-bin restart

===========

stackuser@mypc:~/openstack/devstack$ sudo apt-get install qemu-system
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following packages were automatically installed and are no longer required:
  sharutils librbd1 libnss3 libaio1 librados2 libboost-thread1.46.1 libnspr4
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  kvm-ipxe libasound2 libasyncns0 libbluetooth3 libbrlapi0.5 libcaca0 libfdt1 libflac8 libjson0 libogg0 libpulse0 libsdl1.2debian libsndfile1
  libvde0 libvdeplug2 libvorbis0a libvorbisenc2 qemu-common qemu-keymaps seabios vde2 vgabios
Suggested packages:
  libasound2-plugins libasound2-python pulseaudio mol-drivers-macosx openbios-sparc ubuntu-vm-builder uml-utilities samba vde2-cryptcab qemu
Recommended packages:
  qemu-kvm
The following packages will be REMOVED:
  qemu-utils
The following NEW packages will be installed:
  kvm-ipxe libasound2 libasyncns0 libbluetooth3 libbrlapi0.5 libcaca0 libfdt1 libflac8 libjson0 libogg0 libpulse0 libsdl1.2debian libsndfile1
  libvde0 libvdeplug2 libvorbis0a libvorbisenc2 qemu-common qemu-keymaps qemu-system seabios vde2 vgabios
0 upgraded, 23 newly installed, 1 to remove and 24 not upgraded.
Need to get 19.4 MB of archives.
After this operation, 60.1 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
WARNING: The following packages cannot be authenticated!
  libasound2 libasyncns0 libbluetooth3 libcaca0 libogg0 libflac8 libjson0 libvorbis0a libvorbisenc2 libsndfile1 libpulse0 libsdl1.2debian kvm-ipxe
  libvde0 libvdeplug2 seabios vgabios qemu-common qemu-keymaps libbrlapi0.5 libfdt1 qemu-system vde2
Authentication warning overridden.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libasound2 amd64 1.0.25-1ubuntu10.2 [428 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise/main libasyncns0 amd64 0.8-4 [13.2 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libbluetooth3 amd64 4.98-2ubuntu7.1 [63.3 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu/ precise/main libcaca0 amd64 0.99.beta17-2.1ubuntu2 [246 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu/ precise/main libogg0 amd64 1.2.2~dfsg-1ubuntu1 [17.2 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu/ precise/main libflac8 amd64 1.2.1-6 [144 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu/ precise/main libjson0 amd64 0.9-1ubuntu1 [16.3 kB]
Get:8 http://us.archive.ubuntu.com/ubuntu/ precise/main libvorbis0a amd64 1.3.2-1ubuntu3 [103 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu/ precise/main libvorbisenc2 amd64 1.3.2-1ubuntu3 [136 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu/ precise/main libsndfile1 amd64 1.0.25-4 [163 kB]
Get:11 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libpulse0 amd64 1:1.1-0ubuntu15.4 [289 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu/ precise/main libsdl1.2debian amd64 1.2.14-6.4ubuntu3 [197 kB]                                         
Get:13 http://us.archive.ubuntu.com/ubuntu/ precise/main kvm-ipxe all 1.0.0+git-3.55f6c88-0ubuntu1 [327 kB]                                       
Get:14 http://us.archive.ubuntu.com/ubuntu/ precise/universe libvde0 amd64 2.2.3-3build2 [28.1 kB]                                                
Get:15 http://us.archive.ubuntu.com/ubuntu/ precise/universe libvdeplug2 amd64 2.2.3-3build2 [12.4 kB]                                            
Get:16 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main seabios all 0.6.2-0ubuntu2.1 [70.5 kB]                                           
Get:17 http://us.archive.ubuntu.com/ubuntu/ precise/main vgabios all 0.6c-2ubuntu3 [164 kB]                                                       
Get:18 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main qemu-common all 1.0+noroms-0ubuntu14.13 [22.4 kB]                                
Get:19 http://us.archive.ubuntu.com/ubuntu/ precise-updates/universe qemu-keymaps all 1.0.50-2012.03-0ubuntu2.1 [19.1 kB]                         
Get:20 http://us.archive.ubuntu.com/ubuntu/ precise/main libbrlapi0.5 amd64 4.3-1ubuntu5 [24.1 kB]                                                
Get:21 http://us.archive.ubuntu.com/ubuntu/ precise/main libfdt1 amd64 1.3.0-2 [16.5 kB]                                                          
Get:22 http://us.archive.ubuntu.com/ubuntu/ precise-updates/universe qemu-system amd64 1.0.50-2012.03-0ubuntu2.1 [16.7 MB]                        
Get:23 http://us.archive.ubuntu.com/ubuntu/ precise/universe vde2 amd64 2.2.3-3build2 [220 kB]                                                    
Fetched 19.4 MB in 15s (1,280 kB/s)                                                                                                               
(Reading database ... 102732 files and directories currently installed.)
Removing qemu-utils ...
Processing triggers for man-db ...
Selecting previously unselected package libasound2.
(Reading database ... 102716 files and directories currently installed.)
Unpacking libasound2 (from .../libasound2_1.0.25-1ubuntu10.2_amd64.deb) ...
Selecting previously unselected package libasyncns0.
Unpacking libasyncns0 (from .../libasyncns0_0.8-4_amd64.deb) ...
Selecting previously unselected package libbluetooth3.
Unpacking libbluetooth3 (from .../libbluetooth3_4.98-2ubuntu7.1_amd64.deb) ...
Selecting previously unselected package libcaca0.
Unpacking libcaca0 (from .../libcaca0_0.99.beta17-2.1ubuntu2_amd64.deb) ...
Selecting previously unselected package libogg0.
Unpacking libogg0 (from .../libogg0_1.2.2~dfsg-1ubuntu1_amd64.deb) ...
Selecting previously unselected package libflac8.
Unpacking libflac8 (from .../libflac8_1.2.1-6_amd64.deb) ...
Selecting previously unselected package libjson0.
Unpacking libjson0 (from .../libjson0_0.9-1ubuntu1_amd64.deb) ...
Selecting previously unselected package libvorbis0a.
Unpacking libvorbis0a (from .../libvorbis0a_1.3.2-1ubuntu3_amd64.deb) ...
Selecting previously unselected package libvorbisenc2.
Unpacking libvorbisenc2 (from .../libvorbisenc2_1.3.2-1ubuntu3_amd64.deb) ...
Selecting previously unselected package libsndfile1.
Unpacking libsndfile1 (from .../libsndfile1_1.0.25-4_amd64.deb) ...
Selecting previously unselected package libpulse0.
Unpacking libpulse0 (from .../libpulse0_1%3a1.1-0ubuntu15.4_amd64.deb) ...
Selecting previously unselected package libsdl1.2debian.
Unpacking libsdl1.2debian (from .../libsdl1.2debian_1.2.14-6.4ubuntu3_amd64.deb) ...
Selecting previously unselected package kvm-ipxe.
Unpacking kvm-ipxe (from .../kvm-ipxe_1.0.0+git-3.55f6c88-0ubuntu1_all.deb) ...
Selecting previously unselected package libvde0.
Unpacking libvde0 (from .../libvde0_2.2.3-3build2_amd64.deb) ...
Selecting previously unselected package libvdeplug2.
Unpacking libvdeplug2 (from .../libvdeplug2_2.2.3-3build2_amd64.deb) ...
Selecting previously unselected package seabios.
Unpacking seabios (from .../seabios_0.6.2-0ubuntu2.1_all.deb) ...
Selecting previously unselected package vgabios.
Unpacking vgabios (from .../vgabios_0.6c-2ubuntu3_all.deb) ...
Selecting previously unselected package qemu-common.
Unpacking qemu-common (from .../qemu-common_1.0+noroms-0ubuntu14.13_all.deb) ...
Selecting previously unselected package qemu-keymaps.
Unpacking qemu-keymaps (from .../qemu-keymaps_1.0.50-2012.03-0ubuntu2.1_all.deb) ...
Selecting previously unselected package libbrlapi0.5.
Unpacking libbrlapi0.5 (from .../libbrlapi0.5_4.3-1ubuntu5_amd64.deb) ...
Selecting previously unselected package libfdt1.
Unpacking libfdt1 (from .../libfdt1_1.3.0-2_amd64.deb) ...
Selecting previously unselected package qemu-system.
Unpacking qemu-system (from .../qemu-system_1.0.50-2012.03-0ubuntu2.1_amd64.deb) ...
Selecting previously unselected package vde2.
Unpacking vde2 (from .../vde2_2.2.3-3build2_amd64.deb) ...
Processing triggers for man-db ...
Setting up libasound2 (1.0.25-1ubuntu10.2) ...
Setting up libasyncns0 (0.8-4) ...
Setting up libbluetooth3 (4.98-2ubuntu7.1) ...
Setting up libcaca0 (0.99.beta17-2.1ubuntu2) ...
Setting up libogg0 (1.2.2~dfsg-1ubuntu1) ...
Setting up libflac8 (1.2.1-6) ...
Setting up libjson0 (0.9-1ubuntu1) ...
Setting up libvorbis0a (1.3.2-1ubuntu3) ...
Setting up libvorbisenc2 (1.3.2-1ubuntu3) ...
Setting up libsndfile1 (1.0.25-4) ...
Setting up libpulse0 (1:1.1-0ubuntu15.4) ...
Setting up libsdl1.2debian (1.2.14-6.4ubuntu3) ...
Setting up kvm-ipxe (1.0.0+git-3.55f6c88-0ubuntu1) ...
Setting up libvde0 (2.2.3-3build2) ...
Setting up libvdeplug2 (2.2.3-3build2) ...
Setting up seabios (0.6.2-0ubuntu2.1) ...
Setting up vgabios (0.6c-2ubuntu3) ...
Setting up qemu-common (1.0+noroms-0ubuntu14.13) ...
Setting up qemu-keymaps (1.0.50-2012.03-0ubuntu2.1) ...
Setting up libbrlapi0.5 (4.3-1ubuntu5) ...
Setting up libfdt1 (1.3.0-2) ...
Setting up qemu-system (1.0.50-2012.03-0ubuntu2.1) ...
Setting up vde2 (2.2.3-3build2) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
stackuser@mypc:~/openstack/devstack$
stackuser@mypc:~/openstack/devstack$
stackuser@mypc:~/openstack/devstack$
stackuser@mypc:~/openstack/devstack$
stackuser@mypc:~/openstack/devstack$ sudo service libvirt-bin restart
libvirt-bin stop/waiting
libvirt-bin start/running, process 499
stackuser@mypc:~/openstack/devstack$
stackuser@mypc:~/openstack/devstack$
stackuser@mypc:~/openstack/devstack$ qemu-system-x86_64
The program 'qemu-system-x86_64' is currently not installed.  You can install it by typing:
sudo apt-get install qemu-kvm


stackuser@mypc:~/openstack/devstack$ sudo apt-get install qemu-kvm
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following package was automatically installed and is no longer required:
  sharutils
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  acl qemu-utils
The following NEW packages will be installed:
  acl qemu-kvm qemu-utils
0 upgraded, 3 newly installed, 0 to remove and 24 not upgraded.
Need to get 3,914 kB of archives.
After this operation, 14.3 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
WARNING: The following packages cannot be authenticated!
  acl qemu-utils qemu-kvm
Authentication warning overridden.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/main acl amd64 2.2.51-5ubuntu1 [43.2 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main qemu-utils amd64 1.0+noroms-0ubuntu14.13 [354 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main qemu-kvm amd64 1.0+noroms-0ubuntu14.13 [3,517 kB]
Fetched 3,914 kB in 5s (705 kB/s)    
Selecting previously unselected package acl.
(Reading database ... 103185 files and directories currently installed.)
Unpacking acl (from .../acl_2.2.51-5ubuntu1_amd64.deb) ...
Selecting previously unselected package qemu-utils.
Unpacking qemu-utils (from .../qemu-utils_1.0+noroms-0ubuntu14.13_amd64.deb) ...
Selecting previously unselected package qemu-kvm.
Unpacking qemu-kvm (from .../qemu-kvm_1.0+noroms-0ubuntu14.13_amd64.deb) ...
Processing triggers for man-db ...
Processing triggers for ureadahead ...
Setting up acl (2.2.51-5ubuntu1) ...
Setting up qemu-utils (1.0+noroms-0ubuntu14.13) ...
Setting up qemu-kvm (1.0+noroms-0ubuntu14.13) ...
qemu-kvm start/running
stackuser@mypc:~/openstack/devstack$
stackuser@mypc:~/openstack/devstack$
stackuser@mypc:~/openstack/devstack$ qemu-
qemu-ga                 qemu-io                 qemu-system-m68k        qemu-system-mipsel      qemu-system-sh4eb      
qemu-i386               qemu-nbd                qemu-system-microblaze  qemu-system-ppc         qemu-system-sparc      
qemu-ifdown             qemu-system-arm         qemu-system-mips        qemu-system-ppc64       qemu-system-sparc64    
qemu-ifup               qemu-system-cris        qemu-system-mips64      qemu-system-ppcemb      qemu-system-x86_64     
qemu-img                qemu-system-i386        qemu-system-mips64el    qemu-system-sh4         qemu-x86_64            

stackuser@mypc:~/openstack/devstack$
stackuser@mypc:~/openstack/devstack$

SOLVED:configure: error: libnl-devel >= 1.1 is required for macvtap support

Please Install latest libvirt, libvirt-1.2.3

1)
sudo mkdir -p /opt/libvirt
sudo chmod 00755 /opt/libvirt
sudo chown root:root /opt/libvirt

2)
sudo chmod a+w /opt/libvirt
cd /opt/libvirt
wget http://libvirt.org/sources/libvirt-1.2.3.tar.gz
tar xzvf libvirt-1.2.3.tar.gz
mv libvirt-1.2.3 libvirt
cd libvirt

3)
sudo apt-get install libdevmapper-dev
sudo apt-get install libnl-dev
sudo apt-get install libpciaccess-dev
sudo apt-get install make

4)
./configure \
    --prefix=/usr \
    --localstatedir=/var \
    --sysconfdir=/etc

5)
make -j

6)
sudo make install

7)
$ libvirtd --version
libvirtd (libvirt) 1.2.3

8)
Restart libvirt
sudo service libvirt-bin restart

9)
Ref
https://github.com/stackforge/inception/blob/master/bin/pre_install_libvirt.sh

10)
Remove
cd /opt/libvirt/libvirt
make uninstall

Thursday, April 10, 2014

How to Ubuntu Install Configure and Use tor torify

1)
What is Tor?

https://tor.eff.org/
https://tor.eff.org/about/overview.html.en
https://trac.torproject.org/projects/tor/wiki/doc/TorifyHOWTO

2)
How to install

https://www.torproject.org/docs/debian
https://tor.eff.org/docs/tor-doc-unix.html.en

a)
Find My Public IP
#curl ifconfig.me

b)
Install Tor

#sudo apt-get install tor

c)
Restart tor

#sudo /etc/init.d/tor restart

d)
Find My Public IP

#curl ifconfig.me

e)
Find My Public IP via tor
#sudo torify curl ifconfig.me

g)
How to check ?

* Open google chrome with proxy-server point to tor
#google-chrome --proxy-server="socks://127.0.0.1:9050"

* Visit following sites in google chrome and check the result
http://www.whatismyip.com/
http://www.tracemyip.org/
https://check.torproject.org/

h)
You can also try lik
e
#export http_proxy = "socks://127.0.0.1:9050"
OR
#export all_proxy = "socks://127.0.0.1:9050"


3)
FAQ

https://www.torproject.org/docs/faq.html.en
https://www.torproject.org/docs/faq.html.en#Torisdifferent

How can I tell if Tor is working, and that my connections really are anonymized?
https://www.torproject.org/docs/faq.html.en#IsItWorking

I'm supposed to "edit my torrc". What does that mean?
https://www.torproject.org/docs/faq.html.en#torrc

4)
Download Tor Browser Bundle for GNU/Linux

https://www.torproject.org/download/download-easy.html.en

How to debug Python Application with pdb breakpoint

1)
* Add following code in the application

import pdb
pdb.set_trace()


2)
* Run the application.
* Then you can see a prompt like

(Pdb)

3)
* Type "l" and Press "Enter" to see where you are

(Pdb) l



4)
* Type "p name_of_the_variable" to see the value of a variable

(Pdb) p variabl1
(Pdb) p variabl2

or
(Pdb) pp variabl3

5)
* Press "Enter" to repeate the last command

(Pdb)

6)
* Type "n" and Press "Enter" to execute next statement.
* Type "l" and Press "Enter" to see where yyou are

(Pdb) n
(Pdb) l


7)
* Type "s" and Press "Enter" to Stepping into subroutines/method/function.
* Type "r" and Press "Enter" to goto the end of the current subroutine/method
/function.
(Pdb) s
(Pdb) r


8)
* Type "c" and Press "Enter" to let the program continue running and exit from pdb.

(Pdb) c

9)
* Type "a" and Press "Enter" to Print the argument list of the current function.

(Pdb) a

10)
Very useful

* Type "w" and Press "Enter" to Print a stack trace, with the most recent frame at the bottom. An arrow indicates the current frame, which determines the context of most commands.
* You can use this with "d" and "u".

11)
* Type "d" and Press "Enter" to Move the current frame one level down in the stack trace (to a newer frame).
* You can use this with "w".

(Pdb) d

12)
* Type "u" and Press "Enter" to Move the current frame one level up in the stack trace (to an older frame).
* You can use this with "u".

(Pdb) u

13)
Set Break point on file "utils.py" and line number 66.

(Pdb) b heatclient/common/utils.py:66
Continue the execution upto the break point
(Pdb) c
(Pdb) w


or

Set Break point on first statement of a function named "print_list".
(Pdb) b utils.print_list
Continue the execution upto the break point
(Pdb) c
(Pdb) w


or


(Pdb) import heatclient
Set Break point on first statement of a class method named "json_request".
(Pdb) b heatclient.common.http.HTTPClient.json_request
Continue the execution upto the break point
(Pdb) c
(Pdb) w

https://github.com/openstack/python-heatclient/blob/master/heatclient/common/http.py

or

(Pdb) import httplib
(Pdb) b httplib.HTTPConnection.getresponse
(Pdb) c
(Pdb) w
/usr/lib/python2.7/httplib.py


14)
* "tbreak" is Temporary breakpoint, which is removed automatically when it is first hit. The arguments are the same as break.
Set Break point on file "utils.py" and line number 66.
(Pdb) tbreak heatclient/common/utils.py:66
Continue the execution upto the break point
(Pdb) c

Wednesday, April 9, 2014

How to OpenStack Command Line CLI Works Python heatclient

1)
#heat --help

2)
Find the location of heat executable.

#which heat
/usr/local/bin/heat


3)
Check the content of the executable file

#cat /usr/local/bin/heat

#!/usr/bin/python
# PBR Generated from 'console_scripts'

import sys
##
from heatclient.shell import main

if __name__ == "__main__":
    ##
    sys.exit(main())

4)
https://github.com/openstack/python-heatclient/blob/master/heatclient/shell.py

from keystoneclient.v2_0 import client as ksclient
import heatclient
from heatclient import client as heat_client
import argparse

       
def main(args=None):
    HeatShell().main(args)

class HeatShell(object):
    def main(self, argv):
        #Here value of argv will be ['list'] for the command #heat list
        ##
        subcommand_parser = self.get_subcommand_parser(api_version)
        ##
        args = subcommand_parser.parse_args(argv)
        ##Create Heatclient object (connection object)
        ##
        client = heat_client.Client(api_version, endpoint, **kwargs)
        ##Invoke command function, In this case the function "def do_list(hc, args={})" defined in the heatclient/v1/shell.py
        ##
        args.func(client, args)

    def get_base_parser(self):
        parser = argparse.ArgumentParser(---)
        return parser

    def get_subcommand_parser(self, version):
        ##
        parser = self.get_base_parser()

        self.subcommands = {}
        ##Adding sub-commands or sub-parsers to main parser
        ##http://argparse.googlecode.com/svn/trunk/doc/other-methods.html#sub-commands
        ##
        subparsers = parser.add_subparsers(metavar='')
        ##returns heatclient/v1/shell.py
        submodule = utils.import_versioned_module(version, 'shell')
        ##
        self._find_actions(subparsers, submodule)
        self._find_actions(subparsers, self)
        self._add_bash_completion_subparser(subparsers)

        return parser

    def _find_actions(self, subparsers, actions_module):
        ##
        for attr in (a for a in dir(actions_module) if a.startswith('do_')):
            # I prefer to be hyphen-separated instead of underscores.
            command = attr[3:].replace('_', '-')
            ##Get the function object (callback) from heatclient/v1/shell.py
            callback = getattr(actions_module, attr)
            desc = callback.__doc__ or ''
            help = desc.strip().split('\n')[0]
            ##The decorator "@utils.arg" will add the attribute "arguments" to each function defined in the heatclient/v1/shell.py
            arguments = getattr(callback, 'arguments', [])

            ##Add all sub-command or sub-parser to main parser one by one in a loop.
            ##subparser(sub-command): http://argparse.googlecode.com/svn/trunk/doc/other-methods.html#sub-commands
           subparser = subparsers.add_parser(command,
                                              help=help,
                                              description=desc,
                                              add_help=False,
                                              formatter_class=HelpFormatter)

            subparser.add_argument('-h', '--help',
                                   action='help',
                                   help=argparse.SUPPRESS)
            self.subcommands[command] = subparser
            for (args, kwargs) in arguments:
                subparser.add_argument(*args, **kwargs)

            ##set_defaults: http://argparse.googlecode.com/svn/trunk/doc/other-methods.html#parser-defaults
            ##Set the new attribute "func"
            subparser.set_defaults(func=callback)


5)
https://github.com/openstack/python-heatclient/blob/master/heatclient/v1/shell.py

def do_list(hc, args={}):
    ##

    do_stack_list(hc, args)

def do_stack_list(hc, args={}):    '''List the user's stacks.'''
    kwargs = {}
    ##API Call to get list of stacks
    ##
    stacks = hc.stacks.list(**kwargs)
    fields = ['id', 'stack_name', 'stack_status', 'creation_time']
    ##Format the output of API call and print it
    utils.print_list(stacks, fields, sortby=3)


6)
https://github.com/openstack/python-heatclient/blob/master/heatclient/openstack/common/cliutils.py
or
https://github.com/openstack/python-heatclient/blob/0.2.5/heatclient/common/utils.py

##Print a list or objects as a table, one row per object
def print_list(objs, fields, formatters=None, sortby_index=0, mixed_case_fields=None):

7)
Example-1:

http://argparse.googlecode.com/svn/trunk/doc/other-methods.html
http://argparse.googlecode.com/svn/trunk/doc/other-methods.html#sub-commands
http://infohost.nmt.edu/tcc/help/pubs/python/web/argparse-parse_args.html

##sub-command functions
def foo(args):
    print args.x * args.y
   
def bar(args):
    print '((%s))' % args.z

##create the top-level parser
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()

##create the parser for the "foo" command

parser_foo = subparsers.add_parser('foo')
parser_foo.add_argument('-x', type=int, default=1)
parser_foo.add_argument('y', type=float)
parser_foo.set_defaults(func=foo)

##create the parser for the "bar" command
parser_bar = subparsers.add_parser('bar')
parser_bar.add_argument('z')
parser_bar.set_defaults(func=bar)

##parse the args and call whatever function was selected
args = parser.parse_args('foo 1 -x 2'.split())
args.func(args)
2.0

##parse the args and call whatever function was selected
args = parser.parse_args('bar XYZYX'.split())
args.func(args)
((XYZYX))


8)
Stack Trace
=========
Signal recieved : entering python shell.
Traceback:
  File "/usr/local/bin/heat", line 10, in
    sys.exit(main())
  File "/opt/stack/python-heatclient/heatclient/shell.py", line 385, in main
    HeatShell().main(sys.argv[1:])
  File "/opt/stack/python-heatclient/heatclient/shell.py", line 360, in main
    args.func(client, args)
  File "/opt/stack/python-heatclient/heatclient/v1/shell.py", line 285, in do_list
    do_stack_list(hc, args)
  File "/opt/stack/python-heatclient/heatclient/v1/shell.py", line 293, in do_stack_list
    utils.print_list(stacks, fields, sortby=3)
  File "/opt/stack/python-heatclient/heatclient/common/utils.py", line 66, in print_list
    for o in objs:
  File "/opt/stack/python-heatclient/heatclient/v1/stacks.py", line 81, in paginate
    stacks = self._list(url, "stacks")
  File "/opt/stack/python-heatclient/heatclient/common/base.py", line 56, in _list
    resp, body = self.api.json_request('GET', url)
  File "/opt/stack/python-heatclient/heatclient/common/http.py", line 198, in json_request
    resp, body_str = self._http_request(url, method, **kwargs)
  File "/opt/stack/python-heatclient/heatclient/common/http.py", line 147, in _http_request
    resp = conn.getresponse()
  File "/usr/lib/python2.7/httplib.py", line 1045, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 409, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 365, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib/python2.7/socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)

Monday, April 7, 2014

How to print stack trace from a running Python application

1)
Add following code in the begining of shell.py

#sudo vim /opt/stack/python-heatclient/heatclient/shell.py

import code, traceback, signal

def debug(sig, frame):
    """Interrupt running process, and provide a python prompt for
    interactive debugging."""
    d={'_frame':frame}         # Allow access to frame object.
    d.update(frame.f_globals)  # Unless shadowed by global
    d.update(frame.f_locals)

    i = code.InteractiveConsole(d)
    message  = "Signal recieved : entering python shell.\nTraceback:\n"
    message += ''.join(traceback.format_stack(frame))
    i.interact(message)

def listen():
    signal.signal(signal.SIGUSR1, debug)  # Register handler




2)
Edit shell.py and invoke the newly added "listen" from the "main" method.
So that will get called when we run a heat command like #heat list

#sudo vim /opt/stack/python-heatclient/heatclient/shell.py

class HeatShell(object):
    def main(self, argv):
        listen()


3)
Goto devstack folder and run

#source openrc

4)
Run the heat command

#heat list

5)
Open another terminal and type following command and note the pid of CLI process.

#ps -aux | grep heat
saju     12772  0.6  1.1 119040 23072 pts/11   S+   18:57   0:00 /usr/bin/python /usr/local/bin/heat list

6)
Then open python prompt and type following command

#python
>>> import os, signal
>>> os.kill(12772, signal.SIGUSR1)


7)
Check the terminal where you run the command 

#heat list

8)
Press Ctrl + d to continue



Saturday, April 5, 2014

How to Download Modify Build and Install a Debian Source Package of Python Application

1)
Download the source and packaging script
#sudo apt-get source python-heatclient

2)
Extract the source and packaging script

3)
Modify the source ad packaging script

4)
Build the package again
#dpkg-buildpackage -b

5)
Show how to create new folder and config file like "/etc/projectname/projectconfig.conf" while installing a package. We should specify this while creating the package.

Thursday, April 3, 2014

How to Create Debian Package for Python Application

1)
Clone the project
#git clone https://github.com/sajuptpm/python-smpplib.git
#cd python-smpplib

2)
Create "debian" folder
#mkdir debian




3)
Create "debian/changelog" file
#dch --create

4)
Create an empty copyright File
#vim debian/copyright

5)
Create an empty compat File
#vim debian/compat

6)
Create an empty rules File
#vim debian/rules

7)
Create an empty rules File
#vim debian/control

8)
Try to build the package
#dpkg-buildpackage -b

9)
Edit control File and add following lines
#vim debian/control
Source: python-smpplib
Maintainer: Developer

Package: python-smpplib
Architecture: all

10)

Try to build the package
#dpkg-buildpackage -b

11)

Edit rules file and add following lines
#vim debian/rules
#!/usr/bin/make -f

%:
        dh $@ --with python2


12)

Try to build the package
#dpkg-buildpackage -b

13)

Edit compat file add add following line
#vim debian/compat
10


14)

Try to build the package
#dpkg-buildpackage -b

15)

Try to install the application from resultant debian Package
#cd ../
#dpkg -i python-smpplib_1_all.deb
#python
>>> import smpplib


16)

Remove/Uninstall the installed application
#sudo dpkg --purge python-smpplib
#python
>>> import smpplib


17)

Try Install the application using setup.py command
#sudo python setup.py install
#python
>>> import smpplib


18)

Remove/Uninstall the installed application
#sudo pip uninstall python-smpplib
#python
>>> import smpplib

How to Install Jenkins and Plugins GitHub Plugin

1)
How to Install jenkins


https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -

sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'


sudo apt-get update

sudo apt-get install jenkins

Goto
http://127.0.0.1:8080/



2)
How to Install plugins


a)
How to Install GitHub Plugin

Goto Manage Jenkins ==> Manage Plugins ==> Available ==> GitHub Plugin ==> Install Without restart