Tuesday, December 20, 2016

Serial console on VMWare
Introduction:  We reviewed the DELL Serial Console Option. This document is about the serial console for VMWare Virtual Machines.
Architecture:
The VMWare community suggests using the virtual serial port concentrator. The concentrator also called the proxy has internal connections to several virtual machines in a datacenter and an external connection to a remote system.

The virtual serial port concentrator can be deployed as a virtual appliance involving a single virtual machine. This appliance uses the virtual machine ip address that persists across vMotion events. The Proxy accepts telnet connections from virtual machine and supports the VMWare telnet extension commands and corresponding notifications in addition to forwarding traffic both ways. The proxy serves as a point of authentication on a remote system. Since the telnet connections are internal, they need not be secured. Even a Moxa device server uses telnet console.
A virtual serial port provides out of band access to the virtual machine so that even if we lose network connectivity, we can use the serial console to interact with the machine. When this serial console is available over IP, you can remotely manage a machine even when there is a fault in the OS or the hardware of a machine.
Steps to take on the Proxy:
1.       Start the vspc.py using  - - server option
2.       Configure the vspc.py to start automatically at boot
3.       Edit the local firewall rules on the virtual serial port concentrator to permit 13370/tcp, 13371/tcp and a range of ports for target virtual machines starting at any high value say 63000
Steps to take on each VM
1.       Power off VM
2.       Add a serial port to the VM with the following settings:
On the Hardware tab, click Add.
In the Add Hardware wizard, select Serial Port.
Select where the virtual serial port sends output. It should be one of the following:
Use a physical parallel port
Use output file
Connect to named pipe
Connect via network
Choose the last option
And specify use virtual serial port concentrator and type the vSPC URI as telnet://vspc.local.lan:13370
If we don’t want to use a vSPC and provide a dedicated serial port, We can also use xcat/socat/netcat etc. Refer VMWare how to for virtual serial port configuration
select this end is the server from the first drop-down menu and select
the other end is an application from the second drop-down menu.
To connect the port to the virtual machine when the virtual machine powers on, select Connect at power on.
Click Finish to add the virtual serial port to the virtual machine.
On the Hardware tab, select the new serial port, select Yield CPU on poll, and click OK.
3.       Start the virtual machine
To query the virtual serial port connections opened on the proxy, run, from any machine including laptop with connectivity to the proxy, the following command:
./vSPC.py vspc. local.lan
machine1:500aedefafeae42434-b534dade2eawa5q3:63002
machine2:90834124ewdafwe-aw243123ewdeawdea:63003
etc.
To connect to the serial console, let’s use the corresponding port
telnet vspc.example.com 63002

Caveat : This information is provided as-is by collection from literature. 
Courtesy : VMWare vsphere web services SDK
To view consoles in public cloud refer http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-console.html
#codingexercise
Tell whether a matrix containing 0s and 1s can be divided into 2 sub matrices containing equal number of 1s.
Matrices can be split into two only by vertical or horizontal partitions. We can enumerate all partitions and check

bool HasEqual1and0(int[,] A, int r0, int rn, int c0, int cn)
{
int count = CountOnes(A, r0, rn, c0,cn);
for (int i = r0+1; i <= rn-1; i++)
{
int count1 =  CountOnes(A, r0, i, c0,cn);
int count2 =  CountOnes(A,i+1, rn, c0, cn);
assert(count1+count2 == count);
if (count1 == count2) return true;
}
for (int j = co+1; j<=cn-1;j++)
{
int count1 =  CountOnes(A, r0, rn, c0, j);
int count2 =  CountOnes(A, r0, rn, j+1, cn-1);
assert(count1 + count2 == count);
if (count1 == count2) return true;
}
return false;
}

int CountOnes(int[,] A, int r0, int rn, int c0, int cn)
{
int count = 0;
for (int i = r0; i <= rn; i++)
for (int j = co; j<=cn;j++)
      if (A[i,j] == 1) count++;
return count;
}

Find the largest sub matrix rectangle of 1's in the above matrix:
we  create a histogram and find the maximum area under the histogram
int maxRectange(int[,] A, int R, int C)
{
int result = GetMaxFromHistogram(A[0]); // this is the area of the first row
for (int i = 1; i < R; i++)
{
   for (int j = 0; j < C; j++)
         if (A[i, j] ) A[i, j] += A[i-1, j]
  result = max(result, GetMaxFromHistogram(A[i]));
}
 return result;
}
MaxAreaOfARectangle implemented GetMaxFromHistogram earlier

alternatively the max area of submatrix of 1s can also be found by treating each cell as the top left corner of the rectangle.

No comments:

Post a Comment