Search in sources :

Example 1 with CustomFieldStringValue

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

the class BaseMO method getCustomFieldValue.

public String getCustomFieldValue(String fieldName) throws Exception {
    int key = getCustomFieldKey(fieldName);
    if (key == 0)
        return null;
    CustomFieldStringValue cfValue = (CustomFieldStringValue) _context.getServiceUtil().getDynamicProperty(getMor(), String.format("value[%d]", key));
    if (cfValue != null)
        return cfValue.getValue();
    return null;
}
Also used : CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue)

Example 2 with CustomFieldStringValue

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

the class DatacenterMO method findVmByNameAndLabel.

public List<VirtualMachineMO> findVmByNameAndLabel(String vmLabel) throws Exception {
    CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager());
    int key = cfmMo.getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_UUID);
    assert (key != 0);
    List<VirtualMachineMO> list = new ArrayList<VirtualMachineMO>();
    ObjectContent[] ocs = getVmPropertiesOnDatacenterVmFolder(new String[] { "name", String.format("value[%d]", key) });
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            DynamicProperty[] props = oc.getPropSet();
            if (props != null) {
                for (DynamicProperty prop : props) {
                    if (prop.getVal() != null) {
                        if (prop.getName().equalsIgnoreCase("name")) {
                            if (prop.getVal().toString().equals(vmLabel)) {
                                list.add(new VirtualMachineMO(_context, oc.getObj()));
                                // break out inner loop
                                break;
                            }
                        } else if (prop.getVal() instanceof CustomFieldStringValue) {
                            String val = ((CustomFieldStringValue) prop.getVal()).getValue();
                            if (val.equals(vmLabel)) {
                                list.add(new VirtualMachineMO(_context, oc.getObj()));
                                // break out inner loop
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return list;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty) ArrayList(java.util.ArrayList) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue)

Example 3 with CustomFieldStringValue

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

the class HostDatastoreSystemMO method findDatastore.

public ManagedObjectReference findDatastore(String name) throws Exception {
    // added cloud.com 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);
    ObjectContent[] ocs = getDatastorePropertiesOnHostDatastoreSystem(new String[] { "name", String.format("value[%d]", key) });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            if (oc.getPropSet(0).getVal().equals(name))
                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(name))
                            return oc.getObj();
                    }
                }
            }
        }
    }
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue)

Example 4 with CustomFieldStringValue

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

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.setPathSet(new String[] { "name", "vm", 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.setSelectSet(new SelectionSpec[] { vm2NetworkTraversal });
    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 && ocs.length > 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() : 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)

Example 5 with CustomFieldStringValue

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

the class VmwareResource method getVmStates.

private HashMap<String, PowerState> getVmStates() 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, PowerState> newStates = new HashMap<String, PowerState>();
    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, convertPowerState(powerState));
                }
            }
        }
    }
    return newStates;
}
Also used : DynamicProperty(com.vmware.vim25.DynamicProperty) 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) PowerState(com.cloud.vm.VirtualMachine.PowerState) VirtualMachinePowerState(com.vmware.vim25.VirtualMachinePowerState)

Aggregations

DynamicProperty (com.vmware.vim25.DynamicProperty)18 ObjectContent (com.vmware.vim25.ObjectContent)18 CustomFieldStringValue (com.vmware.vim25.CustomFieldStringValue)13 ArrayList (java.util.ArrayList)5 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)4 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)4 HashMap (java.util.HashMap)4 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 ObjectSpec (com.vmware.vim25.ObjectSpec)2 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)2 PropertySpec (com.vmware.vim25.PropertySpec)2 TraversalSpec (com.vmware.vim25.TraversalSpec)2 VirtualMachinePowerState (com.vmware.vim25.VirtualMachinePowerState)2 RemoteException (java.rmi.RemoteException)2 HostVmStateReportEntry (com.cloud.agent.api.HostVmStateReportEntry)1 VmStatsEntry (com.cloud.agent.api.VmStatsEntry)1 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 VmwareManager (com.cloud.hypervisor.vmware.manager.VmwareManager)1