Package com.cloud.agent.api.to

Examples of com.cloud.agent.api.to.VolumeTO


         */

        try {
            VmwareContext context = getServiceContext();
            VmwareHypervisorHost hyperHost = getHyperHost(context);
            VolumeTO vol = cmd.getVolume();

            ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, vol.getPoolUuid());
            if (morDs == null) {
                String msg = "Unable to find datastore based on volume mount point " + cmd.getVolume().getMountPoint();
                s_logger.error(msg);
                throw new Exception(msg);
            }
View Full Code Here


                            VmwareHelper.deleteVolumeVmdkFiles(dsMo, vmdkName, dcMo);
                            vmMo.createDisk(volumeDatastorePath, (int) (dskch.getSize() / (1024L * 1024L)), morDatastore, -1);
                            vmMo.detachDisk(volumeDatastorePath, false);
                        }

                        VolumeTO vol = new VolumeTO(cmd.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), dskch.getName(), pool.getPath(), vmdkName, dskch.getSize(), null);
                        return new CreateAnswer(cmd, vol);
                    } finally {
                        vmMo.detachAllDisks();

                        s_logger.info("Destroy dummy VM after volume creation");
                        vmMo.destroy();
                    }
                } else {
                    VirtualMachineMO vmTemplate = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(cmd.getTemplateUrl()), true);
                    if (vmTemplate == null) {
                        s_logger.warn("Template host in vSphere is not in connected state, request template reload");
                        return new CreateAnswer(cmd, "Template host in vSphere is not in connected state, request template reload", true);
                    }

                    ManagedObjectReference morPool = hyperHost.getHyperHostOwnerResourcePool();
                    ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
                    ManagedObjectReference morBaseSnapshot = vmTemplate.getSnapshotMor("cloud.template.base");
                    if (morBaseSnapshot == null) {
                        String msg = "Unable to find template base snapshot, invalid template";
                        s_logger.error(msg);
                        throw new Exception(msg);
                    }

                    if(dsMo.folderExists(String.format("[%s]", dsMo.getName()), vmdkName))
                        dsMo.deleteFile(String.format("[%s] %s/", dsMo.getName(), vmdkName), dcMo.getMor(), false);

                    s_logger.info("create linked clone from template");
                    if (!vmTemplate.createLinkedClone(vmdkName, morBaseSnapshot, dcMo.getVmFolder(), morPool, morDatastore)) {
                        String msg = "Unable to clone from the template";
                        s_logger.error(msg);
                        throw new Exception(msg);
                    }

                    VirtualMachineMO vmMo = new ClusterMO(context, morCluster).findVmOnHyperHost(vmdkName);
                    assert (vmMo != null);

                    // we can't rely on un-offical API (VirtualMachineMO.moveAllVmDiskFiles() any more, use hard-coded disk names that we know
                    // to move files
                    s_logger.info("Move volume out of volume-wrapper VM ");
                    dsMo.moveDatastoreFile(String.format("[%s] %s/%s.vmdk", dsMo.getName(), vmdkName, vmdkName),
                            dcMo.getMor(), dsMo.getMor(),
                            String.format("[%s] %s.vmdk", dsMo.getName(), vmdkName), dcMo.getMor(), true);

                    dsMo.moveDatastoreFile(String.format("[%s] %s/%s-delta.vmdk", dsMo.getName(), vmdkName, vmdkName),
                            dcMo.getMor(), dsMo.getMor(),
                            String.format("[%s] %s-delta.vmdk", dsMo.getName(), vmdkName), dcMo.getMor(), true);

                    s_logger.info("detach disks from volume-wrapper VM " + vmdkName);
                    vmMo.detachAllDisks();

                    s_logger.info("destroy volume-wrapper VM " + vmdkName);
                    vmMo.destroy();

                    String srcFile = String.format("[%s] %s/", dsMo.getName(), vmdkName);
                    dsMo.deleteFile(srcFile, dcMo.getMor(), true);

                    VolumeTO vol = new VolumeTO(cmd.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), dskch.getName(), pool.getPath(), vmdkName, dskch.getSize(), null);
                    return new CreateAnswer(cmd, vol);
                }
            } else {
                // create data volume
                VirtualMachineMO vmMo = null;
                String volumeUuid = UUID.randomUUID().toString().replace("-", "");
                String volumeDatastorePath = String.format("[%s] %s.vmdk", dsMo.getName(), volumeUuid);
                String dummyVmName = getWorkerName(context, cmd, 0);
                try {
                    vmMo = prepareVolumeHostDummyVm(hyperHost, dsMo, dummyVmName);
                    if (vmMo == null) {
                        throw new Exception("Unable to create a dummy VM for volume creation");
                    }

                    synchronized (this) {
                        // s_logger.info("Delete file if exists in datastore to clear the way for creating the volume. file: " + volumeDatastorePath);
                        VmwareHelper.deleteVolumeVmdkFiles(dsMo, volumeUuid.toString(), dcMo);

                        vmMo.createDisk(volumeDatastorePath, (int) (dskch.getSize() / (1024L * 1024L)), morDatastore, vmMo.getScsiDeviceControllerKey());
                        vmMo.detachDisk(volumeDatastorePath, false);
                    }

                    VolumeTO vol = new VolumeTO(cmd.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), dskch.getName(), pool.getPath(), volumeUuid, dskch.getSize(), null);
                    return new CreateAnswer(cmd, vol);
                } finally {
                    s_logger.info("Destroy dummy VM after volume creation");
                    vmMo.detachAllDisks();
                    vmMo.destroy();
View Full Code Here

            createPatchVbd(conn, vmName, vm, vmSpec);
        }
    }

    private VolumeTO getVolume(VirtualMachineTO vmSpec, Volume.Type type) {
        VolumeTO volumes[] = vmSpec.getDisks();
        for (VolumeTO volume : volumes) {
            if (volume.getType() == type) {
                return volume;
            }
        }
View Full Code Here

            VirtualMachineTO vmSpec) throws LibvirtException,
            InternalErrorException {

        List<DiskDef> disks = vm.getDevices().getDisks();
        DiskDef rootDisk = disks.get(0);
        VolumeTO rootVol = getVolume(vmSpec, Volume.Type.ROOT);
        String patchName = vmName + "-patchdisk";
        KVMStoragePool pool = _storagePoolMgr.getStoragePool(
                rootVol.getPoolType(),
                rootVol.getPoolUuid());
        String patchDiskPath = pool.getLocalPath() + "/" + patchName;

        List<KVMPhysicalDisk> phyDisks = pool.listPhysicalDisks();
        boolean foundDisk = false;
View Full Code Here

            GuestOSVO guestOS = _guestOSDao.findById(template.getGuestOSId());
            String displayName = null;
            if (guestOS != null) {
                displayName = guestOS.getDisplayName();
            }
            VolumeTO iso = new VolumeTO(profile.getId(), Volume.Type.ISO,
                    StoragePoolType.ISO, null, template.getName(), null,
                    isoPath, 0, null, displayName);

            iso.setDeviceId(3);
            profile.addDisk(iso);
        } else {
            VirtualMachineTemplate template = profile.getTemplate();
            /* create a iso placeholder */
            VolumeTO iso = new VolumeTO(profile.getId(), Volume.Type.ISO,
                    StoragePoolType.ISO, null, template.getName(), null, null,
                    0, null);
            iso.setDeviceId(3);
            profile.addDisk(iso);
        }

        return true;
    }
