Search in sources :

Example 36 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 37 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 38 with Network

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

the class VirtualMachineMO method getNetworksWithDetails.

public List<NetworkDetails> getNetworksWithDetails() throws Exception {
    List<NetworkDetails> networks = new ArrayList<NetworkDetails>();
    int gcTagKey = getCustomFieldKey("Network", CustomFieldConstants.CLOUD_GC);
    if (gcTagKey == 0) {
        gcTagKey = getCustomFieldKey("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP);
        s_logger.debug("The custom key for dvPortGroup is : " + gcTagKey);
    }
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Network");
    pSpec.getPathSet().add("name");
    pSpec.getPathSet().add("vm");
    pSpec.getPathSet().add(String.format("value[%d]", gcTagKey));
    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);
    if (ocs != null && ocs.size() > 0) {
        for (ObjectContent oc : ocs) {
            ArrayOfManagedObjectReference morVms = null;
            String gcTagValue = null;
            String name = null;
            for (DynamicProperty prop : oc.getPropSet()) {
                if (prop.getName().equals("name"))
                    name = prop.getVal().toString();
                else if (prop.getName().equals("vm"))
                    morVms = (ArrayOfManagedObjectReference) prop.getVal();
                else if (prop.getName().startsWith("value[")) {
                    CustomFieldStringValue val = (CustomFieldStringValue) prop.getVal();
                    if (val != null)
                        gcTagValue = val.getValue();
                }
            }
            NetworkDetails details = new NetworkDetails(name, oc.getObj(), (morVms != null ? morVms.getManagedObjectReference().toArray(new ManagedObjectReference[morVms.getManagedObjectReference().size()]) : null), gcTagValue);
            networks.add(details);
        }
        s_logger.debug("Retrieved " + networks.size() + " networks with key : " + gcTagKey);
    }
    return networks;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) DynamicProperty(com.vmware.vim25.DynamicProperty) ArrayList(java.util.ArrayList) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)23 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 ObjectContent (com.vmware.vim25.ObjectContent)12 ObjectSpec (com.vmware.vim25.ObjectSpec)12 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)12 PropertySpec (com.vmware.vim25.PropertySpec)12 TraversalSpec (com.vmware.vim25.TraversalSpec)12 ArrayList (java.util.ArrayList)11 CloudException (com.cloud.exception.CloudException)10 DynamicProperty (com.vmware.vim25.DynamicProperty)10 IOException (java.io.IOException)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 RemoteException (java.rmi.RemoteException)9 Pair (com.cloud.utils.Pair)8 ConfigurationException (javax.naming.ConfigurationException)8 InternalErrorException (com.cloud.exception.InternalErrorException)7 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)7 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)7 ConnectException (java.net.ConnectException)7 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)6