use of com.vmware.vim25.mo.Network in project cloudstack by apache.
the class VmwareManagerImpl method prepareHost.
private void prepareHost(HostMO hostMo, String privateTrafficLabel) throws Exception {
// For ESX host, we need to enable host firewall to allow VNC access
HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
if (firewallMo != null) {
if (hostMo.getHostType() == VmwareHostType.ESX) {
firewallMo.enableRuleset("vncServer");
firewallMo.refreshFirewall();
}
}
// prepare at least one network on the vswitch to enable OVF importing
String vSwitchName;
String vlanId;
String vSwitchType;
VmwareTrafficLabel mgmtTrafficLabelObj = new VmwareTrafficLabel(privateTrafficLabel, TrafficType.Management);
vSwitchName = mgmtTrafficLabelObj.getVirtualSwitchName();
vlanId = mgmtTrafficLabelObj.getVlanId();
vSwitchType = mgmtTrafficLabelObj.getVirtualSwitchType().toString();
s_logger.info("Preparing network on host " + hostMo.getContext().toString() + " for " + privateTrafficLabel);
VirtualSwitchType vsType = VirtualSwitchType.getType(vSwitchType);
// The management network is probably always going to be a physical network with islation type of vlans, so assume BroadcastDomainType VLAN
if (VirtualSwitchType.StandardVirtualSwitch == vsType) {
HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false, BroadcastDomainType.Vlan, null, null);
} else {
int portsPerDvPortGroup = _portsPerDvPortGroup;
AboutInfo about = hostMo.getHostAboutInfo();
if (about != null) {
String version = about.getApiVersion();
if (version != null && (version.equals("4.0") || version.equals("4.1")) && _portsPerDvPortGroup < DEFAULT_PORTS_PER_DV_PORT_GROUP_VSPHERE4_x) {
portsPerDvPortGroup = DEFAULT_PORTS_PER_DV_PORT_GROUP_VSPHERE4_x;
}
}
HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.private", hostMo, vlanId, null, null, null, 180000, vsType, portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, null, null);
}
}
use of com.vmware.vim25.mo.Network in project cloudstack by apache.
the class VmwareSecondaryStorageResourceHandler method getHyperHost.
@Override
public VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd) {
String guid = cmd.getContextParam("guid");
assert (guid != null);
String[] tokens = guid.split("@");
assert (tokens != null && tokens.length == 2);
ManagedObjectReference morHyperHost = new ManagedObjectReference();
String[] hostTokens = tokens[0].split(":");
if (hostTokens == null || hostTokens.length != 2) {
s_logger.error("Invalid content in command context parameter guid");
return null;
}
morHyperHost.setType(hostTokens[0]);
morHyperHost.setValue(hostTokens[1]);
if (morHyperHost.getType().equalsIgnoreCase("HostSystem")) {
HostMO hostMo = new HostMO(context, morHyperHost);
try {
ManagedObjectReference mor = hostMo.getHyperHostCluster();
ClusterMO clusterMo = new ClusterMO(hostMo.getContext(), mor);
List<Pair<ManagedObjectReference, String>> hostsInCluster = clusterMo.getClusterHosts();
for (Pair<ManagedObjectReference, String> hostPair : hostsInCluster) {
HostMO hostIteratorMo = new HostMO(hostMo.getContext(), hostPair.first());
VmwareHypervisorHostNetworkSummary netSummary = hostIteratorMo.getHyperHostNetworkSummary(hostIteratorMo.getHostType() == VmwareHostType.ESXi ? cmd.getContextParam("manageportgroup") : cmd.getContextParam("serviceconsole"));
_resource.ensureOutgoingRuleForAddress(netSummary.getHostIp());
s_logger.info("Setup firewall rule for host: " + netSummary.getHostIp());
}
} catch (Throwable e) {
s_logger.warn("Unable to retrive host network information due to exception " + e.toString() + ", host: " + hostTokens[0] + "-" + hostTokens[1]);
}
return hostMo;
}
assert (false);
return new ClusterMO(context, morHyperHost);
}
use of com.vmware.vim25.mo.Network in project cloudstack by apache.
the class VmwareResource method prepareNetworkFromNicInfo.
private Pair<ManagedObjectReference, String> prepareNetworkFromNicInfo(HostMO hostMo, NicTO nicTo, boolean configureVServiceInNexus, VirtualMachine.Type vmType) throws Exception {
Ternary<String, String, String> switchDetails = getTargetSwitch(nicTo);
VirtualSwitchType switchType = VirtualSwitchType.getType(switchDetails.second());
String switchName = switchDetails.first();
String vlanToken = switchDetails.third();
String namePrefix = getNetworkNamePrefix(nicTo);
Pair<ManagedObjectReference, String> networkInfo = null;
s_logger.info("Prepare network on " + switchType + " " + switchName + " with name prefix: " + namePrefix);
if (VirtualSwitchType.StandardVirtualSwitch == switchType) {
networkInfo = HypervisorHostHelper.prepareNetwork(switchName, namePrefix, hostMo, getVlanInfo(nicTo, vlanToken), nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _opsTimeout, true, nicTo.getBroadcastType(), nicTo.getUuid(), nicTo.getDetails());
} else {
String vlanId = getVlanInfo(nicTo, vlanToken);
String svlanId = null;
boolean pvlannetwork = (getPvlanInfo(nicTo) == null) ? false : true;
if (vmType != null && vmType.equals(VirtualMachine.Type.DomainRouter) && pvlannetwork) {
// plumb this network to the promiscuous vlan.
svlanId = vlanId;
} else {
// plumb this network to the isolated vlan.
svlanId = getPvlanInfo(nicTo);
}
networkInfo = HypervisorHostHelper.prepareNetwork(switchName, namePrefix, hostMo, vlanId, svlanId, nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _opsTimeout, switchType, _portsPerDvPortGroup, nicTo.getGateway(), configureVServiceInNexus, nicTo.getBroadcastType(), _vsmCredentials, nicTo.getDetails());
}
return networkInfo;
}
use of com.vmware.vim25.mo.Network in project cloudstack by apache.
the class VmwareResource method plugPublicNic.
private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final IpAddressTO ipAddressTO) throws Exception {
// TODO : probably need to set traffic shaping
Pair<ManagedObjectReference, String> networkInfo = null;
VirtualSwitchType vSwitchType = VirtualSwitchType.StandardVirtualSwitch;
if (_publicTrafficInfo != null) {
vSwitchType = _publicTrafficInfo.getVirtualSwitchType();
}
/**
* FIXME We have no clue which network this nic is on and that means that we can't figure out the BroadcastDomainType
* so we assume that it's VLAN for now
*/
if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) {
networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, ipAddressTO.getNetworkRate(), null, _opsTimeout, true, BroadcastDomainType.Vlan, null, null);
} else {
networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, ipAddressTO.getNetworkRate(), null, _opsTimeout, vSwitchType, _portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, _vsmCredentials, null);
}
int nicIndex = allocPublicNicIndex(vmMo);
try {
VirtualDevice[] nicDevices = vmMo.getSortedNicDevices();
VirtualEthernetCard device = (VirtualEthernetCard) nicDevices[nicIndex];
if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) {
VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
nicBacking.setDeviceName(networkInfo.second());
nicBacking.setNetwork(networkInfo.first());
device.setBacking(nicBacking);
} else {
HostMO hostMo = vmMo.getRunningHost();
DatacenterMO dataCenterMo = new DatacenterMO(hostMo.getContext(), hostMo.getHyperHostDatacenter());
device.setBacking(dataCenterMo.getDvPortBackingInfo(networkInfo));
}
configureNicDevice(vmMo, device, VirtualDeviceConfigSpecOperation.EDIT, "plugPublicNic");
} catch (Exception e) {
// restore allocation mask in case of exceptions
String nicMasksStr = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK);
int nicMasks = Integer.parseInt(nicMasksStr);
nicMasks &= ~(1 << nicIndex);
vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK, String.valueOf(nicMasks));
throw e;
}
}
use of com.vmware.vim25.mo.Network in project cloudstack by apache.
the class VmwareResource method getVirtualDevice.
private Pair<VirtualDevice, Integer> getVirtualDevice(VirtualMachineMO vmMo, IpAddressTO ip) throws Exception {
NicTO nicTO = ip.getNicTO();
URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
throw new InternalErrorException(String.format("Unable to assign a public IP to a VIF on network %s", ip.getBroadcastUri()));
}
String vlanId = BroadcastDomainType.getValue(broadcastUri);
String publicNetworkName = HypervisorHostHelper.getPublicNetworkNamePrefix(vlanId);
Pair<Integer, VirtualDevice> publicNicInfo = vmMo.getNicDeviceIndex(publicNetworkName);
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Find public NIC index, public network name: %s , index: %s", publicNetworkName, publicNicInfo.first()));
}
return new Pair<>(findVirtualNicDevice(vmMo, nicTO.getMac()), publicNicInfo.first());
}
Aggregations