Package org.jclouds.cloudstack.domain

Examples of org.jclouds.cloudstack.domain.VirtualMachine


      expect(client.getVirtualMachineClient()).andReturn(virtualMachineClient);
   }

   @Test
   public void testWaitForVirtualMachineToBeExpunged() {
      VirtualMachine virtualMachine = VirtualMachine.builder().id("229").build();
      expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(null);

      replay(client, virtualMachineClient);
      assertTrue(new VirtualMachineExpunged(client).apply(virtualMachine));
      verify(client, virtualMachineClient);
   }
View Full Code Here


      verify(client, virtualMachineClient);
   }

   @Test
   public void testNoRemovedYet() {
      VirtualMachine virtualMachine = VirtualMachine.builder().id("229").build();
      expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine);

      replay(client, virtualMachineClient);
      assertFalse(new VirtualMachineExpunged(client).apply(virtualMachine));
      verify(client, virtualMachineClient);
   }
View Full Code Here

      expect(client.getVirtualMachineClient()).andReturn(virtualMachineClient);
   }

   @Test
   public void testIsDestroyed() {
      VirtualMachine virtualMachine = VirtualMachine.builder().
         id("229").state(VirtualMachine.State.DESTROYED).build();

      expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine);

      replay(client, virtualMachineClient);
      assertTrue(new VirtualMachineDestroyed(client).apply(virtualMachine));
      verify(client, virtualMachineClient);
   }
View Full Code Here

      verify(client, virtualMachineClient);
   }

   @Test
   public void testStillRunning() {
      VirtualMachine virtualMachine = VirtualMachine.builder().
         id("229").state(VirtualMachine.State.RUNNING).build();

      expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine);

      replay(client, virtualMachineClient);
      assertFalse(new VirtualMachineDestroyed(client).apply(virtualMachine));
      verify(client, virtualMachineClient);
   }
View Full Code Here

   @Test
   public void testCreateVMWithoutSecurityGroupAssignsDefault() throws Exception {
      skipIfSecurityGroupsNotSupported();
      String defaultTemplate = template != null ? template.getImageId() : null;
      VirtualMachine newVm = VirtualMachineClientLiveTest.createVirtualMachineWithOptionsInZone(DeployVirtualMachineOptions.NONE,
            zone.getId(), defaultTemplateOrPreferredInZone(defaultTemplate, client, zone.getId()), client,
            jobComplete, virtualMachineRunning);
      try {
         VirtualMachine runningVm = client.getVirtualMachineClient().getVirtualMachine(newVm.getId());
         assertEquals(1, runningVm.getSecurityGroups().size());
         assertEquals(Iterables.getOnlyElement(runningVm.getSecurityGroups()).getName(), "default");
      } finally {
         assertTrue(jobComplete.apply(client.getVirtualMachineClient().destroyVirtualMachine(newVm.getId())));
      }
   }
View Full Code Here

      logger.debug("serviceOfferingId %s, templateId %s, zoneId %s, options %s%n", serviceOfferingId, templateId,
         zoneId, options);
      AsyncCreateResponse job = client.getVirtualMachineClient().deployVirtualMachineInZone(zoneId, serviceOfferingId,
         templateId, options);
      VirtualMachine vm = blockUntilJobCompletesAndReturnResult.<VirtualMachine>apply(job);
      logger.debug("--- virtualmachine: %s", vm);
      LoginCredentials credentials = null;
      if (vm.isPasswordEnabled()) {
         assert vm.getPassword() != null : vm;
         credentials = LoginCredentials.builder().password(vm.getPassword()).build();
      } else {
         credentials = LoginCredentials.fromCredentials(credentialStore.get("keypair#" + templateOptions.getKeyPair()));
      }
      if (templateOptions.shouldSetupStaticNat()) {
         Capabilities capabilities = client.getConfigurationClient().listCapabilities();
         // TODO: possibly not all network ids, do we want to do this
         for (String networkId : options.getNetworkIds()) {
            logger.debug(">> creating static NAT for virtualMachine(%s) in network(%s)", vm.getId(), networkId);
            PublicIPAddress ip = staticNATVMInNetwork.create(networks.get(networkId)).apply(vm);
            logger.trace("<< static NATed IPAddress(%s) to virtualMachine(%s)", ip.getId(), vm.getId());
            vm = client.getVirtualMachineClient().getVirtualMachine(vm.getId());
            List<Integer> ports = Ints.asList(templateOptions.getInboundPorts());
            if (capabilities.getCloudStackVersion().startsWith("2")) {
               logger.debug(">> setting up IP forwarding for IPAddress(%s) rules(%s)", ip.getId(), ports);
               Set<IPForwardingRule> rules = setupPortForwardingRulesForIP.apply(ip, ports);
               logger.trace("<< setup %d IP forwarding rules on IPAddress(%s)", rules.size(), ip.getId());
            } else {
               logger.debug(">> setting up firewall rules for IPAddress(%s) rules(%s)", ip.getId(), ports);
               Set<FirewallRule> rules = setupFirewallRulesForIP.apply(ip, ports);
               logger.trace("<< setup %d firewall rules on IPAddress(%s)", rules.size(), ip.getId());
            }
         }
      }
      return new NodeAndInitialCredentials<VirtualMachine>(vm, vm.getId() + "", credentials);
   }
