public void createPortGroup(HostVirtualSwitch vSwitch, String portGroupName, Integer vlanId, HostNetworkSecurityPolicy secPolicy, HostNetworkTrafficShapingPolicy shapingPolicy) throws Exception { assert (portGroupName != null); HostNetworkSystemMO hostNetMo = getHostNetworkSystemMO(); assert (hostNetMo != null); HostPortGroupSpec spec = new HostPortGroupSpec(); spec.setName(portGroupName); if (vlanId != null) spec.setVlanId(vlanId.intValue()); HostNetworkPolicy policy = new HostNetworkPolicy(); if (secPolicy != null) policy.setSecurity(secPolicy); policy.setShapingPolicy(shapingPolicy); spec.setPolicy(policy); spec.setVswitchName(vSwitch.getName()); hostNetMo.addPortGroup(spec); }
public void updatePortGroup(HostVirtualSwitch vSwitch, String portGroupName, Integer vlanId, HostNetworkSecurityPolicy secPolicy, HostNetworkTrafficShapingPolicy shapingPolicy) throws Exception { assert (portGroupName != null); HostNetworkSystemMO hostNetMo = getHostNetworkSystemMO(); assert (hostNetMo != null); HostPortGroupSpec spec = new HostPortGroupSpec(); spec.setName(portGroupName); if (vlanId != null) spec.setVlanId(vlanId.intValue()); HostNetworkPolicy policy = new HostNetworkPolicy(); if (secPolicy != null) policy.setSecurity(secPolicy); policy.setShapingPolicy(shapingPolicy); spec.setPolicy(policy); spec.setVswitchName(vSwitch.getName()); hostNetMo.updatePortGroup(portGroupName, spec); }
public HostPortGroupSpec getHostPortGroupSpec(String portGroupName) throws Exception { HostNetworkInfo hostNetInfo = getHostNetworkInfo(); List<HostPortGroup> portGroups = hostNetInfo.getPortgroup(); if (portGroups != null) { for (HostPortGroup portGroup : portGroups) { HostPortGroupSpec spec = portGroup.getSpec(); if (spec.getName().equals(portGroupName)) return spec; } } return null; }
public String getPortGroupVirtualSwitchName(String portGroupName) throws Exception { HostNetworkInfo hostNetInfo = getHostNetworkInfo(); List<HostPortGroup> portGroups = hostNetInfo.getPortgroup(); if (portGroups != null) { for (HostPortGroup portGroup : portGroups) { HostPortGroupSpec spec = portGroup.getSpec(); if (spec.getName().equals(portGroupName)) return spec.getVswitchName(); } } return null; }
public HostPortGroupSpec getPortGroupSpec(String portGroupName) throws Exception { HostNetworkInfo hostNetInfo = getHostNetworkInfo(); List<HostPortGroup> portGroups = hostNetInfo.getPortgroup(); if (portGroups != null) { for (HostPortGroup portGroup : portGroups) { HostPortGroupSpec spec = portGroup.getSpec(); if (spec.getName().equals(portGroupName)) return spec; } } return null; }
private static void createNvpPortGroup(HostMO hostMo, HostVirtualSwitch vSwitch, String networkName, HostNetworkTrafficShapingPolicy shapingPolicy) throws Exception { /** * No portgroup created yet for this nic * We need to find an unused vlan and create the pg * The vlan is limited to this vSwitch and the NVP vAPP, * so no relation to the other vlans in use in CloudStack. */ String vSwitchName = vSwitch.getName(); // Find all vlanids that we have in use List<Integer> usedVlans = new ArrayList<Integer>(); for (HostPortGroup pg : hostMo.getHostNetworkInfo().getPortgroup()) { HostPortGroupSpec hpgs = pg.getSpec(); if (vSwitchName.equals(hpgs.getVswitchName())) usedVlans.add(hpgs.getVlanId()); } // Find the first free vlanid int nvpVlanId = 0; for (nvpVlanId = 1; nvpVlanId < 4095; nvpVlanId++) { if (!usedVlans.contains(nvpVlanId)) { break; } } if (nvpVlanId == 4095) { throw new InvalidParameterException("No free vlan numbers on " + vSwitchName + " to create a portgroup for nic " + networkName); } // Strict security policy HostNetworkSecurityPolicy secPolicy = new HostNetworkSecurityPolicy(); secPolicy.setAllowPromiscuous(Boolean.FALSE); secPolicy.setForgedTransmits(Boolean.FALSE); secPolicy.setMacChanges(Boolean.FALSE); // Create a portgroup with the uuid of the nic and the vlanid found above hostMo.createPortGroup(vSwitch, networkName, nvpVlanId, secPolicy, shapingPolicy); }
private static boolean isSpecMatch(HostPortGroupSpec spec, Integer vlanId, HostNetworkSecurityPolicy securityPolicy, HostNetworkTrafficShapingPolicy shapingPolicy) { // check VLAN configuration if (vlanId != null) { if (vlanId.intValue() != spec.getVlanId()) return false; } else { if (spec.getVlanId() != 0) return false; } // check security policy for the portgroup HostNetworkSecurityPolicy secPolicyInSpec = null; if (spec.getPolicy() != null) { secPolicyInSpec = spec.getPolicy().getSecurity(); } if ((secPolicyInSpec != null && securityPolicy == null) || (secPolicyInSpec == null && securityPolicy != null)) { return false; } if (secPolicyInSpec != null && securityPolicy != null && ((securityPolicy.isAllowPromiscuous() != null && !securityPolicy.isAllowPromiscuous().equals(secPolicyInSpec.isAllowPromiscuous())) || (securityPolicy.isForgedTransmits() != null && !securityPolicy.isForgedTransmits().equals(secPolicyInSpec.isForgedTransmits())) || (securityPolicy.isMacChanges() != null && securityPolicy.isMacChanges().equals(secPolicyInSpec.isMacChanges())))) { return false; } // check traffic shaping configuration HostNetworkTrafficShapingPolicy policyInSpec = null; if (spec.getPolicy() != null) { policyInSpec = spec.getPolicy().getShapingPolicy(); } if ((policyInSpec != null && shapingPolicy == null) || (policyInSpec == null && shapingPolicy != null)) { return false; } if (policyInSpec == null && shapingPolicy == null) { return true; } // so far policyInSpec and shapingPolicy should both not be null if (policyInSpec.isEnabled() == null || !policyInSpec.isEnabled().booleanValue()) return false; if (policyInSpec.getAverageBandwidth() == null || policyInSpec.getAverageBandwidth().longValue() != shapingPolicy.getAverageBandwidth().longValue()) return false; if (policyInSpec.getPeakBandwidth() == null || policyInSpec.getPeakBandwidth().longValue() != shapingPolicy.getPeakBandwidth().longValue()) return false; if (policyInSpec.getBurstSize() == null || policyInSpec.getBurstSize().longValue() != shapingPolicy.getBurstSize().longValue()) return false; return true; }
public void addPortGroup(HostPortGroupSpec spec) throws Exception { _context.getService().addPortGroup(_mor, spec); }
public void updatePortGroup(String portGroupName, HostPortGroupSpec spec) throws Exception { _context.getService().updatePortGroup(_mor, portGroupName, spec); }