Search in sources :

Example 11 with VolumeTO

use of com.cloud.agent.api.to.VolumeTO in project cloudstack by apache.

the class XenServer610MigrateWithStorageReceiveCommandWrapper method execute.

@Override
public Answer execute(final MigrateWithStorageReceiveCommand command, final XenServer610Resource xenServer610Resource) {
    final Connection connection = xenServer610Resource.getConnection();
    final VirtualMachineTO vmSpec = command.getVirtualMachine();
    final List<Pair<VolumeTO, String>> volumeToStorageUuid = command.getVolumeToStorageUuid();
    try {
        // In a cluster management server setup, the migrate with storage receive and send
        // commands and answers may have to be forwarded to another management server. This
        // happens when the host/resource on which the command has to be executed is owned
        // by the second management server. The serialization/deserialization of the command
        // and answers fails as the xapi SR and Network class type isn't understand by the
        // agent attache. Seriliaze the SR and Network objects here to a string and pass in
        // the answer object. It'll be deserialzed and object created in migrate with
        // storage send command execution.
        Gson gson = new Gson();
        // Get a map of all the SRs to which the vdis will be migrated.
        final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<>();
        for (final Pair<VolumeTO, String> entry : volumeToStorageUuid) {
            final String storageUuid = entry.second();
            final SR sr = xenServer610Resource.getStorageRepository(connection, storageUuid);
            volumeToSr.add(new Pair<VolumeTO, Object>(entry.first(), sr));
        }
        // Get the list of networks to which the vifs will attach.
        final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<Pair<NicTO, Object>>();
        for (final NicTO nicTo : vmSpec.getNics()) {
            final Network network = xenServer610Resource.getNetwork(connection, nicTo);
            nicToNetwork.add(new Pair<NicTO, Object>(nicTo, network));
        }
        final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null);
        final Network network = nativeNetworkForTraffic.getNetwork();
        final XsHost xsHost = xenServer610Resource.getHost();
        final String uuid = xsHost.getUuid();
        final Map<String, String> other = new HashMap<String, String>();
        other.put("live", "true");
        final Host host = Host.getByUuid(connection, uuid);
        final Map<String, String> token = host.migrateReceive(connection, network, other);
        return new MigrateWithStorageReceiveAnswer(command, volumeToSr, nicToNetwork, token);
    } catch (final CloudRuntimeException e) {
        s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
        return new MigrateWithStorageReceiveAnswer(command, e);
    } catch (final Exception e) {
        s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
        return new MigrateWithStorageReceiveAnswer(command, e);
    }
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) VolumeTO(com.cloud.agent.api.to.VolumeTO) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Network(com.xensource.xenapi.Network) Pair(com.cloud.utils.Pair) SR(com.xensource.xenapi.SR) NicTO(com.cloud.agent.api.to.NicTO) Connection(com.xensource.xenapi.Connection) Host(com.xensource.xenapi.Host) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateWithStorageReceiveAnswer(com.cloud.agent.api.MigrateWithStorageReceiveAnswer)

Example 12 with VolumeTO

use of com.cloud.agent.api.to.VolumeTO in project cloudstack by apache.

the class CitrixCreateCommandWrapper method execute.

@Override
public Answer execute(final CreateCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final StorageFilerTO pool = command.getPool();
    final DiskProfile dskch = command.getDiskCharacteristics();
    VDI vdi = null;
    try {
        final SR poolSr = citrixResourceBase.getStorageRepository(conn, pool.getUuid());
        if (command.getTemplateUrl() != null) {
            VDI tmpltvdi = null;
            tmpltvdi = citrixResourceBase.getVDIbyUuid(conn, command.getTemplateUrl());
            vdi = tmpltvdi.createClone(conn, new HashMap<String, String>());
            vdi.setNameLabel(conn, dskch.getName());
        } else {
            final VDI.Record vdir = new VDI.Record();
            vdir.nameLabel = dskch.getName();
            vdir.SR = poolSr;
            vdir.type = Types.VdiType.USER;
            vdir.virtualSize = dskch.getSize();
            vdi = VDI.create(conn, vdir);
        }
        VDI.Record vdir;
        vdir = vdi.getRecord(conn);
        s_logger.debug("Succesfully created VDI for " + command + ".  Uuid = " + vdir.uuid);
        final VolumeTO vol = new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), vdir.nameLabel, pool.getPath(), vdir.uuid, vdir.virtualSize, null);
        return new CreateAnswer(command, vol);
    } catch (final Exception e) {
        s_logger.warn("Unable to create volume; Pool=" + pool + "; Disk: " + dskch, e);
        return new CreateAnswer(command, e);
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) VDI(com.xensource.xenapi.VDI) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile) SR(com.xensource.xenapi.SR)

Example 13 with VolumeTO

use of com.cloud.agent.api.to.VolumeTO in project CloudStack-archive by CloudStack-extras.

the class MockStorageManagerImpl method createVolume.

@Override
public CreateAnswer createVolume(CreateCommand cmd) {
    StorageFilerTO sf = cmd.getPool();
    DiskProfile dskch = cmd.getDiskCharacteristics();
    MockStoragePoolVO storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
    if (storagePool == null) {
        return new CreateAnswer(cmd, "Failed to find storage pool: " + sf.getUuid());
    }
    String volumeName = UUID.randomUUID().toString();
    MockVolumeVO volume = new MockVolumeVO();
    volume.setPoolId(storagePool.getId());
    volume.setName(volumeName);
    volume.setPath(storagePool.getMountPoint() + volumeName);
    volume.setSize(dskch.getSize());
    volume.setType(MockVolumeType.VOLUME);
    volume = _mockVolumeDao.persist(volume);
    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);
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile)

