lost and found ( for me ? )

Python : TCP health monitoring with socket module

Here is a TCP health monitoring script with socket module.
$ cat tcp3way.py
#!/usr/bin/env python

import sys
import socket

argvs = sys.argv
argc = len(argvs)

def client(host, port):
   try:
       s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
       port = int(argvs[2])
       s.connect((host, port))
       #print "success"
       return True
   except:
       #print "can't connect"
       return False
# close a socket
   finally:
       #print "close a socket"
       s.close()

if __name__ == "__main__":
   if argc == 3:
       result = client(argvs[1], argvs[2])
       if result == True:
           print "can connect to %s:%s" % (argvs[1], argvs[2])
       else:
           print "can not connect to %s:%s" % (argvs[1], argvs[2])
           
   else:
       print("usage python tcp3way.py IPaddress PORT")


$ python tcp3way.py 192.168.11.1 80
can connect to 192.168.11.1:80

Here is a capture data.
 1   0.000000 192.168.11.100 -> 192.168.11.1 TCP 74 53387 > 80 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=1355687 TSecr=0 WS=128
1   2   0.999319 192.168.11.100 -> 192.168.11.1 TCP 74 [TCP Retransmission] 53387 > 80 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=1355937 TSecr=0 WS=128
2   3   1.003364 192.168.11.1 -> 192.168.11.100 TCP 74 80 > 53387 [SYN, ACK] Seq=0 Ack=1 Win=5792 Len=0 MSS=1460 SACK_PERM=1 TSval=531209006 TSecr=1355937 WS=2
 4   1.003462 192.168.11.100 -> 192.168.11.1 TCP 66 53387 > 80 [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=1355938 TSecr=531209006
 5   1.003603 192.168.11.100 -> 192.168.11.1 TCP 66 53387 > 80 [FIN, ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=1355938 TSecr=531209006
 6   1.005485 192.168.11.1 -> 192.168.11.100 TCP 66 80 > 53387 [ACK] Seq=1 Ack=2 Win=5792 Len=0 TSval=531209007 TSecr=1355938
 7   1.183689 192.168.11.1 -> 192.168.11.100 TCP 66 80 > 53387 [FIN, ACK] Seq=1 Ack=2 Win=5792 Len=0 TSval=531209039 TSecr=1355938
 8   1.183760 192.168.11.100 -> 192.168.11.1 TCP 66 53387 > 80 [ACK] Seq=2 Ack=2 Win=29312 Len=0 TSval=1355983 TSecr=531209039


$ python tcp3way.py 192.168.11.1 8080
can not connect to 192.168.11.1:8080

capture data
 1   0.000000 192.168.11.100 -> 192.168.11.1 TCP 74 58051 > 8080 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=1370632 TSecr=0 WS=128
 2   0.004244 192.168.11.1 -> 192.168.11.100 TCP 54 8080 > 58051 [RST, ACK] Seq=1 Ack=1 Win=0 Len=0

Install OpenStack Juno on Virtualbox

Here are logs when installing OpenStack Juno on Virtualbox.

Reference
http://openstack-cloud-mylearning.blogspot.jp/2015/02/openstack-juno-devstack-installation.html

Many thanks! I just followed this instruction.

Host OS : Ubuntu 14.04 ( virtualbox )
Guest OS : Ubuntu 14.04 <- I installed Juno within this VM.

Guest OS : vCUP*2, Memory 8GB, vHDD 50GB, vNIC * 1

on the VM.
hattori@ubuntu:~$ sudo apt-get install git -y

hattori@ubuntu:~$ git clone -b stable/juno https://git.openstack.org/openstack-dev/devstack

hattori@ubuntu:~$ cd devstack/

create a local.conf
hattori@ubuntu:~/devstack$ vi local.conf

hattori@ubuntu:~/devstack$ cat local.conf

cal|localrc]]
ADMIN_PASSWORD=stack
SERVICE_TOKEN=$ADMIN_PASSWORD
MYSQL_PASSWORD=$ADMIN_PASSWORD
RABBIT_PASSWORD=$ADMIN_PASSWORD
SERVICE_PASSWORD=$ADMIN_PASSWORD

# Branch
GLANCE_BRANCH=stable/juno
HORIZON_BRANCH=stable/juno
KEYSTONE_BRANCH=stable/juno
NOVA_BRANCH=stable/juno
NEUTRON_BRANCH=stable/juno
HEAT_BRANCH=stable/juno
CEILOMETER_BRANCH=stable/juno
TROVE_BRANCH=stable/juno

# Services
ENABLED_SERVICES=rabbit,mysql,key
ENABLED_SERVICES+=,n-api,n-crt,n-obj,n-cpu,n-cond,n-sch,n-novnc,n-cauth
ENABLED_SERVICES+=,s-proxy,s-object,s-container,s-account
ENABLED_SERVICES+=,g-api,g-reg
ENABLED_SERVICES+=,cinder,c-api,c-vol,c-sch,c-bak
ENABLED_SERVICES+=,trove,tr-api,tr-tmgr,tr-cond
ENABLED_SERVICES+=,horizon

# Ceilometer
ENABLED_SERVICES+=,ceilometer-acompute,ceilometer-acentral,ceilometer-collector,ceilometer-api
ENABLED_SERVICES+=,ceilometer-alarm-notify,ceilometer-alarm-eval

# Heat
ENABLED_SERVICES+=,heat,h-api,h-api-cfn,h-api-cw,h-eng

# Neutron
DISABLED_SERVICES=n-net
ENABLED_SERVICES+=,q-svc,q-agt,q-dhcp,q-l3,q-meta,q-metering,neutron

# Neutron - Load Balancing
ENABLED_SERVICES+=,q-lbaas

