|
230 | 230 | import com.vmware.vim25.VirtualMachinePowerState; |
231 | 231 | import com.vmware.vim25.VirtualMachineRuntimeInfo; |
232 | 232 | import com.vmware.vim25.VirtualSCSISharing; |
233 | | - |
234 | | -public class VmwareResource implements StoragePoolResource, ServerResource, VmwareHostService { |
235 | | - private static final Logger s_logger = Logger.getLogger(VmwareResource.class); |
236 | | - |
237 | | - protected String _name; |
238 | | - |
| 233 | +import com.xensource.xenapi.VLAN; |
| 234 | + |
| 235 | +public class VmwareResource implements StoragePoolResource, ServerResource, VmwareHostService { |
| 236 | + private static final Logger s_logger = Logger.getLogger(VmwareResource.class); |
| 237 | + |
| 238 | + protected String _name; |
| 239 | + |
239 | 240 | protected final long _ops_timeout = 900000; // 15 minutes time out to time |
240 | 241 | protected final int _shutdown_waitMs = 300000; // wait up to 5 minutes for shutdown |
241 | 242 |
|
@@ -1646,52 +1647,60 @@ private HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> inferDatastor |
1646 | 1647 | } |
1647 | 1648 | poolMors.put(vol.getPoolUuid(), new Pair<ManagedObjectReference, DatastoreMO> (morDataStore, new DatastoreMO(context, morDataStore))); |
1648 | 1649 | } |
1649 | | - } |
1650 | | - } |
1651 | | - return poolMors; |
1652 | | - } |
1653 | | - |
1654 | | - private String getVlanInfo(NicTO nicTo) { |
1655 | | - if (nicTo.getBroadcastType() == BroadcastDomainType.Native) { |
1656 | | - return Vlan.UNTAGGED; |
1657 | | - } |
1658 | | - |
1659 | | - if (nicTo.getBroadcastType() == BroadcastDomainType.Vlan) { |
1660 | | - if (nicTo.getBroadcastUri() != null) { |
1661 | | - return nicTo.getBroadcastUri().getHost(); |
1662 | | - } else { |
1663 | | - s_logger.warn("BroadcastType is not claimed as VLAN, but without vlan info in broadcast URI"); |
1664 | | - return Vlan.UNTAGGED; |
1665 | | - } |
1666 | | - } |
1667 | | - |
1668 | | - s_logger.warn("Unrecognized broadcast type in VmwareResource, type: " + nicTo.getBroadcastType().toString()); |
1669 | | - return Vlan.UNTAGGED; |
1670 | | - } |
1671 | | - |
| 1650 | + } |
| 1651 | + } |
| 1652 | + return poolMors; |
| 1653 | + } |
| 1654 | + |
| 1655 | + private String getVlanInfo(NicTO nicTo, String defaultVlan) { |
| 1656 | + if (nicTo.getBroadcastType() == BroadcastDomainType.Native) { |
| 1657 | + return defaultVlan; |
| 1658 | + } |
| 1659 | + |
| 1660 | + if (nicTo.getBroadcastType() == BroadcastDomainType.Vlan) { |
| 1661 | + if (nicTo.getBroadcastUri() != null) { |
| 1662 | + return nicTo.getBroadcastUri().getHost(); |
| 1663 | + } else { |
| 1664 | + s_logger.warn("BroadcastType is not claimed as VLAN, but without vlan info in broadcast URI. Use vlan info from labeling: " + defaultVlan); |
| 1665 | + return defaultVlan; |
| 1666 | + } |
| 1667 | + } |
| 1668 | + |
| 1669 | + s_logger.warn("Unrecognized broadcast type in VmwareResource, type: " + nicTo.getBroadcastType().toString() + ". Use vlan info from labeling: " + defaultVlan); |
| 1670 | + return defaultVlan; |
| 1671 | + } |
| 1672 | + |
1672 | 1673 | private Pair<ManagedObjectReference, String> prepareNetworkFromNicInfo(HostMO hostMo, NicTO nicTo) throws Exception { |
1673 | 1674 |
|
1674 | | - String switchName = getTargetSwitch(nicTo); |
| 1675 | + Pair<String, String> switchName = getTargetSwitch(nicTo); |
1675 | 1676 | String namePrefix = getNetworkNamePrefix(nicTo); |
1676 | 1677 |
|
1677 | | - s_logger.info("Prepare network on vSwitch: " + switchName + " with name prefix: " + namePrefix); |
1678 | | - return HypervisorHostHelper.prepareNetwork(switchName, namePrefix, hostMo, getVlanInfo(nicTo), |
| 1678 | + s_logger.info("Prepare network on vSwitch: " + switchName.first() + " with name prefix: " + namePrefix); |
| 1679 | + return HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, getVlanInfo(nicTo, switchName.second()), |
1679 | 1680 | nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout, |
1680 | 1681 | !namePrefix.startsWith("cloud.private")); |
1681 | 1682 | } |
1682 | 1683 |
|
1683 | | - private String getTargetSwitch(NicTO nicTo) throws Exception { |
1684 | | - if(nicTo.getName() != null && !nicTo.getName().isEmpty()) |
1685 | | - return nicTo.getName(); |
| 1684 | + // return Pair<switch name, vlan tagging> |
| 1685 | + private Pair<String, String> getTargetSwitch(NicTO nicTo) throws Exception { |
| 1686 | + if(nicTo.getName() != null && !nicTo.getName().isEmpty()) { |
| 1687 | + String[] tokens = nicTo.getName().split(","); |
| 1688 | + |
| 1689 | + if(tokens.length == 2) { |
| 1690 | + return new Pair<String, String>(tokens[0], tokens[1]); |
| 1691 | + } else { |
| 1692 | + return new Pair<String, String>(nicTo.getName(), Vlan.UNTAGGED); |
| 1693 | + } |
| 1694 | + } |
1686 | 1695 |
|
1687 | 1696 | if (nicTo.getType() == Networks.TrafficType.Guest) { |
1688 | | - return this._guestNetworkVSwitchName; |
| 1697 | + return new Pair<String, String>(this._guestNetworkVSwitchName, Vlan.UNTAGGED); |
1689 | 1698 | } else if (nicTo.getType() == Networks.TrafficType.Control || nicTo.getType() == Networks.TrafficType.Management) { |
1690 | | - return this._privateNetworkVSwitchName; |
| 1699 | + return new Pair<String, String>(this._privateNetworkVSwitchName, Vlan.UNTAGGED); |
1691 | 1700 | } else if (nicTo.getType() == Networks.TrafficType.Public) { |
1692 | | - return this._publicNetworkVSwitchName; |
| 1701 | + return new Pair<String, String>(this._publicNetworkVSwitchName, Vlan.UNTAGGED); |
1693 | 1702 | } else if (nicTo.getType() == Networks.TrafficType.Storage) { |
1694 | | - return this._privateNetworkVSwitchName; |
| 1703 | + return new Pair<String, String>(this._privateNetworkVSwitchName, Vlan.UNTAGGED); |
1695 | 1704 | } else if (nicTo.getType() == Networks.TrafficType.Vpn) { |
1696 | 1705 | throw new Exception("Unsupported traffic type: " + nicTo.getType().toString()); |
1697 | 1706 | } else { |
|
0 commit comments