mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	bug 10971: support vSphere 5
This commit is contained in:
		
							parent
							
								
									cfc24c49f4
								
							
						
					
					
						commit
						d32241ec9c
					
				| @ -143,6 +143,7 @@ import com.cloud.hypervisor.vmware.mo.CustomFieldConstants; | ||||
| import com.cloud.hypervisor.vmware.mo.CustomFieldsManagerMO; | ||||
| import com.cloud.hypervisor.vmware.mo.DatacenterMO; | ||||
| import com.cloud.hypervisor.vmware.mo.DatastoreMO; | ||||
| import com.cloud.hypervisor.vmware.mo.HostFirewallSystemMO; | ||||
| import com.cloud.hypervisor.vmware.mo.HostMO; | ||||
| import com.cloud.hypervisor.vmware.mo.HostVirtualNicType; | ||||
| import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper; | ||||
| @ -187,6 +188,8 @@ import com.vmware.vim25.ClusterDasConfigInfo; | ||||
| import com.vmware.vim25.ComputeResourceSummary; | ||||
| import com.vmware.vim25.DatastoreSummary; | ||||
| import com.vmware.vim25.DynamicProperty; | ||||
| import com.vmware.vim25.HostFirewallInfo; | ||||
| import com.vmware.vim25.HostFirewallRuleset; | ||||
| import com.vmware.vim25.HostNetworkTrafficShapingPolicy; | ||||
| import com.vmware.vim25.HostPortGroupSpec; | ||||
| import com.vmware.vim25.ManagedObjectReference; | ||||
| @ -3282,7 +3285,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa | ||||
| 	        Collection<Integer> existingPorts = portInfo.values(); | ||||
| 	        int val = random.nextInt(maxVncPorts); | ||||
| 	        int startVal = val; | ||||
| 	        do { | ||||
| 	        do { | ||||
| 	            if (!existingPorts.contains(5900 + val)) { | ||||
| 	                vncPort = 5900 + val; | ||||
| 	                break; | ||||
| @ -3789,7 +3792,29 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa | ||||
|     public synchronized VmwareContext getServiceContext(Command cmd) { | ||||
|         if (_serviceContext == null) { | ||||
|             try { | ||||
|                 _serviceContext = VmwareContextFactory.create(_vCenterAddress, _username, _password); | ||||
|                 _serviceContext = VmwareContextFactory.create(_vCenterAddress, _username, _password); | ||||
|                 VmwareHypervisorHost hyperHost = getHyperHost(_serviceContext, cmd); | ||||
|                 assert(hyperHost instanceof HostMO); | ||||
|                  | ||||
|                 HostFirewallSystemMO firewallMo = ((HostMO)hyperHost).getHostFirewallSystemMO(); | ||||
|                 boolean bRefresh = false; | ||||
|                 if(firewallMo != null) { | ||||
|                 	HostFirewallInfo firewallInfo = firewallMo.getFirewallInfo(); | ||||
|                 	if(firewallInfo != null) { | ||||
|                 		for(HostFirewallRuleset rule : firewallInfo.getRuleset()) { | ||||
|                 			if("vncServer".equalsIgnoreCase(rule.getKey())) { | ||||
|                 				bRefresh = true; | ||||
|                 				firewallMo.enableRuleset("vncServer"); | ||||
|                 			} else if("gdbserver".equalsIgnoreCase(rule.getKey())) { | ||||
|                 				bRefresh = true; | ||||
|                 				firewallMo.enableRuleset("gdbserver"); | ||||
|                 			} | ||||
|                 		} | ||||
|                 	} | ||||
|                 	 | ||||
|                 	if(bRefresh) | ||||
|                 		firewallMo.refreshFirewall(); | ||||
|                 } | ||||
|             } catch (Exception e) { | ||||
|                 s_logger.error("Unable to connect to vSphere server: " + _vCenterAddress, e); | ||||
|                 throw new CloudRuntimeException("Unable to connect to vSphere server: " + _vCenterAddress); | ||||
| @ -3809,8 +3834,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa | ||||
| 
 | ||||
|     @Override | ||||
|     public VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd) { | ||||
|         if (_morHyperHost.getType().equalsIgnoreCase("HostSystem")) { | ||||
|             return new HostMO(context, _morHyperHost); | ||||
|         if (_morHyperHost.getType().equalsIgnoreCase("HostSystem")) { | ||||
|         	return new HostMO(context, _morHyperHost); | ||||
|         } | ||||
|         return new ClusterMO(context, _morHyperHost); | ||||
|     } | ||||
|  | ||||
| @ -7,6 +7,7 @@ package com.cloud.hypervisor.vmware.mo; | ||||
| import org.apache.log4j.Logger; | ||||
| 
 | ||||
| import com.cloud.hypervisor.vmware.util.VmwareContext; | ||||
| import com.cloud.serializer.GsonHelper; | ||||
| import com.cloud.utils.testcase.Log4jEnabledTestCase; | ||||
| import com.google.gson.Gson; | ||||
| import com.vmware.vim25.ManagedObjectReference; | ||||
| @ -15,16 +16,17 @@ import com.vmware.vim25.VirtualMachineConfigSpec; | ||||
| // This test case needs a particular setup, only used for my own test | ||||
| public class TestVmwareMO extends Log4jEnabledTestCase { | ||||
|     private static final Logger s_logger = Logger.getLogger(TestVmwareMO.class); | ||||
|      | ||||
| 
 | ||||
|     public void test() { | ||||
| 		try { | ||||
| 			VmwareContext context = TestVmwareContextFactory.create( | ||||
| 					"192.168.190.18", "Administrator", "Suite219"); | ||||
| 					"10.223.80.29", "Administrator", "Suite219"); | ||||
| 			 | ||||
| 			VirtualMachineMO vmMo = new VirtualMachineMO(context, "VirtualMachine", "vm-700"); | ||||
| 			 | ||||
| 			System.out.println("state " + vmMo.getPowerState().toString()); | ||||
| 			HostMO hostMo = new HostMO(context, "HostSystem", "host-9"); | ||||
| 			 | ||||
| 			System.out.println("host Type " + hostMo.getHostType()); | ||||
| 			Gson gson = GsonHelper.getGsonLogger(); | ||||
| 			System.out.println(gson.toJson(hostMo.getHostFirewallSystemMO().getFirewallInfo())); | ||||
| 			 | ||||
| 			context.close(); | ||||
| 		} catch(Exception e) { | ||||
|  | ||||
| @ -224,7 +224,7 @@ public enum Config { | ||||
|     VmwareGuestNetworkVSwitch("Advanced", ManagementServer.class, String.class, "vmware.guest.vswitch", null, "Specify the vSwitch on host for guest network", null), | ||||
|     VmwareServiceConsole("Advanced", ManagementServer.class, String.class, "vmware.service.console", "Service Console", "Specify the service console network name(for ESX hosts)", null), | ||||
|     VmwareManagementPortGroup("Advanced", ManagementServer.class, String.class, "vmware.management.portgroup", "Management Network", "Specify the management network name(for ESXi hosts)", null), | ||||
|     VmwareAdditionalVncPortRangeStart("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.start", "59000", "Start port number of additional VNC port range", null), | ||||
|     VmwareAdditionalVncPortRangeStart("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.start", "50000", "Start port number of additional VNC port range", null), | ||||
|     VmwareAdditionalVncPortRangeSize("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.size", "1000", "Start port number of additional VNC port range", null), | ||||
|     //VmwareGuestNicDeviceType("Advanced", ManagementServer.class, String.class, "vmware.guest.nic.device.type", "E1000", "Ethernet card type used in guest VM, valid values are E1000, PCNet32, Vmxnet2, Vmxnet3", null), | ||||
|     VmwarePerClusterHostMax("Advanced", ManagementServer.class, Integer.class, "vmware.percluster.host.max", "8", "maxmium hosts per vCenter cluster(do not let it grow over 8)", "1-8"), | ||||
|  | ||||
| @ -75,6 +75,7 @@ import com.cloud.utils.script.Script; | ||||
| import com.cloud.vm.DomainRouterVO; | ||||
| import com.google.gson.Gson; | ||||
| import com.vmware.apputils.vim25.ServiceUtil; | ||||
| import com.vmware.vim25.AboutInfo; | ||||
| import com.vmware.vim25.HostConnectSpec; | ||||
| import com.vmware.vim25.HostPortGroupSpec; | ||||
| import com.vmware.vim25.ManagedObjectReference; | ||||
| @ -301,8 +302,10 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis | ||||
|                 HostMO hostMo = new HostMO(serviceContext, hosts[0]); | ||||
|                 HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO(); | ||||
|                 if(firewallMo != null) { | ||||
|                     firewallMo.enableRuleset("vncServer"); | ||||
|                     firewallMo.refreshFirewall(); | ||||
|             		if(hostMo.getHostType() == VmwareHostType.ESX) { | ||||
| 	                    firewallMo.enableRuleset("vncServer"); | ||||
| 	                    firewallMo.refreshFirewall(); | ||||
|             		} | ||||
|                 } | ||||
| 
 | ||||
|                 // prepare at least one network on the vswitch to enable OVF importing | ||||
| @ -332,8 +335,10 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis | ||||
|                     HostMO hostMo = new HostMO(serviceContext, morHost); | ||||
|                     HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO(); | ||||
|                     if(firewallMo != null) { | ||||
|                         firewallMo.enableRuleset("vncServer"); | ||||
|                         firewallMo.refreshFirewall(); | ||||
|                 		if(hostMo.getHostType() == VmwareHostType.ESX) { | ||||
| 	                        firewallMo.enableRuleset("vncServer"); | ||||
| 	                        firewallMo.refreshFirewall(); | ||||
|                 		} | ||||
|                     } | ||||
| 
 | ||||
|                     String managementPortGroupName = hostMo.getPortGroupNameByNicType(HostVirtualNicType.management); | ||||
| @ -354,8 +359,10 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis | ||||
|                 HostMO hostMo = new HostMO(serviceContext, mor); | ||||
|                 HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO(); | ||||
|                 if(firewallMo != null) { | ||||
|                     firewallMo.enableRuleset("vncServer"); | ||||
|                     firewallMo.refreshFirewall(); | ||||
|             		if(hostMo.getHostType() == VmwareHostType.ESX) { | ||||
| 	                    firewallMo.enableRuleset("vncServer"); | ||||
| 	                    firewallMo.refreshFirewall(); | ||||
|             		} | ||||
|                 } | ||||
| 
 | ||||
|                 String managementPortGroupName = hostMo.getPortGroupNameByNicType(HostVirtualNicType.management); | ||||
|  | ||||
| @ -7,6 +7,8 @@ package com.cloud.hypervisor.vmware.mo; | ||||
| import org.apache.log4j.Logger; | ||||
| 
 | ||||
| import com.cloud.hypervisor.vmware.util.VmwareContext; | ||||
| import com.vmware.vim25.HostFirewallDefaultPolicy; | ||||
| import com.vmware.vim25.HostFirewallInfo; | ||||
| import com.vmware.vim25.ManagedObjectReference; | ||||
| 
 | ||||
| public class HostFirewallSystemMO extends BaseMO { | ||||
| @ -18,6 +20,14 @@ public class HostFirewallSystemMO extends BaseMO { | ||||
| 	 | ||||
| 	public HostFirewallSystemMO(VmwareContext context, String morType, String morValue) { | ||||
| 		super(context, morType, morValue); | ||||
| 	} | ||||
| 	 | ||||
| 	public HostFirewallInfo getFirewallInfo() throws Exception { | ||||
| 		return (HostFirewallInfo)_context.getServiceUtil().getDynamicProperty(_mor, "firewallInfo"); | ||||
| 	} | ||||
| 	 | ||||
| 	public void updateDefaultPolicy(HostFirewallDefaultPolicy policy) throws Exception { | ||||
| 		_context.getService().updateDefaultPolicy(_mor, policy); | ||||
| 	} | ||||
| 	 | ||||
| 	public void enableRuleset(String rulesetName) throws Exception { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user