# VLAN configuration
Q_PLUGIN=ml2
ENABLE_TENANT_VLANS=True

# GRE tunnel configuration
Q_PLUGIN=ml2
ENABLE_TENANT_TUNNELS=True
Q_ML2_TENANT_NETWORK_TYPE=gre

# Logging
LOGFILE=$DEST/logs/stack.sh.log
SCREEN_LOGDIR=$DEST/logs/screen
LOGDAYS=2

# Swift
SWIFT_HASH=66a3d6b56c1f479c8b4e70ab5c2000f5
SWIFT_REPLICAS=1
SWIFT_DATA_DIR=$DEST/data

# Tempest
enable_service tempest
hattori@ubuntu:~/devstack$

There is a sample local.conf under sample directory.
hattori@ubuntu:~/devstack$ ls samples/
local.conf  local.sh

install openstack by using “stack.sh”
hattori@ubuntu:~/devstack$ pwd
/home/hattori/devstack

hattori@ubuntu:~/devstack$
hattori@ubuntu:~/devstack$ ./stack.sh




Horizon is now available at http://10.0.2.15/
Keystone is serving at http://10.0.2.15:5000/v2.0/
Examples on using novaclient command line is in exercise.sh
The default users are: admin and demo
The password: 3f03ff9ca5e9840bb1ad
This is your host ip: 10.0.2.15
2015-06-11 16:46:07.186 | stack.sh completed in 1522 seconds.


configure port forwarding on virtualbox so that we can access to the horizon from the host OS.
on virtualbox,

VM -> Setting -> Network -> Adapter 1 -> Port forward


access to the Horizon. ( http://127.0.0.1:8080 )
login as user ‘demo’


Instances -> Launch Instance


now one instance is running.


hattori@ubuntu:~/devstack$ sudo virsh list --all
Id    Name                           State
----------------------------------------------------
2     instance-00000001              running

access to the VM.
Actions -> Console

“Click here to show only console”
You will not access to the VM, because this tries to access to the VM over TCP 6080, but this is not allowed.


configure port forward on virtualbox.




“Click here to show console” as a new tab and change an IP address to 127.0.0.1:6080

I can’t enter double colon ( : ) via console...

run multiple VMs with vagrant


$ vagrant --version
Vagrant 1.7.2

$ tail -1 /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS"


initialize a project.
$ vagrant box list
trusty64 (libvirt, 0)
trusty64 (virtualbox, 0)

$ vagrant init trusty64


edit Vagrantfile
$ cat Vagrantfile
Vagrant.configure(2) do |config|

 config.vm.define "server01" do |server01|
   server01.vm.box = "trusty64"
 end

 config.vm.define "server02" do |server02|
   server02.vm.box = "trusty64"
 end

end


run VMs
I have used libvirt as its provider.
$ vagrant up server01 --provider=libvirt

$ vagrant up server02 --provider=libvirt

$ virsh list --all
Id    Name                           State
----------------------------------------------------
2     Vagrant_works_server01             running
3     Vagrant_works_server02             running

$ vagrant status
Current machine states:

server01                  running (libvirt)
server02                  running (libvirt)


access to the VMs
$ vagrant ssh server01

$ vagrant ssh server02

Ubuntu 14.04 : install the latest version of vagrant and use vagrant-libvirt plugin for libvirtd

Here are logs when installing the latest version of vagrant and use libvirtd as its hypervisor.

Reference
https://github.com/pradels/vagrant-libvirt

[ libvirtd ]

edit libvirtd.conf so that users belong to a group ‘libvirtd’ can use vagrant-libvirt.

# egrep '^unix_sock|^auth_unix' /etc/libvirt/libvirtd.conf
unix_sock_group = "libvirtd"
unix_sock_ro_perms = "0777"
unix_sock_rw_perms = "0770"
auth_unix_ro = "none"
auth_unix_rw = "none"

# groupadd -G libvirtd -a foo01

[ install vagrant ]

install the latest version, because vagrant shipped with Ubuntu(apt-get) t is a little bit old and vagrant <= 1.4 does not support vagrant-libvirt.

$ sudo apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev libvirt-dev

$ sudo dpkg -i vagrant_1.7.2_x86_64.deb

$ vagrant -v
Vagrant 1.7.2

$ vagrant plugin install vagrant-libvirt
Installing the 'vagrant-libvirt' plugin. This can take a few minutes...
Installed the plugin 'vagrant-libvirt (0.0.29)'!

$ vagrant plugin install vagrant-mutate
Installing the 'vagrant-mutate' plugin. This can take a few minutes...
Installed the plugin 'vagrant-mutate (1.0.0)'!

$ vagrant box add trusty64 https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box
==> box: Adding box 'trusty64' (v0) for provider:
   box: Downloading: https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box
==> box: Successfully added box 'trusty64' (v0) for 'virtualbox'!

$ vagrant box list
trusty64 (virtualbox, 0)

convert
$ vagrant mutate trusty64 libvirt
Converting trusty64 from virtualbox to libvirt.
   (100.00/100%)
The box trusty64 (libvirt) is now ready to use.

$ vagrant box list
trusty64 (libvirt, 0)
trusty64 (virtualbox, 0)

initialize the project.
$ vagrant init trusty64

$ grep -v '#' Vagrantfile  | grep -v ^$
Vagrant.configure(2) do |config|
 config.vm.box = "trusty64"
end

start the VM.
$ vagrant up --provider=libvirt
Bringing machine 'default' up with 'libvirt' provider...
==> default: Uploading base box image as volume into libvirt storage...
==> default: Creating image (snapshot of base box volume).
==> default: Creating domain with the following settings...

access to the VM.
$ vagrant ssh
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-53-generic x86_64)