Skip to content

Commit d32241e

Browse files
author
Kelven Yang
committed
bug 10971: support vSphere 5
1 parent cfc24c4 commit d32241e

5 files changed

Lines changed: 60 additions & 16 deletions

File tree

‎core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
import com.cloud.hypervisor.vmware.mo.CustomFieldsManagerMO;
144144
import com.cloud.hypervisor.vmware.mo.DatacenterMO;
145145
import com.cloud.hypervisor.vmware.mo.DatastoreMO;
146+
import com.cloud.hypervisor.vmware.mo.HostFirewallSystemMO;
146147
import com.cloud.hypervisor.vmware.mo.HostMO;
147148
import com.cloud.hypervisor.vmware.mo.HostVirtualNicType;
148149
import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
@@ -187,6 +188,8 @@
187188
import com.vmware.vim25.ComputeResourceSummary;
188189
import com.vmware.vim25.DatastoreSummary;
189190
import com.vmware.vim25.DynamicProperty;
191+
import com.vmware.vim25.HostFirewallInfo;
192+
import com.vmware.vim25.HostFirewallRuleset;
190193
import com.vmware.vim25.HostNetworkTrafficShapingPolicy;
191194
import com.vmware.vim25.HostPortGroupSpec;
192195
import com.vmware.vim25.ManagedObjectReference;
@@ -3282,7 +3285,7 @@ protected OptionValue[] configureVnc(OptionValue[] optionsToMerge, VmwareHypervi
32823285
Collection<Integer> existingPorts = portInfo.values();
32833286
int val = random.nextInt(maxVncPorts);
32843287
int startVal = val;
3285-
do {
3288+
do {
32863289
if (!existingPorts.contains(5900 + val)) {
32873290
vncPort = 5900 + val;
32883291
break;
@@ -3789,7 +3792,29 @@ private VmwareHypervisorHost getHyperHost(VmwareContext context) {
37893792
public synchronized VmwareContext getServiceContext(Command cmd) {
37903793
if (_serviceContext == null) {
37913794
try {
3792-
_serviceContext = VmwareContextFactory.create(_vCenterAddress, _username, _password);
3795+
_serviceContext = VmwareContextFactory.create(_vCenterAddress, _username, _password);
3796+
VmwareHypervisorHost hyperHost = getHyperHost(_serviceContext, cmd);
3797+
assert(hyperHost instanceof HostMO);
3798+
3799+
HostFirewallSystemMO firewallMo = ((HostMO)hyperHost).getHostFirewallSystemMO();
3800+
boolean bRefresh = false;
3801+
if(firewallMo != null) {
3802+
HostFirewallInfo firewallInfo = firewallMo.getFirewallInfo();
3803+
if(firewallInfo != null) {
3804+
for(HostFirewallRuleset rule : firewallInfo.getRuleset()) {
3805+
if("vncServer".equalsIgnoreCase(rule.getKey())) {
3806+
bRefresh = true;
3807+
firewallMo.enableRuleset("vncServer");
3808+
} else if("gdbserver".equalsIgnoreCase(rule.getKey())) {
3809+
bRefresh = true;
3810+
firewallMo.enableRuleset("gdbserver");
3811+
}
3812+
}
3813+
}
3814+
3815+
if(bRefresh)
3816+
firewallMo.refreshFirewall();
3817+
}
37933818
} catch (Exception e) {
37943819
s_logger.error("Unable to connect to vSphere server: " + _vCenterAddress, e);
37953820
throw new CloudRuntimeException("Unable to connect to vSphere server: " + _vCenterAddress);
@@ -3809,8 +3834,8 @@ public synchronized void invalidateServiceContext(VmwareContext context) {
38093834

38103835
@Override
38113836
public VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd) {
3812-
if (_morHyperHost.getType().equalsIgnoreCase("HostSystem")) {
3813-
return new HostMO(context, _morHyperHost);
3837+
if (_morHyperHost.getType().equalsIgnoreCase("HostSystem")) {
3838+
return new HostMO(context, _morHyperHost);
38143839
}
38153840
return new ClusterMO(context, _morHyperHost);
38163841
}

‎core/test/com/cloud/hypervisor/vmware/mo/TestVmwareMO.java‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.apache.log4j.Logger;
88

99
import com.cloud.hypervisor.vmware.util.VmwareContext;
10+
import com.cloud.serializer.GsonHelper;
1011
import com.cloud.utils.testcase.Log4jEnabledTestCase;
1112
import com.google.gson.Gson;
1213
import com.vmware.vim25.ManagedObjectReference;
@@ -15,16 +16,17 @@
1516
// This test case needs a particular setup, only used for my own test
1617
public class TestVmwareMO extends Log4jEnabledTestCase {
1718
private static final Logger s_logger = Logger.getLogger(TestVmwareMO.class);
18-
19+
1920
public void test() {
2021
try {
2122
VmwareContext context = TestVmwareContextFactory.create(
22-
"192.168.190.18", "Administrator", "Suite219");
23-
24-
VirtualMachineMO vmMo = new VirtualMachineMO(context, "VirtualMachine", "vm-700");
23+
"10.223.80.29", "Administrator", "Suite219");
2524

26-
System.out.println("state " + vmMo.getPowerState().toString());
25+
HostMO hostMo = new HostMO(context, "HostSystem", "host-9");
2726

27+
System.out.println("host Type " + hostMo.getHostType());
28+
Gson gson = GsonHelper.getGsonLogger();
29+
System.out.println(gson.toJson(hostMo.getHostFirewallSystemMO().getFirewallInfo()));
2830

2931
context.close();
3032
} catch(Exception e) {

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public enum Config {
224224
VmwareGuestNetworkVSwitch("Advanced", ManagementServer.class, String.class, "vmware.guest.vswitch", null, "Specify the vSwitch on host for guest network", null),
225225
VmwareServiceConsole("Advanced", ManagementServer.class, String.class, "vmware.service.console", "Service Console", "Specify the service console network name(for ESX hosts)", null),
226226
VmwareManagementPortGroup("Advanced", ManagementServer.class, String.class, "vmware.management.portgroup", "Management Network", "Specify the management network name(for ESXi hosts)", null),
227-
VmwareAdditionalVncPortRangeStart("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.start", "59000", "Start port number of additional VNC port range", null),
227+
VmwareAdditionalVncPortRangeStart("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.start", "50000", "Start port number of additional VNC port range", null),
228228
VmwareAdditionalVncPortRangeSize("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.size", "1000", "Start port number of additional VNC port range", null),
229229
//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),
230230
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"),

‎server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import com.cloud.vm.DomainRouterVO;
7676
import com.google.gson.Gson;
7777
import com.vmware.apputils.vim25.ServiceUtil;
78+
import com.vmware.vim25.AboutInfo;
7879
import com.vmware.vim25.HostConnectSpec;
7980
import com.vmware.vim25.HostPortGroupSpec;
8081
import com.vmware.vim25.ManagedObjectReference;
@@ -301,8 +302,10 @@ public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceCon
301302
HostMO hostMo = new HostMO(serviceContext, hosts[0]);
302303
HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
303304
if(firewallMo != null) {
304-
firewallMo.enableRuleset("vncServer");
305-
firewallMo.refreshFirewall();
305+
if(hostMo.getHostType() == VmwareHostType.ESX) {
306+
firewallMo.enableRuleset("vncServer");
307+
firewallMo.refreshFirewall();
308+
}
306309
}
307310

308311
// prepare at least one network on the vswitch to enable OVF importing
@@ -332,8 +335,10 @@ public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceCon
332335
HostMO hostMo = new HostMO(serviceContext, morHost);
333336
HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
334337
if(firewallMo != null) {
335-
firewallMo.enableRuleset("vncServer");
336-
firewallMo.refreshFirewall();
338+
if(hostMo.getHostType() == VmwareHostType.ESX) {
339+
firewallMo.enableRuleset("vncServer");
340+
firewallMo.refreshFirewall();
341+
}
337342
}
338343

339344
String managementPortGroupName = hostMo.getPortGroupNameByNicType(HostVirtualNicType.management);
@@ -354,8 +359,10 @@ public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceCon
354359
HostMO hostMo = new HostMO(serviceContext, mor);
355360
HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
356361
if(firewallMo != null) {
357-
firewallMo.enableRuleset("vncServer");
358-
firewallMo.refreshFirewall();
362+
if(hostMo.getHostType() == VmwareHostType.ESX) {
363+
firewallMo.enableRuleset("vncServer");
364+
firewallMo.refreshFirewall();
365+
}
359366
}
360367

361368
String managementPortGroupName = hostMo.getPortGroupNameByNicType(HostVirtualNicType.management);

‎vmware-base/src/com/cloud/hypervisor/vmware/mo/HostFirewallSystemMO.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.apache.log4j.Logger;
88

99
import com.cloud.hypervisor.vmware.util.VmwareContext;
10+
import com.vmware.vim25.HostFirewallDefaultPolicy;
11+
import com.vmware.vim25.HostFirewallInfo;
1012
import com.vmware.vim25.ManagedObjectReference;
1113

1214
public class HostFirewallSystemMO extends BaseMO {
@@ -18,6 +20,14 @@ public HostFirewallSystemMO(VmwareContext context, ManagedObjectReference morFir
1820

1921
public HostFirewallSystemMO(VmwareContext context, String morType, String morValue) {
2022
super(context, morType, morValue);
23+
}
24+
25+
public HostFirewallInfo getFirewallInfo() throws Exception {
26+
return (HostFirewallInfo)_context.getServiceUtil().getDynamicProperty(_mor, "firewallInfo");
27+
}
28+
29+
public void updateDefaultPolicy(HostFirewallDefaultPolicy policy) throws Exception {
30+
_context.getService().updateDefaultPolicy(_mor, policy);
2131
}
2232

2333
public void enableRuleset(String rulesetName) throws Exception {

0 commit comments

Comments
 (0)