Search in sources :

Example 51 with Network

use of com.vmware.vim25.mo.Network in project cloudstack by apache.

the class VirtualMachineMO method getNetworks.

public String[] getNetworks() throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Network");
    pSpec.getPathSet().add("name");
    TraversalSpec vm2NetworkTraversal = new TraversalSpec();
    vm2NetworkTraversal.setType("VirtualMachine");
    vm2NetworkTraversal.setPath("network");
    vm2NetworkTraversal.setName("vm2NetworkTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(vm2NetworkTraversal);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);
    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
    List<String> networks = new ArrayList<String>();
    if (ocs != null && ocs.size() > 0) {
        for (ObjectContent oc : ocs) {
            networks.add(oc.getPropSet().get(0).getVal().toString());
        }
    }
    return networks.toArray(new String[0]);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList)

Example 52 with Network

use of com.vmware.vim25.mo.Network in project cloudstack by apache.

the class HypervisorHostHelper method waitForNetworkReady.

public static ManagedObjectReference waitForNetworkReady(HostMO hostMo, String networkName, long timeOutMs) throws Exception {
    ManagedObjectReference morNetwork = null;
    // if portGroup is just created, getNetwork may fail to retrieve it, we
    // need to retry
    long startTick = System.currentTimeMillis();
    while (System.currentTimeMillis() - startTick <= timeOutMs) {
        morNetwork = hostMo.getNetworkMor(networkName);
        if (morNetwork != null) {
            break;
        }
        s_logger.info("Waiting for network " + networkName + " to be ready");
        Thread.sleep(1000);
    }
    return morNetwork;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 53 with Network

use of com.vmware.vim25.mo.Network in project cloudstack by apache.

the class HypervisorHostHelper method createPortGroup.

private static void createPortGroup(String physicalNetwork, String networkName, String vlanRange, Integer vid, Integer spvlanid, DatacenterMO dataCenterMo, DVSTrafficShapingPolicy shapingPolicy, DVSSecurityPolicy secPolicy, DVSMacManagementPolicy macManagementPolicy, VMwareDVSPortgroupPolicy portGroupPolicy, DistributedVirtualSwitchMO dvSwitchMo, int numPorts, boolean autoExpandSupported, boolean dvSwitchSupportNewPolicies) throws Exception {
    VmwareDistributedVirtualSwitchVlanSpec vlanSpec = null;
    VmwareDistributedVirtualSwitchPvlanSpec pvlanSpec = null;
    VMwareDVSPortSetting dvsPortSetting = null;
    DVPortgroupConfigSpec newDvPortGroupSpec;
    // NOTE - VmwareDistributedVirtualSwitchPvlanSpec extends VmwareDistributedVirtualSwitchVlanSpec.
    if (vid == null || spvlanid == null) {
        vlanSpec = createDVPortVlanSpec(vid, vlanRange);
        dvsPortSetting = createVmwareDVPortSettingSpec(shapingPolicy, secPolicy, macManagementPolicy, vlanSpec, dvSwitchSupportNewPolicies);
    } else if (spvlanid != null) {
        // Create a pvlan spec. The pvlan spec is different from the pvlan config spec
        // that we created earlier. The pvlan config spec is used to configure the switch
        // with a <primary vlanId, secondary vlanId> tuple. The pvlan spec is used
        // to configure a port group (i.e., a network) with a secondary vlan id. We don't
        // need to mention more than the secondary vlan id because one secondary vlan id
        // can be associated with only one primary vlan id. Give vCenter the secondary vlan id,
        // and it will find out the associated primary vlan id and do the rest of the
        // port group configuration.
        pvlanSpec = createDVPortPvlanIdSpec(spvlanid);
        dvsPortSetting = createVmwareDVPortSettingSpec(shapingPolicy, secPolicy, macManagementPolicy, pvlanSpec, dvSwitchSupportNewPolicies);
    }
    newDvPortGroupSpec = createDvPortGroupSpec(networkName, dvsPortSetting, autoExpandSupported);
    if (portGroupPolicy != null) {
        newDvPortGroupSpec.setPolicy(portGroupPolicy);
    }
    if (!dataCenterMo.hasDvPortGroup(networkName)) {
        s_logger.info("Distributed Virtual Port group " + networkName + " not found.");
        // TODO(sateesh): Handle Exceptions
        try {
            newDvPortGroupSpec.setNumPorts(numPorts);
            dvSwitchMo.createDVPortGroup(newDvPortGroupSpec);
        } catch (Exception e) {
            String msg = "Failed to create distributed virtual port group " + networkName + " on dvSwitch " + physicalNetwork;
            msg += ". " + VmwareHelper.getExceptionMessage(e);
            throw new Exception(msg);
        }
    } else {
        s_logger.info("Found Distributed Virtual Port group " + networkName);
        DVPortgroupConfigInfo currentDvPortgroupInfo = dataCenterMo.getDvPortGroupSpec(networkName);
        if (!isSpecMatch(currentDvPortgroupInfo, newDvPortGroupSpec, dvSwitchSupportNewPolicies)) {
            s_logger.info("Updating Distributed Virtual Port group " + networkName);
            newDvPortGroupSpec.setDefaultPortConfig(dvsPortSetting);
            newDvPortGroupSpec.setConfigVersion(currentDvPortgroupInfo.getConfigVersion());
            ManagedObjectReference morDvPortGroup = dataCenterMo.getDvPortGroupMor(networkName);
            try {
                dvSwitchMo.updateDvPortGroup(morDvPortGroup, newDvPortGroupSpec);
            } catch (Exception e) {
                String msg = "Failed to update distributed virtual port group " + networkName + " on dvSwitch " + physicalNetwork;
                msg += ". " + VmwareHelper.getExceptionMessage(e);
                throw new Exception(msg);
            }
        }
    }
}
Also used : VMwareDVSPortSetting(com.vmware.vim25.VMwareDVSPortSetting) VmwareDistributedVirtualSwitchPvlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchPvlanSpec) VmwareDistributedVirtualSwitchVlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec) DVPortgroupConfigSpec(com.vmware.vim25.DVPortgroupConfigSpec) InvalidParameterException(java.security.InvalidParameterException) CloudException(com.cloud.exception.CloudException) TransformerException(javax.xml.transform.TransformerException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DVPortgroupConfigInfo(com.vmware.vim25.DVPortgroupConfigInfo) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 54 with Network

use of com.vmware.vim25.mo.Network in project cloudstack by apache.

the class HostMO method getPortGroupNameByNicType.

public String getPortGroupNameByNicType(HostVirtualNicType nicType) throws Exception {
    assert (nicType != null);
    List<VirtualNicManagerNetConfig> netConfigs = _context.getVimClient().getDynamicProperty(_mor, "config.virtualNicManagerInfo.netConfig");
    if (netConfigs != null) {
        for (VirtualNicManagerNetConfig netConfig : netConfigs) {
            if (netConfig.getNicType().equals(nicType.toString())) {
                List<HostVirtualNic> nics = netConfig.getCandidateVnic();
                if (nics != null) {
                    for (HostVirtualNic nic : nics) {
                        return nic.getPortgroup();
                    }
                }
            }
        }
    }
    if (nicType == HostVirtualNicType.management) {
        // ESX management network is configured in service console
        HostNetworkInfo netInfo = getHostNetworkInfo();
        assert (netInfo != null);
        List<HostVirtualNic> nics = netInfo.getConsoleVnic();
        if (nics != null) {
            for (HostVirtualNic nic : nics) {
                return nic.getPortgroup();
            }
        }
    }
    return null;
}
Also used : HostVirtualNic(com.vmware.vim25.HostVirtualNic) HostNetworkInfo(com.vmware.vim25.HostNetworkInfo) VirtualNicManagerNetConfig(com.vmware.vim25.VirtualNicManagerNetConfig)

Example 55 with Network

use of com.vmware.vim25.mo.Network in project cloudstack by apache.

the class HostMO method waitForPortGroup.

public ManagedObjectReference waitForPortGroup(String networkName, long timeOutMs) throws Exception {
    ManagedObjectReference morNetwork = null;
    // if portGroup is just created, getNetwork may fail to retrieve it, we
    // need to retry
    long startTick = System.currentTimeMillis();
    while (System.currentTimeMillis() - startTick <= timeOutMs) {
        morNetwork = getNetworkMor(networkName);
        if (morNetwork != null) {
            break;
        }
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Waiting for network " + networkName + " to be ready");
        }
        Thread.sleep(1000);
    }
    return morNetwork;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

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