Пример #1
0
long FBTestPluginAPI::countArrayLength(const FB::JSObjectPtr &jso) 
{
    if (!jso->HasProperty("getArray"))
        throw FB::invalid_arguments();
    FB::VariantList array = jso->GetProperty("getArray").cast<FB::VariantList>();
    long len = array.size();// array->GetProperty("length").convert_cast<long>();
    return len;
}
Пример #2
0
/**
 * Asynchronous function to open a new session
 */
void CVMWebAPISession::thread_open( const FB::variant& oConfigHash  ){
    CRASH_REPORT_BEGIN;
    int cpus = this->session->cpus;
    int ram = this->session->memory;
    int disk = this->session->disk;
    int flags = this->session->flags;
    std::string ver = this->session->version;
    int ans = 0;
    
    // If the user has provided an object, process overridable parameters
    if (oConfigHash.is_of_type<FB::JSObjectPtr>()) {
        FB::JSObjectPtr o = oConfigHash.cast<FB::JSObjectPtr>();
        
        // Check basic overridable: options
        if (o->HasProperty("cpus")  && __canOverride("cpus", this->session)) cpus = o->GetProperty("cpus").convert_cast<int>();
        if (o->HasProperty("ram")   && __canOverride("ram", this->session))  ram = o->GetProperty("ram").convert_cast<int>();
        if (o->HasProperty("disk")  && __canOverride("disk", this->session)) disk = o->GetProperty("disk").convert_cast<int>();
        
        // Check for overridable: flags
        if (o->HasProperty("flags") && __canOverride("flags", this->session)) {
            try {
                flags = o->GetProperty("flags").convert_cast<int>();
            } catch ( const FB::bad_variant_cast &) {
            }
        }
        
        // Check for overridable: diskURL
        if (o->HasProperty("diskURL") && __canOverride("diskURL", this->session)) {
            ver = o->GetProperty("diskURL").convert_cast<std::string>();
            flags |= HVF_DEPLOYMENT_HDD;
            
            // Check for 64bit image
            bool is64bit = false;
            if (o->HasProperty("cpu64bit")) {
                try {
                    is64bit = o->GetProperty("cpu64bit").convert_cast<bool>();
                } catch ( const FB::bad_variant_cast &) {
                    is64bit = false;
                }
            }
            if (is64bit)
                flags |= HVF_SYSTEM_64BIT;
            
        // Check for overridable: version
        } else if (o->HasProperty("version") && __canOverride("version", this->session)) {
            ver = o->GetProperty("version").convert_cast<std::string>();
            if (!isSanitized(&ver, "01234567890.-")) ver=DEFAULT_CERNVM_VERSION;
            flags |= HVF_SYSTEM_64BIT; // Micro is currently only 64-bit

        }
    }
    
    // Open session with the given flags
    ans = this->session->open( cpus, ram, disk, ver, flags );
    if (ans == 0) {
        WHEN_SAFE this->fire_open();
        
    } else {
        
        // Close session in case of a problem
        this->session->close( true );
        
        // Then fire errors
        WHEN_SAFE this->fire_openError(hypervisorErrorStr(ans), ans);
        WHEN_SAFE this->fire_error(hypervisorErrorStr(ans), ans, "open");
    }
    
    // The requirements of having a daemon might have changed
    try {
        CVMWebPtr p = this->getPlugin();
        if (p->hv != NULL) p->hv->checkDaemonNeed();
    } catch (...) {
        // InvalidPlugin might occur if the user unloads
        // the page while downloading the VM.
    }
    
    /* Start probing timer */
    this->probeTimer->start();

    CRASH_REPORT_END;
}