1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Added dynamic virtualswitch selection in VMWare drivers

git-svn-id: http://svn.opennebula.org/one/trunk@671 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Constantino Vázquez Blanco 2009-07-10 14:19:17 +00:00
parent e9017be87a
commit b4529d3024
4 changed files with 151 additions and 163 deletions

View File

@ -125,9 +125,9 @@ class OneImVmware extends Thread
}
argsWithHost[arguments.length] = "--url";
// argsWithHost[arguments.length + 1 ] = "https://" + hostToMonitor + ":443/sdk";
argsWithHost[arguments.length + 1 ] = "https://" + hostToMonitor + ":443/sdk";
argsWithHost[arguments.length + 1 ] = "https://localhost:8008/sdk";
// argsWithHost[arguments.length + 1 ] = "https://localhost:8008/sdk";
gP = new GetProperty(argsWithHost, "HostSystem", hostToMonitor);
// Now it's time to build the response gathering the properties needed

View File

@ -217,8 +217,8 @@ public class DeployVM
vmConfigSpec.setCpuAllocation(raInfo);
// DISKs
addDisks();
// TODO finish disk support
// addDisks();
// Network
@ -253,6 +253,137 @@ public class DeployVM
}
void configureNetwork()
{
String[][] nics = pXML.getNet();
if(nics.length==1 && nics[0].equals(""))
{
return;
}
// First, let's find out the number of NICs to be removed
// VirtualDevice [] test = vmConfigInfo.getHardware().getDevice();
// Lenth of array is #nicsToBeRemoved-#nicsToBeAdded
//test.length+
VirtualDeviceConfigSpec [] nicSpecArray = new VirtualDeviceConfigSpec[
nics.length];
// Let's remove existing NICs
/* for(int i=0;i<test.length;i++)
{
VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec();
VirtualEthernetCard nic;
nicSpec.setOperation(VirtualDeviceConfigSpecOperation.remove);
nic = (VirtualEthernetCard)test[i];
nicSpec.setDevice(nic);
nicSpecArray[i] = nicSpec;
}
*/
// Let's add specified NICs
for(int i=0;i<nics.length;i++)
{
VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec();
String networkName = nics[i][1];
nicSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
VirtualEthernetCard nic = new VirtualPCNet32();
VirtualEthernetCardNetworkBackingInfo nicBacking
= new VirtualEthernetCardNetworkBackingInfo();
nicBacking.setDeviceName(networkName);
nic.setAddressType("manual");
nic.setMacAddress(nics[i][0]);
nic.setBacking(nicBacking);
nic.setKey(4);
nicSpec.setDevice(nic);
nicSpecArray[i] = nicSpec; // +test.length
}
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++)
{
argsWithHost[i] = args[i];
}
argsWithHost[args.length] = "--url";
argsWithHost[args.length + 1 ] = "https://" + hostName + ":443/sdk";
//argsWithHost[args.length + 1 ] = "https://localhost:8008/sdk";
cb = AppUtil.initialize("DeployVM", null, argsWithHost);
cb.connect();
datastoreName = _datastore;
datacenterName = _datacenter;
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();
}
DeployVM(String[] args, String hostName, String _vmName, String _datastore, String _datacenter) throws Exception
{
String[] argsWithHost = new String[args.length+2];
for(int i=0;i<args.length;i++)
{
argsWithHost[i] = args[i];
}
argsWithHost[args.length] = "--url";
argsWithHost[args.length + 1 ] = "https://" + hostName + ":443/sdk";
//argsWithHost[args.length + 1 ] = "https://localhost:8008/sdk";
cb = AppUtil.initialize("DeployVM", null, argsWithHost);
cb.connect();
datastoreName = _datastore;
datacenterName = _datacenter;
vmName = _vmName;
vmDiskName = _vmName.substring(0,_vmName.lastIndexOf("-"));
// 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();
}
/*
void addDisks()
{
String[] disks = pXML.getDisk();
@ -313,152 +444,5 @@ public class DeployVM
}
vmConfigSpec.setDeviceChange(vdiskSpecArray);
}
void configureNetwork()
{
String[] nics = pXML.getNet();
if(nics.length==1 && nics[0].equals(""))
{
return;
}
// First, let's find out the number of NICs to be removed
VirtualDevice [] test = vmConfigInfo.getHardware().getDevice();
// Lenth of array is #nicsToBeRemoved-#nicsToBeAdded
VirtualDeviceConfigSpec [] nicSpecArray = new VirtualDeviceConfigSpec[test.length+
nics.length];
// Let's remove existing NICs
/* for(int i=0;i<test.length;i++)
{
VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec();
VirtualEthernetCard nic;
nicSpec.setOperation(VirtualDeviceConfigSpecOperation.remove);
nic = (VirtualEthernetCard)test[i];
nicSpec.setDevice(nic);
nicSpecArray[i] = nicSpec;
}
*/
// Let's add specified NICs
for(int i=0;i<nics.length;i++)
{
VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec();
// TODO make this dynamic
String networkName = "one-net";
nicSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
VirtualEthernetCard nic = new VirtualPCNet32();
VirtualEthernetCardNetworkBackingInfo nicBacking
= new VirtualEthernetCardNetworkBackingInfo();
nicBacking.setDeviceName(networkName);
nic.setAddressType(nics[i]);
nic.setBacking(nicBacking);
nic.setKey(4);
nicSpec.setDevice(nic);
nicSpecArray[i+test.length] = nicSpec;
}
}
/*
private String getDataStoreName(int size) throws Exception{
String dsName = null;
ManagedObjectReference [] datastores
= (ManagedObjectReference [])cb.getServiceUtil().getDynamicProperty(
_virtualMachine,"datastore");
for(int i=0; i<datastores.length; i++) {
DatastoreSummary ds
= (DatastoreSummary)cb.getServiceUtil().getDynamicProperty(datastores[i],
"summary");
if(ds.getFreeSpace() > size) {
dsName = ds.getName();
i = datastores.length + 1;
}
}
return dsName;
}
*/
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++)
{
argsWithHost[i] = args[i];
}
argsWithHost[args.length] = "--url";
//argsWithHost[args.length + 1 ] = "https://" + hostName + ":443/sdk";
argsWithHost[args.length + 1 ] = "https://localhost:8008/sdk";
cb = AppUtil.initialize("DeployVM", null, argsWithHost);
cb.connect();
datastoreName = _datastore;
datacenterName = _datacenter;
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();
}
DeployVM(String[] args, String hostName, String _vmName, String _datastore, String _datacenter) throws Exception
{
String[] argsWithHost = new String[args.length+2];
for(int i=0;i<args.length;i++)
{
argsWithHost[i] = args[i];
}
argsWithHost[args.length] = "--url";
//argsWithHost[args.length + 1 ] = "https://" + hostName + ":443/sdk";
argsWithHost[args.length + 1 ] = "https://localhost:8008/sdk";
cb = AppUtil.initialize("DeployVM", null, argsWithHost);
cb.connect();
datastoreName = _datastore;
datacenterName = _datacenter;
vmName = _vmName;
vmDiskName = _vmName.substring(0,_vmName.lastIndexOf("-"));
// 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();
}
}*/
}

