Search in sources :

Example 26 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 27 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)

Example 28 with VirtualMachine

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

the class VSphereServiceConnectionWithMockedInventoryNavigator method shouldCallSearchManagedEntityAndReturnVMForDoItGetVirtualMachineById.

@Test
public void shouldCallSearchManagedEntityAndReturnVMForDoItGetVirtualMachineById() throws RemoteException {
    VSphereServiceConnectionWithMockedInventoryNavigator service = new VSphereServiceConnectionWithMockedInventoryNavigator();
    InventoryNavigator inventoryNavigatorMock = service.getInventoryNavigatorMock();
    VirtualMachine vmMock = mock(VirtualMachine.class);
    when(inventoryNavigatorMock.searchManagedEntity(VIRTUAL_MACHINE_TYPE_NAME, "instanceId")).thenReturn(vmMock);
    VirtualMachine actualVM = service.getVirtualMachineById("instanceId");
    verify(inventoryNavigatorMock).searchManagedEntity(VIRTUAL_MACHINE_TYPE_NAME, "instanceId");
    assertSame(vmMock, actualVM);
}
Also used : InventoryNavigator(com.vmware.vim25.mo.InventoryNavigator) VirtualMachine(com.vmware.vim25.mo.VirtualMachine) Test(org.testng.annotations.Test)

Example 29 with VirtualMachine

use of com.vmware.vim25.mo.VirtualMachine in project opennms by OpenNMS.

the class VmwareViJavaAccessTest method testGetVirtualMachineByManagedObjectId.

@Test
public void testGetVirtualMachineByManagedObjectId() throws Exception {
    replay(mockServiceInstance, MorUtil.class, ServiceInstance.class);
    try {
        vmwareViJavaAccess.connect();
    } catch (MalformedURLException e) {
        Assert.fail(e.getMessage());
    } catch (RemoteException e) {
        Assert.fail(e.getMessage());
    }
    VirtualMachine returnedVirtualMachine = vmwareViJavaAccess.getVirtualMachineByManagedObjectId("moIdVm");
    Assert.assertNotNull(returnedVirtualMachine);
    Assert.assertEquals(virtualMachine.getMOR().getVal(), returnedVirtualMachine.getMOR().getVal());
    verify(mockServiceInstance, MorUtil.class, ServiceInstance.class);
}
Also used : MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException) VirtualMachine(com.vmware.vim25.mo.VirtualMachine) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 30 with VirtualMachine

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

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)15 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)13 TraversalSpec (com.vmware.vim25.TraversalSpec)12 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)7 RemoteException (java.rmi.RemoteException)7 CustomFieldStringValue (com.vmware.vim25.CustomFieldStringValue)6 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)6 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)5 HashMap (java.util.HashMap)5 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)4 Gson (com.google.gson.Gson)4 VirtualMachinePowerState (com.vmware.vim25.VirtualMachinePowerState)4 InventoryNavigator (com.vmware.vim25.mo.InventoryNavigator)4 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)3 HostSystemPowerState (com.vmware.vim25.HostSystemPowerState)3