1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

(Much) better handling of hypervisor connections.

Fied minor TM configuration bug

git-svn-id: http://svn.opennebula.org/one/trunk@697 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Constantino Vázquez Blanco 2009-07-16 14:52:19 +00:00
parent 9996625bf4
commit bc3bbebd3d
6 changed files with 249 additions and 89 deletions

View File

@ -34,6 +34,10 @@ import java.rmi.RemoteException;
public class GetProperty
{
String[] args;
String entity;
String entityName;
// Helpers from VI samples
private static ServiceContent content;
private static AppUtil cb = null;
@ -261,19 +265,41 @@ public class GetProperty
{
return measure;
}
GetProperty(String[] args, String entity, String entityName) throws Exception
public boolean connect()
{
cb = AppUtil.initialize("GetProperty", null, args);
cb.connect();
try
{
cb = AppUtil.initialize("GetProperty", null, args);
cb.connect();
moRef = cb.getServiceUtil().getDecendentMoRef(null,entity,
entityName);
moRef = cb.getServiceUtil().getDecendentMoRef(null,entity,
entityName);
com.vmware.apputils.vim.ServiceConnection sc = cb.getConnection();
content = sc.getServiceContent();
service = sc.getService();
return true;
}
catch(Exception e)
{
return false;
}
}
com.vmware.apputils.vim.ServiceConnection sc = cb.getConnection();
content = sc.getServiceContent();
service = sc.getService();
public void disconnect()
{
try
{
cb.disConnect();
}
catch(Exception e){}
}
GetProperty(String[] arguments, String _entity, String _entityName)
{
args = arguments;
entity = _entity;
entityName = _entityName;
}
}

View File

