function get_sshterm_appliance_link($appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $p_appliance = new appliance();
    $p_appliance->get_instance_by_id($appliance_id);
    $p_resource = new resource();
    $p_resource->get_instance_by_id($p_appliance->resources);
    // get the parameters from the plugin config file
    $OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/sshterm/etc/openqrm-plugin-sshterm.conf";
    $store = openqrm_parse_conf($OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE);
    extract($store);
    $sshterm_login_ip = $p_resource->ip;
    $sshterm_window = 'window' . str_replace('.', '', $sshterm_login_ip);
    $sshterm_login_url = "https://{$sshterm_login_ip}:{$OPENQRM_PLUGIN_WEBSHELL_PORT}";
    $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects');
    $a = $html->a();
    $a->label = 'SSHTerm';
    $a->css = 'badge';
    $a->href = '#';
    $a->handler = 'onclick="sshwindow = window.open(\'' . $sshterm_login_url . '\',\'' . $sshterm_window . '\', \'location=0,status=0,scrollbars=yes,resizable=yes,width=972,height=500,left=100,top=100,screenX=400,screenY=100\'); sshwindow.focus(); return false;"';
    $plugin_link = '';
    if (strstr($p_appliance->state, "active")) {
        $plugin_link = $a;
    }
    if ($p_resource->id == 0) {
        $plugin_link = $a;
    }
    if ($p_resource->id == '') {
        $plugin_link = "";
    }
    return $plugin_link;
}
function openqrm_hybrid_cloud_monitor()
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $openqrm_server;
    global $BaseDir;
    global $RootDir;
    $now = $_SERVER['REQUEST_TIME'];
    // $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-monitor-hook", "Hybrid Cloud monitor hook DISABLED for now!!!", "", "", 0, 0, 0);
    // return;
    // $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-monitor-hook", "Hybrid Cloud monitor hook", "", "", 0, 0, 0);
    $last_stats = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/web/hybrid-cloud-stat/last_statistics";
    if (file_exists($last_stats)) {
        $last_host_stats = file_get_contents($last_stats);
        $secs_after_last_host_stat = $now - $last_host_stats;
        if ($secs_after_last_host_stat > 35) {
            file_put_contents($last_stats, $now);
            $server = new openqrm_server();
            $hc = new hybrid_cloud();
            $hc_account_arr = $hc->get_ids();
            foreach ($hc_account_arr as $id) {
                $hc_account_id = $id['hybrid_cloud_id'];
                $hc->get_instance_by_id($hc_account_id);
                $hc_authentication = '';
                // for every ec2/euca cloud account monitor every configured region
                if ($hc->account_type == 'aws' || $hc->account_type == 'euca') {
                    $hybrid_cloud_conf = $OPENQRM_SERVER_BASE_DIR . '/openqrm/plugins/hybrid-cloud/etc/openqrm-plugin-hybrid-cloud.conf';
                    $hybrid_cloud_conf_arr = openqrm_parse_conf($hybrid_cloud_conf);
                    $region_arr = explode(",", $hybrid_cloud_conf_arr['OPENQRM_PLUGIN_HYBRID_CLOUD_REGIONS']);
                    $hc_authentication .= ' -O ' . $hc->access_key;
                    $hc_authentication .= ' -W ' . $hc->secret_key;
                }
                // one region for openstack
                if ($hc->account_type == 'lc-openstack') {
                    $region_arr = array("OpenStack");
                    $hc_authentication .= ' -u ' . $hc->username;
                    $hc_authentication .= ' -p ' . $hc->password;
                    $hc_authentication .= ' -q ' . $hc->host;
                    $hc_authentication .= ' -x ' . $hc->port;
                    $hc_authentication .= ' -g ' . $hc->tenant;
                    $hc_authentication .= ' -e ' . $hc->endpoint;
                }
                foreach ($region_arr as $region) {
                    $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-monitor-hook", "Hybrid Cloud monitor - checking Cloud statistics for Account " . $hc->account_name . " - " . $region, "", "", 0, 0, 0);
                    $statfile = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/web/hybrid-cloud-stat/" . $hc_account_id . ".instances_statistics.log";
                    $command = $OPENQRM_SERVER_BASE_DIR . '/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm describe --statistics true';
                    $command .= ' -i ' . $hc->id;
                    $command .= ' -n ' . $hc->account_name;
                    $command .= ' -t ' . $hc->account_type;
                    $command .= ' -ir ' . $region;
                    $command .= $hc_authentication;
                    $command .= ' --openqrm-cmd-mode background';
                    if (file_exists($statfile)) {
                        unlink($statfile);
                    }
                    $server->send_command($command, NULL, true);
                    while (!file_exists($statfile)) {
                        usleep(10000);
                        clearstatcache();
                    }
                    $content = file_get_contents($statfile);
                    $content = explode("\n", $content);
                    $b = array();
                    foreach ($content as $k => $v) {
                        if ($v !== '') {
                            $tmp = explode('@', $v);
                            $name = $tmp[1];
                            $ami = $tmp[2];
                            $public_hostname = $tmp[3];
                            $private_hostname = $tmp[4];
                            $state = $tmp[5];
                            $keypair = $tmp[6];
                            $unknown1 = $tmp[7];
                            $unknown2 = $tmp[8];
                            $type = $tmp[9];
                            $date = $tmp[10];
                            $region = $tmp[11];
                            $unknown4 = $tmp[12];
                            $unknown5 = $tmp[13];
                            $unknown6 = $tmp[14];
                            $monitoring = $tmp[15];
                            $public_ip = $hc->format_ip_address($tmp[16]);
                            $private_ip = $hc->format_ip_address($tmp[17]);
                            $unknown7 = $tmp[18];
                            $unknown8 = $tmp[19];
                            $store = $tmp[20];
                            $unknown9 = $tmp[21];
                            $unknown10 = $tmp[22];
                            $unknown11 = $tmp[23];
                            $unknown12 = $tmp[24];
                            $hvm = $tmp[25];
                            $virt_type = $tmp[26];
                            $mac = '';
                            // check for idle instances
                            $resource = new resource();
                            if ($state == 'idle') {
                                $mac = $tmp[30];
                                $resource->get_instance_by_mac($mac);
                                $resource_fields["resource_state"] = 'active';
                                $resource_fields["resource_lastgood"] = $now;
                                $resource_fields["resource_cpunumber"] = $hc->translate_resource_components('cpu', $type);
                                $resource_fields["resource_nics"] = $hc->translate_resource_components('net', $type);
                                $resource_fields["resource_memtotal"] = $hc->translate_resource_components('mem', $type);
                                $resource_fields["resource_memused"] = "0";
                                $resource_fields["resource_load"] = "0";
                                // restore mgmt ip
                                $resource_fields["resource_ip"] = $resource->network;
                                $resource->update_info($resource->id, $resource_fields);
                            } else {
                                if ($state == 'running') {
                                    // check if existing, if not auto-create resource, image and appliance
                                    if ($resource->exists_by_name($name)) {
                                        // update stats
                                        $resource->get_instance_id_by_hostname($name);
                                        $resource->get_instance_by_id($resource->id);
                                        $resource_fields["resource_state"] = 'active';
                                        $resource_fields["resource_lastgood"] = $now;
                                        $resource_fields["resource_cpunumber"] = $hc->translate_resource_components('cpu', $type);
                                        $resource_fields["resource_nics"] = $hc->translate_resource_components('net', $type);
                                        $resource_fields["resource_memtotal"] = $hc->translate_resource_components('mem', $type);
                                        $resource_fields["resource_memused"] = $resource_fields["resource_memtotal"];
                                        $resource_fields["resource_load"] = "1";
                                        if (strlen($public_ip) && $resource->ip != $public_ip) {
                                            // set public ip, update early and run nagios hook
                                            $resource_fields["resource_ip"] = $public_ip;
                                            $resource->update_info($resource->id, $resource_fields);
                                            // nagios enabled and started ?
                                            if (file_exists($RootDir . "/plugins/nagios3/.running")) {
                                                $virtualization = new virtualization();
                                                $virtualization->get_instance_by_type("hybrid-cloud-vm-local");
                                                $hc_appliance = new appliance();
                                                $hc_appliance->get_instance_by_virtualization_and_resource($virtualization->id, $resource->id);
                                                if (strlen($hc_appliance->name)) {
                                                    // special nagios classes
                                                    require_once $RootDir . "/plugins/nagios3/class/nagios3_service.class.php";
                                                    require_once $RootDir . "/plugins/nagios3/class/nagios3_host.class.php";
                                                    // get the nagios service checks
                                                    $nagios_host = new nagios3_host();
                                                    $nagios_host->get_instance_by_appliance_id($hc_appliance->id);
                                                    $active_nagios_services = explode(',', $nagios_host->appliance_services);
                                                    $nagios_service_list = '';
                                                    foreach ($active_nagios_services as $service_id) {
                                                        $nagios_service = new nagios3_service();
                                                        $nagios_service->get_instance_by_id($service_id);
                                                        $nagios_service_list = $nagios_service_list . "," . $nagios_service->port;
                                                    }
                                                    $nagios_service_list = substr($nagios_service_list, 1);
                                                    if (strlen($nagios_service_list)) {
                                                        // appliance has nagios service checks configured
                                                        $nagios_appliance_stop_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nagios3/bin/openqrm-nagios-manager remove_host -n " . $hc_appliance->name . " --openqrm-cmd-mode background";
                                                        $server->send_command($nagios_appliance_stop_cmd, NULL, true);
                                                        sleep(2);
                                                        $nagios_appliance_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nagios3/bin/openqrm-nagios-manager add -n " . $hc_appliance->name . " -i " . $public_ip . " -p " . $nagios_service_list . " --openqrm-cmd-mode background";
                                                        $server->send_command($nagios_appliance_start_cmd, NULL, true);
                                                    }
                                                }
                                            }
                                            // nagios finished
                                        }
                                        $resource->update_info($resource->id, $resource_fields);
                                    } else {
                                        // through error for now
                                        $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-monitor-hook", "New Resource detected with name " . $name . "!", "", "", 0, 0, 0);
                                    }
                                }
                            }
                        }
                    }
                    unlink($statfile);
                }
            }
        }
    } else {
        file_put_contents($last_stats, $now);
    }
}
 function __region_select()
 {
     $response = $this->response;
     $form = $response->get_form($this->actions_name, $this->action);
     $hybrid_cloud_conf = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/etc/openqrm-plugin-hybrid-cloud.conf';
     $hybrid_cloud_conf_arr = openqrm_parse_conf($hybrid_cloud_conf);
     $region_arr = explode(",", $hybrid_cloud_conf_arr['OPENQRM_PLUGIN_HYBRID_CLOUD_REGIONS']);
     $regions = array();
     foreach ($region_arr as $region) {
         $region = trim($region);
         $regions[] = array($region);
     }
     $region = $response->html->request()->get('region');
     if ($region === '' && count($regions) > 0) {
         $region = $regions[0][0];
         $_REQUEST['region'] = $region;
     }
     $this->response->add('region', $region);
     $d['region']['label'] = '';
     $d['region']['object']['type'] = 'htmlobject_select';
     $d['region']['object']['attrib']['id'] = 'region';
     $d['region']['object']['attrib']['name'] = 'region';
     $d['region']['object']['attrib']['css'] = 'region';
     $d['region']['object']['attrib']['handler'] = 'onchange="form.submit(); return false;"';
     $d['region']['object']['attrib']['index'] = array(0, 0);
     $d['region']['object']['attrib']['options'] = $regions;
     $d['region']['object']['attrib']['selected'] = array($region);
     $form->add($d);
     $submit = $form->get_elements('submit');
     $submit->handler = 'onclick="wait();"';
     $form->add($submit, 'submit');
     $submit = $form->get_elements('cancel');
     $submit->style = 'display:none;';
     $form->add($submit, 'cancel');
     return $form->get_string();
 }
