Wednesday 14 October 2015

INTEGRATING HUBOT WITH HIPCHAT


Creating Hipchat account for one admin and two users

FOR ADMIN

1. Goto www.hipchat.com

  • sign-up (Full Name, Working Email)
  • Create new team
  • Click on “No thanks, I’ll send invites later”
  • Click on Hipchat logo on top left corner
  • Group admin Users Add

The above step will add users and send invitation to their mail.

FOR USERS

2. Check your mail and join the invitation

  • Fill in details with working mail id
  • Click on Launch the web app“

3. Installing node.js and npm

4. Installing hubot yeoman generator

5. Installing the Heroku Toolbelt

6. Clone the repository

7. Configure it


$ heroku config:add HEROKU_URL=http://.herokuapp.com

Go to hipchat home page (not chat page) of one of the user or admin Accoount settings → XMPP/Jabber info

$ heroku config:add HUBOT_HIPCHAT_JID="id from above"
$ heroku config:add HUBOT_HIPCHAT_PASSWORD="password when you created account"


Logout the hipchat account which you have just registered for robot, here in this case we chose admin account for hubot.
Check on both user hipchat account that admin green bubble turned grey ;)  
8. Deploy your changes

9. Running process

AS soon as the above process run, check the hipchat user account, bot’s bubble turned to green and available.

Go to one of the room and check by texting @<your_bot_name> help, it’ll respond with some set of instructions.

[Below are some useful commands]

Stopping process
Current process state
Checking log
Restart heroku

Monday 12 October 2015

KICK START WITH JENKINS JOB BUILDER(JJB)

What is JJB?

It’s a YAML file that enable us to write jenkins job description in human readable format and store in VCS to manage versioning on them.

Who created JJB?

Openstack Infra team.

Why JJB is created?

Jobs are stored in CI server in XML format which is not best readable format to write jenkins jobs manually so they came with JJB to manage jobs at graphical interface level.


Prerequisite:

All these commands should be run on Jenkins server

$ sudo apt-get install python-yaml
$ sudo apt-get install python-dev python-pip
$ cd jenkins-job-builder
$ sudo pip install --user -e .
$ sudo python setup.py install

Configuration:

$ nano /etc/jenkins_jobs/jenkins_jobs.ini 

[job_builder]
allow_duplicates=True
[jenkins]
user=USERNAME
password=PASSWORD
url=jenkins_url(http://localhost:8080)


Test a YAML job definition:

$ jenkins-jobs test tests/yamlparser/fixtures/templates002.yaml

The above command prints the generated Jenkins XML to the console. If you prefer to send it to a directory use following command.

$ jenkins-jobs test -o output tests/yamlparser/fixtures/templates002.yaml

The output directory will contain files with the XML configurations.

Updating Jenkins Jobs:

$  jenkins-jobs --conf /etc/jenkins_jobs/jenkins_jobs.ini update

tests/yamlparser/fixtures/templates002.yaml

OR

$ jenkins-jobs update tests/yamlparser/fixtures/templates002.yaml

The above command will update your Jenkins master with the generated jobs.

Deleting a job:

$ jenkins-jobs --conf etc/jenkins_jobs.ini delete <job-name>

Reference doc:

http://docs.openstack.org/infra/jenkins-job-builder/quick-start.html


Example: my-job.yaml

 - job:
name: my-first-job-test
description: "Checking system's uptime and polling job every minute"
project-type: freestyle
block-downstream: false
triggers:
- pollscm: '*/1 * * * *'
builders:
           - shell: |
uptime
publishers:
- email:
          recipients: test@test.com


Thursday 30 July 2015

DIFFERENCE BETWEEN @STATICMETHOD AND @CLASSMETHOD IN PYTHON

@classmethod
To pass class as argument instead of instance(self). We could have achieved this by creating function out of class and passing that class as argument but that could raise mentainance problem in future. So to overcome this Python2.2 came up with @classmethod.

1) Maintainance Problem Causing Senario
def get_no_of_instance(ins_obj):
    return ins_obj.__class__.no_inst

class Test(object):
    no_inst = 0

    def __init__(self):
        Test.no_inst = Test.no_inst + 1

inst1 = Test()
inst2 = Test()

print get_no_of_instance(inst1)  # will output 2

2) Implementation using @classmethod
class Test(object):
    no_inst = 0

    def __init__(self):
        Test.no_inst = Test.no_inst +1

    @classmethod
    def get_no_of_instance(test_class):
        return test_class.no_inst

inst1 = Test()
inst2 = Test()

print inst1.get_no_of_instance() # will output 2
print Test.get_no_of_instance()  # will output 2

So calling @classmethod either by instance or by Class it'll pass the same argument to @classmethod.

@staticmethod
Sometimes we don't need instance method but the normal method, to access those methods we need to decorate them with @staticmethod. It's implementation is same as @classmethod but we don't pass class as argument to method. Without using decorator also we could have achieved this by creating function outside of class but it would have raised maintainance issue in future as code was increased.

1) Maintainance Problem Causing Senario
def checkTOF():
    return true

class Test(object):
    def __init__(self,data):
        self.data = data

    def play1(self):
        if checkTOF():
            print 'play one data is ',self.data

test = Test(10)
test.play1()   

2) Implemenatation using @staticmethod
class Test(object):
    def __init__(self,data):
        self.data = data

    @staticmethod
    def checkTOF():
        return 'true'

    def play1(self):
        if self.checkTOF():
            print 'play one data is ',self.data

test = Test(10)
test.play1()

So this way can bring all related code at one class.

