Package com.vmware.aurora.vc

Examples of com.vmware.aurora.vc.VcVirtualMachine


   @Override
   public void initResource() {
      final String serverMobId =
            Configuration.getString(Constants.SERENGETI_SERVER_VM_MOBID);
      logger.info("server mob id:" + serverMobId);
      final VcVirtualMachine serverVm = findVM(serverMobId);
      VcResourcePool vcRP = getVmRp(serverVm);
      String clusterName = vcRP.getVcCluster().getName();
      String vcRPName = vcRP.getName();
      logger.info("vc rp: " + vcRPName + ", cluster: " + clusterName);
      String networkName = getVMNetwork(serverVm);
View Full Code Here


   /**
    * @param serverMobId
    * @return
    */
   private VcVirtualMachine findVM(final String serverMobId) {
      final VcVirtualMachine serverVm =
            VcContext.inVcSessionDo(new VcSession<VcVirtualMachine>() {
               @Override
               protected VcVirtualMachine body() throws Exception {
                  VcVirtualMachine vm = VcCache.get(serverMobId);
                  if (vm == null) {
                     VcProviderException.SERVER_NOT_FOUND(serverMobId);
                  }
                  return vm;
               }
View Full Code Here

   public static void rename(final String vmId, final String newName) {
      VcContext.inVcSessionDo(new VcSession<Void>() {
         @Override
         protected Void body() throws Exception {
            VcVirtualMachine vm = VcCache.getIgnoreMissing(vmId);
            vm.rename(newName);

            return null;
         }

         @Override
View Full Code Here

   public static boolean validateCPU(final String vmId, final int cpuNum) {
      if (cpuNum < 0) {
         return false;
      }

      VcVirtualMachine vm = VcCache.getIgnoreMissing(vmId);
      if (vm == null) {
         logger.error("cannot found vm of id: " + vmId);
         return false;
      }

      String coresPerSocketKey = "cpuid.coresPerSocket";
      if (vm.getConfig() != null && vm.getConfig().getExtraConfig() != null) {
         for (OptionValue optionValue : vm.getConfig().getExtraConfig()) {
            if (coresPerSocketKey.equals(optionValue.getKey())) {
               int coresPerSocket =
                     Integer.parseInt((String) optionValue.getValue());
               if (cpuNum % coresPerSocket == 0) {
                  return true;
View Full Code Here

            return true;
         }

         @Override
         protected Void body() throws Exception {
            final VcVirtualMachine template =
                  VcCache.get(vmSchema.diskSchema.getParent());
            VcSnapshot snap =
                  template.getSnapshotByName(vmSchema.diskSchema
                        .getParentSnap());
            if (snap == null) {
               // this is a blocking call
               snap =
                     template.createSnapshot(
                           vmSchema.diskSchema.getParentSnap(),
                           "Serengeti template Root Snapshot");
            }
            return null;
         }
View Full Code Here

   @Test
   public void testDeleteVm() throws Exception {
      String vmName = "clonedVM1";
      // Need to import the VM first, since TM layer doesn't persist data.
      VcVirtualMachine vm = util.testImportVM(vmName, rp).getResult();

      DeleteVmSP sp = new DeleteVmSP(vm);
      sp.call();
   }
View Full Code Here

public class VmHaTest extends AbstractVcTest {

   @Test
   public void changeVmHaSettingTest() throws Exception {
      String vmId = properties.getProperty("testVmReference");
      VcVirtualMachine vm = VcCache.get(vmId);
      AuAssert.check(vm != null);

      vm.modifyHASettings(RestartPriority.disabled, null, null);
   }
View Full Code Here

         } catch (InterruptedException e) {
            logger.error("VM status updator is interrupted.");
            return;
         }
         for (int j = 0; j < nodeNum; j++) {
            VcVirtualMachine vm = MockVcCache.getIgnoreMissing(VM_MOB_PREFIX + j);
            Map<String, String> map = new HashMap<String, String>();
            switch (settings) {
            case 0:
               if (flag) {
                  map.put(Constants.VM_DISK_FORMAT_STATUS_KEY, "1");
               }
               break;
            case 1:
               if (flag) {
                  map.put(Constants.VM_DISK_FORMAT_STATUS_KEY, "0");
               } else {
                  map.put(Constants.VM_DISK_FORMAT_STATUS_KEY, "1");
               }
               break;
            default:
               break;
            }
            Mockito.when(vm.getGuestVariables()).thenReturn(map);
         }
      }
View Full Code Here

   @Test
   public void uploadVmTemplate() throws Exception {
      init();
      System.out.println("upload VM template to " + myRP + d1 + net1 + net2);
      VcVirtualMachine vm = null, vm1 = null;
      String vmName = "junit-VcFileTest-VM-" + VcTestConfig.testPostfix;
      String vm1Name = "junit-VcFileTest-VM%1-" + VcTestConfig.testPostfix;
      VcDatacenter dc = d1.getDatacenter();
      try {
         /*
          * Always clean up VMs from previous runs.
          */
         if ((vm = dc.getVirtualMachine(vmName)) != null) {
            vm.destroy();
         }
         if ((vm1 = dc.getVirtualMachine(vm1Name)) != null) {
            vm1.destroy();
         }
         /*
          * Import a VM from OVF.
          */
         vm = VcFileManager.importVm(vmName, myRP, d1, net1, VcTestConfig.ovfPath);
         System.out.println(vm);
         vm = dc.getVirtualMachine(vmName);
         System.out.println(vm);
         vm.dumpDevices();
         System.out.println(VcFileManager.getDsPath(vm, ""));

         /* test device identification */
         DeviceId diskId = new DeviceId("VirtualLsiLogicController:0:0");
         VirtualDevice scsi1 = vm.getVirtualController(diskId);
         VirtualDevice disk1 = vm.getVirtualDevice(diskId);
         DeviceId genDiskId = new DeviceId(scsi1, disk1);
         if (!diskId.equals(genDiskId)) {
            throw new Exception("unmatched disk id " + diskId + " " + genDiskId);
         }

         VirtualDevice.BackingInfo disk1Bk = vm.getVirtualDevice(diskId).getBacking();
         System.out.println("Remove a disk");
         vm.detachVirtualDisk(diskId, false);
         vm.dumpDevices();

         System.out.println("Attach a new disk");
         vm.attachVirtualDisk(new DeviceId("VirtualLsiLogicController", 0, 2),
               VmConfigUtil.createVmdkBackingInfo(vm, "data.vmdk", DiskMode.persistent),
               true, DiskSize.sizeFromGB(8));
         vm.dumpDevices();

         /* test setting extra config */
         Map<String, String> map = new HashMap<String, String>();
         map.put("vmid", "junit-test-vm");
         vm.setDbvmConfig(map);
         map = vm.getDbvmConfig();
         System.out.println(map);

         if(VmConfigUtil.isDetachDiskEnabled()) {
            System.out.println("Attach a disk");
            vm.attachVirtualDisk(diskId, disk1Bk, false, null);
            vm.dumpDevices();
         }

         // create a snapshot so that we can do linked clone
         vm.createSnapshot("snap1", "snap1");
         // test finding snapshots
         vm.createSnapshot("snap2", "snap2");
         VcSnapshot snap1 = vm.getSnapshotByName("snap1");
         AuAssert.check(snap1 != null);
         VcSnapshot snap2 = vm.getSnapshotByName("snap2");
         AuAssert.check(snap2 != null);
         System.out.println("snap1: " + snap1 + " snap2: " + snap2);

         System.out.println("Mark the VM as template");
         vm.markAsTemplate();
         System.out.println(dc.getVirtualMachine(vmName).getInfo());

         /*
          * Test file operations using data.vmdk
          */
         System.out.println("data.vmdk uuid=" +
               VcFileManager.queryVirtualDiskUuid(
                     VcFileManager.getDsPath(vm, "data.vmdk"), dc));
         testFileOp(VcFileManager.getDsPath(vm, "data.vmdk"));

         /*
          * Clone the template VM.
          */
         System.out.println("clone the template VM to a VM");
         ConfigSpec spec = new ConfigSpecImpl();
         vm1 = vm.cloneTemplate(vm1Name, myRP, d1, spec);
         System.out.println(vm1.getInfo());
         vm1.dumpDevices();
         map = vm1.getDbvmConfig();
         System.out.println(map);

         System.out.println("Attach a new disk");
         DeviceId archiveDiskId = new DeviceId("VirtualLsiLogicController:0:3");
         DeviceId tempDiskId = new DeviceId("VirtualLsiLogicController:0:4");
         vm1.attachVirtualDisk(archiveDiskId,
               VmConfigUtil.createVmdkBackingInfo(vm1, d1, "archive.vmdk", DiskMode.persistent, true),
               true, DiskSize.sizeFromGB(2));
         // test copying and attaching a new disk
         System.out.println("Copy and attach a new disk");
         vm1.copyAttachVirtualDisk(tempDiskId, vm1, archiveDiskId,
                                   "temp.vmdk", DiskMode.persistent);

         List<VirtualDeviceSpec> changes = new ArrayList<VirtualDeviceSpec>();
         changes.add(vm1.reconfigNetworkSpec("Network adapter 1", net1));
         changes.add(vm1.reconfigNetworkSpec("Network adapter 2", net2));
         vm1.reconfigure(VmConfigUtil.createConfigSpec(changes));

         /*
          * Start the VM and reconfigure online.
          */
         vm1.powerOn();
         Thread.sleep(1000);
         // extend the disk online
         vm1.extendVirtualDisk(tempDiskId, DiskSize.sizeFromGB(3));
         vm1.dumpDevices();
         vm1.powerOff();

         /*
          * Clean up.
          */
         vm.destroy();
         vm1.destroy();
      } catch (Exception e) {
         System.out.println(e);
         if (vm != null) {
            vm.destroy();
         }
         if (vm1 != null) {
            vm1.destroy();
         }
         throw e;
View Full Code Here

      this.vmName = vcVm.getName();
   }

   @Override
   public Void call() throws Exception {
      final VcVirtualMachine vcVm = VcCache.getIgnoreMissing(vmId);
      if (vcVm == null) {
         logger.info("vm " + vmId
               + " is deleted from vc. Ignore the power off request.");
         return null;
      }
      if (vcVm.isPoweredOff()) {
         logger.info("vm " + vcVm.getName() + " is already powered off.");
         return null;
      }
      VcContext.inVcSessionDo(new VcSession<Void>() {
         @Override
         protected Void body() throws Exception {
            if (vmPoweroff) {
               vcVm.powerOff();
            } else {
               if (!vcVm
                     .shutdownGuest(Constants.VM_SHUTDOWN_WAITING_SEC * 1000)) {
                  logger.info("shutdown guest OS failed, power off directly");
                  vcVm.powerOff();
               }
            }
            return null;
         }

View Full Code Here

TOP

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

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.