Examples of VirtualMachine


Examples of org.jclouds.cloudstack.domain.VirtualMachine

      this.jobComplete = checkNotNull(jobComplete, "jobComplete");
   }

   @Override
   public ImageTemplate buildImageTemplateFromNode(String name, String id) {
      VirtualMachine vm = client.getVirtualMachineClient().getVirtualMachine(id);
      if (vm == null)
         throw new NoSuchElementException("Cannot find vm with id: " + id);
      CloneImageTemplate template = new ImageTemplateBuilder.CloneImageTemplateBuilder().nodeId(id).name(name).build();
      return template;
   }
View Full Code Here

Examples of org.jclouds.cloudstack.domain.VirtualMachine

   public ListenableFuture<Image> createImage(ImageTemplate template) {
      checkState(template instanceof CloneImageTemplate,
               " cloudstack only currently supports creating images through cloning.");
      CloneImageTemplate cloneTemplate = (CloneImageTemplate) template;

      VirtualMachine vm = client.getVirtualMachineClient().getVirtualMachine(cloneTemplate.getSourceNodeId());
      String stopJob = client.getVirtualMachineClient().stopVirtualMachine(vm.getId());
      jobComplete.apply(stopJob);

      Set<Volume> volumes = client.getVolumeClient().listVolumes(ListVolumesOptions.Builder.virtualMachineId(vm.getId()));
      Volume volume = Iterables.getOnlyElement(volumes);
     
      CreateTemplateOptions options = CreateTemplateOptions.Builder.volumeId(volume.getId());
      AsyncCreateResponse templateJob = client.getTemplateClient().createTemplate(TemplateMetadata.builder()
                                                                                  .name(cloneTemplate.getName())
                                                                                  .osTypeId(vm.getGuestOSId())
                                                                                  .displayText(cloneTemplate.getName())
                                                                                  .build(), options);
      Template newTemplate = blockUntilJobCompletesAndReturnResult.<Template>apply(templateJob);

      logger.info(">> Registered new template %s, waiting for it to become available.", newTemplate.getId());

      final AtomicReference<Image> image = Atomics.newReference(new ImageBuilder()
                                                                .location(find(locations.get(), idEquals(vm.getZoneId())))
                                                                .id(newTemplate.getId())
                                                                .providerId(newTemplate.getId())
                                                                .description(cloneTemplate.getName())
                                                                .operatingSystem(OperatingSystem.builder().description(cloneTemplate.getName()).build())
                                                                .status(Image.Status.PENDING).build());
View Full Code Here

Examples of org.jclouds.cloudstack.domain.VirtualMachine

      assertPredicateResult(State.ERROR, true);
   }

   private void assertPredicateResult(State state, boolean expected) {
      String virtualMachineId = "229";
      VirtualMachine virtualMachine = VirtualMachine.builder().
         id(virtualMachineId).state(state).build();

      expect(virtualMachineClient.getVirtualMachine(virtualMachineId)).andReturn(virtualMachine);
      replay(client, virtualMachineClient);
View Full Code Here

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

Examples of org.jclouds.cloudstack.domain.VirtualMachine

      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

Examples of org.jclouds.cloudstack.domain.VirtualMachine

      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

Examples of org.jclouds.cloudstack.domain.VirtualMachine

      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

Examples of org.opennebula.client.vm.VirtualMachine

            int newVMID = Integer.parseInt(rc.getMessage());
            System.out.println("ok, ID " + newVMID + ".");

            // We can create a representation for the new VM, using the returned
            // VM-ID
            VirtualMachine vm = new VirtualMachine(newVMID, oneClient);

            // Let's hold the VM, so the scheduler won't try to deploy it
            System.out.print("Trying to hold the new VM... ");
            rc = vm.hold();

            if(rc.isError())
            {
                System.out.println("failed!");
                throw new Exception( rc.getErrorMessage() );
            }
            else
                System.out.println("ok.");

            // And now we can request its information.
            rc = vm.info();

            if(rc.isError())
                throw new Exception( rc.getErrorMessage() );

            System.out.println();
            System.out.println(
                    "This is the information OpenNebula stores for the new VM:");
            System.out.println(rc.getMessage() + "\n");

            // This VirtualMachine object has some helpers, so we can access its
            // attributes easily (remember to load the data first using the info
            // method).
            System.out.println("The new VM " +
                    vm.getName() + " has status: " + vm.status());

            // And we can also use xpath expressions
            System.out.println("The path of the disk is");
            System.out.println( "\t" + vm.xpath("template/disk/source") );

            // Let's delete the VirtualMachine object.
            vm = null;

            // The reference is lost, but we can ask OpenNebula about the VM
            // again. This time however, we are going to use the VM pool
            VirtualMachinePool vmPool = new VirtualMachinePool(oneClient);
            // Remember that we have to ask the pool to retrieve the information
            // from OpenNebula
            rc = vmPool.info();

            if(rc.isError())
                throw new Exception( rc.getErrorMessage() );

            System.out.println(
                    "\nThese are all the Virtual Machines in the pool:");
            for ( VirtualMachine vmachine : vmPool )
            {
                System.out.println("\tID :" + vmachine.getId() +
                                   ", Name :" + vmachine.getName() );

                // Check if we have found the VM we are looking for
                if ( vmachine.getId().equals( ""+newVMID ) )
                {
                    vm = vmachine;
                }
            }

            // We have also some useful helpers for the actions you can perform
            // on a virtual machine, like cancel:
            rc = vm.cancel();
            System.out.println("\nTrying to cancel the VM " + vm.getId() +
                                " (should fail)...");

            // This is all the information you can get from the OneResponse:
            System.out.println("\tOpenNebula response");
            System.out.println("\t  Error:  " + rc.isError());
            System.out.println("\t  Msg:    " + rc.getMessage());
            System.out.println("\t  ErrMsg: " + rc.getErrorMessage());

            rc = vm.finalizeVM();
            System.out.println("\nTrying to finalize (delete) the VM " +
                                vm.getId() + "...");

            System.out.println("\tOpenNebula response");
            System.out.println("\t  Error:  " + rc.isError());
            System.out.println("\t  Msg:    " + rc.getMessage());
            System.out.println("\t  ErrMsg: " + rc.getErrorMessage());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.