Exemplo n.º 1
0
void ProjectCentral::check()
{
  m_CheckInfos.clear();

  if (!mp_FXDesc->modelDescriptor().items().empty())
  {
    checkModel();
  }
  else
  {
    m_CheckInfos.part(ProjectCheckInfos::PART_MODELDEF).updateStatus(PRJ_ERROR);
    m_CheckInfos.part(ProjectCheckInfos::PART_MODELDEF).addMessage(tr("Model is empty"));
  }

  checkSpatialDomain();

  checkDatastore();

  if (!mp_FXDesc->monitoringDescriptor().items().empty())
  {
    checkMonitoring();
  }
  else
  {
    m_CheckInfos.part(ProjectCheckInfos::PART_MONITORING).updateStatus(PRJ_WARNING);
    m_CheckInfos.part(ProjectCheckInfos::PART_MONITORING).addMessage(tr("Monitoring is empty"));
  }

  checkRunConfig();
}
Exemplo n.º 2
0
Arquivo: Rimp.cpp Projeto: benn-cs/aim
void Rimp::deleteVirtualImageFromDatastore(std::string& datastore, const std::string& virtualMachineUUID)
{
    string error("");
    RimpException rexecption;

    // check datastore path end with '/'
    if (datastore.at(datastore.size() - 1) != '/')
    {
        datastore = datastore.append("/");
    }
    
    checkRimpConfiguration();
    if (!checkDatastore(datastore))
    {
        error = error.append("Provided ''datastore'' :").append(datastore).append(" can not be used");
        LOG("[ERROR] [RIMP] %s", error.c_str());
        rexecption.description = error;
        throw rexecption;
    }

    LOG("[DEBUG] [RIMP] Deleting virtual machine [%s]", virtualMachineUUID.c_str());

    string viDatastorePath(datastore);
    viDatastorePath = viDatastorePath.append(virtualMachineUUID);

    // check the file exist on the datastore
    if (access(viDatastorePath.c_str(), F_OK) == -1)
    {
        error = error.append("Virtual image file does not exist on the ''datastore'' :");
        error = error.append(viDatastorePath);

        LOG("[WARNING] [RIMP] %s", error.c_str());
        return;
    }

    if (autobackup)
    {
        // Then backup the file rather than deleting it.
        string viDatastorePathBackup(datastore);
        viDatastorePathBackup = viDatastorePathBackup.append("backup/");
        viDatastorePathBackup = viDatastorePathBackup.append(virtualMachineUUID);

        if (access(viDatastorePathBackup.c_str(), F_OK) == 0)
        {
            // Then a backup already exists, delete it.
            remove(viDatastorePathBackup.c_str());
        }

        // Then perform a recovery rather then a full deploy.
        string renameError2 = fileRename( viDatastorePath, viDatastorePathBackup);

        if (!renameError2.empty())
        {
            error = error.append("Can not move :").append(viDatastorePath).append(" to :").append(viDatastorePathBackup).append("\nCaused by :").append(renameError2);

            LOG("[ERROR] [RIMP] %s", error.c_str());
            rexecption.description = error;
            throw rexecption;
        }

        LOG("[INFO] [RIMP] Backedup virtual machine [%s]", virtualMachineUUID.c_str());
        return;
    }

    remove(viDatastorePath.c_str());

    LOG("[INFO] [RIMP] Deleted virtual machine [%s]", virtualMachineUUID.c_str());
}
Exemplo n.º 3
0
Arquivo: Rimp.cpp Projeto: benn-cs/aim
void Rimp::copyFromRepositoryToDatastore(const std::string& virtualImageRepositoryPath, std::string& datastore,
        const std::string& virtualMachineUUID)
{
    string error("");
    RimpException rexecption;

    // check datastore path end with '/'
    if (datastore.at(datastore.size() - 1) != '/')
    {
        datastore = datastore.append("/");
    }
    
    checkRimpConfiguration();
    if (!checkDatastore(datastore))
    {
        error = error.append("Provided ''datastore'' :").append(datastore).append(" can not be used");
        LOG("[ERROR] [RIMP] %s", error.c_str());
        rexecption.description = error;
        throw rexecption;
    }

    LOG("[DEBUG] [RIMP] Instantiating virtual image [%s] for virtual machine [%s]",
            virtualImageRepositoryPath.c_str(), virtualMachineUUID.c_str());

    string viRepositoryPath(repository);
    viRepositoryPath = viRepositoryPath.append(virtualImageRepositoryPath);

    // Check the source file (on the repository) exist and can be read
    if (access(viRepositoryPath.c_str(), F_OK | R_OK) == -1)
    {
        error = error.append("Source file does not exist at [").append(viRepositoryPath).append("]");

        LOG("[ERROR] [RIMP] %s", error.c_str());
        rexecption.description = error;
        throw rexecption;
    }

    unsigned long int viSize = getFileSize(viRepositoryPath);

    /** Copy from ''Local Repository'' to ''Datastore''. */
    string viDatastorePath(datastore);
    viDatastorePath = viDatastorePath.append(virtualMachineUUID);

    // if the file exist on the datastore delete it
    if (access(viDatastorePath.c_str(), F_OK) == 0)
    {
        if (autorestore && autobackup)
        {
            // Sometimes an undeploy fails and the origional image does not get re/moved so we don't want to delete it and we don't need to try to recover so there is nothing to do.
            // NOTE: You really do want this, don't over think it.

            LOG("[INFO] [RIMP] Not checking for backup; existing virtual image instance found for virtual machine [%s]", virtualMachineUUID.c_str());
            return;
        }

        LOG("[WARNING] [RIMP] File with the same UUID already present on the ''datastore'' [%s], removing it.",
                viDatastorePath.c_str());

        remove(viDatastorePath.c_str());
    }

    if (autorestore)
    {
        string viDatastorePathBackup(datastore);
        viDatastorePathBackup = viDatastorePathBackup.append("backup/");
        viDatastorePathBackup = viDatastorePathBackup.append(virtualMachineUUID);
        if (access(viDatastorePathBackup.c_str(), F_OK | R_OK) == 0)
        {
            // Then perform a recovery rather then a full deploy.
            string renameError2 = fileRename(viDatastorePathBackup, viDatastorePath);

            if (!renameError2.empty())
            {
                error = error.append("Can not move :").append(viDatastorePathBackup).append(" to :").append(viDatastorePath).append("\nCaused by :").append(renameError2);

                LOG("[ERROR] [RIMP] %s", error.c_str());
                rexecption.description = error;
                throw rexecption;
            }

            LOG("[INFO] [RIMP] Recovered virtual image instance for virtual machine [%s]", virtualMachineUUID.c_str());
            return;
        }
    }

    // XXX viSize is the same on the repository and on the local repository
    unsigned long int datastoreFreeSize = getFreeSpaceOn(datastore);

    if (datastoreFreeSize < viSize)
    {
        error = error.append("There is no enough space left to copy the file :");
        error = error.append(viRepositoryPath).append(" to :").append(datastore);

        LOG("[ERROR] [RIMP] %s", error.c_str());
        rexecption.description = error;
        throw rexecption;
    }

    string copyError2 = fileCopy(viRepositoryPath, viDatastorePath);

    if (!copyError2.empty())
    {
        error = error.append("Can not copy to :").append(viDatastorePath).append("\nCaused by :").append(copyError2);

        LOG("[ERROR] [RIMP] %s", error.c_str());
        rexecption.description = error;
        throw rexecption;
    }

    LOG("[INFO] [RIMP] Created virtual image instance for virtual machine [%s]", virtualMachineUUID.c_str());
}