Ejemplo n.º 4
0
 function __vmlist($id, $vm, $vtype)
 {
     $port = '';
     $basedir = $this->openqrm->get('basedir');
     $vm_resource = $this->openqrm->resource();
     $vm_resource->get_instance_by_id($id);
     $resource = $this->openqrm->resource();
     $resource->get_instance_by_id($vm_resource->vhostid);
     switch ($vtype) {
         case 'kvm':
             if ($vm_resource->vnc != '') {
                 return $vm_resource->vnc;
             }
             $file = $basedir . '/plugins/' . $vtype . '/web/' . $vtype . '-stat/' . $resource->id . '.vm_list';
             if ($this->file->exists($file)) {
                 $this->file->remove($file);
             }
             $command = $basedir . '/plugins/' . $vtype . '/bin/openqrm-' . $vtype . '-vm post_vm_list';
             $command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
             $command .= ' --openqrm-ui-user ' . $this->user->name;
             $command .= ' --openqrm-cmd-mode regular';
             $resource->send_command($resource->ip, $command);
             while (!$this->file->exists($file)) {
                 usleep(10000);
                 // sleep 10ms to unload the CPU
                 clearstatcache();
             }
             if ($this->file->exists($file)) {
                 $lines = explode("\n", $this->file->get_contents($file));
                 foreach ($lines as $line) {
                     if ($line !== '') {
                         $line = explode('@', $line);
                         if ($line[1] === $vm) {
                             $tmp = explode(':', $line[5]);
                             $port = $tmp[1];
                             // update vnc in resource
                             if ($vm_resource->vnc == '') {
                                 $resource_fields["resource_vnc"] = $port;
                                 $resource_fields["resource_vname"] = $vm;
                                 $vm_resource->update_info($id, $resource_fields);
                             }
                             break;
                         }
                     }
                 }
             }
             return $port;
             break;
         case 'vmware-esx':
             // make sure vnc is enabled in the Hosts firewall
             $command = $this->openqrm->get('basedir') . "/plugins/vmware-esx/bin/openqrm-vmware-esx-vm enable_vnc -i " . $resource->ip;
             $command .= ' --openqrm-ui-user ' . $this->user->name;
             $command .= ' --openqrm-cmd-mode background';
             $this->openqrm_server->send_command($command, NULL, true);
             sleep(5);
             if ($vm_resource->vnc != '') {
                 return $vm_resource->vnc;
             }
             $file = $basedir . '/plugins/' . $vtype . '/web/' . $vtype . '-stat/' . $resource->ip . '.' . $vm . '.vm_config';
             if ($this->file->exists($file)) {
                 $this->file->remove($file);
             }
             $command = $basedir . '/plugins/' . $vtype . '/bin/openqrm-' . $vtype . '-vm post_vm_config';
             $command .= ' -i ' . $resource->ip . ' -n ' . $vm;
             $command .= ' --openqrm-ui-user ' . $this->user->name;
             $command .= ' --openqrm-cmd-mode regular';
             $this->openqrm_server->send_command($command, NULL, true);
             while (!$this->file->exists($file)) {
                 usleep(10000);
                 // sleep 10ms to unload the CPU
                 clearstatcache();
             }
             if ($this->file->exists($file)) {
                 $data = openqrm_parse_conf($file);
                 if (!isset($data['OPENQRM_VMWARE_ESX_VM_VNC_PORT'])) {
                     return;
                 }
                 $tport = $data['OPENQRM_VMWARE_ESX_VM_VNC_PORT'];
                 if ($tport > 0) {
                     $tport = $tport - 5900;
                     // $this->event->log("console", $_SERVER['REQUEST_TIME'], 2, "novnc.console.class.php", "NoVNC FILE $file EXISTS port $tport !", "", "", 0, 0, 0);
                     // update vnc in resource
                     if ($vm_resource->vnc == '') {
                         $resource_fields["resource_vnc"] = $tport;
                         $resource_fields["resource_vname"] = $vm;
                         $vm_resource->update_info($id, $resource_fields);
                     }
                     return $tport;
                 } else {
                     return;
                 }
             }
             return;
             break;
         default:
             $this->event->log("console", $_SERVER['REQUEST_TIME'], 2, "novnc.console.class.php", "NoVNC console for VM type " . $vtype . " is not yet supported!", "", "", 0, 0, 0);
             break;
     }
 }
