if (empty($record)) {
         $record = (object) array('name' => $submitteddata->name, 'shortname' => $submitteddata->shortname, 'description' => $submitteddata->description, 'vhostname' => $submitteddata->vhostname, 'vdbtype' => $submitteddata->vdbtype, 'vdbhost' => $submitteddata->vdbhost, 'vdblogin' => $submitteddata->vdblogin, 'vdbpass' => $submitteddata->vdbpass, 'vdbname' => $submitteddata->vdbname, 'vdbpersist' => $submitteddata->vdbpersist, 'vdbprefix' => $submitteddata->vdbprefix, 'vdbpersist' => $submitteddata->vdbpersist, 'vdatapath' => $submitteddata->vdatapath, 'mnet' => $submitteddata->mnet);
         $DB->insert_record('local_vmoodle', $record);
     }
     if (empty($automation)) {
         $message_object->message = get_string('plateformreactivate', 'local_vmoodle');
         $message_object->style = 'notifysuccess';
         $SESSION->vmoodle_ma['confirm_message'] = $message_object;
         redirect(new moodle_url('/local/vmoodle/view.php', array('view' => 'management')));
         die;
     }
     return 0;
 } else {
     // Checks if the chosen template still exists.
     $templates = vmoodle_get_available_templates();
     if (empty($templates) || !vmoodle_exist_template($submitteddata->vtemplate)) {
         // If the snapshot has been deleted between loading the add form and submitting it.
         $message_object->message = get_string('notemplates', 'local_vmoodle');
         if (empty($automation)) {
             $SESSION->vmoodle_ma['confirm_message'] = $message_object;
             redirect(new moodle_url('/local/vmoodle/view.php', array('view' => 'management')));
             die;
         }
         mtrace(get_string('notemplates', 'local_vmoodle'));
         return -1;
     }
     // Check if the required hostname has DNS resolution
     $domainname = preg_replace('/https?:\\/\\//', '', $submitteddata->vhostname);
     if (!gethostbynamel($domainname)) {
         if ($submitteddata->forcedns) {
             print_string('unknownhostforced', 'local_vmoodle');
}
$nodes = vmoodle_parse_csv_nodelist($options['nodes']);
if ($options['lint']) {
    print_object($nodes);
    die;
}
if (empty($nodes)) {
    cli_error(get_string('cliemptynodelist', 'local_vmoodle'));
}
mtrace(get_string('clistart', 'local_vmoodle'));
foreach ($nodes as $n) {
    mtrace(get_string('climakenode', 'local_vmoodle', $n->vhostname));
    $n->forcedns = 0;
    if (!empty($n->vtemplate)) {
        mtrace(get_string('cliusingtemplate', 'local_vmoodle', $n->vtemplate));
        if (!vmoodle_exist_template($n->vtemplate)) {
            mtrace(get_string('climissingtemplateskip', 'local_vmoodle', $n->vtemplate));
            continue;
        }
    }
    if ($DB->get_record('local_vmoodle', array('vhostname' => $n->vhostname))) {
        mtrace(get_string('clinodeexistsskip', 'local_vmoodle'));
        continue;
    }
    /*
     * This launches automatically all steps of the controller.management.php script several times
     * with the "doadd" action and progressing in steps.
     */
    $action = 'doadd';
    $SESSION->vmoodledata = $n;
    $automation = true;