View Full Code Here

      AsyncJob<VirtualMachine> jobWithResult = client.getAsyncJobClient().<VirtualMachine> getAsyncJob(job.getJobId());
      if (jobWithResult.getError() != null)
         Throwables.propagate(new ExecutionException(String.format("job %s failed with exception %s", job.getId(),
               jobWithResult.getError().toString())) {
         });
      VirtualMachine vm = jobWithResult.getResult();
      if (vm.isPasswordEnabled()) {
         assert vm.getPassword() != null : vm;
      }
      assertTrue(virtualMachineRunning.apply(vm));
      assertEquals(vm.getServiceOfferingId(), serviceOfferingId);
      assertEquals(vm.getTemplateId(), templateId);
      assertEquals(vm.getZoneId(), zoneId);
      return vm;
   }
View Full Code Here

   public void testListVirtualMachines() throws Exception {
      Set<VirtualMachine> response = client.getVirtualMachineClient().listVirtualMachines();
      assert null != response;
      assertTrue(response.size() >= 0);
      for (VirtualMachine vm : response) {
         VirtualMachine newDetails = getOnlyElement(client.getVirtualMachineClient().listVirtualMachines(
               ListVirtualMachinesOptions.Builder.id(vm.getId())));
         assertEquals(vm.getId(), newDetails.getId());
         checkVm(vm);
      }
   }
View Full Code Here

      final Volume volume = createPreferredVolumeFromDisk();
      try {

         checkVolume(volume);

         VirtualMachine virtualMachine = getPreferredVirtualMachine();

         logger.info("attaching volume %s to vm %s", volume, virtualMachine);
         AsyncCreateResponse job = client.getVolumeClient().attachVolume(volume.getId(), virtualMachine.getId());
         assertTrue(jobComplete.apply(job.getJobId()));
         Volume attachedVolume = findVolumeWithId(volume.getId());

         checkVolume(attachedVolume);
         assertEquals(virtualMachine.getId(), attachedVolume.getVirtualMachineId());
         assertNotNull(attachedVolume.getAttached());

         logger.info("detaching volume %s from vm %s", volume, virtualMachine);
         job = client.getVolumeClient().detachVolume(volume.getId());
         assertTrue(jobComplete.apply(job.getJobId()));
View Full Code Here

      AsyncJob<VirtualMachine> jobWithResult = client.getAsyncJobApi().<VirtualMachine> getAsyncJob(job.getJobId());
      if (jobWithResult.getError() != null)
         Throwables.propagate(new ExecutionException(String.format("job %s failed with exception %s", job.getId(),
               jobWithResult.getError().toString())) {
         });
      VirtualMachine vm = jobWithResult.getResult();
      if (vm.isPasswordEnabled()) {
         assert vm.getPassword() != null : vm;
      }
      assertTrue(virtualMachineRunning.apply(vm));
      assertEquals(vm.getServiceOfferingId(), serviceOfferingId);
      assertEquals(vm.getTemplateId(), templateId);
      assertEquals(vm.getZoneId(), zoneId);
      return vm;
   }
View Full Code Here

TOP

Related Classes of org.jclouds.cloudstack.domain.VirtualMachine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.