View Full Code Here

        vol = OvmVolume.createFromTemplate(_conn, primaryStorage.getUuid(),  cmd.getTemplateUrl());
      } else {
        vol = OvmVolume.createDataDsik(_conn, primaryStorage.getUuid(), Long.toString(disk.getSize()), disk.getType() == Volume.Type.ROOT);
      }
     
      VolumeTO volume = new VolumeTO(cmd.getVolumeId(), disk.getType(),
          primaryStorage.getType(), primaryStorage.getUuid(), primaryStorage.getPath(),
          vol.name, vol.path, vol.size, null);
      return new CreateAnswer(cmd, volume);
    } catch (Exception e) {
      s_logger.debug("CreateCommand failed", e);
View Full Code Here

      txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
    }

    VolumeTO volumeTo = new VolumeTO(cmd.getVolumeId(), dskch.getType(), sf.getType(), sf.getUuid(),
        volume.getName(), storagePool.getMountPoint(), volume.getPath(), volume.getSize(), null);

    return new CreateAnswer(cmd, volumeTo);
  }
View Full Code Here

            GuestOSVO guestOS = _guestOSDao.findById(template.getGuestOSId());
            String displayName = null;
            if (guestOS != null) {
                displayName = guestOS.getDisplayName();
            }
            VolumeTO iso = new VolumeTO(profile.getId(), Volume.Type.ISO, StoragePoolType.ISO, null, template.getName(), null, isoPath, 0, null, displayName);

            iso.setDeviceId(3);
            profile.addDisk(iso);
        } else {
            VirtualMachineTemplate template = profile.getTemplate();
            /* create a iso placeholder */
            VolumeTO iso = new VolumeTO(profile.getId(), Volume.Type.ISO, StoragePoolType.ISO, null, template.getName(), null, null, 0, null);
            iso.setDeviceId(3);
            profile.addDisk(iso);
        }

        return true;
    }
View Full Code Here

                }
            } else {
                vol = primaryPool.createPhysicalDisk(UUID.randomUUID()
                        .toString(), dskch.getSize());
            }
            VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(),
                    pool.getType(), pool.getUuid(), pool.getPath(),
                    vol.getName(), vol.getName(), disksize, null);
            return new CreateAnswer(cmd, volume);
        } catch (CloudRuntimeException e) {
            s_logger.debug("Failed to create volume: " + e.toString());
View Full Code Here

        }
       
    }

    public Answer execute(DestroyCommand cmd) {
        VolumeTO vol = cmd.getVolume();

        try {
            KVMStoragePool pool = _storagePoolMgr.getStoragePool(
                    vol.getPoolType(),
                    vol.getPoolUuid());
            pool.deletePhysicalDisk(vol.getPath());
            String vmName = cmd.getVmName();
            String poolPath = pool.getLocalPath();

            /* if vol is a root disk for a system vm, try to remove accompanying patch disk as well
               this is a bit tricky since the patchdisk is only a LibvirtComputingResource construct
               and not tracked anywhere in cloudstack */
            if (vol.getType() == Volume.Type.ROOT && vmName.matches("^[rsv]-\\d+-.+$")) {
                File patchVbd = new File(poolPath + File.separator + vmName + "-patchdisk");
                if(patchVbd.exists()){
                    try {
                        _storagePoolMgr.deleteVbdByPath(vol.getPoolType(),patchVbd.getAbsolutePath());
                    } catch(CloudRuntimeException e) {
                        s_logger.warn("unable to destroy patch disk '" + patchVbd.getAbsolutePath() +
                                "' while removing root disk for " + vmName + " : " + e);
                    }
                } else {
View Full Code Here

TOP

Related Classes of com.cloud.agent.api.to.VolumeTO

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.