Monday, July 14, 2014

collobrate with Cloud9 IDE ( now i know why they say "am on cloud 9")

Note sure if u have mentioned it earlier..but i am a visual person.
I have gotten myself to use vim with its basics (delete copy past navigate search) ..but i will dislike it!
I love IDEs .. except that I H8 them when they are slow but i would still take and IDE over vim unless its just painfully unworkable slow .. i push it to its limits!

BTW
I have used slick edit ...nice when its now slow
I tried bit of Eclipse.. fine
I tried RubyMine for ruby ...fine
I tried Pycharm for python...good!


and now imagine if you have to collaborate with somebody..not sure what they are comfortable in.
want to watch them /work with them .. in your or their comfortable setting!

your solution is cloud9

check it out!  it is literally code anywhere anytime with anyone!
 no learning curve at all ..almost!

great tool for conducting interviews too!

https://c9.io/


Friday, July 11, 2014

simple way to add supervisor to your project



Add a supersvisord.conf 
and start it or callit from vagrant like this:-

sudo supervisord -c /vagrant/scripts/supervisord.conf

if you get an error like "locked "
try
sudo unlink /tmp/supervisor.sock
and kill
ps -ef | grep supervisord





sample supervisord.conf
 [unix_http_server]
file=/tmp/supervisor.sock

[supervisord]
logfile = /tmp/supervisord.log
pidfile = /tmp/supervisord.pid
directory = /tmp
identifier = supervisor


