Search in sources :

Example 61 with Network

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);
    }
}
Also used : VmwareTrafficLabel(com.cloud.network.VmwareTrafficLabel) AboutInfo(com.vmware.vim25.AboutInfo) HostFirewallSystemMO(com.cloud.hypervisor.vmware.mo.HostFirewallSystemMO) VirtualSwitchType(com.cloud.hypervisor.vmware.mo.VirtualSwitchType)

Example 62 with Network

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);
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VmwareHypervisorHostNetworkSummary(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary) ClusterMO(com.cloud.hypervisor.vmware.mo.ClusterMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Example 63 with Network

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;
}
Also used : VirtualSwitchType(com.cloud.hypervisor.vmware.mo.VirtualSwitchType) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 64 with Network

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;
    }
}
Also used : VirtualEthernetCardNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualSwitchType(com.cloud.hypervisor.vmware.mo.VirtualSwitchType) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Example 65 with Network

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());
}
Also used : VirtualDevice(com.vmware.vim25.VirtualDevice) InternalErrorException(com.cloud.exception.InternalErrorException) URI(java.net.URI) NicTO(com.cloud.agent.api.to.NicTO) Pair(com.cloud.utils.Pair)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)39 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)21 IOException (java.io.IOException)19 CloudException (com.cloud.exception.CloudException)17 ArrayList (java.util.ArrayList)16 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)14 TraversalSpec (com.vmware.vim25.TraversalSpec)14 ObjectSpec (com.vmware.vim25.ObjectSpec)13 PropertySpec (com.vmware.vim25.PropertySpec)13 RemoteException (java.rmi.RemoteException)13 Pair (com.cloud.utils.Pair)12 ObjectContent (com.vmware.vim25.ObjectContent)12 UnsupportedEncodingException (java.io.UnsupportedEncodingException)12 InternalErrorException (com.cloud.exception.InternalErrorException)11 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)11 ConfigurationException (javax.naming.ConfigurationException)11 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)10 DynamicProperty (com.vmware.vim25.DynamicProperty)10 VirtualDevice (com.vmware.vim25.VirtualDevice)10 ConnectException (java.net.ConnectException)10