Search in sources :

Example 26 with HostSystem

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

the class ClusterMO method getVmPropertiesOnHyperHost.

@Override
public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
    TraversalSpec host2VmFolderTraversal = new TraversalSpec();
    host2VmFolderTraversal.setType("HostSystem");
    host2VmFolderTraversal.setPath("vm");
    host2VmFolderTraversal.setName("host2VmFolderTraversal");
    TraversalSpec cluster2HostFolderTraversal = new TraversalSpec();
    cluster2HostFolderTraversal.setType("ClusterComputeResource");
    cluster2HostFolderTraversal.setPath("host");
    cluster2HostFolderTraversal.setName("cluster2HostFolderTraversal");
    cluster2HostFolderTraversal.getSelectSet().add(host2VmFolderTraversal);
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(getMor());
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(cluster2HostFolderTraversal);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);
    List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() done");
    return properties.toArray(new ObjectContent[properties.size()]);
}
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) Gson(com.google.gson.Gson)

Example 27 with HostSystem

use of com.vmware.vim25.mo.HostSystem 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)

Aggregations

TraversalSpec (com.vmware.vim25.TraversalSpec)13 ObjectSpec (com.vmware.vim25.ObjectSpec)12 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)12 PropertySpec (com.vmware.vim25.PropertySpec)12 ObjectContent (com.vmware.vim25.ObjectContent)10 ArrayList (java.util.ArrayList)10 HostSystem (com.vmware.vim25.mo.HostSystem)9 Gson (com.google.gson.Gson)8 RemoteException (java.rmi.RemoteException)8 MalformedURLException (java.net.MalformedURLException)6 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)5 CIMObject (org.sblim.wbem.cim.CIMObject)5 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)4 HostSystemPowerState (com.vmware.vim25.HostSystemPowerState)4 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)4 VmwareViJavaAccess (org.opennms.protocols.vmware.VmwareViJavaAccess)4 SelectionSpec (com.vmware.vim25.SelectionSpec)3 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)3 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)2 AboutInfo (com.vmware.vim25.AboutInfo)2