Ejemplo n.º 5
0
 function get_response()
 {
     $response = $this->response;
     $form = $response->get_form($this->actions_name, 'update');
     $cpus[] = array("1", "1 CPU");
     $cpus[] = array("2", "2 CPUs");
     $cpus[] = array("4", "4 CPUs");
     $cpus[] = array("8", "8 CPUs");
     $cpus[] = array("16", "16 CPUs");
     $ram[] = array("256", "256 MB");
     $ram[] = array("512", "512 MB");
     $ram[] = array("1024", "1 GB");
     $ram[] = array("2048", "2 GB");
     $ram[] = array("4096", "4 GB");
     $ram[] = array("8192", "8 GB");
     $ram[] = array("16384", "16 GB");
     $ram[] = array("32768", "32 GB");
     $ram[] = array("65536", "64 GB");
     $nics[] = array("virtio", $this->lang['form_net_virtio']);
     $nics[] = array("e1000", $this->lang['form_net_e1000']);
     $nics[] = array("rtl8139", $this->lang['form_net_rtl8139']);
     $keymaps[] = array("de", "de");
     $keymaps[] = array("en-us", "en-us");
     $keymaps[] = array("es", "es");
     $keymaps[] = array("fr", "fr");
     $keymaps[] = array("it", "it");
     $keymaps[] = array("ja", "ja");
     $keymaps[] = array("nl", "nl");
     $keymaps[] = array("ru", "ru");
     $keymaps[] = array("none", "none");
     $disk_interfaces[] = array("virtio", "Virtio");
     $disk_interfaces[] = array("ide", "IDE");
     $disk_select_arr[] = array('1024', '1 GB');
     $disk_select_arr[] = array('2048', '2 GB');
     $disk_select_arr[] = array('10240', '10 GB');
     $disk_select_arr[] = array('20480', '20 GB');
     $disk_select_arr[] = array('51200', '50 GB');
     $disk_select_arr[] = array('102400', '100 GB');
     $swap_select_arr[] = array('1024', '1 GB');
     $swap_select_arr[] = array('2048', '2 GB');
     $file = $this->openqrm->get('basedir') . '/plugins/kvm/web/kvm-stat/' . $this->resource->id . '.' . $this->vm . '.vm_config';
     $ini = openqrm_parse_conf($file);
     $bridges = array();
     $bridge_list = $ini['OPENQRM_KVM_BRIDGES'];
     $bridge_list = rtrim($bridge_list, ":");
     $bridge_array = explode(':', $bridge_list);
     // handle no bridge error
     if (isset($bridge_array[0]) && $bridge_array[0] !== '') {
         foreach ($bridge_array as $b) {
             $bridges[] = array($b, $b);
         }
         $this->response->params['mac'] = $ini['OPENQRM_KVM_VM_MAC_1'];
         $submit = $form->get_elements('submit');
         $submit->handler = 'onclick="wait();"';
         $form->add($submit, 'submit');
         $submit = $form->get_elements('cancel');
         $submit->handler = 'onclick="cancel();"';
         $form->add($submit, 'cancel');
         $d['name']['label'] = $this->lang['form_name'];
         $d['name']['static'] = true;
         $d['name']['object']['type'] = 'htmlobject_input';
         $d['name']['object']['attrib']['name'] = 'name';
         $d['name']['object']['attrib']['id'] = 'name';
         $d['name']['object']['attrib']['type'] = 'text';
         $d['name']['object']['attrib']['value'] = $this->vm;
         $d['name']['object']['attrib']['disabled'] = true;
         $d['cpus']['label'] = $this->lang['form_cpus'];
         $d['cpus']['required'] = true;
         $d['cpus']['object']['type'] = 'htmlobject_select';
         $d['cpus']['object']['attrib']['name'] = 'cpus';
         $d['cpus']['object']['attrib']['index'] = array(0, 1);
         $d['cpus']['object']['attrib']['options'] = $cpus;
         $d['cpus']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_CPUS']);
         $d['memory']['label'] = $this->lang['form_memory'];
         $d['memory']['required'] = true;
         $d['memory']['object']['type'] = 'htmlobject_select';
         $d['memory']['object']['attrib']['name'] = 'memory';
         $d['memory']['object']['attrib']['index'] = array(0, 1);
         $d['memory']['object']['attrib']['options'] = $ram;
         if ($ini['OPENQRM_KVM_VM_RAM'] !== '') {
             $d['memory']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_RAM']);
         }
         $vmtype = $this->response->html->request()->get('vmtype');
         if ($vmtype === 'kvm-vm-net') {
             $d['disk']['label'] = $this->lang['form_swap'];
             $d['disk']['object']['type'] = 'htmlobject_select';
             $d['disk']['object']['attrib']['index'] = array(0, 1);
             $d['disk']['object']['attrib']['id'] = 'disk';
             $d['disk']['object']['attrib']['name'] = 'disk';
             $d['disk']['object']['attrib']['options'] = $swap_select_arr;
             $d['cdrom_iso_path'] = "";
             $d['cdrom_button'] = "";
         } else {
             $d['disk']['label'] = $this->lang['form_disk'];
             $d['disk']['object']['type'] = 'htmlobject_select';
             $d['disk']['object']['attrib']['index'] = array(0, 1);
             $d['disk']['object']['attrib']['id'] = 'disk';
             $d['disk']['object']['attrib']['name'] = 'disk';
             $d['disk']['object']['attrib']['options'] = $disk_select_arr;
             $d['cdrom_iso_path']['label'] = $this->lang['form_cdrom'];
             $d['cdrom_iso_path']['object']['type'] = 'htmlobject_input';
             $d['cdrom_iso_path']['object']['attrib']['type'] = 'text';
             $d['cdrom_iso_path']['object']['attrib']['id'] = 'cdrom';
             $d['cdrom_iso_path']['object']['attrib']['name'] = 'cdrom';
             if ($ini['OPENQRM_KVM_VM_CDROM2'] !== '') {
                 $cdrompath = str_replace('-drive file=', '', $ini['OPENQRM_KVM_VM_CDROM2']);
                 $cdrompath = str_replace(',media=cdrom', '', $cdrompath);
                 $d['cdrom_iso_path']['object']['attrib']['value'] = $cdrompath;
             }
             $d['cdrom_button']['static'] = true;
             $d['cdrom_button']['object']['type'] = 'htmlobject_input';
             $d['cdrom_button']['object']['attrib']['type'] = 'button';
             $d['cdrom_button']['object']['attrib']['name'] = 'cdrom_button';
             $d['cdrom_button']['object']['attrib']['id'] = 'cdrom_button';
             $d['cdrom_button']['object']['attrib']['css'] = 'browse-button';
             $d['cdrom_button']['object']['attrib']['handler'] = 'onclick="filepicker.init(\'cdrom\'); return false;"';
             $d['cdrom_button']['object']['attrib']['style'] = "display:none;";
             $d['cdrom_button']['object']['attrib']['value'] = $this->lang['lang_browse'];
         }
         $d['disk_interface']['label'] = $this->lang['form_disk_interface'];
         $d['disk_interface']['required'] = true;
         $d['disk_interface']['object']['type'] = 'htmlobject_select';
         $d['disk_interface']['object']['attrib']['name'] = 'disk_interface';
         $d['disk_interface']['object']['attrib']['id'] = 'disk_interface';
         $d['disk_interface']['object']['attrib']['index'] = array(0, 1);
         $d['disk_interface']['object']['attrib']['options'] = $disk_interfaces;
         $d['disk_interface']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_DISK_INTERFACE']);
         $d['net0']['label'] = $this->lang['lang_net_0'];
         $d['net0']['object']['type'] = 'htmlobject_input';
         $d['net0']['object']['attrib']['type'] = 'checkbox';
         $d['net0']['object']['attrib']['id'] = 'net0';
         $d['net0']['object']['attrib']['name'] = 'net0';
         $d['net0']['object']['attrib']['value'] = 'enabled';
         $d['net0']['object']['attrib']['checked'] = true;
         $d['net0']['object']['attrib']['disabled'] = true;
         $d['mac']['label'] = $this->lang['form_mac'];
         $d['mac']['static'] = true;
         $d['mac']['object']['type'] = 'htmlobject_input';
         $d['mac']['object']['attrib']['name'] = 'dummy';
         $d['mac']['object']['attrib']['type'] = 'text';
         $d['mac']['object']['attrib']['value'] = $ini['OPENQRM_KVM_VM_MAC_1'];
         $d['mac']['object']['attrib']['maxlength'] = 50;
         $d['mac']['object']['attrib']['disabled'] = true;
         $d['bridge']['label'] = $this->lang['form_bridge'];
         $d['bridge']['required'] = true;
         $d['bridge']['object']['type'] = 'htmlobject_select';
         $d['bridge']['object']['attrib']['name'] = 'bridge';
         $d['bridge']['object']['attrib']['index'] = array(0, 1);
         $d['bridge']['object']['attrib']['options'] = $bridges;
         $d['bridge']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_BRIDGE_1']);
         $d['nic']['label'] = $this->lang['form_netdevice'];
         $d['nic']['required'] = true;
         $d['nic']['object']['type'] = 'htmlobject_select';
         $d['nic']['object']['attrib']['name'] = 'nic';
         $d['nic']['object']['attrib']['index'] = array(0, 1);
         $d['nic']['object']['attrib']['options'] = $nics;
         $d['nic']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_NIC_TYPE_1']);
         // net 1
         $checked = false;
         if ($ini['OPENQRM_KVM_VM_MAC_2'] !== '') {
             $mac = $ini['OPENQRM_KVM_VM_MAC_2'];
             $checked = true;
         } else {
             $this->resource->generate_mac();
             $mac = $this->resource->mac;
         }
         $d['net1']['label'] = $this->lang['lang_net_1'];
         $d['net1']['object']['type'] = 'htmlobject_input';
         $d['net1']['object']['attrib']['type'] = 'checkbox';
         $d['net1']['object']['attrib']['id'] = 'net1';
         $d['net1']['object']['attrib']['name'] = 'net1';
         $d['net1']['object']['attrib']['value'] = 'enabled';
         $d['net1']['object']['attrib']['checked'] = $checked;
         $d['net1']['object']['attrib']['handler'] = 'onchange="nettoggle(this);"';
         $d['mac1']['label'] = $this->lang['form_mac'];
         $d['mac1']['object']['type'] = 'htmlobject_input';
         $d['mac1']['object']['attrib']['name'] = 'mac1';
         $d['mac1']['object']['attrib']['type'] = 'text';
         $d['mac1']['object']['attrib']['value'] = $mac;
         $d['mac1']['object']['attrib']['maxlength'] = 50;
         $d['bridge1']['label'] = $this->lang['form_bridge'];
         $d['bridge1']['object']['type'] = 'htmlobject_select';
         $d['bridge1']['object']['attrib']['name'] = 'bridge1';
         $d['bridge1']['object']['attrib']['index'] = array(0, 1);
         $d['bridge1']['object']['attrib']['options'] = $bridges;
         if (isset($ini['OPENQRM_KVM_VM_BRIDGE_2']) && $checked === true) {
             $d['bridge1']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_BRIDGE_2']);
         }
         $d['nic1']['label'] = $this->lang['form_netdevice'];
         $d['nic1']['object']['type'] = 'htmlobject_select';
         $d['nic1']['object']['attrib']['name'] = 'nic1';
         $d['nic1']['object']['attrib']['index'] = array(0, 1);
         $d['nic1']['object']['attrib']['options'] = $nics;
         if ($checked === true) {
             $d['nic1']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_NIC_TYPE_2']);
         }
         // net 2
         $checked = false;
         if ($ini['OPENQRM_KVM_VM_MAC_3'] !== '') {
             $mac = $ini['OPENQRM_KVM_VM_MAC_3'];
             $checked = true;
         } else {
             $this->resource->generate_mac();
             $mac = $this->resource->mac;
         }
         $d['net2']['label'] = $this->lang['lang_net_2'];
         $d['net2']['object']['type'] = 'htmlobject_input';
         $d['net2']['object']['attrib']['type'] = 'checkbox';
         $d['net2']['object']['attrib']['id'] = 'net2';
         $d['net2']['object']['attrib']['name'] = 'net2';
         $d['net2']['object']['attrib']['value'] = 'enabled';
         $d['net2']['object']['attrib']['checked'] = $checked;
         $d['net2']['object']['attrib']['handler'] = 'onchange="nettoggle(this);"';
         $d['mac2']['label'] = $this->lang['form_mac'];
         $d['mac2']['object']['type'] = 'htmlobject_input';
         $d['mac2']['object']['attrib']['name'] = 'mac2';
         $d['mac2']['object']['attrib']['type'] = 'text';
         $d['mac2']['object']['attrib']['maxlength'] = 50;
         $d['mac2']['object']['attrib']['value'] = $mac;
         $d['bridge2']['label'] = $this->lang['form_bridge'];
         $d['bridge2']['object']['type'] = 'htmlobject_select';
         $d['bridge2']['object']['attrib']['name'] = 'bridge2';
         $d['bridge2']['object']['attrib']['index'] = array(0, 1);
         $d['bridge2']['object']['attrib']['options'] = $bridges;
         if (isset($ini['OPENQRM_KVM_VM_BRIDGE_3']) && $checked === true) {
             $d['bridge2']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_BRIDGE_3']);
         }
         $d['nic2']['label'] = $this->lang['form_netdevice'];
         $d['nic2']['object']['type'] = 'htmlobject_select';
         $d['nic2']['object']['attrib']['name'] = 'nic2';
         $d['nic2']['object']['attrib']['index'] = array(0, 1);
         $d['nic2']['object']['attrib']['options'] = $nics;
         if ($checked === true) {
             $d['nic2']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_NIC_TYPE_3']);
         }
         // net 3
         $checked = false;
         if ($ini['OPENQRM_KVM_VM_MAC_4'] !== '') {
             $mac = $ini['OPENQRM_KVM_VM_MAC_4'];
             $checked = true;
         } else {
             $this->resource->generate_mac();
             $mac = $this->resource->mac;
         }
         $d['net3']['label'] = $this->lang['lang_net_3'];
         $d['net3']['object']['type'] = 'htmlobject_input';
         $d['net3']['object']['attrib']['type'] = 'checkbox';
         $d['net3']['object']['attrib']['id'] = 'net3';
         $d['net3']['object']['attrib']['name'] = 'net3';
         $d['net3']['object']['attrib']['value'] = 'enabled';
         $d['net3']['object']['attrib']['checked'] = $checked;
         $d['net3']['object']['attrib']['handler'] = 'onchange="nettoggle(this);"';
         $d['mac3']['label'] = $this->lang['form_mac'];
         $d['mac3']['object']['type'] = 'htmlobject_input';
         $d['mac3']['object']['attrib']['name'] = 'mac3';
         $d['mac3']['object']['attrib']['type'] = 'text';
         $d['mac3']['object']['attrib']['value'] = $mac;
         $d['mac3']['object']['attrib']['maxlength'] = 50;
         $d['bridge3']['label'] = $this->lang['form_bridge'];
         $d['bridge3']['object']['type'] = 'htmlobject_select';
         $d['bridge3']['object']['attrib']['name'] = 'bridge3';
         $d['bridge3']['object']['attrib']['index'] = array(0, 1);
         $d['bridge3']['object']['attrib']['options'] = $bridges;
         if (isset($ini['OPENQRM_KVM_VM_BRIDGE_4']) && $checked === true) {
             $d['bridge3']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_BRIDGE_4']);
         }
         $d['nic3']['label'] = $this->lang['form_netdevice'];
         $d['nic3']['object']['type'] = 'htmlobject_select';
         $d['nic3']['object']['attrib']['name'] = 'nic3';
         $d['nic3']['object']['attrib']['index'] = array(0, 1);
         $d['nic3']['object']['attrib']['options'] = $nics;
         if ($checked === true) {
             $d['nic3']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_NIC_TYPE_4']);
         }
         // net 4
         $checked = false;
         if ($ini['OPENQRM_KVM_VM_MAC_5'] !== '') {
             $mac = $ini['OPENQRM_KVM_VM_MAC_5'];
             $checked = true;
         } else {
             $this->resource->generate_mac();
             $mac = $this->resource->mac;
         }
         $d['net4']['label'] = $this->lang['lang_net_4'];
         $d['net4']['object']['type'] = 'htmlobject_input';
         $d['net4']['object']['attrib']['type'] = 'checkbox';
         $d['net4']['object']['attrib']['id'] = 'net4';
         $d['net4']['object']['attrib']['name'] = 'net4';
         $d['net4']['object']['attrib']['value'] = 'enabled';
         $d['net4']['object']['attrib']['checked'] = $checked;
         $d['net4']['object']['attrib']['handler'] = 'onchange="nettoggle(this);"';
         $d['mac4']['label'] = $this->lang['form_mac'];
         $d['mac4']['object']['type'] = 'htmlobject_input';
         $d['mac4']['object']['attrib']['name'] = 'mac4';
         $d['mac4']['object']['attrib']['type'] = 'text';
         $d['mac4']['object']['attrib']['value'] = $mac;
         $d['mac4']['object']['attrib']['maxlength'] = 50;
         $d['bridge4']['label'] = $this->lang['form_bridge'];
         $d['bridge4']['object']['type'] = 'htmlobject_select';
         $d['bridge4']['object']['attrib']['name'] = 'bridge4';
         $d['bridge4']['object']['attrib']['index'] = array(0, 1);
         $d['bridge4']['object']['attrib']['options'] = $bridges;
         if (isset($ini['OPENQRM_KVM_VM_BRIDGE_5']) && $checked === true) {
             $d['bridge4']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_BRIDGE_5']);
         }
         $d['nic4']['label'] = $this->lang['form_netdevice'];
         $d['nic4']['object']['type'] = 'htmlobject_select';
         $d['nic4']['object']['attrib']['name'] = 'nic4';
         $d['nic4']['object']['attrib']['index'] = array(0, 1);
         $d['nic4']['object']['attrib']['options'] = $nics;
         if ($checked === true) {
             $d['nic4']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_NIC_TYPE_5']);
         }
         // boot from
         $d['boot_cd'] = '';
         $d['boot_iso'] = '';
         $d['boot_iso_path'] = '';
         $d['boot_local'] = '';
         $d['browse_button'] = '';
         if ($vmtype !== 'kvm-vm-net') {
             $d['boot_cd']['label'] = $this->lang['form_boot_cd'];
             $d['boot_cd']['object']['type'] = 'htmlobject_input';
             $d['boot_cd']['object']['attrib']['type'] = 'radio';
             $d['boot_cd']['object']['attrib']['name'] = 'boot';
             $d['boot_cd']['object']['attrib']['value'] = 'cdrom';
             if ($ini['OPENQRM_KVM_VM_BOOT'] === 'cdrom') {
                 $d['boot_cd']['object']['attrib']['checked'] = true;
             }
             $d['boot_iso']['label'] = $this->lang['form_boot_iso'];
             $d['boot_iso']['object']['type'] = 'htmlobject_input';
             $d['boot_iso']['object']['attrib']['type'] = 'radio';
             $d['boot_iso']['object']['attrib']['id'] = 'boot_iso';
             $d['boot_iso']['object']['attrib']['name'] = 'boot';
             $d['boot_iso']['object']['attrib']['value'] = 'iso';
             if (strpos($ini['OPENQRM_KVM_VM_BOOT'], 'iso') !== false) {
                 $isopath = str_replace('iso:', '', $ini['OPENQRM_KVM_VM_BOOT']);
                 $d['boot_iso']['object']['attrib']['checked'] = true;
             }
             $d['boot_iso_path']['label'] = $this->lang['form_iso_path'];
             $d['boot_iso_path']['object']['type'] = 'htmlobject_input';
             $d['boot_iso_path']['object']['attrib']['type'] = 'text';
             $d['boot_iso_path']['object']['attrib']['id'] = 'iso_path';
             $d['boot_iso_path']['object']['attrib']['name'] = 'iso_path';
             if (isset($isopath)) {
                 $d['boot_iso_path']['object']['attrib']['value'] = $isopath;
             }
             $d['browse_button']['static'] = true;
             $d['browse_button']['object']['type'] = 'htmlobject_input';
             $d['browse_button']['object']['attrib']['type'] = 'button';
             $d['browse_button']['object']['attrib']['name'] = 'browse_button';
             $d['browse_button']['object']['attrib']['id'] = 'browsebutton';
             $d['browse_button']['object']['attrib']['css'] = 'browse-button';
             $d['browse_button']['object']['attrib']['handler'] = 'onclick="filepicker.init(\'iso_path\'); return false;"';
             $d['browse_button']['object']['attrib']['style'] = "display:none;";
             $d['browse_button']['object']['attrib']['value'] = $this->lang['lang_browse'];
             $d['boot_local']['label'] = $this->lang['form_boot_local'];
             $d['boot_local']['object']['type'] = 'htmlobject_input';
             $d['boot_local']['object']['attrib']['type'] = 'radio';
             $d['boot_local']['object']['attrib']['name'] = 'boot';
             $d['boot_local']['object']['attrib']['value'] = 'local';
             if ($ini['OPENQRM_KVM_VM_BOOT'] === 'local') {
                 $d['boot_local']['object']['attrib']['checked'] = true;
             }
         }
         $d['boot_net']['label'] = $this->lang['form_boot_net'];
         $d['boot_net']['object']['type'] = 'htmlobject_input';
         $d['boot_net']['object']['attrib']['type'] = 'radio';
         $d['boot_net']['object']['attrib']['name'] = 'boot';
         $d['boot_net']['object']['attrib']['value'] = 'network';
         if ($ini['OPENQRM_KVM_VM_BOOT'] === 'network') {
             $d['boot_net']['object']['attrib']['checked'] = true;
         }
         $d['vnc']['label'] = $this->lang['form_vnc'];
         $d['vnc']['required'] = true;
         $d['vnc']['object']['type'] = 'htmlobject_input';
         $d['vnc']['object']['attrib']['name'] = 'vnc';
         $d['vnc']['object']['attrib']['id'] = 'vnc';
         $d['vnc']['object']['attrib']['type'] = 'password';
         $d['vnc']['object']['attrib']['value'] = $ini['OPENQRM_KVM_VM_VNCPASSWORD'];
         $d['vnc']['object']['attrib']['maxlength'] = 50;
         $d['vnc_1']['label'] = $this->lang['form_vnc_repeat'];
         $d['vnc_1']['required'] = true;
         $d['vnc_1']['object']['type'] = 'htmlobject_input';
         $d['vnc_1']['object']['attrib']['name'] = 'vnc_1';
         $d['vnc_1']['object']['attrib']['id'] = 'vnc_1';
         $d['vnc_1']['object']['attrib']['type'] = 'password';
         $d['vnc_1']['object']['attrib']['value'] = $ini['OPENQRM_KVM_VM_VNCPASSWORD'];
         $d['vnc_1']['object']['attrib']['maxlength'] = 50;
         $d['vnc_keymap']['label'] = $this->lang['form_vnc_keymap'];
         $d['vnc_keymap']['object']['type'] = 'htmlobject_select';
         $d['vnc_keymap']['object']['attrib']['name'] = 'vnc_keymap';
         $d['vnc_keymap']['object']['attrib']['index'] = array(0, 1);
         $d['vnc_keymap']['object']['attrib']['options'] = $keymaps;
         $d['vnc_keymap']['object']['attrib']['selected'] = array($ini['OPENQRM_KVM_VM_VNCKEYMAP']);
         $form->add($d);
         $response->form = $form;
     } else {
         $response->msg = $this->lang['error_no_bridge'];
         $response->form = $form;
     }
     return $response;
 }