DIFFERENCE BETWEEN BEHAVIOUR AND FUNCTIONALITY...

BEHAVIOUR: How should one act in general. For example Pen behaviour is writting, eraser baviour is erasing and mobile phone behaviour is taking and making call.

FUNCTIONALITY: Rather it is same as behaviour but it marely depend upon state. For example, though PEN's behaviour is writting but its depend upon ink is there or not, I mean Refill is filled-up or not. Though phone"s behaviour is taking and making call but it's state may vary like silent mode, ringing mode, etc.

Tuesday 28 July 2015

THREE NODE ARCHITECTURE

Openstack three node architecture

1) Controller
2) Compute
3) Network

Following setting is applied to Oracle VM VirtualBox Manager.

Before creating 3 nodes we need to set-up.
- Management Network
 For openstack service communication
- Tunnel Network
 For openstack VM's communication      
- External Network
 Provides internet access to the virtual machines.

Now we'll set-up these networks.

Goto File-->Preferences-->Network-->Host-only Networks
Add three interfaces and edit it.
1st interface:
IPv4 Address: 10.10.10.1
IPv4 Network Mask: 255.255.255.0

2st interface:
IPv4 Address: 10.20.20.1
IPv4 Network Mask: 255.255.255.0

3st interface:
IPv4 Address: 192.168.100.1
IPv4 Network Mask: 255.255.255.0


Controller :

Create new VM
Name: Controller
Type: Linux
Version: Ubuntu(64 bit)
-->Next
Memory size: 2048MB or more
-->Next
Select Create a virtual hard drive now
-->Next
Select VDI(Virtual Disk Image)
-->Next
Select Dynamically allocated
-->Next
File Location: browse where it is available
Size: 20GB or more


Start the same VM and select ubuntu server image and complete the installation.
While installation Choose software to install: OpenSSH server
OR
Later also you can install this if it is skipped.
   
Once you finished the installation, try to ping google.com and if it works means VM is created successfully.

The first thing need to do is update and upgrade it.
   
$sudo su
#nano /etc/hosts
comment out 127.0.0.1
introduce the following host
10.10.10.10 controller
10.10.10.11 compute
10.10.10.12 network


On the same VM
Goto Setting-->Network

Under Adapter 1:    
Check Enable Network Adapter
Attached to: Host-only Adapter
Name: et0
Under Advanced
Adapter Type: Paravirtualized Network(virtio-net)
Promiscuous Mode: Allow All

Under Adapter 2:
Check Enable Network Adapter
Attached to: NAT
Under Advanced
Adapter Type: Paravirtualized Network(virtio-net)


Now let's create two clone of this VM so we can have CONTROLLER, COMPUTE and NETWORK node.

Controller Node: -
# nano /etc/hostname
controller

# nano /etc/network/interfaces
auto eth0
iface eth0 inet static
address 10.10.10.10
netmask 255.255.255.0

auto eth1
iface eth1 inet dhcp

# restart

Compute :

Compute Node: -
Goto Setting-->Network

Under Adapter 1:    
Check Enable Network Adapter
Attached to: Host-only Adapter
Name: et0
Under Advanced
Adapter Type: Paravirtualized Network(virtio-net)
Promiscuous Mode: Allow All

Under Adapter 2:    
Check Enable Network Adapter
Attached to: Host-only Adapter
Name: et1
Under Advanced
Adapter Type: Paravirtualized Network(virtio-net)
Promiscuous Mode: Allow All

Under Adapter 3:
Check Enable Network Adapter
Attached to: NAT
Under Advanced
Adapter Type: Paravirtualized Network(virtio-net)
   
$sudo su
#nano /etc/hostname
compute

#nano /etc/network/interfaces
auto eth0
iface eth0 inet static
address 10.10.10.11
netmask 255.255.255.0
   
auto eth1
iface eth1 inet static
address 10.20.20.11
netmask 255.255.255.0

auto eth2
iface eth2 inet dhcp

# ping google.com
# ping 10.10.10.10
# restart

Network :

Network Node: -
Goto Setting-->Network

Under Adapter 1:    
Check Enable Network Adapter
Attached to: Host-only Adapter
Name: et0
Under Advanced
Adapter Type: Paravirtualized Network(virtio-net)
Promiscuous Mode: Allow All

Under Adapter 2:    
Check Enable Network Adapter
Attached to: Host-only Adapter
Name: et1
Under Advanced
Adapter Type: Paravirtualized Network(virtio-net)
Promiscuous Mode: Allow All

Under Adapter 3:    
Check Enable Network Adapter
Attached to: Host-only Adapter
Name: et2
Under Advanced
Adapter Type: Paravirtualized Network(virtio-net)
Promiscuous Mode: Allow All

Under Adapter 4:
Check Enable Network Adapter
Attached to: NAT
Under Advanced
Adapter Type: Paravirtualized Network(virtio-net)
   
$sudo su
#nano /etc/hostname
network

#nano /etc/network/interfaces
auto eth0
iface eth0 inet static
address 10.10.10.11
netmask 255.255.255.0
   
auto eth1
iface eth1 inet static
address 10.20.20.11
netmask 255.255.255.0

auto eth2
iface eth2 inet manual
up ip link set dev $IFACE up
down ip link set dev $IFACE down    

auto eth3
iface eth3 inet dhcp

#ping google.com
#ping 10.10.10.10
#ping 10.10.10.11
# restart

If nodes are set-up well then you should be able to ping among all node to each other.

At this level if all work well then openstack services are ready to install on these nodes.