Search in sources :

Example 21 with DynamicProperty

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

the class ClusterMO method findDatastore.

@Override
public ManagedObjectReference findDatastore(String poolUuid) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastore(). target MOR: " + _mor.get_value() + ", poolUuid: " + poolUuid);
    CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager());
    int key = cfmMo.getCustomFieldKey("Datastore", CustomFieldConstants.CLOUD_UUID);
    assert (key != 0);
    ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "name", String.format("value[%d]", key) });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            if (oc.getPropSet(0).getVal().equals(poolUuid))
                return oc.getObj();
            if (oc.getPropSet().length > 1) {
                DynamicProperty prop = oc.getPropSet(1);
                if (prop != null && prop.getVal() != null) {
                    if (prop.getVal() instanceof CustomFieldStringValue) {
                        String val = ((CustomFieldStringValue) prop.getVal()).getValue();
                        if (val.equalsIgnoreCase(poolUuid)) {
                            if (s_logger.isTraceEnabled())
                                s_logger.trace("vCenter API trace - findDatastore() done(successfully)");
                            return oc.getObj();
                        }
                    }
                }
            }
        }
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastore() done(failed)");
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue)

Example 22 with DynamicProperty

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

the class HostMO method getNetworkMor.

public ManagedObjectReference getNetworkMor(String portGroupName) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Network");
    pSpec.getPathSet().add("summary.name");
    TraversalSpec host2NetworkTraversal = new TraversalSpec();
    host2NetworkTraversal.setType("HostSystem");
    host2NetworkTraversal.setPath("network");
    host2NetworkTraversal.setName("host2NetworkTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(host2NetworkTraversal);
    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.getVal().equals(portGroupName))
                        return oc.getObj();
                }
            }
        }
    }
    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) ArrayList(java.util.ArrayList)

Example 23 with DynamicProperty

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

the class DatacenterMO method getDvPortGroupMor.

public ManagedObjectReference getDvPortGroupMor(String dvPortGroupName) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.getPathSet().add("name");
    TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
    datacenter2DvPortGroupTraversal.setType("Datacenter");
    datacenter2DvPortGroupTraversal.setPath("network");
    datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal);
    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.getVal().equals(dvPortGroupName))
                        return oc.getObj();
                }
            }
        }
    }
    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) ArrayList(java.util.ArrayList)

Example 24 with DynamicProperty

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

the class HostDatastoreSystemMO method findDatastore.

public ManagedObjectReference findDatastore(String name) throws Exception {
    // added Apache CloudStack specific name convention, we will use custom field "cloud.uuid" as datastore name as well
    CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager());
    int key = cfmMo.getCustomFieldKey("Datastore", CustomFieldConstants.CLOUD_UUID);
    assert (key != 0);
    List<ObjectContent> ocs = getDatastorePropertiesOnHostDatastoreSystem(new String[] { "name", String.format("value[%d]", key) });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            if (oc.getPropSet().get(0).getVal().equals(name))
                return oc.getObj();
            if (oc.getPropSet().size() > 1) {
                DynamicProperty prop = oc.getPropSet().get(1);
                if (prop != null && prop.getVal() != null) {
                    if (prop.getVal() instanceof CustomFieldStringValue) {
                        String val = ((CustomFieldStringValue) prop.getVal()).getValue();
                        if (val.equalsIgnoreCase(name))
                            return oc.getObj();
                    }
                }
            }
        }
    }
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue)

Example 25 with DynamicProperty

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

the class VmwareResource method getHostVmStateReport.

private HashMap<String, HostVmStateReportEntry> getHostVmStateReport() throws Exception {
    VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
    int key = ((HostMO) hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
    if (key == 0) {
        s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
    }
    String instanceNameCustomField = "value[" + key + "]";
    // CLOUD_VM_INTERNAL_NAME stores the internal CS generated vm name. This was earlier stored in name. Now, name can be either the hostname or
    // the internal CS name, but the custom field CLOUD_VM_INTERNAL_NAME always stores the internal CS name.
    ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] { "name", "runtime.powerState", "config.template", instanceNameCustomField });
    HashMap<String, HostVmStateReportEntry> newStates = new HashMap<String, HostVmStateReportEntry>();
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            List<DynamicProperty> objProps = oc.getPropSet();
            if (objProps != null) {
                boolean isTemplate = false;
                String name = null;
                String VMInternalCSName = null;
                VirtualMachinePowerState powerState = VirtualMachinePowerState.POWERED_OFF;
                for (DynamicProperty objProp : objProps) {
                    if (objProp.getName().equals("config.template")) {
                        if (objProp.getVal().toString().equalsIgnoreCase("true")) {
                            isTemplate = true;
                        }
                    } else if (objProp.getName().equals("runtime.powerState")) {
                        powerState = (VirtualMachinePowerState) objProp.getVal();
                    } else if (objProp.getName().equals("name")) {
                        name = (String) objProp.getVal();
                    } else if (objProp.getName().contains(instanceNameCustomField)) {
                        if (objProp.getVal() != null)
                            VMInternalCSName = ((CustomFieldStringValue) objProp.getVal()).getValue();
                    } else {
                        assert (false);
                    }
                }
                if (VMInternalCSName != null)
                    name = VMInternalCSName;
                if (!isTemplate) {
                    newStates.put(name, new HostVmStateReportEntry(convertPowerState(powerState), hyperHost.getHyperHostName()));
                }
            }
        }
    }
    return newStates;
}
Also used : DynamicProperty(com.vmware.vim25.DynamicProperty) HostVmStateReportEntry(com.cloud.agent.api.HostVmStateReportEntry) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HashMap(java.util.HashMap) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ObjectContent(com.vmware.vim25.ObjectContent) VirtualMachinePowerState(com.vmware.vim25.VirtualMachinePowerState)

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