View File

@ -287,9 +287,9 @@ public class OperationsOverVM
}
argsWithHost[args.length] = "--url";
//argsWithHost[args.length + 1 ] = "https://" + hostName + ":443/sdk";
argsWithHost[args.length + 1 ] = "https://" + hostName + ":443/sdk";
argsWithHost[args.length + 1 ] = "https://localhost:8008/sdk";
// argsWithHost[args.length + 1 ] = "https://localhost:8008/sdk";
cb = AppUtil.initialize("DeployVM", null, argsWithHost);
cb.connect();

View File

@ -13,12 +13,12 @@ import org.xml.sax.SAXParseException;
public class ParseXML
{
private String name = "";
private String cpu = "";
private String[] disk = {""};
private String memory = "";
private String[] macs = {""};
private String vmID = "";
private String name = "";
private String cpu = "";
private String[] disk = {""};
private String memory = "";
private String[][] macs;
private String vmID = "";
/**
* Parses the XML file and fills the values
@ -97,13 +97,17 @@ public class ParseXML
if(nwNL.getLength()!=0)
{
macs = new String[nwNL.getLength()];
macs = new String[nwNL.getLength()][2];
for(int i=0; i<nwNL.getLength(); i++)
{
NodeList mac = ((Element)nwNL.item(i)).getElementsByTagName("MAC");
macs[i] = ((Node)mac.item(0)).getFirstChild().getNodeValue().trim();
macs[i][0] = ((Node)mac.item(0)).getFirstChild().getNodeValue().trim();
NodeList bridge = ((Element)nwNL.item(i)).getElementsByTagName("BRIDGE");
macs[i][1] = ((Node)bridge.item(0)).getFirstChild().getNodeValue().trim();
}
}
}
@ -145,7 +149,7 @@ public class ParseXML
* Returns networks MACs
* @return macs array with the macs of the NICs to be added to this VM
**/
String[] getNet()
String[][] getNet()
{
return macs;
}