Search in sources :

Example 1 with StoragePlugin

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin in project cloudstack by apache.

the class Ovm3StoragePool method execute.

/**
     * Gets the details of a storage pool, size etc
     *
     * @param cmd
     * @return
     */
public Answer execute(ModifyStoragePoolCommand cmd) {
    StorageFilerTO pool = cmd.getPool();
    LOGGER.debug("modifying pool " + pool);
    try {
        if (config.getAgentInOvm3Cluster()) {
        // no native ovm cluster for now, I got to break it in horrible
        // ways
        }
        if (pool.getType() == StoragePoolType.NetworkFilesystem) {
            createRepo(pool);
            StoragePlugin store = new StoragePlugin(c);
            String propUuid = store.deDash(pool.getUuid());
            String mntUuid = pool.getUuid();
            String nfsHost = pool.getHost();
            String nfsPath = pool.getPath();
            StorageDetails ss = store.storagePluginGetFileSystemInfo(propUuid, mntUuid, nfsHost, nfsPath);
            Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
            return new ModifyStoragePoolAnswer(cmd, Long.parseLong(ss.getSize()), Long.parseLong(ss.getFreeSize()), tInfo);
        } else if (pool.getType() == StoragePoolType.OCFS2) {
            createOCFS2Sr(pool);
        }
        return new Answer(cmd, false, "The pool type: " + pool.getType().name() + " is not supported.");
    } catch (Exception e) {
        LOGGER.debug("ModifyStoragePoolCommand failed", e);
        return new Answer(cmd, false, e.getMessage());
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) Answer(com.cloud.agent.api.Answer) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) StorageDetails(com.cloud.hypervisor.ovm3.objects.StoragePlugin.StorageDetails) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 2 with StoragePlugin

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin in project cloudstack by apache.

the class Ovm3StoragePool method prepareSecondaryStorageStore.

/**
     * Copy the systemvm.iso in if it doesn't exist or the size differs.
     *
     * @param storageUrl
     * @param poolUuid
     * @param host
     */
private void prepareSecondaryStorageStore(String storageUrl, String poolUuid, String host) {
    String mountPoint = storageUrl;
    GlobalLock lock = GlobalLock.getInternLock("prepare.systemvm");
    try {
        /* double check */
        if (config.getAgentHasMaster() && config.getAgentInOvm3Pool()) {
            LOGGER.debug("Skip systemvm iso copy, leave it to the master");
            return;
        }
        if (lock.lock(3600)) {
            try {
                /*
                     * save src iso real name for reuse, so we don't depend on
                     * other happy little accidents.
                     */
                File srcIso = getSystemVMPatchIsoFile();
                String destPath = mountPoint + "/ISOs/";
                try {
                    StoragePlugin sp = new StoragePlugin(c);
                    FileProperties fp = sp.storagePluginGetFileInfo(poolUuid, host, destPath + "/" + srcIso.getName());
                    if (fp.getSize() != srcIso.getTotalSpace()) {
                        LOGGER.info(" System VM patch ISO file already exists: " + srcIso.getAbsolutePath().toString() + ", destination: " + destPath);
                    }
                } catch (Exception e) {
                    LOGGER.info("Copy System VM patch ISO file to secondary storage. source ISO: " + srcIso.getAbsolutePath() + ", destination: " + destPath);
                    try {
                        /* Perhaps use a key instead ? */
                        SshHelper.scpTo(c.getIp(), 22, config.getAgentSshUserName(), null, config.getAgentSshPassword(), destPath, srcIso.getAbsolutePath().toString(), "0644");
                    } catch (Exception es) {
                        LOGGER.error("Unexpected exception ", es);
                        String msg = "Unable to copy systemvm ISO on secondary storage. src location: " + srcIso.toString() + ", dest location: " + destPath;
                        LOGGER.error(msg);
                        throw new CloudRuntimeException(msg, es);
                    }
                }
            } finally {
                lock.unlock();
            }
        }
    } finally {
        lock.releaseRef();
    }
}
Also used : GlobalLock(com.cloud.utils.db.GlobalLock) FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) File(java.io.File) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 3 with StoragePlugin

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin in project cloudstack by apache.

the class Ovm3StoragePool method execute.

/**
     * Gets statistics for storage.
     *
     * @param cmd
     * @return
     */
public GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
    LOGGER.debug("Getting stats for: " + cmd.getStorageId());
    try {
        Linux host = new Linux(c);
        Linux.FileSystem fs = host.getFileSystemByUuid(cmd.getStorageId(), "nfs");
        StoragePlugin store = new StoragePlugin(c);
        String propUuid = store.deDash(cmd.getStorageId());
        String mntUuid = cmd.getStorageId();
        if (store == null || propUuid == null || mntUuid == null || fs == null) {
            String msg = "Null returned when retrieving stats for " + cmd.getStorageId();
            LOGGER.error(msg);
            return new GetStorageStatsAnswer(cmd, msg);
        }
        /* or is it mntUuid ish ? */
        StorageDetails sd = store.storagePluginGetFileSystemInfo(propUuid, mntUuid, fs.getHost(), fs.getDevice());
        /*
             * FIXME: cure me or kill me, this needs to trigger a reinit of
             * primary storage, actually the problem is more deeprooted, as when
             * the hypervisor reboots it looses partial context and needs to be
             * reinitiated.... actually a full configure round... how to trigger
             * that ?
             */
        if ("".equals(sd.getSize())) {
            String msg = "No size when retrieving stats for " + cmd.getStorageId();
            LOGGER.debug(msg);
            return new GetStorageStatsAnswer(cmd, msg);
        }
        long total = Long.parseLong(sd.getSize());
        long used = total - Long.parseLong(sd.getFreeSize());
        return new GetStorageStatsAnswer(cmd, total, used);
    } catch (Ovm3ResourceException e) {
        LOGGER.debug("GetStorageStatsCommand for " + cmd.getStorageId() + " failed", e);
        return new GetStorageStatsAnswer(cmd, e.getMessage());
    }
}
Also used : GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) StorageDetails(com.cloud.hypervisor.ovm3.objects.StoragePlugin.StorageDetails) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Example 4 with StoragePlugin

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin in project cloudstack by apache.

the class Ovm3StorageProcessor method createVolume.

/**
     * Creates a volume, just a normal empty volume.
     */
@Override
public Answer createVolume(CreateObjectCommand cmd) {
    LOGGER.debug("execute createVolume: " + cmd.getClass());
    DataTO data = cmd.getData();
    VolumeObjectTO volume = (VolumeObjectTO) data;
    try {
        /*
             * public Boolean storagePluginCreate(String uuid, String ssuuid,
             * String host, String file, Integer size)
             */
        String poolUuid = data.getDataStore().getUuid();
        String storeUrl = data.getDataStore().getUrl();
        URI uri = new URI(storeUrl);
        String host = uri.getHost();
        String file = getVirtualDiskPath(volume.getUuid(), poolUuid);
        Long size = volume.getSize();
        StoragePlugin sp = new StoragePlugin(c);
        FileProperties fp = sp.storagePluginCreate(poolUuid, host, file, size, false);
        if (!fp.getName().equals(file)) {
            return new CreateObjectAnswer("Filename mismatch: " + fp.getName() + " != " + file);
        }
        VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setName(volume.getName());
        newVol.setSize(fp.getSize());
        newVol.setPath(volume.getUuid());
        return new CreateObjectAnswer(newVol);
    } catch (Ovm3ResourceException | URISyntaxException e) {
        LOGGER.info("Volume creation failed: " + e.toString(), e);
        return new CreateObjectAnswer(e.toString());
    }
}
Also used : FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) DataTO(com.cloud.agent.api.to.DataTO) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Example 5 with StoragePlugin

use of com.cloud.hypervisor.ovm3.objects.StoragePlugin in project cloudstack by apache.

the class Ovm3StorageProcessor method deleteSnapshot.

/**
     * Is not used in normal operation, the SSVM takes care of this.
     */
@Override
public Answer deleteSnapshot(DeleteCommand cmd) {
    LOGGER.debug("execute deleteSnapshot: " + cmd.getClass());
    DataTO data = cmd.getData();
    SnapshotObjectTO snap = (SnapshotObjectTO) data;
    String storeUrl = data.getDataStore().getUrl();
    String snapUuid = snap.getPath();
    try {
        // snapshots/accountid/volumeid
        String secPoolUuid = pool.setupSecondaryStorage(storeUrl);
        String filePath = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + snapUuid + ".raw";
        StoragePlugin sp = new StoragePlugin(c);
        sp.storagePluginDestroy(secPoolUuid, filePath);
        LOGGER.debug("Snapshot deletion success: " + filePath);
        return new Answer(cmd, true, "Deleted Snapshot " + filePath);
    } catch (Ovm3ResourceException e) {
        LOGGER.info("Snapshot deletion failed: " + e.toString(), e);
        return new CreateObjectAnswer(e.toString());
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) Answer(com.cloud.agent.api.Answer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) DataTO(com.cloud.agent.api.to.DataTO) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Aggregations

Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)10 StoragePlugin (com.cloud.hypervisor.ovm3.objects.StoragePlugin)10 Answer (com.cloud.agent.api.Answer)4 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)4 DataTO (com.cloud.agent.api.to.DataTO)4 Linux (com.cloud.hypervisor.ovm3.objects.Linux)4 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)4 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)4 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)3 CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)3 FileProperties (com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties)3 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)3 ResignatureAnswer (org.apache.cloudstack.storage.command.ResignatureAnswer)3 SnapshotAndCopyAnswer (org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer)3 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)2 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)2 VolumeTO (com.cloud.agent.api.to.VolumeTO)2 StorageDetails (com.cloud.hypervisor.ovm3.objects.StoragePlugin.StorageDetails)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 URISyntaxException (java.net.URISyntaxException)2