function create_hybrid_cloud_vm_local($host_resource_id, $name, $mac, $memory, $cpu, $swap, $additional_nic_str, $origin_resource_id)
{
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $RESOURCE_INFO_TABLE;
    global $event;
    global $RootDir;
    $event->log("create_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-ha-hook", "Creating Cloud VM {$name} on Host resource {$host_resource_id}", "", "", 0, 0, 0);
    $file = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/etc/openqrm-plugin-hybrid-cloud.conf";
    $ini = openqrm_parse_conf($file);
    $origin_resource = new resource();
    $origin_resource->get_instance_by_id($origin_resource_id);
    // get hybrid-cloud account from origin resource
    $hybrid_acl_id = $origin_resource->get_resource_capabilities("HCACL");
    $hc = new hybrid_cloud();
    $hc->get_instance_by_id($hybrid_acl_id);
    $hc_authentication = '';
    if ($hc->account_type == 'aws' || $hc->account_type == 'euca') {
        $hc_authentication .= ' -O ' . $hc->access_key;
        $hc_authentication .= ' -W ' . $hc->secret_key;
    }
    if ($hc->account_type == 'lc-openstack') {
        $hc_authentication .= ' -u ' . $hc->username;
        $hc_authentication .= ' -p ' . $hc->password;
        $hc_authentication .= ' -q ' . $hc->host;
        $hc_authentication .= ' -x ' . $hc->port;
        $hc_authentication .= ' -g ' . $hc->tenant;
        $hc_authentication .= ' -e ' . $hc->endpoint;
    }
    $statfile = $RootDir . "/plugins/hybrid-cloud/hybrid-cloud-stat/" . $hc->id . "." . $origin_resource->hostname . ".ha_configuration.log";
    if (file_exists($statfile)) {
        unlink($statfile);
    }
    $openqrm = new openqrm_server();
    $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm ha_configuration ";
    $command .= ' -i ' . $hc->id;
    $command .= ' -n ' . $hc->account_name;
    $command .= ' -t ' . $hc->account_type;
    $command .= $hc_authentication;
    $command .= ' -in ' . $origin_resource->hostname;
    $command .= ' --openqrm-cmd-mode background';
    $event->log("create_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-ha-hook", "Running {$command}", "", "", 0, 0, 0);
    $openqrm->send_command($command, NULL, true);
    // debug
    // echo "1:".$command."<br>";
    while (!file_exists($statfile)) {
        usleep(10000);
        clearstatcache();
    }
    $new_vm_config = openqrm_parse_conf($statfile);
    $hc_authentication = '';
    if ($hc->account_type == 'aws' || $hc->account_type == 'euca') {
        $hc_authentication .= ' -O ' . $hc->access_key;
        $hc_authentication .= ' -W ' . $hc->secret_key;
        $hc_authentication .= ' -iz ' . $new_vm_config['OPENQRM_HA_AVAILABILITY_ZONE'];
        $hc_authentication .= ' -ir ' . $new_vm_config['OPENQRM_HA_REGION'];
        $hc_authentication .= ' -in ' . $hc->account_type . $new_resource->id;
    }
    if ($hc->account_type == 'lc-openstack') {
        $hc_authentication .= ' -u ' . $hc->username;
        $hc_authentication .= ' -p ' . $hc->password;
        $hc_authentication .= ' -q ' . $hc->host;
        $hc_authentication .= ' -x ' . $hc->port;
        $hc_authentication .= ' -g ' . $hc->tenant;
        $hc_authentication .= ' -e ' . $hc->endpoint;
        $hc_authentication .= ' -in ' . $origin_resource->hostname;
    }
    // set hybrid-cloud account in new resource
    $new_resource = new resource();
    $new_resource->get_instance_by_mac($mac);
    $new_resource->set_resource_capabilities("HCACL", $hybrid_acl_id);
    $openqrm = new openqrm_server();
    $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm create ";
    $command .= ' -i ' . $hc->id;
    $command .= ' -n ' . $hc->account_name;
    $command .= ' -t ' . $hc->account_type;
    $command .= $hc_authentication;
    $command .= ' -a ' . $new_vm_config['OPENQRM_HA_AMI'];
    $command .= ' -it ' . $new_vm_config['OPENQRM_HA_TYPE'];
    $command .= ' -ig ' . $new_vm_config['OPENQRM_HA_SECURITY_GROUP'];
    $command .= ' -ik ' . $new_vm_config['OPENQRM_HA_KEYPAIR'];
    $command .= ' -im ' . $new_resource->mac;
    $custom_script_url = $new_vm_config['OPENQRM_HA_CUSTOM_SCRIPT_URL'];
    if (strlen($custom_script_url)) {
        $command .= ' -ic ' . $custom_script_url;
    }
    $command .= ' --openqrm-cmd-mode background';
    $event->log("create_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-ha-hook", "Running {$command}", "", "", 0, 0, 0);
    $openqrm->send_command($command, NULL, true);
    // set resource hostname
    // check to have a ip from the dhcpd-resource hook
    while ($new_resource->ip == "0.0.0.0") {
        sleep(1);
        clearstatcache();
        $new_resource->get_instance_by_mac($new_resource->mac);
    }
    // save the mgmt ip in the resource network field
    $new_resource_hostname = $hc->account_type . $new_resource->id;
    $rufields["resource_network"] = $new_resource->ip;
    if ($hc->account_type == 'aws' || $hc->account_type == 'euca') {
        $rufields["resource_hostname"] = $hc->account_type . $new_resource->id;
    }
    if ($hc->account_type == 'lc-openstack') {
        $rufields["resource_hostname"] = $origin_resource->hostname;
    }
    // set resource to idle/active to make the HA hook continue directly
    $rufields["resource_state"] = 'active';
    $new_resource->update_info($new_resource->id, $rufields);
    // debug
    // echo "2:".$command."<br>";
}
function create_clone_kvm_lvm_deployment($cloud_image_id, $image_clone_name, $disk_size)
{
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $RESOURCE_INFO_TABLE;
    global $event;
    // clone or snap cloud action
    $kvm_plugin_config = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/etc/openqrm-plugin-kvm.conf";
    $store = openqrm_parse_conf($kvm_plugin_config);
    $kvm_plugin_cloud_create_volume_action = "snap";
    if (isset($store['OPENQRM_PLUGIN_KVM_CLOUD_CREATE_VOLUME_ACTION'])) {
        if ($store['OPENQRM_PLUGIN_KVM_CLOUD_CREATE_VOLUME_ACTION'] == 'clone') {
            $kvm_plugin_cloud_create_volume_action = "clone";
        }
    }
    // we got the cloudimage id here, get the image out of it
    $cloudimage = new cloudimage();
    $cloudimage->get_instance_by_id($cloud_image_id);
    $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Creating clone " . $image_clone_name . " of image " . $cloudimage->image_id . " on the storage", "", "", 0, 0, 0);
    // get image, this is already the new logical clone
    // we just need to physical snapshot it and update the rootdevice
    $image = new image();
    $image->get_instance_by_id($cloudimage->image_id);
    $image_id = $image->id;
    $image_name = $image->name;
    $image_type = $image->type;
    $image_version = $image->version;
    $image_rootdevice = $image->rootdevice;
    $image_rootfstype = $image->rootfstype;
    $imageid = $image->storageid;
    $image_isshared = $image->isshared;
    $image_comment = $image->comment;
    $image_capabilities = $image->capabilities;
    $image_deployment_parameter = $image->deployment_parameter;
    $openqrm_admin_user = new user("openqrm");
    $openqrm_admin_user->set_user();
    // get image storage
    $storage = new storage();
    $storage->get_instance_by_id($imageid);
    $storage_resource_id = $storage->resource_id;
    // get deployment type
    $deployment = new deployment();
    $deployment->get_instance_by_id($storage->type);
    // get storage resource
    $resource = new resource();
    $resource->get_instance_by_id($storage_resource_id);
    $resource_id = $resource->id;
    $resource_ip = $resource->ip;
    // kvm-lvm-deployment
    $image->get_instance_by_id($image_id);
    // parse the volume group info in the identifier
    $volume_group_location = dirname($image_rootdevice);
    $volume_group = basename($volume_group_location);
    $image_location_name = basename($image_rootdevice);
    // set default snapshot size
    if (!strlen($disk_size)) {
        $disk_size = 5000;
    }
    // update the image rootdevice parameter
    $ar_image_update = array('image_rootdevice' => "/dev/" . $volume_group . "/" . $image_clone_name);
    // For kvm vms we assume that the image is located on the vm-host
    // so we send the auth command to the vm-host instead of the image storage.
    // This enables using a SAN backend with dedicated volumes per vm-host which all
    // contain all "golden-images" which are used for snapshotting.
    // We do this to overcome the current lvm limitation of not supporting cluster-wide snapshots
    // get the vm resource
    $vm_resource = new resource();
    $vm_resource->get_instance_by_id($cloudimage->resource_id);
    // get the lxc host
    $vm_host_resource = new resource();
    $vm_host_resource->get_instance_by_id($vm_resource->vhostid);
    // san backend ?
    if ($vm_host_resource->id != $resource->id) {
        $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Image " . $image_id . " IS NOT available on this kvm host, " . $resource->id . " not equal " . $vm_host_resource->id . " !! Assuming SAN Backend", "", "", 0, 0, 0);
        // update the image storage id with the vm-host-resource
        $image_deployment = new deployment();
        $image_deployment->get_instance_by_type($image_type);
        // loop over all storage id from type $image_type
        $found_image = 0;
        $storage_list_by_type = new storage();
        $storage_id_list_by_type = $storage_list_by_type->get_ids_by_storage_type($image_deployment->id);
        foreach ($storage_id_list_by_type as $storage_id_list) {
            $storage_id = $storage_id_list['storage_id'];
            $tstorage = new storage();
            $tstorage->get_instance_by_id($storage_id);
            if ($tstorage->resource_id == $vm_host_resource->id) {
                // re-create update array + new storage id
                $ar_image_update = array('image_rootdevice' => "/dev/" . $volume_group . "/" . $image_clone_name, 'image_storageid' => $tstorage->id);
                $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Updating Image " . $image_id . " / " . $image_name . " with storage id " . $tstorage->id . ".", "", "", 0, 0, 0);
                $found_image = 1;
                break;
            }
        }
        if ($found_image == 0) {
            $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 2, "openqrm-kvm-lvm-deployment-cloud-hook.php", "SETUP ERROR: Could not find a storage server type " . $image_type . " using resource " . $vm_host_resource->id . ". Please create one!", "", "", 0, 0, 0);
            $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 2, "openqrm-kvm-lvm-deployment-cloud-hook.php", "SETUP ERROR: Not cloning image " . $image_id . ".", "", "", 0, 0, 0);
            return;
        }
    } else {
        $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Image " . $image_id . " IS available on this kvm host, " . $resource->id . " equal " . $vm_host_resource->id . ".", "", "", 0, 0, 0);
    }
    $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Updating rootdevice of image " . $image_id . " / " . $image_name . " with /dev/" . $volume_group . "/" . $image_clone_name, "", "", 0, 0, 0);
    $image->update($image_id, $ar_image_update);
    $image_clone_cmd = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/kvm/bin/openqrm-kvm " . $kvm_plugin_cloud_create_volume_action . " -n " . $image_location_name . " -v " . $volume_group . " -s " . $image_clone_name . " -m " . $disk_size . " -t " . $deployment->type . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background";
    $event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Running : " . $image_clone_cmd, "", "", 0, 0, 0);
    $resource->send_command($vm_host_resource->ip, $image_clone_cmd);
}
function remove_hybrid_cloud_vm_local($host_resource_id, $name, $mac)
{
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $RESOURCE_INFO_TABLE;
    global $event;
    $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-cloud-hook", "Removing Cloud VM {$name}/{$mac} from Host resource {$host_resource_id}", "", "", 0, 0, 0);
    $openqrm = new openqrm_server();
    $cloud_resource = new resource();
    $cloud_resource->get_instance_by_mac($mac);
    $hc_default_account_id = $cloud_resource->get_resource_capabilities("HCACL");
    $cloud_resource_hostname = $cloud_resource->hostname;
    if (strlen($hc_default_account_id)) {
        // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "!!! found Cloud Account ".$hc_default_account_id." from resource config", "", "", 0, 0, 0);
    } else {
        $file = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/etc/openqrm-plugin-hybrid-cloud.conf";
        $ini = openqrm_parse_conf($file);
        $hc_default_account_id = $ini['OPENQRM_PLUGIN_HYBRID_CLOUD_DEFAULT_ACCOUNT'];
        // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "!!! got Cloud Account ".$hc_default_account_id." from plugin config", "", "", 0, 0, 0);
    }
    $hc = new hybrid_cloud();
    $hc->get_instance_by_id($hc_default_account_id);
    $hc_authentication = '';
    if ($hc->account_type == 'aws' || $hc->account_type == 'euca') {
        $hc_authentication .= ' -O ' . $hc->access_key;
        $hc_authentication .= ' -W ' . $hc->secret_key;
    }
    if ($hc->account_type == 'lc-openstack') {
        $hc_authentication .= ' -u ' . $hc->username;
        $hc_authentication .= ' -p ' . $hc->password;
        $hc_authentication .= ' -q ' . $hc->host;
        $hc_authentication .= ' -x ' . $hc->port;
        $hc_authentication .= ' -g ' . $hc->tenant;
        $hc_authentication .= ' -e ' . $hc->endpoint;
    }
    $openqrm = new openqrm_server();
    $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm remove ";
    $command .= ' -i ' . $hc->id;
    $command .= ' -n ' . $hc->account_name;
    $command .= ' -t ' . $hc->account_type;
    $command .= $hc_authentication;
    $command .= ' -in ' . $cloud_resource_hostname;
    $command .= ' --openqrm-cmd-mode background';
    // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "Running $command", "", "", 0, 0, 0);
    $openqrm->send_command($command, NULL, true);
}
Ejemplo n.º 9
0
 function select()
 {
     $h['state']['title'] = $this->lang['appliances']['state'];
     $h['id']['title'] = $this->lang['appliances']['id'];
     $h['id']['hidden'] = true;
     $h['name']['title'] = $this->lang['create']['hostname'];
     $h['name']['hidden'] = true;
     $h['type']['title'] = $this->lang['create']['type'];
     $h['type']['hidden'] = true;
     $h['cpu']['title'] = $this->lang['create']['cpu'];
     $h['cpu']['hidden'] = true;
     $h['ram']['title'] = $this->lang['create']['ram'];
     $h['ram']['hidden'] = true;
     $h['config']['title'] = '&#160;';
     $h['config']['sortable'] = false;
     $h['kernel']['title'] = $this->lang['create']['kernel'];
     $h['kernel']['hidden'] = true;
     $h['disk']['title'] = $this->lang['create']['disk'];
     $h['disk']['hidden'] = true;
     $h['image']['title'] = $this->lang['create']['image'];
     $h['image']['hidden'] = true;
     $h['comment']['title'] = '&#160;';
     $h['comment']['sortable'] = false;
     $h['action']['title'] = '&#160;';
     $h['action']['sortable'] = false;
     // mark sorted values
     $sort = $this->response->html->request()->get('cloud_table[sort]');
     if ($sort === 'id') {
         $this->lang['appliances']['id'] = '<span>' . $this->lang['appliances']['id'] . '</span>';
     } else {
         if ($sort === 'name') {
             $this->lang['create']['hostname'] = '<span>' . $this->lang['create']['hostname'] . '</span>';
         } else {
             if ($sort === 'type') {
                 $this->lang['create']['type'] = '<span>' . $this->lang['create']['type'] . '</span>';
             } else {
                 if ($sort === 'cpu') {
                     $this->lang['create']['cpu'] = '<span>' . $this->lang['create']['cpu'] . '</span>';
                 } else {
                     if ($sort === 'ram') {
                         $this->lang['create']['ram'] = '<span>' . $this->lang['create']['ram'] . '</span>';
                     } else {
                         if ($sort === 'kernel') {
                             $this->lang['create']['kernel'] = '<span>' . $this->lang['create']['kernel'] . '</span>';
                         } else {
                             if ($sort === 'disk') {
                                 $this->lang['create']['disk'] = '<span>' . $this->lang['create']['disk'] . '</span>';
                             } else {
                                 if ($sort === 'image') {
                                     $this->lang['create']['image'] = '<span>' . $this->lang['create']['image'] . '</span>';
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $cloudreq_array = $this->cloudrequest->get_all_ids_per_user($this->clouduser->id);
     $user_requests = array();
     // build an array of our appliance id's
     foreach ($cloudreq_array as $cr) {
         $user_requests[] = $cr['cr_id'];
     }
     $show_ip_mgmt = false;
     if (!strcmp($this->cloudconfig->get_value_by_key('ip-management'), "true")) {
         $show_ip_mgmt = true;
     }
     $sshterm_enabled = false;
     if (!strcmp($this->cloudconfig->get_value_by_key('show_sshterm_login'), "true")) {
         $sshterm_enabled = true;
     }
     $show_application_ha = false;
     if (!strcmp($this->cloudconfig->get_value_by_key('show_ha_checkbox'), "true")) {
         $show_application_ha = true;
     }
     $collectd_graph_enabled = false;
     if (!strcmp($this->cloudconfig->get_value_by_key('show_collectd_graphs'), "true")) {
         $collectd_graph_enabled = true;
     }
     $private_image_config_enabled = false;
     if (!strcmp($this->cloudconfig->get_value_by_key('show_private_image'), "true")) {
         $private_image_config_enabled = true;
     }
     $show_pause_button = false;
     $show_unpause_button = false;
     // now we go over all our appliances from the users request list
     $app_count = 0;
     $ta = array();
     foreach ($user_requests as $reqid) {
         $appliance = null;
         $this->cloudrequest->get_instance_by_id($reqid);
         if (strlen($this->cloudrequest->appliance_id) && $this->cloudrequest->appliance_id != 0) {
             $appliance = $this->openqrm->appliance();
             $appliance->get_instance_by_id($this->cloudrequest->appliance_id);
         }
         $sshterm_login = false;
         $appliance_resources_str = "";
         $res_ip_loop = 0;
         $resource = $this->openqrm->resource();
         // prepare values
         $str_cpu = intval($this->cloudrequest->cpu_req);
         if ($str_cpu === 0) {
             $str_cpu = 'Auto';
         }
         $str_ram = intval($this->cloudrequest->ram_req);
         if ($str_ram === 0) {
             $str_ram = 'Auto';
         } else {
             if ($str_ram >= 1000) {
                 $str_ram = round($str_ram / 1000, 3, PHP_ROUND_HALF_DOWN) . ' GB';
             } else {
                 $str_ram = $str_ram . ' MB';
             }
         }
         if (isset($appliance)) {
             $appliance_resources = $appliance->resources;
             #if (!strlen($sshterm_login_ip)) {
             // in case no external ip was given to the appliance we show the internal ip
             $resource->get_instance_by_id($appliance->resources);
             $appliance_resources_str .= $resource->ip;
             $sshterm_login_ip = $resource->ip;
             $sshterm_login = true;
             #}
             if ($appliance_resources >= 0) {
                 // check ip-mgmt
                 if ($show_ip_mgmt) {
                     if (file_exists($this->rootdir . "/plugins/ip-mgmt/.running")) {
                         require_once $this->rootdir . "/plugins/ip-mgmt/class/ip-mgmt.class.php";
                         $ip_mgmt = new ip_mgmt();
                         $appliance_first_nic_ip_mgmt_id = $ip_mgmt->get_id_by_appliance($appliance->id, 1);
                         if ($appliance_first_nic_ip_mgmt_id > 0) {
                             $appliance_ip_mgmt_config_arr = $ip_mgmt->get_instance('id', $appliance_first_nic_ip_mgmt_id);
                             if (isset($appliance_ip_mgmt_config_arr['ip_mgmt_address'])) {
                                 $sshterm_login_ip = $appliance_ip_mgmt_config_arr['ip_mgmt_address'];
                                 $appliance_resources_str .= ', ' . $appliance_ip_mgmt_config_arr['ip_mgmt_address'];
                                 $sshterm_login = true;
                             }
                         }
                     }
                 }
                 // check if we need to NAT the ip address
                 $cn_nat_enabled = $this->cloudconfig->get_value_by_key('cloud_nat');
                 // 18 is cloud_nat
                 if (!strcmp($cn_nat_enabled, "true")) {
                     $appliance_resources_str = $this->cloudnat->translate($appliance_resources_str);
                     $sshterm_login_ip = $this->cloudnat->translate($sshterm_login_ip);
                 }
             } else {
                 // an appliance with resource auto-select enabled
                 $appliance_resources_str = "auto-select";
                 $sshterm_login = false;
             }
             // state
             $state = $this->cloudrequest->getstatus($this->cloudrequest->id);
             $this->cloudappliance->get_instance_by_appliance_id($appliance->id);
             switch ($this->cloudappliance->state) {
                 case 0:
                     if ($state === 'starting' || $resource->state === 'transition') {
                         $cloudappliance_state = 'busy';
                         $sshterm_login = false;
                         $show_application_ha = false;
                         $show_pause_button = false;
                         $private_image_enabled = false;
                     } else {
                         $cloudappliance_state = "paused";
                         $sshterm_login = false;
                         $show_unpause_button = true;
                         $show_pause_button = false;
                         $show_application_ha = false;
                         $private_image_enabled = false;
                     }
                     break;
                 case 1:
                     if ($resource->state === 'active' && $state === 'active') {
                         $cloudappliance_state = "active";
                         $sshterm_login = true;
                         $show_application_ha = true;
                         $show_pause_button = true;
                         $private_image_enabled = true;
                     } else {
                         $cloudappliance_state = 'busy';
                         $sshterm_login = false;
                         $show_application_ha = false;
                         $show_pause_button = false;
                         $private_image_enabled = false;
                     }
                     break;
             }
             $kernel = $this->openqrm->kernel();
             if (isset($appliance->kernelid) && $appliance->kernelid !== '') {
                 $kernel->get_instance_by_id($appliance->kernelid);
             }
             $image_size = '';
             $image = $this->openqrm->image();
             if (isset($appliance->imageid) && $appliance->imageid !== '') {
                 $image->get_instance_by_id($appliance->imageid);
                 // image disk size
                 $this->cloudimage->get_instance_by_image_id($image->id);
                 $image_size = $this->cloudimage->disk_size;
             }
             $virtualization = $this->openqrm->virtualization();
             if (isset($appliance->virtualization) && $appliance->virtualization !== '') {
                 $virtualization->get_instance_by_id($appliance->virtualization);
             }
             // prepare actions
             $cloudappliance_action = "";
             $plugin_action = "";
             // sshterm login
             if ($sshterm_enabled) {
                 if ($sshterm_login && isset($sshterm_login_ip)) {
                     // get the parameters from the plugin config file
                     $OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE = $this->openqrm->get('basedir') . "/plugins/sshterm/etc/openqrm-plugin-sshterm.conf";
                     $store = openqrm_parse_conf($OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE);
                     extract($store);
                     $sshterm_window = 'window' . str_replace('.', '', $sshterm_login_ip);
                     $sshterm_login_url = "https://{$sshterm_login_ip}:{$OPENQRM_PLUGIN_WEBSHELL_PORT}";
                     $a = $this->response->html->a();
                     $a->label = $this->lang['appliances']['plugin_ssh'];
                     $a->handler = "";
                     $a->css = 'plugin console';
                     $a->href = '#';
                     $a->handler = 'onclick="sshwindow = window.open(\'' . $sshterm_login_url . '\',\'' . $sshterm_window . '\', \'location=0,status=0,scrollbars=yes,resizable=yes,width=973,height=500,left=100,top=100,screenX=400,screenY=100\'); sshwindow.focus(); return false;"';
                     $plugin_action .= $a->get_string();
                 }
             }
             // application ha
             /*
             				if ($show_application_ha) {
             					$lcmc_gui="lcmc/lcmc-gui.php";
             					$icon_size = "width='21' height='21'";
             					$icon_title = $this->lang['appliances']['plugin_ha'];
             					$lcmc_url = "<a style=\"text-decoration:none\" href=\"#\" onClick=\"javascript:window.open('$lcmc_gui','','location=0,status=0,scrollbars=1,width=1024,height=768,left=50,top=20,screenX=50,screenY=20');\">
             						<image border=\"0\" alt=\"".$icon_title."\" title=\"".$icon_title."\" src=\"../img/ha.png\">
             						</a>";
             					$plugin_action .= $lcmc_url;
             				}
             */
             // regular actions
             if ($show_pause_button) {
                 // pause
                 $a = $this->response->html->a();
                 $a->title = $this->lang['appliances']['action_pause'];
                 $a->label = $this->lang['appliances']['action_pause'];
                 $a->handler = "";
                 $a->css = 'pause';
                 $a->href = $this->response->get_url($this->actions_name, 'pause') . '&' . $this->identifier_name . '[]=' . $this->cloudappliance->id;
                 $cloudappliance_action .= $a->get_string();
                 // restart
                 $a = $this->response->html->a();
                 $a->title = $this->lang['appliances']['action_restart'];
                 $a->label = $this->lang['appliances']['action_restart'];
                 $a->handler = "";
                 $a->css = 'restart';
                 $a->href = $this->response->get_url($this->actions_name, 'restart') . '&' . $this->identifier_name . '[]=' . $this->cloudappliance->id;
                 $cloudappliance_action .= $a->get_string();
             }
             if ($show_unpause_button) {
                 // pause
                 $a = $this->response->html->a();
                 $a->title = $this->lang['appliances']['action_unpause'];
                 $a->label = $this->lang['appliances']['action_unpause'];
                 $a->handler = "";
                 $a->css = 'start';
                 $a->href = $this->response->get_url($this->actions_name, 'unpause') . '&' . $this->identifier_name . '[]=' . $this->cloudappliance->id;
                 $cloudappliance_action .= $a->get_string();
             }
             if ($collectd_graph_enabled) {
                 // system stats
                 $data = $this->openqrm->get('basedir') . '/plugins/collectd/data/' . $appliance->name;
                 if (file_exists($data)) {
                     $a = $this->response->html->a();
                     $a->label = $this->lang['appliances']['plugin_collectd'];
                     $a->handler = "";
                     $a->css = 'plugin collectd';
                     $a->href = $this->response->get_url($this->actions_name, 'statistics') . '&appliance_id=' . $appliance->id;
                     $plugin_action .= $a->get_string();
                 }
             }
             // private images
             if ($private_image_enabled && $private_image_config_enabled) {
                 $a = $this->response->html->a();
                 $a->label = $this->lang['appliances']['action_private_image'];
                 $a->title = $this->lang['appliances']['action_private_image'];
                 $a->handler = "";
                 $a->css = 'private';
                 $a->href = $this->response->get_url($this->actions_name, 'image_private') . '&appliance_id=' . $appliance->id;
                 $cloudappliance_action .= $a->get_string();
             }
             // noVNC
             if (!strcmp($this->cloudconfig->get_value_by_key('allow_vnc_access'), "true") && $show_pause_button) {
                 $a = $this->response->html->a();
                 $a->label = $this->lang['appliances']['plugin_novnc'];
                 $a->handler = "";
                 $a->css = 'plugin novnc';
                 $a->href = 'api.php?action=novnc&appliance_id=' . $appliance->id;
                 $a->target = '_blank';
                 $plugin_action .= $a->get_string();
             }
             if ($cloudappliance_state === 'active' || $cloudappliance_state === 'paused') {
                 // appliance update
                 $a = $this->response->html->a();
                 $a->title = $this->lang['appliances']['action_update'];
                 $a->label = $this->lang['appliances']['action_update'];
                 $a->handler = "";
                 $a->css = 'edit';
                 $a->href = $this->response->get_url($this->actions_name, 'appliance_update') . '&' . $this->identifier_name . '=' . $this->cloudappliance->id;
                 $cloudappliance_action .= $a->get_string();
                 // deprovision
                 $a = $this->response->html->a();
                 $a->title = $this->lang['appliances']['action_deprovision'];
                 $a->label = $this->lang['appliances']['action_deprovision'];
                 $a->handler = "";
                 $a->css = 'remove';
                 $a->href = $this->response->get_url($this->actions_name, 'deprovision') . '&' . $this->identifier_name . '[]=' . $this->cloudappliance->id;
                 $cloudappliance_action .= $a->get_string();
             }
             $disk = intval($image_size);
             if ($disk >= 1000) {
                 $disk = round($disk / 1000, 2, PHP_ROUND_HALF_DOWN) . ' GB';
             } else {
                 $disk = $disk . ' MB';
             }
             $config_column = '<b>' . $this->lang['appliances']['id'] . '</b> ' . $this->cloudrequest->id . '<br>';
             $config_column .= '<b>' . $this->lang['create']['hostname'] . '</b> ' . $appliance->name . '<br>';
             $config_column .= '<b>' . $this->lang['create']['type'] . '</b> ' . $virtualization->name . '<br>';
             $config_column .= '<b>' . $this->lang['create']['cpu'] . '</b> ' . $str_cpu . '<br>';
             $config_column .= '<b>' . $this->lang['create']['ram'] . '</b> ' . $str_ram . '<br>';
             $config_column .= '<b>' . $this->lang['create']['kernel'] . '</b> ' . $kernel->name . '<br>';
             $config_column .= '<b>' . $this->lang['create']['disk'] . '</b> ' . $disk . '<br>';
             $config_column .= '<b>' . $this->lang['create']['image'] . '</b> ' . $image->name . '<br>';
             $config_column .= '<b>IP</b> ' . $appliance_resources_str;
             $comment = $appliance->comment . '<hr>' . $plugin_action;
             if ($cloudappliance_state === 'busy') {
                 $comment = $this->lang['appliances']['error_command_running'];
                 $comment = $appliance->comment . '<hr><div class="busy_appliance">&#160;</div>';
             }
             #$comment .= '<textarea id="'.$this->cloudrequest->id.'" style="height:60px;width:95%;font-size:10px;"></textarea><script>get_state("'.$this->cloudrequest->id.'");</script>';
             $ta[] = array('id' => $this->cloudappliance->id, 'state' => '<span class="pill ' . $cloudappliance_state . '">' . $cloudappliance_state . '</span>', 'name' => $appliance->name, 'type' => $virtualization->name, 'cpu' => $this->cloudrequest->cpu_req, 'ram' => $this->cloudrequest->ram_req, 'disk' => $image_size, 'kernel' => $kernel->name, 'image' => $image->name, 'config' => $config_column, 'comment' => $comment, 'action' => $cloudappliance_action);
             $app_count++;
         } else {
             $this->cloudrequest->get_instance_by_id($reqid);
             $state = $this->cloudrequest->getstatus($this->cloudrequest->id);
             if ($state !== 'done') {
                 $kernel = $this->openqrm->kernel();
                 if (isset($this->cloudrequest->kernel_id) && $this->cloudrequest->kernel_id !== '') {
                     $kernel->get_instance_by_id($this->cloudrequest->kernel_id);
                 }
                 $image = $this->openqrm->image();
                 if (isset($this->cloudrequest->image_id) && $this->cloudrequest->image_id !== '') {
                     $image->get_instance_by_id($this->cloudrequest->image_id);
                 }
                 $virtualization = $this->openqrm->virtualization();
                 if (isset($this->cloudrequest->resource_type_req) && $this->cloudrequest->resource_type_req !== '') {
                     $virtualization->get_instance_by_id($this->cloudrequest->resource_type_req);
                 }
                 $disk = intval($this->cloudrequest->disk_req);
                 if ($disk >= 1000) {
                     $disk = round($disk / 1000, 2, PHP_ROUND_HALF_DOWN) . ' GB';
                 } else {
                     $disk = $disk . ' MB';
                 }
                 $config_column = '<b>' . $this->lang['appliances']['id'] . '</b> ' . $this->cloudrequest->id . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['hostname'] . '</b> ' . $this->cloudrequest->appliance_hostname . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['type'] . '</b> ' . $virtualization->name . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['cpu'] . '</b> ' . $str_cpu . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['ram'] . '</b> ' . $str_ram . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['kernel'] . '</b> ' . $kernel->name . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['disk'] . '</b> ' . $disk . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['image'] . '</b> ' . $image->name . '<br>';
                 $config_column .= '<b>IP</b>';
                 $comment = '';
                 if (isset($this->lang['appliances']['info_' . $state])) {
                     $comment = $this->lang['appliances']['info_' . $state];
                 }
                 $ta[] = array('id' => $this->cloudrequest->id, 'state' => '<span class="pill ' . $state . '">' . $state . '</span>', 'name' => $this->cloudrequest->appliance_hostname, 'type' => $virtualization->name, 'cpu' => $this->cloudrequest->cpu_req, 'ram' => $this->cloudrequest->ram_req, 'disk' => $this->cloudrequest->disk_req, 'kernel' => $kernel->name, 'image' => $image->name, 'config' => $config_column, 'comment' => $comment, 'action' => '');
                 $app_count++;
             }
         }
     }
     // redirect if $ta is empty
     if (count($ta) > 0) {
         $table = $this->response->html->tablebuilder('cloud_table', $this->response->get_array($this->actions_name, 'appliances'));
         $table->css = 'htmlobject_table';
         $table->limit = 10;
         $table->id = 'cloud_appliances';
         $table->head = $h;
         $table->sort = 'state';
         $table->autosort = true;
         $table->sort_link = false;
         $table->actions_name = $this->actions_name;
         $table->form_action = $this->response->html->thisfile;
         $table->form_method = 'GET';
         $table->max = $app_count;
         $table->body = $ta;
         return $table;
     } else {
         $this->response->redirect($this->response->get_url($this->actions_name, 'create', $this->message_param, $this->lang['appliances']['msg_no_appliances_to_manage']));
     }
 }
Ejemplo n.º 10
0
 function parse_subsection($menuname, $name)
 {
     global $OPENQRM_SERVER_BASE_DIR;
     $str = '';
     $folders = $this->file->get_folders($this->RootDir . '/plugins');
     $menu = ".|{$menuname}\n";
     foreach ($folders as $plug) {
         $filename = $this->PluginsDir . '/' . $plug['name'] . '/menu.txt';
         $plugin_config = $plug['path'] . '/etc/openqrm-plugin-' . $plug['name'] . '.conf';
         if ($this->file->exists($plugin_config)) {
             $store = "";
             $store = openqrm_parse_conf($plugin_config);
             extract($store);
             if (!strcmp($store['OPENQRM_PLUGIN_TYPE'], $name)) {
                 if ($this->file->exists($filename)) {
                     $str .= implode('', file($filename));
                 }
             }
         }
     }
     // workaround for img path
     if ($str !== '') {
         $str = str_replace('|../../', '|', $str);
         $str = $menu . $str;
     }
     return $str;
 }
Ejemplo n.º 11
0
    function login()
    {
        $form = $this->response->get_form($this->actions_name, 'login');
        $cloud_cloudappliance_id_arr = $this->response->html->request()->get($this->identifier_name);
        $show_ip_mgmt = false;
        if (!strcmp($this->cloudconfig->get_value_by_key('ip-management'), "true")) {
            $show_ip_mgmt = true;
        }
        if (!strcmp($this->cloudconfig->get_value_by_key('show_sshterm_login'), "true")) {
            // is sshterm plugin enabled + started ?
            if (file_exists($this->rootdir . "/plugins/sshterm/.running")) {
                // get the parameters from the plugin config file
                $OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE = $this->OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/sshterm/etc/openqrm-plugin-sshterm.conf";
                $store = openqrm_parse_conf($OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE);
                extract($store);
                foreach ($cloud_cloudappliance_id_arr as $key => $cloudappliance_id) {
                    $this->cloudappliance->get_instance_by_id($cloudappliance_id);
                    $this->appliance->get_instance_by_id($this->cloudappliance->appliance_id);
                    $this->cloudrequest->get_instance_by_id($this->cloudappliance->cr_id);
                    if ($this->cloudrequest->cu_id != $this->clouduser->id) {
                        // not request of the authuser
                        exit(1);
                    }
                    // here we check which ip to send to the user
                    // check ip-mgmt
                    $sshterm_login_ip = '';
                    if ($show_ip_mgmt) {
                        if (file_exists($this->rootdir . "/plugins/ip-mgmt/.running")) {
                            require_once $this->rootdir . "/plugins/ip-mgmt/class/ip-mgmt.class.php";
                            $ip_mgmt = new ip_mgmt();
                            $appliance_first_nic_ip_mgmt_id = $ip_mgmt->get_id_by_appliance($this->cloudappliance->appliance_id, 1);
                            if ($appliance_first_nic_ip_mgmt_id > 0) {
                                $appliance_ip_mgmt_config_arr = $ip_mgmt->get_instance('id', $appliance_first_nic_ip_mgmt_id);
                                if (isset($appliance_ip_mgmt_config_arr['ip_mgmt_address'])) {
                                    $sshterm_login_ip = $appliance_ip_mgmt_config_arr['ip_mgmt_address'];
                                }
                            }
                        }
                    }
                    if (!strlen($sshterm_login_ip)) {
                        // in case no external ip was given to the appliance we show the internal ip
                        $this->resourde->get_instance_by_id($this->appliance->resources);
                        $sshterm_login_ip = $this->resourde->ip;
                    }
                    if (!strlen($sshterm_login_ip)) {
                        continue;
                    }
                    $redirect_url = "https://{$sshterm_login_ip}:{$OPENQRM_PLUGIN_WEBSHELL_PORT}";
                    $left = 50 + $cloudappliance_id * 50;
                    $top = 100 + $cloudappliance_id * 50;
                    // add the javascript function to open an sshterm
                    ?>
								<script type="text/javascript">
								function open_sshterm (url) {
									sshterm_window = window.open(url, "<?php 
                    echo $sshterm_login_ip;
                    ?>
", "width=580,height=420,scrollbars=1,left=<?php 
                    echo $left;
                    ?>
,top=<?php 
                    echo $top;
                    ?>
");
									open_sshterm.focus();
								}
								open_sshterm("<?php 
                    echo $redirect_url;
                    ?>
");
								</script>
					<?php 
                }
            }
        }
        flush();
        $this->response->redirect($this->response->get_url($this->actions_name, 'appliances'));
        return $form;
    }
Ejemplo n.º 12
0
}
$OPENQRM_SERVER_CONFIG_FILE = "{$OPENQRM_BASE_DIR}/openqrm/etc/openqrm-server.conf";
// function to get infos from the openqrm-server.conf
function openqrm_parse_conf($filepath)
{
    $ini = file($filepath);
    if (count($ini) == 0) {
        return array();
    }
    $sections = array();
    $values = array();
    $globals = array();
    $i = 0;
    foreach ($ini as $line) {
        $line = trim($line);
        // Comments
        if ($line == '' || $line[0] != 'O') {
            continue;
        }
        // Key-value pair
        list($key, $value) = explode('=', $line, 2);
        $key = trim($key);
        $value = trim($value);
        $value = str_replace("\"", "", $value);
        $globals[$key] = $value;
    }
    return $globals;
}
$store = openqrm_parse_conf($OPENQRM_SERVER_CONFIG_FILE);
extract($store);
global $OPENQRM_SERVER_CONFIG_FILE;
Ejemplo n.º 13
0
 function get_response()
 {
     $OPENQRM_SERVER_BASE_DIR = $this->openqrm->get('basedir');
     $response = $this->response;
     $form = $response->get_form($this->actions_name, 'add');
     $cpus[] = array("1", "1 CPU");
     $cpus[] = array("2", "2 CPUs");
     $cpus[] = array("4", "4 CPUs");
     $cpus[] = array("8", "8 CPUs");
     $cpus[] = array("16", "16 CPUs");
     $ram[] = array("256", "256 MB");
     $ram[] = array("512", "512 MB");
     $ram[] = array("1024", "1 GB");
     $ram[] = array("2048", "2 GB");
     $ram[] = array("4096", "4 GB");
     $ram[] = array("8192", "8 GB");
     $ram[] = array("16384", "16 GB");
     $ram[] = array("32768", "32 GB");
     $ram[] = array("65536", "64 GB");
     $nics[] = array("virtio", $this->lang['form_net_virtio']);
     $nics[] = array("e1000", $this->lang['form_net_e1000']);
     $nics[] = array("rtl8139", $this->lang['form_net_rtl8139']);
     $keymaps[] = array("de", "de");
     $keymaps[] = array("en-us", "en-us");
     $keymaps[] = array("es", "es");
     $keymaps[] = array("fr", "fr");
     $keymaps[] = array("it", "it");
     $keymaps[] = array("ja", "ja");
     $keymaps[] = array("nl", "nl");
     $keymaps[] = array("ru", "ru");
     $keymaps[] = array("none", "none");
     $disk_interfaces[] = array("virtio", "Virtio");
     $disk_interfaces[] = array("ide", "IDE");
     $swap_select_arr[] = array('1024', '1 GB');
     $swap_select_arr[] = array('2048', '2 GB');
     $swap_select_arr[] = array('4096', '4 GB');
     // if we come from the wizard suggest the server name
     $vm_name_suggestion = '';
     if (isset($this->user->wizard_name) && $this->user->wizard_name === 'appliance' && $this->user->wizard_step == 2) {
         $appliance = new appliance();
         $appliance->get_instance_by_id($this->user->wizard_id);
         $vm_name_suggestion = $appliance->name;
     }
     // get a list of existing kvm localboot images to select
     $existing_image_arr = array();
     $image = new image();
     $image_image_id_ar = $image->get_ids_by_type('kvm-lvm-deployment');
     foreach ($image_image_id_ar as $iid_ar) {
         $image_id = $iid_ar['image_id'];
         $image->get_instance_by_id($image_id);
         $existing_image_arr[] = array($image->id, $image->name);
     }
     $image_image_id_ar = $image->get_ids_by_type('kvm-bf-deployment');
     foreach ($image_image_id_ar as $iid_ar) {
         $image_id = $iid_ar['image_id'];
         $image->get_instance_by_id($image_id);
         $existing_image_arr[] = array($image->id, $image->name);
     }
     $image_image_id_ar = $image->get_ids_by_type('kvm-gluster-deployment');
     foreach ($image_image_id_ar as $iid_ar) {
         $image_id = $iid_ar['image_id'];
         $image->get_instance_by_id($image_id);
         $existing_image_arr[] = array($image->id, $image->name);
     }
     $existing_image_arr[] = array('', '');
     // get a list of network-deployment images for netboot vms
     $existing_netboot_image_arr = array();
     $existing_netboot_image_id_ar = $image->get_ids();
     foreach ($existing_netboot_image_id_ar as $iid_ar) {
         $image_id = $iid_ar['image_id'];
         $image->get_instance_by_id($image_id);
         if ($image->is_network_deployment()) {
             $existing_netboot_image_arr[] = array($image->id, $image->name);
         }
     }
     $existing_netboot_image_arr[] = array('', '');
     $file = $OPENQRM_SERVER_BASE_DIR . '/plugins/kvm/web/kvm-stat/' . $this->resource->id . '.bridge_config';
     $data = openqrm_parse_conf($file);
     $bridges = array();
     $bridge_list = $data['OPENQRM_KVM_BRIDGES'];
     $bridge_list = rtrim($bridge_list, ":");
     $bridge_array = explode(':', $bridge_list);
     // handle no bridge error
     if (isset($bridge_array[0]) && $bridge_array[0] !== '') {
         foreach ($bridge_array as $b) {
             $bridges[] = array($b, $b);
         }
         $submit = $form->get_elements('submit');
         $submit->handler = 'onclick="wait();"';
         $form->add($submit, 'submit');
         $submit = $form->get_elements('cancel');
         $submit->handler = 'onclick="cancel();"';
         $form->add($submit, 'cancel');
         $d['name']['label'] = $this->lang['form_name'];
         $d['name']['required'] = true;
         $d['name']['validate']['regex'] = '/^[a-z0-9._]+$/i';
         $d['name']['validate']['errormsg'] = sprintf($this->lang['error_name'], 'a-z0-9._');
         $d['name']['object']['type'] = 'htmlobject_input';
         $d['name']['object']['attrib']['name'] = 'name';
         $d['name']['object']['attrib']['id'] = 'name';
         $d['name']['object']['attrib']['type'] = 'text';
         $d['name']['object']['attrib']['css'] = 'namegen';
         $d['name']['object']['attrib']['customattribs'] = 'data-prefix="kvm" data-length="6"';
         $d['name']['object']['attrib']['value'] = $vm_name_suggestion;
         $d['name']['object']['attrib']['maxlength'] = 50;
         $d['cpus']['label'] = $this->lang['form_cpus'];
         $d['cpus']['required'] = true;
         $d['cpus']['object']['type'] = 'htmlobject_select';
         $d['cpus']['object']['attrib']['name'] = 'cpus';
         $d['cpus']['object']['attrib']['index'] = array(0, 1);
         $d['cpus']['object']['attrib']['options'] = $cpus;
         $d['memory']['label'] = $this->lang['form_memory'];
         $d['memory']['required'] = true;
         $d['memory']['object']['type'] = 'htmlobject_select';
         $d['memory']['object']['attrib']['name'] = 'memory';
         $d['memory']['object']['attrib']['index'] = array(0, 1);
         $d['memory']['object']['attrib']['options'] = $ram;
         $d['memory']['object']['attrib']['selected'] = array(512);
         $vmtype = $this->response->html->request()->get('vmtype');
         if ($vmtype === 'kvm-vm-net') {
             $d['netboot_image']['label'] = $this->lang['form_existing_disk'];
             $d['netboot_image']['object']['type'] = 'htmlobject_select';
             $d['netboot_image']['object']['attrib']['index'] = array(0, 1);
             $d['netboot_image']['object']['attrib']['id'] = 'netboot_image';
             $d['netboot_image']['object']['attrib']['name'] = 'netboot_image';
             $d['netboot_image']['object']['attrib']['options'] = $existing_netboot_image_arr;
             $d['netboot_image']['object']['attrib']['selected'] = array('');
             $d['disk_interface'] = "";
             $d['localboot_image'] = "";
             $d['cdrom_iso_path'] = "";
             $d['cdrom_button'] = "";
         } else {
             $d['localboot_image']['label'] = $this->lang['form_existing_disk'];
             $d['localboot_image']['object']['type'] = 'htmlobject_select';
             $d['localboot_image']['object']['attrib']['index'] = array(0, 1);
             $d['localboot_image']['object']['attrib']['id'] = 'localboot_image';
             $d['localboot_image']['object']['attrib']['name'] = 'localboot_image';
             $d['localboot_image']['object']['attrib']['options'] = $existing_image_arr;
             $d['localboot_image']['object']['attrib']['selected'] = array('');
             $d['disk_interface']['label'] = $this->lang['form_disk_interface'];
             $d['disk_interface']['required'] = true;
             $d['disk_interface']['object']['type'] = 'htmlobject_select';
             $d['disk_interface']['object']['attrib']['name'] = 'disk_interface';
             $d['disk_interface']['object']['attrib']['id'] = 'disk_interface';
             $d['disk_interface']['object']['attrib']['index'] = array(0, 1);
             $d['disk_interface']['object']['attrib']['options'] = $disk_interfaces;
             $d['cdrom_iso_path']['label'] = $this->lang['form_cdrom'];
             $d['cdrom_iso_path']['object']['type'] = 'htmlobject_input';
             $d['cdrom_iso_path']['object']['attrib']['type'] = 'text';
             $d['cdrom_iso_path']['object']['attrib']['id'] = 'cdrom';
             $d['cdrom_iso_path']['object']['attrib']['name'] = 'cdrom';
             $d['cdrom_button']['static'] = true;
             $d['cdrom_button']['object']['type'] = 'htmlobject_input';
             $d['cdrom_button']['object']['attrib']['type'] = 'button';
             $d['cdrom_button']['object']['attrib']['name'] = 'cdrom_button';
             $d['cdrom_button']['object']['attrib']['id'] = 'cdrom_button';
             $d['cdrom_button']['object']['attrib']['css'] = 'browse-button';
             $d['cdrom_button']['object']['attrib']['handler'] = 'onclick="filepicker.init(\'cdrom\'); return false;"';
             $d['cdrom_button']['object']['attrib']['style'] = "display:none;";
             $d['cdrom_button']['object']['attrib']['value'] = $this->lang['lang_browse'];
             $d['netboot_image'] = "";
         }
         $mac = '';
         if (isset($this->resource)) {
             $this->resource->generate_mac();
             $mac = $this->resource->mac;
         }
         $d['net0']['label'] = $this->lang['lang_net_0'];
         $d['net0']['object']['type'] = 'htmlobject_input';
         $d['net0']['object']['attrib']['type'] = 'checkbox';
         $d['net0']['object']['attrib']['id'] = 'net0';
         $d['net0']['object']['attrib']['name'] = 'net0';
         $d['net0']['object']['attrib']['value'] = 'enabled';
         $d['net0']['object']['attrib']['checked'] = true;
         $d['net0']['object']['attrib']['disabled'] = true;
         $d['mac']['label'] = $this->lang['form_mac'];
         $d['mac']['required'] = true;
         $d['mac']['object']['type'] = 'htmlobject_input';
         $d['mac']['object']['attrib']['name'] = 'mac';
         $d['mac']['object']['attrib']['type'] = 'text';
         $d['mac']['object']['attrib']['value'] = $mac;
         $d['mac']['object']['attrib']['maxlength'] = 50;
         $d['bridge']['label'] = $this->lang['form_bridge'];
         $d['bridge']['required'] = true;
         $d['bridge']['object']['type'] = 'htmlobject_select';
         $d['bridge']['object']['attrib']['name'] = 'bridge';
         $d['bridge']['object']['attrib']['index'] = array(0, 1);
         $d['bridge']['object']['attrib']['options'] = $bridges;
         $d['nic']['label'] = $this->lang['form_netdevice'];
         $d['nic']['required'] = true;
         $d['nic']['object']['type'] = 'htmlobject_select';
         $d['nic']['object']['attrib']['name'] = 'nic';
         $d['nic']['object']['attrib']['index'] = array(0, 1);
         $d['nic']['object']['attrib']['options'] = $nics;
         // net 1
         if (isset($this->resource)) {
             $this->resource->generate_mac();
             $mac = $this->resource->mac;
         }
         $d['net1']['label'] = $this->lang['lang_net_1'];
         $d['net1']['object']['type'] = 'htmlobject_input';
         $d['net1']['object']['attrib']['type'] = 'checkbox';
         $d['net1']['object']['attrib']['id'] = 'net1';
         $d['net1']['object']['attrib']['name'] = 'net1';
         $d['net1']['object']['attrib']['value'] = 'enabled';
         $d['net1']['object']['attrib']['handler'] = 'onchange="nettoggle(this);"';
         $d['mac1']['label'] = $this->lang['form_mac'];
         $d['mac1']['object']['type'] = 'htmlobject_input';
         $d['mac1']['object']['attrib']['name'] = 'mac1';
         $d['mac1']['object']['attrib']['type'] = 'text';
         $d['mac1']['object']['attrib']['value'] = $mac;
         $d['mac1']['object']['attrib']['maxlength'] = 50;
         $d['bridge1']['label'] = $this->lang['form_bridge'];
         $d['bridge1']['object']['type'] = 'htmlobject_select';
         $d['bridge1']['object']['attrib']['name'] = 'bridge1';
         $d['bridge1']['object']['attrib']['index'] = array(0, 1);
         $d['bridge1']['object']['attrib']['options'] = $bridges;
         $d['nic1']['label'] = $this->lang['form_netdevice'];
         $d['nic1']['object']['type'] = 'htmlobject_select';
         $d['nic1']['object']['attrib']['name'] = 'nic1';
         $d['nic1']['object']['attrib']['index'] = array(0, 1);
         $d['nic1']['object']['attrib']['options'] = $nics;
         // net 2
         if (isset($this->resource)) {
             $this->resource->generate_mac();
             $mac = $this->resource->mac;
         }
         $d['net2']['label'] = $this->lang['lang_net_2'];
         $d['net2']['object']['type'] = 'htmlobject_input';
         $d['net2']['object']['attrib']['type'] = 'checkbox';
         $d['net2']['object']['attrib']['id'] = 'net2';
         $d['net2']['object']['attrib']['name'] = 'net2';
         $d['net2']['object']['attrib']['value'] = 'enabled';
         $d['net2']['object']['attrib']['handler'] = 'onchange="nettoggle(this);"';
         $d['mac2']['label'] = $this->lang['form_mac'];
         $d['mac2']['object']['type'] = 'htmlobject_input';
         $d['mac2']['object']['attrib']['name'] = 'mac2';
         $d['mac2']['object']['attrib']['type'] = 'text';
         $d['mac2']['object']['attrib']['value'] = $mac;
         $d['mac2']['object']['attrib']['maxlength'] = 50;
         $d['bridge2']['label'] = $this->lang['form_bridge'];
         $d['bridge2']['object']['type'] = 'htmlobject_select';
         $d['bridge2']['object']['attrib']['name'] = 'bridge2';
         $d['bridge2']['object']['attrib']['index'] = array(0, 1);
         $d['bridge2']['object']['attrib']['options'] = $bridges;
         $d['nic2']['label'] = $this->lang['form_netdevice'];
         $d['nic2']['object']['type'] = 'htmlobject_select';
         $d['nic2']['object']['attrib']['name'] = 'nic2';
         $d['nic2']['object']['attrib']['index'] = array(0, 1);
         $d['nic2']['object']['attrib']['options'] = $nics;
         // net 3
         if (isset($this->resource)) {
             $this->resource->generate_mac();
             $mac = $this->resource->mac;
         }
         $d['net3']['label'] = $this->lang['lang_net_3'];
         $d['net3']['object']['type'] = 'htmlobject_input';
         $d['net3']['object']['attrib']['type'] = 'checkbox';
         $d['net3']['object']['attrib']['id'] = 'net3';
         $d['net3']['object']['attrib']['name'] = 'net3';
         $d['net3']['object']['attrib']['value'] = 'enabled';
         $d['net3']['object']['attrib']['handler'] = 'onchange="nettoggle(this);"';
         $d['mac3']['label'] = $this->lang['form_mac'];
         $d['mac3']['object']['type'] = 'htmlobject_input';
         $d['mac3']['object']['attrib']['name'] = 'mac3';
         $d['mac3']['object']['attrib']['type'] = 'text';
         $d['mac3']['object']['attrib']['value'] = $mac;
         $d['mac3']['object']['attrib']['maxlength'] = 50;
         $d['bridge3']['label'] = $this->lang['form_bridge'];
         $d['bridge3']['object']['type'] = 'htmlobject_select';
         $d['bridge3']['object']['attrib']['name'] = 'bridge3';
         $d['bridge3']['object']['attrib']['index'] = array(0, 1);
         $d['bridge3']['object']['attrib']['options'] = $bridges;
         $d['nic3']['label'] = $this->lang['form_netdevice'];
         $d['nic3']['object']['type'] = 'htmlobject_select';
         $d['nic3']['object']['attrib']['name'] = 'nic3';
         $d['nic3']['object']['attrib']['index'] = array(0, 1);
         $d['nic3']['object']['attrib']['options'] = $nics;
         // net 4
         if (isset($this->resource)) {
             $this->resource->generate_mac();
             $mac = $this->resource->mac;
         }
         $d['net4']['label'] = $this->lang['lang_net_4'];
         $d['net4']['object']['type'] = 'htmlobject_input';
         $d['net4']['object']['attrib']['type'] = 'checkbox';
         $d['net4']['object']['attrib']['name'] = 'net4';
         $d['net4']['object']['attrib']['id'] = 'net4';
         $d['net4']['object']['attrib']['value'] = 'enabled';
         $d['net4']['object']['attrib']['handler'] = 'onchange="nettoggle(this);"';
         $d['mac4']['label'] = $this->lang['form_mac'];
         $d['mac4']['object']['type'] = 'htmlobject_input';
         $d['mac4']['object']['attrib']['name'] = 'mac4';
         $d['mac4']['object']['attrib']['type'] = 'text';
         $d['mac4']['object']['attrib']['value'] = $mac;
         $d['mac4']['object']['attrib']['maxlength'] = 50;
         $d['bridge4']['label'] = $this->lang['form_bridge'];
         $d['bridge4']['object']['type'] = 'htmlobject_select';
         $d['bridge4']['object']['attrib']['name'] = 'bridge4';
         $d['bridge4']['object']['attrib']['index'] = array(0, 1);
         $d['bridge4']['object']['attrib']['options'] = $bridges;
         $d['nic4']['label'] = $this->lang['form_netdevice'];
         $d['nic4']['object']['type'] = 'htmlobject_select';
         $d['nic4']['object']['attrib']['name'] = 'nic4';
         $d['nic4']['object']['attrib']['index'] = array(0, 1);
         $d['nic4']['object']['attrib']['options'] = $nics;
         // boot from
         $d['boot_cd'] = '';
         $d['boot_iso'] = '';
         $d['boot_iso_path'] = '';
         $d['boot_local'] = '';
         $d['browse_button'] = '';
         if ($vmtype !== 'kvm-vm-net') {
             $d['boot_cd']['label'] = $this->lang['form_boot_cd'];
             $d['boot_cd']['object']['type'] = 'htmlobject_input';
             $d['boot_cd']['object']['attrib']['type'] = 'radio';
             $d['boot_cd']['object']['attrib']['name'] = 'boot';
             $d['boot_cd']['object']['attrib']['value'] = 'cdrom';
             $d['boot_iso']['label'] = $this->lang['form_boot_iso'];
             $d['boot_iso']['object']['type'] = 'htmlobject_input';
             $d['boot_iso']['object']['attrib']['type'] = 'radio';
             $d['boot_iso']['object']['attrib']['id'] = 'boot_iso';
             $d['boot_iso']['object']['attrib']['name'] = 'boot';
             $d['boot_iso']['object']['attrib']['value'] = 'iso';
             $d['boot_iso_path']['label'] = $this->lang['form_iso_path'];
             $d['boot_iso_path']['object']['type'] = 'htmlobject_input';
             $d['boot_iso_path']['object']['attrib']['type'] = 'text';
             $d['boot_iso_path']['object']['attrib']['id'] = 'iso_path';
             $d['boot_iso_path']['object']['attrib']['name'] = 'iso_path';
             $d['boot_local']['label'] = $this->lang['form_boot_local'];
             $d['boot_local']['object']['type'] = 'htmlobject_input';
             $d['boot_local']['object']['attrib']['type'] = 'radio';
             $d['boot_local']['object']['attrib']['name'] = 'boot';
             $d['boot_local']['object']['attrib']['value'] = 'local';
             $d['boot_local']['object']['attrib']['checked'] = true;
             $d['browse_button']['static'] = true;
             $d['browse_button']['object']['type'] = 'htmlobject_input';
             $d['browse_button']['object']['attrib']['type'] = 'button';
             $d['browse_button']['object']['attrib']['name'] = 'browse_button';
             $d['browse_button']['object']['attrib']['id'] = 'browsebutton';
             $d['browse_button']['object']['attrib']['css'] = 'browse-button';
             $d['browse_button']['object']['attrib']['handler'] = 'onclick="filepicker.init(\'iso_path\'); return false;"';
             $d['browse_button']['object']['attrib']['style'] = "display:none;";
             $d['browse_button']['object']['attrib']['value'] = $this->lang['lang_browse'];
         }
         $d['boot_net']['label'] = $this->lang['form_boot_net'];
         $d['boot_net']['object']['type'] = 'htmlobject_input';
         $d['boot_net']['object']['attrib']['type'] = 'radio';
         $d['boot_net']['object']['attrib']['name'] = 'boot';
         $d['boot_net']['object']['attrib']['value'] = 'network';
         if ($vmtype === 'kvm-vm-net') {
             $d['boot_net']['object']['attrib']['checked'] = true;
         }
         $d['vnc']['label'] = $this->lang['form_vnc'];
         $d['vnc']['required'] = true;
         $d['vnc']['object']['type'] = 'htmlobject_input';
         $d['vnc']['object']['attrib']['name'] = 'vnc';
         $d['vnc']['object']['attrib']['id'] = 'vnc';
         $d['vnc']['object']['attrib']['type'] = 'password';
         $d['vnc']['object']['attrib']['value'] = '';
         $d['vnc']['object']['attrib']['maxlength'] = 50;
         $d['vnc_1']['label'] = $this->lang['form_vnc_repeat'];
         $d['vnc_1']['required'] = true;
         $d['vnc_1']['object']['type'] = 'htmlobject_input';
         $d['vnc_1']['object']['attrib']['name'] = 'vnc_1';
         $d['vnc_1']['object']['attrib']['id'] = 'vnc_1';
         $d['vnc_1']['object']['attrib']['value'] = '';
         $d['vnc_1']['object']['attrib']['type'] = 'password';
         $d['vnc_1']['object']['attrib']['maxlength'] = 50;
         $d['vnc_keymap']['label'] = $this->lang['form_vnc_keymap'];
         $d['vnc_keymap']['object']['type'] = 'htmlobject_select';
         $d['vnc_keymap']['object']['attrib']['name'] = 'vnc_keymap';
         $d['vnc_keymap']['object']['attrib']['index'] = array(0, 1);
         $d['vnc_keymap']['object']['attrib']['options'] = $keymaps;
         $form->add($d);
         $response->form = $form;
     } else {
         $response->msg = $this->lang['error_no_bridge'];
         $response->form = $form;
     }
     return $response;
 }