Search in sources :

Example 16 with VirtualMachine

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

the class HostMO method loadVmCache.

private void loadVmCache() throws Exception {
    if (s_logger.isDebugEnabled())
        s_logger.debug("load VM cache on host");
    _vmCache.clear();
    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 ?!");
    }
    // name is the name of the VM as it appears in vCenter. The CLOUD_VM_INTERNAL_NAME custom
    // field value contains the name of the VM as it is maintained internally by cloudstack (i-x-y).
    ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name", "value[" + key + "]" });
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            List<DynamicProperty> props = oc.getPropSet();
            if (props != null) {
                String vmVcenterName = null;
                String vmInternalCSName = null;
                for (DynamicProperty prop : props) {
                    if (prop.getName().equals("name")) {
                        vmVcenterName = prop.getVal().toString();
                    } else if (prop.getName().startsWith("value[")) {
                        if (prop.getVal() != null)
                            vmInternalCSName = ((CustomFieldStringValue) prop.getVal()).getValue();
                    }
                }
                String vmName = null;
                if (vmInternalCSName != null && isUserVMInternalCSName(vmInternalCSName)) {
                    vmName = vmInternalCSName;
                } else {
                    vmName = vmVcenterName;
                }
                if (s_logger.isTraceEnabled())
                    s_logger.trace("put " + vmName + " into host cache");
                _vmCache.put(vmName, new VirtualMachineMO(_context, oc.getObj()));
            }
        }
    }
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty)

Example 17 with VirtualMachine

use of com.vmware.vim25.mo.VirtualMachine 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 18 with VirtualMachine

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

use of com.vmware.vim25.mo.VirtualMachine in project SimianArmy by Netflix.

the class VSphereClient method describeAutoScalingGroups.

@Override
public List<AutoScalingGroup> describeAutoScalingGroups(String... names) {
    final VSphereGroups groups = new VSphereGroups();
    try {
        connection.connect();
        for (VirtualMachine virtualMachine : connection.describeVirtualMachines()) {
            String instanceId = virtualMachine.getName();
            String groupName = virtualMachine.getParent().getName();
            boolean shouldAddNamedGroup = true;
            if (names != null) {
                // TODO need to implement this feature!!!
                throw new RuntimeException("This feature (selecting groups by name) is not implemented yet");
            }
            if (shouldAddNamedGroup) {
                groups.addInstance(instanceId, groupName);
            }
        }
    } finally {
        connection.disconnect();
    }
    return groups.asList();
}
Also used : VirtualMachine(com.vmware.vim25.mo.VirtualMachine)

Example 20 with VirtualMachine

use of com.vmware.vim25.mo.VirtualMachine in project SimianArmy by Netflix.

the class VSphereClient method terminateInstance.

@Override
public /**
     * reinstall the given instance. If it is powered down this will be ignored and the
     * reinstall occurs the next time the machine is powered up.
     */
void terminateInstance(String instanceId) {
    try {
        connection.connect();
        VirtualMachine virtualMachine = connection.getVirtualMachineById(instanceId);
        this.terminationStrategy.terminate(virtualMachine);
    } catch (RemoteException e) {
        throw new AmazonServiceException("cannot destroy & recreate " + instanceId, e);
    } finally {
        connection.disconnect();
    }
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) RemoteException(java.rmi.RemoteException) VirtualMachine(com.vmware.vim25.mo.VirtualMachine)

Aggregations

ObjectContent (com.vmware.vim25.ObjectContent)22 DynamicProperty (com.vmware.vim25.DynamicProperty)16 ObjectSpec (com.vmware.vim25.ObjectSpec)15 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)15 PropertySpec (com.vmware.vim25.PropertySpec)15 ArrayList (java.util.ArrayList)14 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)13 TraversalSpec (com.vmware.vim25.TraversalSpec)12 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)7 RemoteException (java.rmi.RemoteException)7 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)6 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)5 CustomFieldStringValue (com.vmware.vim25.CustomFieldStringValue)5 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)4 Gson (com.google.gson.Gson)4 InventoryNavigator (com.vmware.vim25.mo.InventoryNavigator)4 HashMap (java.util.HashMap)4 PerfCounterInfo (com.vmware.vim25.PerfCounterInfo)3 VirtualMachinePowerState (com.vmware.vim25.VirtualMachinePowerState)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3