use of com.cloud.agent.api.to.StorageFilerTO 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);
}
use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.
the class Ovm3StorageProcessor method execute.
public CreateAnswer execute(CreateCommand cmd) {
LOGGER.debug("execute: " + cmd.getClass());
StorageFilerTO primaryStorage = cmd.getPool();
DiskProfile disk = cmd.getDiskCharacteristics();
/* disk should have a uuid */
// should also be replaced with getVirtualDiskPath ?
String fileName = UUID.randomUUID().toString() + ".raw";
String dst = primaryStorage.getPath() + "/" + primaryStorage.getUuid() + "/" + fileName;
try {
StoragePlugin store = new StoragePlugin(c);
if (cmd.getTemplateUrl() != null) {
LOGGER.debug("CreateCommand " + cmd.getTemplateUrl() + " " + dst);
Linux host = new Linux(c);
host.copyFile(cmd.getTemplateUrl(), dst);
} else {
/* this is a dup with the createVolume ? */
LOGGER.debug("CreateCommand " + dst);
store.storagePluginCreate(primaryStorage.getUuid(), primaryStorage.getHost(), dst, disk.getSize(), false);
}
FileProperties fp = store.storagePluginGetFileInfo(primaryStorage.getUuid(), primaryStorage.getHost(), dst);
VolumeTO volume = new VolumeTO(cmd.getVolumeId(), disk.getType(), primaryStorage.getType(), primaryStorage.getUuid(), primaryStorage.getPath(), fileName, fp.getName(), fp.getSize(), null);
return new CreateAnswer(cmd, volume);
} catch (Exception e) {
LOGGER.debug("CreateCommand failed", e);
return new CreateAnswer(cmd, e.getMessage());
}
}
use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.
the class Ovm3StoragePool method execute.
/**
* Create the primary storage pool, should add iSCSI and OCFS2
*
* @param cmd
* @return
*/
public Answer execute(CreateStoragePoolCommand cmd) {
StorageFilerTO pool = cmd.getPool();
LOGGER.debug("creating pool " + pool);
try {
if (pool.getType() == StoragePoolType.NetworkFilesystem) {
createRepo(pool);
} else if (pool.getType() == StoragePoolType.IscsiLUN) {
return new Answer(cmd, false, "iSCSI is unsupported at the moment");
/*
* iScsi like so: getIscsiSR(conn, pool.getUuid(),
* pool.getHost(), pool.getPath(), null, null, false);
*/
} else if (pool.getType() == StoragePoolType.OCFS2) {
return new Answer(cmd, false, "OCFS2 is unsupported at the moment");
} else if (pool.getType() == StoragePoolType.PreSetup) {
LOGGER.warn("pre setup for pool " + pool);
} else {
return new Answer(cmd, false, "The pool type: " + pool.getType().name() + " is not supported.");
}
} catch (Exception e) {
String msg = "Catch Exception " + e.getClass().getName() + ", create StoragePool failed due to " + e.toString() + " on host:" + config.getAgentHostname() + " pool: " + pool.getHost() + pool.getPath();
LOGGER.warn(msg, e);
return new Answer(cmd, false, msg);
}
return new Answer(cmd, true, "success");
}
use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.
the class XenServer610MigrateWithStorageCommandWrapper method execute.
@Override
public Answer execute(final MigrateWithStorageCommand command, final XenServer610Resource xenServer610Resource) {
final Connection connection = xenServer610Resource.getConnection();
final VirtualMachineTO vmSpec = command.getVirtualMachine();
final List<Pair<VolumeTO, StorageFilerTO>> volumeToFiler = command.getVolumeToFilerAsList();
final String vmName = vmSpec.getName();
Task task = null;
final XsHost xsHost = xenServer610Resource.getHost();
final String uuid = xsHost.getUuid();
try {
xenServer610Resource.prepareISO(connection, vmName, null, null);
// Get the list of networks and recreate VLAN, if required.
for (final NicTO nicTo : vmSpec.getNics()) {
xenServer610Resource.getNetwork(connection, nicTo);
}
final Map<String, String> other = new HashMap<String, String>();
other.put("live", "true");
final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null);
final Network networkForSm = nativeNetworkForTraffic.getNetwork();
// Create the vif map. The vm stays in the same cluster so we have to pass an empty vif map.
final Map<VIF, Network> vifMap = new HashMap<VIF, Network>();
final Map<VDI, SR> vdiMap = new HashMap<VDI, SR>();
for (final Pair<VolumeTO, StorageFilerTO> entry : volumeToFiler) {
final StorageFilerTO storageFiler = entry.second();
final VolumeTO volume = entry.first();
vdiMap.put(xenServer610Resource.getVDIbyUuid(connection, volume.getPath()), xenServer610Resource.getStorageRepository(connection, storageFiler.getUuid()));
}
// Get the vm to migrate.
final Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName());
final VM vmToMigrate = vms.iterator().next();
// Check migration with storage is possible.
final Host host = Host.getByUuid(connection, uuid);
final Map<String, String> token = host.migrateReceive(connection, networkForSm, other);
task = vmToMigrate.assertCanMigrateAsync(connection, token, true, vdiMap, vifMap, other);
try {
// poll every 1 seconds
final long timeout = xenServer610Resource.getMigrateWait() * 1000L;
xenServer610Resource.waitForTask(connection, task, 1000, timeout);
xenServer610Resource.checkForSuccess(connection, task);
} catch (final Types.HandleInvalid e) {
s_logger.error("Error while checking if vm " + vmName + " can be migrated to the destination host " + host, e);
throw new CloudRuntimeException("Error while checking if vm " + vmName + " can be migrated to the " + "destination host " + host, e);
}
// Migrate now.
task = vmToMigrate.migrateSendAsync(connection, token, true, vdiMap, vifMap, other);
try {
// poll every 1 seconds.
final long timeout = xenServer610Resource.getMigrateWait() * 1000L;
xenServer610Resource.waitForTask(connection, task, 1000, timeout);
xenServer610Resource.checkForSuccess(connection, task);
} catch (final Types.HandleInvalid e) {
s_logger.error("Error while migrating vm " + vmName + " to the destination host " + host, e);
throw new CloudRuntimeException("Error while migrating vm " + vmName + " to the destination host " + host, e);
}
// Volume paths would have changed. Return that information.
final List<VolumeObjectTO> volumeToList = xenServer610Resource.getUpdatedVolumePathsOfMigratedVm(connection, vmToMigrate, vmSpec.getDisks());
vmToMigrate.setAffinity(connection, host);
return new MigrateWithStorageAnswer(command, volumeToList);
} catch (final Exception e) {
s_logger.warn("Catch Exception " + e.getClass().getName() + ". Storage motion failed due to " + e.toString(), e);
return new MigrateWithStorageAnswer(command, e);
} finally {
if (task != null) {
try {
task.destroy(connection);
} catch (final Exception e) {
s_logger.debug("Unable to destroy task " + task.toString() + " on host " + uuid + " due to " + e.toString());
}
}
}
}
use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.
the class CitrixCreateStoragePoolCommandWrapper method execute.
@Override
public Answer execute(final CreateStoragePoolCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
final StorageFilerTO pool = command.getPool();
try {
if (command.getCreateDatastore()) {
Map<String, String> details = command.getDetails();
String srNameLabel = details.get(CreateStoragePoolCommand.DATASTORE_NAME);
String storageHost = details.get(CreateStoragePoolCommand.STORAGE_HOST);
String iqn = details.get(CreateStoragePoolCommand.IQN);
citrixResourceBase.getIscsiSR(conn, srNameLabel, storageHost, iqn, null, null, false);
} else {
if (pool.getType() == StoragePoolType.NetworkFilesystem) {
citrixResourceBase.getNfsSR(conn, Long.toString(pool.getId()), pool.getUuid(), pool.getHost(), pool.getPath(), pool.toString());
} else if (pool.getType() == StoragePoolType.IscsiLUN) {
citrixResourceBase.getIscsiSR(conn, pool.getUuid(), pool.getHost(), pool.getPath(), null, null, false);
} else if (pool.getType() == StoragePoolType.PreSetup) {
} else {
return new Answer(command, false, "The pool type: " + pool.getType().name() + " is not supported.");
}
}
return new Answer(command, true, "success");
} catch (final Exception e) {
final String msg = "Catch Exception " + e.getClass().getName() + ", create StoragePool failed due to " + e.toString() + " on host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
}
}
Aggregations