[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl = unix:///tmp/supervisor.sock

[program:name]
command = python /vagrant/nameof the application
redirect_stderr=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/%(program_name).out.log
priority=1




you can user supervisorctl to check the status of your programms
sudo supervisorctl -c /vagrant/scripts/supervisord.conf


more info :-
http://supervisord.org/

simple way to add vagrant to your project

Here is a simple vagrant  file ( not too fancy) to get you going.

This will basically get your virtual machine up  :-

VagrantFile


VAGRANTFILE_API_VERSION = "2"

Vagrant.configure("2") do |config|
    # Ubuntu 12.04, 64 bit
    config.vm.box = "precise64"
    config.vm.box_url = "http://files.vagrantup.com/precise64.box"

    #http://127.0.0.1:1234
    config.vm.network :forwarded_port, guest: 80, host: 1234

    # Set virtual machine size
    config.vm.provider :virtualbox do |vbox|
        vbox.customize ["modifyvm", :id, "--memory", 1024,"--cpus", "2", "--natdnshostresolver1", "on", "--natdnsproxy1", "on"]
    end

    config.ssh.forward_agent = true

    config.vm.define 'whatevernameyourprefer' do |whatevernameyourprefer_config|
        buzz_config.vm.host_name = 'whatevernameyourprefer'
    end

    config.vm.provision :shell do |shell|
        shell.path = "install_scriptyouhavetomake.sh"
    end
end





now go ahead and write whatever you want to be done on the vm after its up in yout install_script (like stand up your application):-
install_scriptyouhavetomake.sh

 #!/bin/sh
cd /vagrant

sudo apt-get update
sudo apt-get -y install rabbitmq-server python-pip python-dev build-essential git sshpass
#curl pythonbrew vim
rabbitmq-server start
rabbitmqctl start_app
rabbitmqctl status

sudo pip install --upgrade pip virtualenv



simple way to add logging to your python project

#import the relevant module 
import logging
#you can give you specific name or use the module name
logger = logging.getLogger(__name__)
#if you see duplicate logs .. this should solve the problem for you
#duplicate logs are because there is some other logger catching your logs too
logger.propagate = False
# again multiple handlers can lead to duplicate logs .. so  check before adding new handler

if not logger.handlers:
    #suit yourself and specify whatever format you want easily
    frmt = logging.Formatter('%(asctime)s  %(name)s  %(levelname)s  %(message)s')
    #console
    hdlr = logging.StreamHandler()
    hdlr.setFormatter(frmt)
    logger.addHandler(hdlr)
    #you decide what level of info you want info/dbg/criticla/warn
    logger.setLevel(logging.DEBUG)






now you are ready to publish logs .. sample :-

def test_a(logger):
    logger.debug("debug")
    logger.info("info")
    logger.warning("warning")
    logger.error("error")





for more info refer


https://docs.python.org/2/library/logging.html

Friday, June 27, 2014

openstack:My first bug (nova)

choose a bug from launchpad and


  •  login as non root(njain) to your devstack vm
  •  cd /home/njain/projects/devstack 
  •  source openrc admin admin 
  • ./rejoin-stack.sh
  • Test a command ( nova aggregate-list)
  • if things don't work try ./unstack.sh ./stack.sh 
  • if you get : Policy doesn't allow  then make sure you source openrc admin admin no as demo
  • CTRL A D will exit from screen 
  • CTRL A 5 will take you to nova api server
  • work on your code test it and write text cases
  •  git config --list (git config --global --add gitreview.username "neetu")
  • git remote update
  • git chekout -b "new"
  • git review -s
  •  ./run_tests.sh
  • git commit -m ""    
  • if you want to revert ..git  checkout HEAD filename
  • if you want to go back  git rebase -i UUID
  • git commit --ammend
  • git review
  • checkout your changesin launchpad and assign  reviewers if you know any
In devstack, logs of openstack services are attached with linux screens. you can find them by running following command
screen -x stack
you can traverse forward through screens by pressing CTRL a n and backwards with CTRL a p
to restart a particular service, go to the relevant screen, press CTRL c (it will kill the process) and rerun the last command ( press up Arrow then Enter )

Tuesday, June 24, 2014

vagrant ..virtualbox and variety!

I recently got an opportunity to explore vagrant!
Its really cool .. (specially when you don't want users to know about the zillion steps+tools needed before your project is all set to run :))

check it out here :-
http://www.vagrantup.com/

For windows it was not much trouble .. just download the installation package and restart and voila!

But on Ubuntu i ran into some issues vagrant virtualbox versions e.t.c



Number of links on net did not work for me.
Finally this is what worked for me.

sudo apt-get purge --auto-remove vagrant
sudo apt-get purge --auto-remove virtulabox
sudo apt-get install dpkg-dev virtualbox-dkms
if you see
WARNING: The character device /dev/vboxdrv does not exist. then do 
sudo dpkg-reconfigure virtualbox-dkms

sudo dpkg-reconfigure virtualbox

 if needed 


dpkg -l | grep virtualbox
wget http://files.vagrantup.com/packages/a40522f5fabccb9ddabad03d836e120ff5d14093/vagrant_1.3.5_x86_64.deb

dpkg -i vagrant_1.3.5_x86_64.deb
sudo apt-get install linux-headers-$(uname -r)

 
if you already have some vagrant installed remove it as said above since it will conflict if you did remove it and you see seomthing like
-is-not-co-installable-with-errors  on-ubuntu
 is not co-installable with vagrant:i386 1.2.4
sudo dpkg -r vagrant:i386 1.2.4

dpkg -i vagrant_1.3.5_x86_64.deb
 


...hopefully now you are all set to run "vagrant up"  where your Vagrantfile is . 

If you face this :- 
 the machine is already locked by a session  then kill the process

ps ax | grep -i virtualbox
 
  or 
 
VBoxManage controlvm "vagrant_buzz_1403293185" poweroff
 
  
of If you have a vm that you want to start

vboxmanage startvm "vagrant_buzz_1403293185" --type headless

if not headless then :- 
vboxmanage startvm "vagrant_buzz_1403293185" 


to see what vms are present

vboxmanage list vms


If you want to see the details or vagrant up then do
VAGRANT_LOG=DEBUG vagrant up
 
If you want to seewhats going on in the vm
 vagrant ssh




BTW

Could not find Git in your PATH environment


if you see error related to not seeing git in your path then this might solve it   :-
 set PATH=%PATH%;C:\Program Files (x86)\Git\bin



to remove trace of the vm you ever setup just do
 vagrant destroy









Thursday, June 5, 2014

get git

From vcs to svn to git ..

I am thinking of blogging about my git discoveries also ..( more for my personal documentation like all my posts) :)


here is a quick cheat sheet i created for myself


svn info -> git remote show origin
svn co  -> git clone
svn commit  -> git commit ; git push
svn update . -> git pull
     
git revert 
revert changes

git remote -v
show the remote hooks ( should be a link to the global repo and then to your repo)

git pull --rebase upstream master

git me the latest code from master of the upstream(usually the link you cloned)

git fech upstream
 =>svn update from master ( provided upstream is master branch)

Once you've set an upstream, you can run
git pull upstream master
  to pull changes on SoftLayer's
 master into your local repo. Then you use
git push origin
to push them up to your GitHub fork.

https://help.github.com/articles/fork-a-repo  
 for ex:-
when you start a project this is what you do
1. fork
  654  git clone https://github.com/user/jumpgate.git
  655  cd jumpgate/
  656  git remote add upstream git@github.com:softlayer/jumpgate.git
  657  git fetch upstream
  658  history
  659  git remote -v




to go back

git rebase --soft HEAD~1
git commit -a


or
git add.
git commit --amend
 and give the chang-id as footer