@ -132,19 +132,25 @@ class OneImVmware extends Thread
boolean rf;
String response = "HYPERVISOR=vmware";
String[] argsWithHost = new String[arguments.length+2];
for(int i=0;i<arguments.length;i++)
{
argsWithHost[i] = arguments[i];
}
argsWithHost[arguments.length] = "--url";
argsWithHost[arguments.length + 1 ] = "https://" + hostToMonitor + ":443/sdk";
gP = new GetProperty(argsWithHost, "HostSystem", hostToMonitor);
try
{
String[] argsWithHost = new String[arguments.length+2];
for(int i=0;i<arguments.length;i++)
{
argsWithHost[i] = arguments[i];
}
argsWithHost[arguments.length] = "--url";
argsWithHost[arguments.length + 1 ] = "https://" + hostToMonitor + ":443/sdk";
gP = new GetProperty(argsWithHost, "HostSystem", hostToMonitor);
if(!gP.connect())
{
throw new Exception("Connection to host " + hostToMonitor + " failed.");
}
// Now it's time to build the response gathering the properties needed
@ -204,9 +210,12 @@ class OneImVmware extends Thread
// Send the actual response
System.err.println("MONITOR SUCCESS " + hid_str + " " + response);
gP.disconnect();
}
catch(Exception e)
{
gP.disconnect();
System.out.println("Failed monitoring host " + hostToMonitor);
if(debug)
{

View File

@ -2,5 +2,5 @@ CLONE = vmware/tm_clone.sh
LN = dummy/tm_dummy.sh
MKSWAP = dummy/tm_dummy.sh
MKIMAGE = dummy/tm_dummy.sh
DELETE = dummy/tm_delete.sh
DELETE = vmware/tm_delete.sh
MV = dummy/tm_dummy.sh

View File

@ -34,6 +34,9 @@ import java.rmi.RemoteException;
public class DeployVM
{
String[] args;
String hostName;
// Helpers from VI samples
private static ServiceContent content;
static AppUtil cb = null;
@ -43,7 +46,9 @@ public class DeployVM
private String datastoreName = "";
private String vmName = "";
private String vmDiskName = "";
private String vid = "";
ParseXML pXML;
// VM configuration objects
@ -112,7 +117,7 @@ public class DeployVM
if(hostFound)
{
String vmxPath = "[" + getDataStoreName() + "]"+getDiskName()+"/"+getDiskName()+".vmx";
String vmxPath = "[" + getDataStoreName() + "]one-"+getID()+"/one-"+getID()+".vmx";
// Resource Pool
ManagedObjectReference resourcePool
= cb.getServiceUtil().getFirstDecendentMoRef(null, "ResourcePool");
@ -178,7 +183,16 @@ public class DeployVM
{
return datastoreName;
}
/**
* Gets the vid
* @returns vid
*/
private String getID()
{
return vid;
}
public boolean shapeVM() throws Exception
{
@ -300,70 +314,84 @@ public class DeployVM
}
vmConfigSpec.setDeviceChange(nicSpecArray);
}
}
DeployVM(String[] args, String hostName, String vid, ParseXML _pXML, String _datastore, String _datacenter) throws Exception
{
String[] argsWithHost = new String[args.length+2];
for(int i=0;i<args.length;i++)
public boolean connect()
{
try
{
argsWithHost[i] = args[i];
cb = AppUtil.initialize("DeployVM", null, args);
cb.connect();
// Get reference to host
hostMor = cb.getServiceUtil().getDecendentMoRef(null,"HostSystem",
hostName);
com.vmware.apputils.vim.ServiceConnection sc = cb.getConnection();
content = sc.getServiceContent();
service = sc.getService();
return true;
}
catch(Exception e)
{
return false;
}
}
public void disconnect()
{
try
{
cb.disConnect();
}
catch(Exception e){}
}
DeployVM(String[] arguments, String _hostName, String _vid, ParseXML _pXML, String _datastore, String _datacenter) throws Exception
{
args = new String[arguments.length+2];
for(int i=0;i<arguments.length;i++)
{
args[i] = arguments[i];
}
argsWithHost[args.length] = "--url";
argsWithHost[args.length + 1 ] = "https://" + hostName + ":443/sdk";
args[arguments.length] = "--url";
args[arguments.length + 1 ] = "https://" + _hostName + ":443/sdk";
cb = AppUtil.initialize("DeployVM", null, argsWithHost);
cb.connect();
datastoreName = _datastore;
datacenterName = _datacenter;
vmName = _pXML.getName() + "-" + vid;
vmName = _pXML.getName() + "-" + _vid;
vmDiskName = _pXML.getName();
pXML = _pXML;
// Get reference to host
hostMor = cb.getServiceUtil().getDecendentMoRef(null,"HostSystem",
hostName);
com.vmware.apputils.vim.ServiceConnection sc = cb.getConnection();
content = sc.getServiceContent();
service = sc.getService();
vid = _vid;
hostName = _hostName;
}
DeployVM(String[] args, String hostName, String _vmName, String _datastore, String _datacenter) throws Exception
DeployVM(String[] arguments, String _hostName, String _vmName, String _vid, String _datastore, String _datacenter) throws Exception
{
String[] argsWithHost = new String[args.length+2];
args = new String[arguments.length+2];
for(int i=0;i<args.length;i++)
for(int i=0;i<arguments.length;i++)
{
argsWithHost[i] = args[i];
args[i] = arguments[i];
}
argsWithHost[args.length] = "--url";
argsWithHost[args.length + 1 ] = "https://" + hostName + ":443/sdk";
args[arguments.length] = "--url";
args[arguments.length + 1 ] = "https://" + _hostName + ":443/sdk";
cb = AppUtil.initialize("DeployVM", null, argsWithHost);
cb.connect();
datastoreName = _datastore;
datacenterName = _datacenter;
vmName = _vmName;
vmDiskName = _vmName.substring(0,_vmName.lastIndexOf("-"));
vid = _vid;
// Get reference to host
hostMor = cb.getServiceUtil().getDecendentMoRef(null,"HostSystem",
hostName);
com.vmware.apputils.vim.ServiceConnection sc = cb.getConnection();
content = sc.getServiceContent();
service = sc.getService();
hostName = _hostName;
}
/*

View File

@ -59,7 +59,6 @@ class OneVmmVmware extends Thread
OneVmmVmware(String[] args, boolean _debug)
{
debug = _debug;
arguments = args;
}
@ -146,6 +145,11 @@ class OneVmmVmware extends Thread
System.getProperty("datastore"),
System.getProperty("datacenter"));
if(!dVM.connect())
{
throw new Exception("DeployVM: Failed connection to host " + hostName);
}
if(!dVM.registerVirtualMachine())
{
// We will skip this error, it may be pre-registered
@ -167,12 +171,21 @@ class OneVmmVmware extends Thread
throw new Exception("Error reconfiguring VM (" + pXML.getName() + ").");
}
dVM.disconnect();
try
{
oVM = new OperationsOverVM(arguments,hostName);
if(!oVM.connect())
{
throw new Exception("Failed connection to host " + hostName);
}
}
catch(Exception e)
{
oVM.disconnect();
synchronized (System.err)
{
System.err.println(action + " FAILURE " + vid_str + " Failed connection to host " +
@ -186,11 +199,13 @@ class OneVmmVmware extends Thread
// Will try and deregister VM
try
{
oVM = new OperationsOverVM(arguments,hostName);
String vmName = pXML.getName() + "-" + vid_str;
oVM.deregisterVM(vmName);
}
catch(Exception e){}
catch(Exception e)
{
oVM.disconnect();
}
throw new Exception("Error powering on VM(" + pXML.getName() + ").");
}
@ -198,6 +213,8 @@ class OneVmmVmware extends Thread
{
System.err.println("DEPLOY SUCCESS " + vid_str + " " + pXML.getName() + "-" + vid_str);
}
oVM.disconnect();
continue;
@ -244,6 +261,10 @@ class OneVmmVmware extends Thread
try
{
oVM = new OperationsOverVM(arguments,hostName);
if(!oVM.connect())
{
throw new Exception("Failed connection to host " + hostName);
}
}
catch(Exception e)
{
@ -252,6 +273,7 @@ class OneVmmVmware extends Thread
System.err.println(action + " FAILURE " + vid_str + " Failed connection to host " +
hostName +". Reason: " + e.getMessage());
}
oVM.disconnect();
continue;
}
@ -262,6 +284,8 @@ class OneVmmVmware extends Thread
System.err.println(action + " FAILURE " + vid_str + " Failed shutdown VM in host " +
hostName);
}
oVM.disconnect();
continue;
}
if(!oVM.deregisterVM(vmName))
@ -271,6 +295,7 @@ class OneVmmVmware extends Thread
System.err.println(action + " FAILURE " + vid_str + " Failed deregistering of " +vmName
+ " in host " + hostName +".");
}
oVM.disconnect();
continue;
}
else
@ -281,7 +306,7 @@ class OneVmmVmware extends Thread
}
}
}
oVM.disconnect();
continue;
} // if (action.equals("SHUTDOWN or CANCEL"))
@ -308,6 +333,10 @@ class OneVmmVmware extends Thread
try
{
oVM = new OperationsOverVM(arguments,hostName);
if(!oVM.connect())
{
throw new Exception("Failed connection to host " + hostName);
}
}
catch(Exception e)
{
@ -316,6 +345,7 @@ class OneVmmVmware extends Thread
System.err.println(action + " FAILURE " + vid_str + " Failed connection to host " +
hostName +". Reason: " + e.getMessage());
}
oVM.disconnect();
continue;
}
@ -326,6 +356,7 @@ class OneVmmVmware extends Thread
System.err.println(action + " FAILURE " + vid_str + " Failed suspending VM in host " +
hostName);
}
oVM.disconnect();
continue;
}
@ -336,6 +367,7 @@ class OneVmmVmware extends Thread
System.err.println(action + " FAILURE " + vid_str + " Failed deregistering of " +vmName
+ " in host " + hostName +".");
}
oVM.disconnect();
continue;
}
else
@ -345,7 +377,7 @@ class OneVmmVmware extends Thread
System.err.println(action + " SUCCESS " + vid_str);
}
}
oVM.disconnect();
continue;
}
} // if (action.equals("SAVE"))
@ -372,6 +404,10 @@ class OneVmmVmware extends Thread
try
{
oVM = new OperationsOverVM(arguments,hostName);
if(!oVM.connect())
{
throw new Exception("Failed connection to host " + hostName);
}
}
catch(Exception e)
{
@ -380,6 +416,7 @@ class OneVmmVmware extends Thread
System.err.println(action + " FAILURE " + vid_str + " Failed connection to host " +
hostName +". Reason: " + e.getMessage());
}
oVM.disconnect();
continue;
}
@ -390,6 +427,8 @@ class OneVmmVmware extends Thread
System.err.println(action + " FAILURE " + vid_str + " Failed suspending VM in host " +
hostName);
}
oVM.disconnect();
continue;
}
else
{
@ -398,7 +437,7 @@ class OneVmmVmware extends Thread
System.err.println(action + " SUCCESS " + vid_str);
}
}
oVM.disconnect();
continue;
}
} // if (action.equals("CHECKPOINT"))
@ -429,9 +468,18 @@ class OneVmmVmware extends Thread
dVM = new DeployVM(arguments,
hostName,
vmName,
vid_str,
System.getProperty("datastore"),
System.getProperty("datacenter"));
if(!oVM.connect())
{
throw new Exception("Failed connection to host " + hostName);
}
if(!dVM.connect())
{
throw new Exception("Failed connection to host " + hostName);
}
if(!dVM.registerVirtualMachine())
{
// We will skip this error, it may be pre-registered
@ -443,8 +491,10 @@ class OneVmmVmware extends Thread
{
System.err.println(action + " FAILURE " + vid_str + " Failed connection to host " +
hostName +". Reason: " + e.getMessage());
continue;
}
oVM.disconnect();
dVM.disconnect();
continue;
}
if(!oVM.restoreCheckpoint(vmName))
@ -454,6 +504,9 @@ class OneVmmVmware extends Thread
System.err.println(action + " FAILURE " + vid_str + " Failed restoring VM in host " +
hostName);
}
oVM.disconnect();
dVM.disconnect();
continue;
}
else
{
@ -470,6 +523,9 @@ class OneVmmVmware extends Thread
{
System.err.println(action + " SUCCESS " + vid_str);
}
oVM.disconnect();
dVM.disconnect();
continue;
}
}
catch(Exception e)
@ -478,12 +534,15 @@ class OneVmmVmware extends Thread
{
System.err.println(action + " FAILURE " + vid_str + " Failed connection to host " +
hostName +". Reason: " + e.getMessage());
continue;
}
oVM.disconnect();
dVM.disconnect();
continue;
}
}
oVM.disconnect();
dVM.disconnect();
continue;
}
} // if (action.equals("RESTORE"))
@ -531,17 +590,30 @@ class OneVmmVmware extends Thread
argsWithHost[arguments.length + 1 ] = "https://" + hostName + ":443/sdk";
GetProperty gPHost = new GetProperty(argsWithHost, "HostSystem", hostName);
GetProperty gpVM = new GetProperty(argsWithHost, "VirtualMachine", vmName);
GetProperty gPVM = new GetProperty(argsWithHost, "VirtualMachine", vmName);
if(!gPHost.connect())
{
throw new Exception();
}
String hostCPUMhz = gPHost.getObjectProperty("summary.hardware.cpuMhz").toString();
gPHost.disconnect();
if(!gPVM.connect())
{
throw new Exception();
}
String vmCPUMhz =
gpVM.getObjectProperty("summary.quickStats.overallCpuUsage").toString();
gPVM.getObjectProperty("summary.quickStats.overallCpuUsage").toString();
String vmMEMMb =
gpVM.getObjectProperty("summary.quickStats.guestMemoryUsage").toString();
gPVM.getObjectProperty("summary.quickStats.guestMemoryUsage").toString();
gPVM.disconnect();
int hostCPUMhz_i = Integer.parseInt(hostCPUMhz);
int vmCPUMhz_i = Integer.parseInt(vmCPUMhz);
int vmCPUperc = (vmCPUMhz_i / hostCPUMhz_i) * 100;

View File

@ -33,7 +33,9 @@ import java.rmi.RemoteException;
*/
public class OperationsOverVM
{
{
String[] args;
// Helpers from VI samples
private static AppUtil cb = null;
@ -277,21 +279,44 @@ public class OperationsOverVM
return snapmor;
}
OperationsOverVM(String[] args, String hostName) throws Exception
{
String[] argsWithHost = new String[args.length+2];
for(int i=0;i<args.length;i++)
public boolean connect()
{
try
{
cb = AppUtil.initialize("OperationsOverVM", null, args);
cb.connect();
return true;
}
catch(Exception e)
{
return false;
}
}
public void disconnect()
{
try
{
cb.disConnect();
}
catch(Exception e){}
}
OperationsOverVM(String[] arguments, String hostName) throws Exception
{
args = new String[arguments.length+2];
for(int i=0;i<arguments.length;i++)
{
argsWithHost[i] = args[i];
args[i] = arguments[i];
}
argsWithHost[args.length] = "--url";
argsWithHost[args.length + 1 ] = "https://" + hostName + ":443/sdk";
args[arguments.length] = "--url";
args[arguments.length + 1 ] = "https://" + hostName + ":443/sdk";
cb = AppUtil.initialize("DeployVM", null, argsWithHost);
cb.connect();
datastoreName = System.getProperty("VMWARE_DATASTORE");
datacenterName = System.getProperty("VMWARE_DATACENTER");
}