Search in sources :

Example 16 with DynamicProperty

use of com.vmware.vim25.DynamicProperty in project cloudstack by apache.

the class HostMO method getVmVncPortsOnHost.

public HashMap<String, Integer> getVmVncPortsOnHost() throws Exception {
    int key = getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
    if (key == 0) {
        s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
    }
    ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name", "config.extraConfig[\"RemoteDisplay.vnc.port\"]", "value[" + key + "]" });
    HashMap<String, Integer> portInfo = new HashMap<String, Integer>();
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            List<DynamicProperty> objProps = oc.getPropSet();
            if (objProps != null) {
                String vmName = null;
                String value = null;
                String vmInternalCSName = null;
                for (DynamicProperty objProp : objProps) {
                    if (objProp.getName().equals("name")) {
                        vmName = (String) objProp.getVal();
                    } else if (objProp.getName().startsWith("value[")) {
                        if (objProp.getVal() != null)
                            vmInternalCSName = ((CustomFieldStringValue) objProp.getVal()).getValue();
                    } else {
                        OptionValue optValue = (OptionValue) objProp.getVal();
                        value = (String) optValue.getValue();
                    }
                }
                if (vmInternalCSName != null && isUserVMInternalCSName(vmInternalCSName))
                    vmName = vmInternalCSName;
                if (vmName != null && value != null) {
                    portInfo.put(vmName, Integer.parseInt(value));
                }
            }
        }
    }
    return portInfo;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty) HashMap(java.util.HashMap) OptionValue(com.vmware.vim25.OptionValue)

Example 17 with DynamicProperty

use of com.vmware.vim25.DynamicProperty in project cloudstack by apache.

the class HypervisorHostHelper method findVmFromObjectContent.

public static VirtualMachineMO findVmFromObjectContent(VmwareContext context, ObjectContent[] ocs, String name, String instanceNameCustomField) {
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            String vmNameInvCenter = null;
            String vmInternalCSName = null;
            List<DynamicProperty> objProps = oc.getPropSet();
            if (objProps != null) {
                for (DynamicProperty objProp : objProps) {
                    if (objProp.getName().equals("name")) {
                        vmNameInvCenter = (String) objProp.getVal();
                    } else if (objProp.getName().contains(instanceNameCustomField)) {
                        if (objProp.getVal() != null)
                            vmInternalCSName = ((CustomFieldStringValue) objProp.getVal()).getValue();
                    }
                    if ((vmNameInvCenter != null && name.equalsIgnoreCase(vmNameInvCenter)) || (vmInternalCSName != null && name.equalsIgnoreCase(vmInternalCSName))) {
                        VirtualMachineMO vmMo = new VirtualMachineMO(context, oc.getObj());
                        return vmMo;
                    }
                }
            }
        }
    }
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty)

Example 18 with DynamicProperty

use of com.vmware.vim25.DynamicProperty in project cloudstack by apache.

the class VirtualMachineMO method getFileLayout.

public VirtualMachineFileLayoutEx getFileLayout() throws Exception {
    VirtualMachineFileLayoutEx fileLayout = null;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("VirtualMachine");
    pSpec.getPathSet().add("layoutEx");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.FALSE);
    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) {
        for (ObjectContent oc : ocs) {
            List<DynamicProperty> props = oc.getPropSet();
            if (props != null) {
                for (DynamicProperty prop : props) {
                    if (prop.getName().equals("layoutEx")) {
                        fileLayout = (VirtualMachineFileLayoutEx) prop.getVal();
                        break;
                    }
                }
            }
        }
    }
    return fileLayout;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) DynamicProperty(com.vmware.vim25.DynamicProperty) ArrayList(java.util.ArrayList) VirtualMachineFileLayoutEx(com.vmware.vim25.VirtualMachineFileLayoutEx)

Example 19 with DynamicProperty

use of com.vmware.vim25.DynamicProperty in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method getOwnerDatastore.

public Pair<DatastoreMO, String> getOwnerDatastore(String dsFullPath) throws Exception {
    String dsName = DatastoreFile.getDatastoreNameFromPath(dsFullPath);
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.setPathSet(new String[] { "name" });
    TraversalSpec vmDatastoreTraversal = new TraversalSpec();
    vmDatastoreTraversal.setType("VirtualMachine");
    vmDatastoreTraversal.setPath("datastore");
    vmDatastoreTraversal.setName("vmDatastoreTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { vmDatastoreTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    ObjectContent[] ocs = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            DynamicProperty prop = oc.getPropSet(0);
            if (prop.getVal().toString().equals(dsName)) {
                return new Pair<DatastoreMO, String>(new DatastoreMO(_context, oc.getObj()), dsName);
            }
        }
    }
    return null;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) DynamicProperty(com.vmware.vim25.DynamicProperty) TraversalSpec(com.vmware.vim25.TraversalSpec) Pair(com.cloud.utils.Pair)

Example 20 with DynamicProperty

use of com.vmware.vim25.DynamicProperty in project CloudStack-archive by CloudStack-extras.

the class ClusterMO method getVmVncPortsOnCluster.

public HashMap<String, Integer> getVmVncPortsOnCluster() throws Exception {
    ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name", "config.extraConfig[\"RemoteDisplay.vnc.port\"]" });
    HashMap<String, Integer> portInfo = new HashMap<String, Integer>();
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            DynamicProperty[] objProps = oc.getPropSet();
            if (objProps != null) {
                String name = null;
                String value = null;
                for (DynamicProperty objProp : objProps) {
                    if (objProp.getName().equals("name")) {
                        name = (String) objProp.getVal();
                    } else {
                        OptionValue optValue = (OptionValue) objProp.getVal();
                        value = (String) optValue.getValue();
                    }
                }
                if (name != null && value != null) {
                    portInfo.put(name, Integer.parseInt(value));
                }
            }
        }
    }
    return portInfo;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty) HashMap(java.util.HashMap) OptionValue(com.vmware.vim25.OptionValue)

Aggregations

DynamicProperty (com.vmware.vim25.DynamicProperty)34 ObjectContent (com.vmware.vim25.ObjectContent)34 ObjectSpec (com.vmware.vim25.ObjectSpec)16 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)16 PropertySpec (com.vmware.vim25.PropertySpec)16 ArrayList (java.util.ArrayList)14 TraversalSpec (com.vmware.vim25.TraversalSpec)12 CustomFieldStringValue (com.vmware.vim25.CustomFieldStringValue)9 HashMap (java.util.HashMap)7 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)4 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)4 OptionValue (com.vmware.vim25.OptionValue)4 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)2 Pair (com.cloud.utils.Pair)2 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)2 DVPortgroupConfigInfo (com.vmware.vim25.DVPortgroupConfigInfo)2 VirtualMachineFileInfo (com.vmware.vim25.VirtualMachineFileInfo)2 VirtualMachinePowerState (com.vmware.vim25.VirtualMachinePowerState)2 HostVmStateReportEntry (com.cloud.agent.api.HostVmStateReportEntry)1