Example 14 with VolumeTO

use of com.cloud.agent.api.to.VolumeTO in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method createVbd.

protected void createVbd(Connect conn, VirtualMachineTO vmSpec, String vmName, LibvirtVMDef vm) throws InternalErrorException, LibvirtException, URISyntaxException {
    List<VolumeTO> disks = Arrays.asList(vmSpec.getDisks());
    Collections.sort(disks, new Comparator<VolumeTO>() {

        @Override
        public int compare(VolumeTO arg0, VolumeTO arg1) {
            return arg0.getDeviceId() > arg1.getDeviceId() ? 1 : -1;
        }
    });
    for (VolumeTO volume : disks) {
        KVMPhysicalDisk physicalDisk = null;
        KVMStoragePool pool = null;
        if (volume.getType() == Volume.Type.ISO && volume.getPath() != null) {
            String volPath = volume.getPath();
            int index = volPath.lastIndexOf("/");
            String volDir = volPath.substring(0, index);
            String volName = volPath.substring(index + 1);
            KVMStoragePool secondaryStorage = _storagePoolMgr.getStoragePoolByURI(volDir);
            physicalDisk = secondaryStorage.getPhysicalDisk(volName);
        } else if (volume.getType() != Volume.Type.ISO) {
            pool = _storagePoolMgr.getStoragePool(volume.getPoolUuid());
            physicalDisk = pool.getPhysicalDisk(volume.getPath());
        }
        String volPath = null;
        if (physicalDisk != null) {
            volPath = physicalDisk.getPath();
        }
        DiskDef.diskBus diskBusType = getGuestDiskModel(vmSpec.getOs());
        DiskDef disk = new DiskDef();
        if (volume.getType() == Volume.Type.ISO) {
            if (volPath == null) {
                /* Add iso as placeholder */
                disk.defISODisk(null);
            } else {
                disk.defISODisk(volPath);
            }
        } else {
            int devId = (int) volume.getDeviceId();
            if (volume.getType() == Volume.Type.DATADISK) {
                disk.defFileBasedDisk(physicalDisk.getPath(), devId, DiskDef.diskBus.VIRTIO, DiskDef.diskFmtType.QCOW2);
            } else {
                disk.defFileBasedDisk(physicalDisk.getPath(), devId, diskBusType, DiskDef.diskFmtType.QCOW2);
            }
        }
        vm.getDevices().addDevice(disk);
    }
    if (vmSpec.getType() != VirtualMachine.Type.User) {
        if (_sysvmISOPath != null) {
            DiskDef iso = new DiskDef();
            iso.defISODisk(_sysvmISOPath);
            vm.getDevices().addDevice(iso);
        }
        createPatchVbd(conn, vmName, vm, vmSpec);
    }
}
Also used : VolumeTO(com.cloud.agent.api.to.VolumeTO) DiskDef(com.cloud.agent.resource.computing.LibvirtVMDef.DiskDef) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk)

Example 15 with VolumeTO

use of com.cloud.agent.api.to.VolumeTO in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method createPatchVbd.

private void createPatchVbd(Connect conn, String vmName, LibvirtVMDef vm, VirtualMachineTO vmSpec) throws LibvirtException, InternalErrorException {
    List<DiskDef> disks = vm.getDevices().getDisks();
    DiskDef rootDisk = disks.get(0);
    VolumeTO rootVol = getVolume(vmSpec, Volume.Type.ROOT);
    KVMStoragePool pool = _storagePoolMgr.getStoragePool(rootVol.getPoolUuid());
    KVMPhysicalDisk disk = pool.createPhysicalDisk(UUID.randomUUID().toString(), KVMPhysicalDisk.PhysicalDiskFormat.RAW, 10L * 1024 * 1024);
    /* Format/create fs on this disk */
    final Script command = new Script(_createvmPath, _timeout, s_logger);
    command.add("-f", disk.getPath());
    String result = command.execute();
    if (result != null) {
        s_logger.debug("Failed to create data disk: " + result);
        throw new InternalErrorException("Failed to create data disk: " + result);
    }
    String datadiskPath = disk.getPath();
    /* add patch disk */
    DiskDef patchDisk = new DiskDef();
    patchDisk.defFileBasedDisk(datadiskPath, 1, rootDisk.getBusType(), DiskDef.diskFmtType.RAW);
    disks.add(patchDisk);
    String bootArgs = vmSpec.getBootArgs();
    patchSystemVm(bootArgs, datadiskPath, vmName);
}
Also used : Script(com.cloud.utils.script.Script) DiskDef(com.cloud.agent.resource.computing.LibvirtVMDef.DiskDef) VolumeTO(com.cloud.agent.api.to.VolumeTO) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) InternalErrorException(com.cloud.exception.InternalErrorException)

Aggregations

VolumeTO (com.cloud.agent.api.to.VolumeTO)31 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 Answer (com.cloud.agent.api.Answer)14 Pair (com.cloud.utils.Pair)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 NicTO (com.cloud.agent.api.to.NicTO)10 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)10 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)9 Connection (com.xensource.xenapi.Connection)8 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)7 DiskProfile (com.cloud.vm.DiskProfile)7 SR (com.xensource.xenapi.SR)6 VDI (com.xensource.xenapi.VDI)6 Test (org.junit.Test)6 MigrateWithStorageCommand (com.cloud.agent.api.MigrateWithStorageCommand)5 Network (com.xensource.xenapi.Network)5 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)4 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)4