Package com.vmware.aurora.vc

Examples of com.vmware.aurora.vc.VcVirtualMachine$DiskCreateSpec


      }
      return (new Gson()).toJson(volumes);
   }

   public static void destroyVm(final String vmId) throws Exception {
      VcVirtualMachine vm = VcCache.getIgnoreMissing(vmId);

      FaultToleranceConfigInfo info = vm.getConfig().getFtInfo();
      if (info != null && info.getRole() == 1) {
         logger.info("VM " + vm.getName()
               + " is FT primary VM, disable FT before delete it.");
         vm.turnOffFT();
      }
      // try guest shut down first, wait for 3 minutes, power it off after time out
      if (vm.isPoweredOn()
            && !vm.shutdownGuest(Constants.VM_FAST_SHUTDOWN_WAITING_SEC * 1000)) {
         vm.powerOff();
      }

      /*
       * TRICK: destroy vm with unaccessible disks will throw exceptions, ignore
       * it and destroy it again.
       */
      try {
         vm.destroy(false);
      } catch (Exception e) {
         logger.warn("failed to delete vm " + vm.getName() + " as "
               + e.getMessage());
         logger.info("try to unregister it again");
         vm.unregister();
      }
      logger.info("VM " + vm.getName() + " deleted");
   }
View Full Code Here


   /* (non-Javadoc)
    * @see java.util.concurrent.Callable#call()
    */
   @Override
   public Void call() throws Exception {
      final VcVirtualMachine vcVm = VcCache.getIgnoreMissing(vmId);
      if (vcVm == null) {
         logger.info("vm: " + vmId + " is not found.");
         return null;
      }
      if (vcVm.isPoweredOn()) {
         logger.info("vm " + vcVm.getName()
               + " must be powered off before scaling");
         return null;
      }
      logger.info("scale vm,vmId:" + vmId + ",cpuNumber:" + cpuNumber
            + ",memory:" + memory);
      return VcContext.inVcSessionDo(new VcSession<Void>() {
         @Override
         protected Void body() throws Exception {           
            //start config vm if max configuration check is passed
            ConfigSpecImpl newConfigSpec = new ConfigSpecImpl();
            if (cpuNumber > 0) {
               newConfigSpec.setNumCPUs(cpuNumber);
            }
            if (memory > 0) {
               VmConfigUtil.setMemoryAndBalloon(newConfigSpec, memory);

               if (targetDs != null) {
                  logger.info("current ds swap disk placed: "
                        + swapDisk.getDatastoreName());
                  logger.info("target ds to place swap disk: "
                        + targetDs.getName());
                  vcVm.detachVirtualDisk(
                        new DeviceId(swapDisk.getExternalAddress()), true);
                  AllocationType allocType =
                        swapDisk.getAllocType() == null ? null : AllocationType
                              .valueOf(swapDisk.getAllocType());
                  DiskCreateSpec[] addDisks =
                        { new DiskCreateSpec(new DeviceId(swapDisk
                              .getExternalAddress()), targetDs, swapDisk
                              .getName(), DiskMode.independent_persistent,
                              DiskSize.sizeFromMB(newSwapSizeInMB), allocType) };
                  // changeDisks() will run vcVm.reconfigure() itself
                  vcVm.changeDisks(null, addDisks);
               }
            }

            vcVm.reconfigure(newConfigSpec);
            return null;
         }

         protected boolean isTaskSession() {
            return true;
View Full Code Here

   public static VcVirtualMachine findVmInRp(final VcResourcePool rp,
         final String vmName) {
      return VcContext.inVcSessionDo(new VcSession<VcVirtualMachine>() {
         @Override
         protected VcVirtualMachine body() throws Exception {
            VcVirtualMachine targetVm = null;
            for (VcVirtualMachine vm : rp.getChildVMs()) {
               if (vm.getName().equals(vmName)) {
                  targetVm = vm;
                  break;
               }
View Full Code Here

                  JobConstants.GROUP_NAME_JOB_PARAM);
      String targetNode =
            getJobParameters(chunkContext).getString(
                  JobConstants.SUB_JOB_NODE_NAME);

      VcVirtualMachine vm = null;
      try {
         vm = healService.checkNodeStatus(clusterName, groupName, targetNode);
      } catch (Exception e) {
         putIntoJobExecutionContext(chunkContext,
               JobConstants.CURRENT_ERROR_MESSAGE, e.getMessage());
         throw e;
      }

      // need to create replace vm to recover disk fix
      if (vm == null) {
         // find bad disks
         List<DiskSpec> badDisks = healService.getBadDisks(targetNode);
         AuAssert.check(!badDisks.isEmpty());

         // find replacements for bad disks
         logger.debug("get replacements for bad disks");
         List<DiskSpec> replacements;
         try {
            replacements =
                  healService.getReplacementDisks(clusterName, groupName,
                        targetNode, badDisks);
            AuAssert.check(badDisks.size() == replacements.size());
         } catch (Exception e) {
            putIntoJobExecutionContext(chunkContext,
                  JobConstants.CURRENT_ERROR_MESSAGE, e.getMessage());
            throw e;
         }

         logger.debug("get replacement disk set for recovery "
               + replacements.toString());
         jobExecutionStatusHolder.setCurrentStepProgress(
               getJobExecutionId(chunkContext), 0.3);

         // clone and recover
         logger.debug("start recovering bad vm " + targetNode);
         try {
            VcVirtualMachine newVm =
                  healService.createReplacementVm(clusterName, groupName,
                        targetNode, replacements);

            // assert, if creation failed, exception should be thrown from previous method
            if (newVm != null) {
               logger.info("created replacement vm " + newVm.getId()
                     + " for node " + targetNode);

               putIntoJobExecutionContext(chunkContext,
                     JobConstants.REPLACE_VM_ID, newVm.getId());
            } else {
               logger.error("failed creating replacement vm for node "
                     + targetNode);
               throw ClusterHealServiceException
                     .FAILED_CREATE_REPLACEMENT_VM(targetNode);
View Full Code Here

TOP

Related Classes of com.vmware.aurora.vc.VcVirtualMachine$DiskCreateSpec

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.