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 edit() { $resource_icon_default = "/img/resource.png"; $storage_icon = "/plugins/kvm/img/plugin.png"; //$state_icon = $this->openqrm->get('baseurl')."/img/".$this->resource->state.".png"; if ($this->file->exists($this->openqrm->get('webdir') . $storage_icon)) { $resource_icon_default = $storage_icon; } $resource_icon_default = $this->openqrm->get('baseurl') . $resource_icon_default; // check if we have a plugin implementing the remote console $remote_console = false; $plugin = new plugin(); $enabled_plugins = $plugin->enabled(); foreach ($enabled_plugins as $index => $plugin_name) { //$plugin_remote_console_running = $this->openqrm->get('webdir')."/plugins/".$plugin_name."/.running"; $plugin_remote_console_hook = $this->openqrm->get('webdir') . "/plugins/" . $plugin_name . "/openqrm-" . $plugin_name . "-remote-console-hook.php"; if ($this->file->exists($plugin_remote_console_hook)) { require_once "{$plugin_remote_console_hook}"; $link_function = str_replace("-", "_", "openqrm_" . "{$plugin_name}" . "_remote_console"); if (function_exists($link_function)) { $remote_functions[] = $link_function; $remote_console = true; } } } // prepare list of all Host resource id for the migration select // we need a select with the ids/ips from all resources which // are used by appliances with kvm capabilities $kvm_hosts = array(); $appliance_list = new appliance(); $appliance_list_array = $appliance_list->get_list(); foreach ($appliance_list_array as $index => $app) { $appliance_kvm_host_check = new appliance(); $appliance_kvm_host_check->get_instance_by_id($app["value"]); // only active appliances if (!strcmp($appliance_kvm_host_check->state, "active") || $appliance_kvm_host_check->resources == 0) { $virtualization = new virtualization(); $virtualization->get_instance_by_id($appliance_kvm_host_check->virtualization); if (!strcmp($virtualization->type, "kvm") && !strstr($virtualization->type, "kvm-vm")) { $kvm_host_resource = new resource(); $kvm_host_resource->get_instance_by_id($appliance_kvm_host_check->resources); // exclude source host #if ($kvm_host_resource->id == $this->resource->id) { # continue; #} // only active appliances if (!strcmp($kvm_host_resource->state, "active")) { $migration_select_label = "Res. " . $kvm_host_resource->id . "/" . $kvm_host_resource->ip; $kvm_hosts[] = array("value" => $kvm_host_resource->id, "label" => $migration_select_label); } } } } $d['state'] = '<span class="pill ' . $this->resource->state . '">' . $this->resource->state . '</span>'; $d['resource'] = $this->resource->id . ' / ' . $this->resource->ip; $d['name'] = $this->appliance->name; $d['id'] = $this->appliance->id; $a = $this->response->html->a(); $a->label = $this->lang['action_add_local_vm']; $a->css = 'add'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "add") . '&vmtype=kvm-vm-local'; $d['add_local_vm'] = $a->get_string(); $a = $this->response->html->a(); $a->label = $this->lang['action_add_network_vm']; $a->css = 'add'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "add") . '&vmtype=kvm-vm-net'; $d['add_network_vm'] = $a->get_string(); $body = array(); $identifier_disabled = array(); $file = $this->statfile; if ($this->file->exists($file)) { $lines = explode("\n", $this->file->get_contents($file)); if (count($lines) >= 1) { $i = 0; foreach ($lines as $line) { if ($line !== '') { $line = explode('@', $line); $state = $line[0]; $name = $line[1]; $mac = $line[2]; $resource = new resource(); $resource->get_instance_by_mac($mac); if ($resource->vhostid != $this->resource->id) { continue; } $res_virtualization = new virtualization(); $res_virtualization->get_instance_by_id($resource->vtype); $update = ''; $a = $this->response->html->a(); $a->title = $this->lang['action_update']; $a->label = $this->lang['action_update']; $a->handler = 'onclick="wait();"'; $a->css = 'edit'; $a->href = $this->response->get_url($this->actions_name, "update") . '&vm=' . $name . '&vmtype=' . $res_virtualization->type; $update_link = $a->get_string(); $clone = ''; $a = $this->response->html->a(); $a->title = $this->lang['action_clone']; $a->label = $this->lang['action_clone']; $a->handler = 'onclick="wait();"'; $a->css = 'clone'; $a->href = $this->response->get_url($this->actions_name, "clone") . '&vm=' . $name . '&mac=' . $mac; $clone_link = $a->get_string(); if ($res_virtualization->type == 'kvm-vm-local') { if ($state === '0' && $resource->image === 'idle') { $update = $update_link; $clone = $clone_link; } } if ($res_virtualization->type == 'kvm-vm-net') { if ($state !== '2' && $resource->image === 'idle') { $update = $update_link; $clone = $clone_link; } } $migrate = ''; $a = $this->response->html->a(); $a->title = $this->lang['action_migrate']; $a->label = $this->lang['action_migrate']; $a->handler = 'onclick="wait();"'; $a->css = 'migrate'; $a->href = $this->response->get_url($this->actions_name, "migrate") . '&vm=' . $name . '&mac=' . $mac; if (count($kvm_hosts) >= 1 && $state === '1') { $migrate = $a->get_string(); } $data = '<b>' . $this->lang['table_id'] . '</b>: ' . $resource->id . '<br>'; $data .= '<b>' . $this->lang['table_name'] . '</b>: ' . $name . '<br>'; $data .= '<b>' . $this->lang['table_type'] . '</b>: ' . $res_virtualization->name . '<br>'; $data .= '<b>' . $this->lang['table_ip'] . '</b>: ' . $resource->ip . '<br>'; $data .= '<b>' . $this->lang['table_mac'] . '</b>: ' . $mac . '<br>'; $data .= '<b>' . $this->lang['table_vnc'] . '</b>: ' . $line[5] . '<br>'; $data .= '<b>' . $this->lang['table_cpu'] . '</b>: ' . $line[3] . '<br>'; $data .= '<b>' . $this->lang['table_ram'] . '</b>: ' . $line[4] . '<br>'; $data .= '<b>' . $this->lang['table_nics'] . '</b>: ' . $resource->nics; $appliance = new appliance(); $appliance->get_instance_by_virtualization_and_resource($resource->vtype, $resource->id); $server = array(); $server[0] = ''; $server[1] = '1000000000000000000000000'; if ($appliance->id !== '') { $kernel = new kernel(); $kernel->get_instance_by_id($appliance->kernelid); $image = new image(); $image->get_instance_by_id($appliance->imageid); $storage = new storage(); $storage->get_instance_by_id($image->storageid); $s = '<b>' . $this->lang['table_appliance'] . '</b>: ' . $appliance->id . '<br>'; $s .= '<b>' . $this->lang['table_name'] . '</b>: ' . $appliance->name . '<br>'; $s .= '<b>' . $this->lang['table_kernel'] . '</b>: ' . $kernel->name . '<br>'; $s .= '<b>' . $this->lang['table_image'] . '</b>: ' . $image->name . '<br>'; $s .= '<b>' . $this->lang['table_storage'] . '</b>: ' . $storage->name . '<br>'; $server[0] = $s; $server[1] = $appliance->id; } $console = ''; if ($state === '2') { $t = $this->response->html->template($this->openqrm->get('webdir') . '/js/openqrm-progressbar.js'); $identifier_disabled[] = $name; // progressbar $t->add(uniqid('b'), 'id'); $t->add($this->openqrm->get('baseurl') . '/api.php?action=plugin&plugin=kvm&controller=kvm-vm&kvm_vm_action=progress&name=' . $name . '.vm_migration_progress', 'url'); $t->add($this->lang['action_migrate_in_progress'], 'lang_in_progress'); $t->add($this->lang['action_migrate_finished'], 'lang_finished'); $console = $t->get_string(); } else { if ($remote_console === true && $resource->imageid !== 1 && $state === '1') { foreach ($remote_functions as $function) { $a = $function($resource->id); if (is_object($a)) { $console .= $a->get_string(); } } } } $state = array(); $state[0] = '<span class="pill idle">idle</span>'; $state[1] = 'i'; if ($line[0] === '1' && $resource->image !== 'idle') { $state[0] = '<span class="pill active">active</span>'; $state[1] = 'a'; } if ($res_virtualization->type == 'kvm-vm-net' && $line[0] === '0') { $state[0] = '<span class="pill off">off</span>'; $state[1] = 'o'; } $action = ''; if (!in_array($name, $identifier_disabled)) { $action = $update . $clone . $migrate; } $body[$i] = array('state' => $state[0], 'state_s' => $state[1], 'name' => $name, 'id' => $resource->id, 'mac' => $mac, 'cpu' => $line[3], 'ram' => $line[4], 'ip' => $resource->ip, 'vnc' => $line[5], 'data' => $data, 'appliance' => $server[0], 'appliance_s' => $server[1], 'plugins' => $console, 'action' => $action); } $i++; } } } $h['state']['title'] = $this->lang['table_state']; $h['state']['sortable'] = false; $h['state_s']['title'] = $this->lang['table_state']; $h['state_s']['sortable'] = true; $h['state_s']['hidden'] = true; $h['id']['title'] = $this->lang['table_id']; $h['id']['hidden'] = true; $h['name']['title'] = $this->lang['table_name']; $h['name']['hidden'] = true; $h['ip']['title'] = $this->lang['table_ip']; $h['ip']['hidden'] = true; $h['mac']['title'] = $this->lang['table_mac']; $h['mac']['hidden'] = true; $h['vnc']['title'] = $this->lang['table_vnc']; $h['vnc']['hidden'] = true; $h['cpu']['title'] = $this->lang['table_cpu']; $h['cpu']['hidden'] = true; $h['ram']['title'] = $this->lang['table_ram']; $h['ram']['hidden'] = true; $h['nics']['title'] = $this->lang['table_nics']; $h['nics']['hidden'] = true; $h['data']['title'] = ' '; $h['data']['sortable'] = false; $h['appliance']['title'] = ' '; $h['appliance']['sortable'] = false; $h['appliance_s']['title'] = $this->lang['table_appliance']; $h['appliance_s']['sortable'] = true; $h['appliance_s']['hidden'] = true; $h['plugins']['title'] = ' '; $h['plugins']['sortable'] = false; $h['action']['title'] = ' '; $h['action']['sortable'] = false; $table = $this->response->html->tablebuilder('kvm_vm_edit', $this->response->get_array($this->actions_name, 'edit')); $table->sort = 'name'; $table->limit = 10; $table->offset = 0; $table->order = 'ASC'; $table->max = count($body); $table->autosort = true; $table->sort_link = false; $table->id = 'Tabelle'; $table->css = 'htmlobject_table'; $table->border = 1; $table->cellspacing = 0; $table->cellpadding = 3; $table->form_action = $this->response->html->thisfile; $table->head = $h; $table->body = $body; $table->identifier = 'name'; $table->identifier_name = $this->identifier_name; $table->identifier_disabled = $identifier_disabled; $table->actions_name = $this->actions_name; $table->actions = array(array('start' => $this->lang['action_start']), array('stop' => $this->lang['action_stop']), array('reboot' => $this->lang['action_reboot']), array('remove' => $this->lang['action_remove'])); $d['table'] = $table->get_string(); return $d; }
require_once $cloud_product_hook; openqrm_hybrid_cloud_cloud_product("add", $cloud_hook_config); } } } break; case 'uninstall': $drop_hybrid_cloud_table = "drop table hybrid_cloud_accounts"; $db = openqrm_get_db_connection(); $recordSet = $db->Execute($drop_hybrid_cloud_table); $db->Close(); // remove Cloud Host Server and Storage $virtualization = new virtualization(); $virtualization->get_instance_by_type("hybrid-cloud"); $appliance = new appliance(); $appliance->get_instance_by_virtualization_and_resource($virtualization->id, '0'); if (strlen($appliance->id)) { $appliance->remove($appliance->id); } $deployment = new deployment(); $deployment->get_instance_by_name('ami-deployment'); $storage = new storage(); $hc_id_list = $storage->get_ids_by_storage_type($deployment->id); $found_hc = false; $found_hc_id = -1; foreach ($hc_id_list as $list) { foreach ($list as $hc_id) { $storage->get_instance_by_id($hc_id); if ($storage->resource_id == 0) { $found_hc = true; $found_hc_id = $storage->id;
function select() { $d = array(); $h = array(); $h['resource_state']['title'] = $this->lang['table_state']; $h['resource_state']['sortable'] = false; $h['resource_id']['title'] = $this->lang['table_id']; $h['resource_id']['hidden'] = true; $h['resource_hostname']['title'] = $this->lang['table_name']; $h['resource_hostname']['hidden'] = true; $h['resource_mac']['title'] = $this->lang['table_mac']; $h['resource_mac']['hidden'] = true; $h['resource_ip']['title'] = $this->lang['table_ip']; $h['resource_ip']['hidden'] = true; $h['resource_type']['title'] = $this->lang['table_type']; $h['resource_type']['sortable'] = false; $h['resource_type']['hidden'] = true; $h['resource_memtotal']['title'] = $this->lang['table_memory']; $h['resource_memtotal']['hidden'] = true; $h['resource_cpunumber']['title'] = $this->lang['table_cpu']; $h['resource_cpunumber']['hidden'] = true; $h['resource_nics']['title'] = $this->lang['table_nics']; $h['resource_nics']['hidden'] = true; $h['resource_load']['title'] = $this->lang['table_load']; $h['resource_load']['hidden'] = true; $h['data']['title'] = ' '; $h['data']['sortable'] = false; $h['hw']['title'] = ' '; $h['hw']['sortable'] = false; $resource = new resource(); $params = $this->response->get_array($this->actions_name, 'select'); $b = array(); #$this->response->html->help($resource->find_resource('00:e0:53:13')); // unset unnecessary params unset($params['resource_type_filter']); unset($params['resource_filter']); unset($params['resource[sort]']); unset($params['resource[order]']); unset($params['resource[limit]']); unset($params['resource[offset]']); $table = $this->response->html->tablebuilder('resource', $params); $table->offset = 0; $table->sort = 'resource_id'; $table->limit = 20; $table->order = 'ASC'; $table->max = $resource->get_count('all'); $table->init(); // handle table params $tps = $table->get_params(); $tp = ''; foreach ($tps['resource'] as $k => $v) { $tp .= '&resource[' . $k . ']=' . $v; } $resource_filter = null; if ($this->response->html->request()->get('resource_filter') !== '') { $resource_filter = array(); $ar = $resource->find_resource($this->response->html->request()->get('resource_filter')); if (count($ar) > 0) { foreach ($ar as $k => $v) { $resource_filter[] = $v['resource_id']; } } } $resources = $resource->display_overview(0, 10000, $table->sort, $table->order); foreach ($resources as $index => $resource_db) { // prepare the values for the array $resource = new resource(); $resource->get_instance_by_id($resource_db["resource_id"]); $res_id = $resource->id; if ($this->response->html->request()->get('resource_type_filter') === '' || $this->response->html->request()->get('resource_type_filter') == $resource->vtype) { // Skip all resources not in $resource_filter if (isset($resource_filter)) { if (!in_array($resource->id, $resource_filter)) { continue; } } $mem_total = $resource_db['resource_memtotal']; $mem_used = $resource_db['resource_memused']; $mem = "{$mem_used}/{$mem_total}"; $swap_total = $resource_db['resource_swaptotal']; $swap_used = $resource_db['resource_swapused']; $swap = "{$swap_used}/{$swap_total}"; $resource_mac = $resource_db["resource_mac"]; // the resource_type $link = ''; if (strlen($resource->vtype) && !strstr($resource->vtype, "NULL")) { // find out what should be preselected $virtualization = new virtualization(); $virtualization->get_instance_by_id($resource->vtype); $virtualization_plugin_name = $virtualization->get_plugin_name(); $virtualization_vm_action_name = str_replace("-", "_", $virtualization_plugin_name); if ($virtualization->id == 1) { $resource_type = $virtualization->name; } else { $resource_type_link_text = $virtualization->name; if ($resource->id == $resource->vhostid) { // physical system or host $host_appliance = new appliance(); $host_appliance->get_instance_by_virtualization_and_resource($virtualization->id, $resource->id); if ($virtualization->id > 0 && $resource->id > 0) { $link = '?plugin=' . $virtualization_plugin_name . '&controller=' . $virtualization_plugin_name . '-vm&' . $virtualization_vm_action_name . '_vm_action=edit&appliance_id=' . $host_appliance->id; $resource_type_link_text = "<nobr>" . $virtualization->name . " Server " . $host_appliance->name . "</nobr>"; } } else { // vm $host_virtualization = new virtualization(); $host_virtualization->get_instance_by_type($virtualization_plugin_name); $host_appliance = new appliance(); if ($host_virtualization->id > 0) { $host_appliance->get_instance_by_virtualization_and_resource($host_virtualization->id, $resource->vhostid); $host_resource = new resource(); $host_resource->get_instance_by_id($resource->vhostid); $link = '?plugin=' . $virtualization_plugin_name . '&controller=' . $virtualization_plugin_name . '-vm&' . $virtualization_vm_action_name . '_vm_action=edit&appliance_id=' . $host_appliance->id; $resource_type_link_text = "<nobr>" . $virtualization->name . " on Res. " . $host_resource->hostname . "</nobr>"; } } $resource_type = $resource_type_link_text; } } else { $resource_type = "Unknown"; } // openQRM resource ? if ($resource->id == 0) { $resource_icon_default = "/openqrm/base/img/logo.png"; } else { $resource_icon_default = "/openqrm/base/img/resource.png"; } $state_icon = '<span class="pill ' . $resource->state . '">' . $resource->state . '</span>'; // idle ? if ("{$resource->imageid}" == "1" && "{$resource->state}" == "active") { $state_icon = '<span class="pill idle">idle</span>'; } $resource_cpus = $resource_db["resource_cpunumber"]; if (!strlen($resource_cpus)) { $resource_cpus = '?'; } $resource_nics = $resource_db["resource_nics"]; if (!strlen($resource_nics)) { $resource_nics = '?'; } isset($resource_db["resource_hostname"]) ? $name = $resource_db["resource_hostname"] : ($name = ' '); isset($resource_db["resource_nics"]) ? $nics = $resource_db["resource_nics"] : ($nics = ' '); isset($resource_db["resource_load"]) ? $load = $resource_db["resource_load"] : ($load = ' '); $data = '<b>' . $this->lang['table_id'] . '</b>: ' . $resource_db["resource_id"] . '<br>'; $data .= '<b>' . $this->lang['table_name'] . '</b>: ' . $name . '<br>'; $data .= '<b>' . $this->lang['table_mac'] . '</b>: ' . $resource_mac . '<br>'; $data .= '<b>' . $this->lang['table_ip'] . '</b>: ' . $resource_db["resource_ip"] . '<br>'; $data .= '<b>' . $this->lang['table_type'] . '</b>: ' . $resource_type; $hw = '<b>' . $this->lang['table_cpu'] . '</b>: ' . $resource_cpus . '<br>'; $hw .= '<b>' . $this->lang['table_memory'] . '</b>: ' . $mem . '<br>'; $hw .= '<b>' . $this->lang['table_nics'] . '</b>: ' . $nics . '<br>'; $hw .= '<b>' . $this->lang['table_load'] . '</b>: ' . $load; $b[] = array('resource_state' => $state_icon, 'resource_id' => $resource_db["resource_id"], 'resource_hostname' => $name, 'resource_mac' => $resource_mac, 'resource_ip' => $resource_db["resource_ip"], 'resource_type' => $resource_type, 'resource_memtotal' => $mem, 'resource_cpunumber' => $resource_cpus, 'resource_nics' => $nics, 'resource_load' => $load, 'data' => $data, 'hw' => $hw); } } // Type Filter $virtulization_types = new virtualization(); $list = $virtulization_types->get_list(); $filter = array(); $filter[] = array('', ''); foreach ($list as $l) { $filter[] = array($l['label'], $l['value']); } asort($filter); $select = $this->response->html->select(); $select->add($filter, array(1, 0)); $select->name = 'resource_type_filter'; $select->handler = 'onchange="wait();this.form.submit();return false;"'; $select->selected = array($this->response->html->request()->get('resource_type_filter')); $box1 = $this->response->html->box(); $box1->add($select); $box1->id = 'resource_type_filter'; $box1->css = 'htmlobject_box'; $box1->label = $this->lang['lang_type_filter']; // Resource Filter $input = $this->response->html->input(); $input->name = 'resource_filter'; $input->value = $this->response->html->request()->get('resource_filter'); $input->title = $this->lang['lang_filter_title']; $box2 = $this->response->html->box(); $box2->add($input); $box2->id = 'resource_filter'; $box2->css = 'htmlobject_box'; $box2->label = $this->lang['lang_filter']; $add = $this->response->html->a(); $add->title = $this->lang['action_add']; $add->label = $this->lang['action_add']; $add->handler = 'onclick="wait();"'; $add->css = 'add'; $add->href = $this->response->get_url($this->actions_name, "add") . '' . $tp; $table->id = 'Tabelle'; $table->css = 'htmlobject_table'; $table->border = 1; $table->cellspacing = 0; $table->cellpadding = 3; $table->autosort = false; $table->sort_link = false; $table->head = $h; $table->body = $b; $table->max = count($b); $table->actions_name = $this->actions_name; $table->actions = array(array('reboot' => $this->lang['action_reboot']), array('poweroff' => $this->lang['action_poweroff']), array('remove' => $this->lang['action_remove'])); $table->identifier = 'resource_id'; $table->identifier_name = $this->identifier_name; $table->identifier_disabled = array(0); $table->limit_select = array(array("value" => 10, "text" => 10), array("value" => 20, "text" => 20), array("value" => 30, "text" => 30), array("value" => 50, "text" => 50), array("value" => 100, "text" => 100)); $d['form'] = $this->response->get_form($this->actions_name, 'select', false)->get_elements(); $d['add'] = $add->get_string(); $d['resource_type_filter'] = $box1->get_string(); $d['resource_filter'] = $box2->get_string(); $d['table'] = $table; return $d; }
function select() { $d = array(); $h = array(); $h['appliance_state']['title'] = $this->lang['table_state']; $h['appliance_id']['title'] = $this->lang['table_id']; $h['appliance_id']['hidden'] = true; $h['appliance_name']['title'] = $this->lang['table_name']; $h['appliance_name']['hidden'] = true; $h['appliance_values']['title'] = ' '; $h['appliance_values']['sortable'] = false; $h['appliance_comment']['title'] = ' '; $h['appliance_comment']['sortable'] = false; $h['appliance_virtualization']['title'] = 'Type'; $h['appliance_virtualization']['sortable'] = true; $h['appliance_virtualization']['hidden'] = true; $h['appliance_edit']['sortable'] = false; $appliance = new appliance(); $params = $this->response->get_array($this->actions_name, 'select'); $b = array(); // unset unnecessary params unset($params['resource_type_filter']); unset($params['resource_filter']); unset($params['appliance[sort]']); unset($params['appliance[order]']); unset($params['appliance[limit]']); unset($params['appliance[offset]']); $table = $this->response->html->tablebuilder('appliance', $params); $table->offset = 0; $table->sort = 'appliance_id'; $table->limit = 20; $table->order = 'ASC'; $table->max = $appliance->get_count(); $table->init(); // handle table params #$tps = $table->get_params(); $tp = ''; #foreach($tps['appliance'] as $k => $v) { # $tp .= '&appliance['.$k.']='.$v; #} $resource_filter = null; if ($this->response->html->request()->get('resource_filter') !== '') { $resource = $this->openqrm->resource(); $resource_filter = array(); $ar = $resource->find_resource($this->response->html->request()->get('resource_filter')); if (count($ar) > 0) { foreach ($ar as $k => $v) { $resource_filter[] = $v['resource_id']; } } } $disabled = array(); $appliances = $appliance->display_overview(0, 10000, $table->sort, $table->order); foreach ($appliances as $index => $appliance_db) { $appliance = new appliance(); $appliance->get_instance_by_id($appliance_db["appliance_id"]); $resource = new resource(); $resource->get_instance_by_id($appliance->resources); $appliance_resources = $appliance_db["appliance_resources"]; $kernel = new kernel(); $kernel->get_instance_by_id($appliance_db["appliance_kernelid"]); $image = new image(); $image->get_instance_by_id($appliance_db["appliance_imageid"]); $virtualization = new virtualization(); $virtualization->get_instance_by_id($appliance_db["appliance_virtualization"]); $appliance_virtualization_name = $virtualization->name; $virtualization_plugin_name = $virtualization->get_plugin_name(); $resource_is_local_server = false; if ($this->response->html->request()->get('resource_type_filter') === '' || $this->response->html->request()->get('resource_type_filter') == $resource->vtype) { // Skip all resources not in $resource_filter if (isset($resource_filter)) { if (!in_array($resource->id, $resource_filter)) { continue; } } if ($appliance_resources >= 0) { // an appliance with a pre-selected resource $resource->get_instance_by_id($appliance_resources); $resource_state_icon = '<span class="pill ' . $resource->state . '">' . $resource->state . '</span>'; // idle ? if ("{$resource->imageid}" == "1" && "{$resource->state}" == "active") { $resource_state_icon = '<span class="pill idle">idle</span>'; } // link to resource list $virtualization_vm_action_name = $virtualization->name; if (strstr($resource->capabilities, "TYPE=local-server")) { $resource_is_local_server = true; } $appliance_resources_str = ''; if (strpos($virtualization->type, "-vm")) { $host_resource = new resource(); $host_resource->get_instance_by_id($resource->vhostid); $host_virtualization = new virtualization(); $host_virtualization_name = $virtualization->get_plugin_name(); $host_virtualization->get_instance_by_type($host_virtualization_name); $host_appliance = new appliance(); $host_appliance->get_instance_by_virtualization_and_resource($host_virtualization->id, $resource->vhostid); $link = '?base=appliance&appliance_action=load_select'; $link .= '&aplugin=' . $virtualization_plugin_name; $link .= '&acontroller=' . $virtualization_plugin_name . '-vm'; $link .= '&' . $virtualization_plugin_name . '_vm_action=update'; $link .= '&appliance_id=' . $host_appliance->id; $link .= '&vm=' . $resource->hostname; $appliance_resources_str = '<a href="' . $this->response->html->thisfile . $link . '" onclick="wait();">' . $resource->hostname . '</a> ' . $resource_state_icon; } else { $appliance_resources_str = $resource->hostname . ' ' . $resource_state_icon; } } else { // an appliance with resource auto-select enabled $appliance_resources_str = "auto-select"; } // active or inactive $resource_icon_default = "/openqrm/base/img/appliance.png"; $active_state_icon = '<span class="pill active">active</span>'; $inactive_state_icon = '<span class="pill inactive">incative</span>'; if ($appliance->stoptime == 0 || $appliance_resources == 0) { $state_icon = $active_state_icon; } else { $state_icon = $inactive_state_icon; } // link to image edit if ($image->id > 0) { $link = '?base=image'; $link .= '&image_action=edit'; $link .= '&image_id=' . $image->id; $image_edit_link = '<a href="' . $this->response->html->thisfile . $link . '" onclick="wait();">' . $image->name . '</a>'; } else { $image_edit_link = $image->name; } // release resource $release_resource = ''; if ($appliance->stoptime == 0 || $appliance_resources == 0) { $release_resource = ''; } else { if ($appliance->resources != -1) { $a = $this->response->html->a(); $a->label = $this->lang['action_release']; $a->title = $this->lang['resource_release']; $a->css = 'enable'; $a->href = $this->response->get_url($this->actions_name, 'release') . '&appliance_id=' . $appliance->id . '' . $tp; $release_resource = $a->get_string(); } } $str = '<strong>' . $this->lang['table_id'] . ':</strong> ' . $appliance_db["appliance_id"] . '<br> <strong>' . $this->lang['table_name'] . ':</strong> ' . $appliance_db["appliance_name"] . '<br> <strong>Type:</strong> ' . $appliance_virtualization_name . '<br> <strong>Kernel:</strong> ' . $kernel->name . '<br> <strong>Image:</strong> ' . $image_edit_link . '<br> <strong>Resource:</strong> ' . $appliance_resources_str . '<br> <strong>IP:</strong> ' . $resource->ip; if (strpos($virtualization->type, "-vm") && isset($resource->vhostid) && $resource->vhostid != '') { $happliance = new appliance(); $hresource = $happliance->get_ids_per_resource($resource->vhostid); if (isset($hresource[0]['appliance_id'])) { $happliance->get_instance_by_id($hresource[0]['appliance_id']); $link = '?base=appliance'; $link .= '&appliance_action=edit'; $link .= '&appliance_id=' . $happliance->id; $href = '<a href="' . $this->response->html->thisfile . $link . '" onclick="wait();">' . $happliance->name . '</a>'; $str .= '<br><strong>Host:</strong> ' . $href; } } // appliance edit $a = $this->response->html->a(); $a->title = $this->lang['action_edit']; $a->label = $this->lang['action_edit']; $a->handler = 'onclick="wait();"'; $a->css = 'edit'; $a->href = $this->response->get_url($this->actions_name, 'edit') . '&appliance_id=' . $appliance->id . '' . $tp; $strEdit = $a->get_string(); // appliance start $strStart = ''; if ($appliance_resources !== '0') { $a = $this->response->html->a(); $a->handler = 'onclick="wait();"'; if ($appliance->stoptime == 0) { $a->title = $this->lang['action_stop']; $a->label = $this->lang['action_stop']; $a->css = 'disable'; $a->href = $this->response->get_url($this->actions_name, 'stop') . '&' . $this->identifier_name . '[]=' . $appliance->id . '' . $tp; } else { $a->title = $this->lang['action_start']; $a->label = $this->lang['action_start']; $a->css = 'enable'; $a->href = $this->response->get_url($this->actions_name, 'start') . '&' . $this->identifier_name . '[]=' . $appliance->id . '' . $tp; } $strStart = $a->get_string(); } // build the plugin link section $appliance_link_section = ''; // add link to continue if appliance has unfinished wizard $disabled = array(); if (isset($appliance->wizard) && strpos($appliance->wizard, 'wizard') !== false) { $params = explode(',', $appliance->wizard); $wizard_step = explode('=', $params[0]); $wizard_user = explode('=', $params[1]); if ($wizard_user[1] === $this->user->name) { // continue button $a = $this->response->html->a(); $a->title = $this->lang['action_continue']; $a->label = $this->lang['action_continue']; $a->handler = 'onclick="wait();"'; $a->css = 'badge continue'; $a->href = $this->response->get_url($this->actions_name, $wizard_step[1]) . '&appliance_wizard_id=' . $appliance->id . '' . $tp; $appliance_comment = $a->get_string(); } else { $appliance_comment = sprintf($this->lang['appliance_create_in_progress'], $wizard_user[1]); } // disable all buttons $disabled[] = $appliance->id; $strEdit = ''; $strStart = ''; $strStop = ''; $release_resource = ''; } else { $plugin = new plugin(); $enabled_plugins = $plugin->enabled(); foreach ($enabled_plugins as $index => $plugin_name) { $plugin_appliance_link_section_hook = $this->openqrm->get('webdir') . "/plugins/" . $plugin_name . "/openqrm-" . $plugin_name . "-appliance-link-hook.php"; if (file_exists($plugin_appliance_link_section_hook)) { require_once "{$plugin_appliance_link_section_hook}"; $appliance_get_link_function = str_replace("-", "_", "get_" . "{$plugin_name}" . "_appliance_link"); if (function_exists($appliance_get_link_function)) { $p = $plugin->get_config($plugin_name); $alink = $appliance_get_link_function($appliance->id); if (is_object($alink)) { // $alink->handler = $alink->handler.' onclick="wait();"'; $alink->css = 'enable'; $alink->title = preg_replace('~(.*?)<a.*>(.*?)</a>(.*?)~i', '$1$2$3', $p['description']); $alink = $alink->get_string(); } $appliance_link_section .= $alink; } } } if ($appliance_db["appliance_comment"] !== '') { $appliance_comment = $appliance_db["appliance_comment"]; $appliance_comment .= "<hr>"; $appliance_comment .= $appliance_link_section; } else { $appliance_comment = $appliance_link_section; } } $b[] = array('appliance_state' => $state_icon, 'appliance_id' => $appliance_db["appliance_id"], 'appliance_name' => $appliance_db["appliance_name"], 'appliance_values' => $str, 'appliance_comment' => $appliance_comment, 'appliance_virtualization' => $appliance_db["appliance_virtualization"], 'appliance_edit' => $strEdit . '' . $strStart . '' . $release_resource); } } // Filter $virtulization_types = new virtualization(); $list = $virtulization_types->get_list(); $filter = array(); $filter[] = array('', ''); foreach ($list as $l) { $filter[] = array($l['label'], $l['value']); } asort($filter); $select = $this->response->html->select(); $select->add($filter, array(1, 0)); $select->name = 'resource_type_filter'; $select->handler = 'onchange="wait();this.form.submit();return false;"'; $select->selected = array($this->response->html->request()->get('resource_type_filter')); $box1 = $this->response->html->box(); $box1->add($select); $box1->id = 'resource_type_filter'; $box1->css = 'htmlobject_box'; $box1->label = $this->lang['lang_type_filter']; // Resource Filter $input = $this->response->html->input(); $input->name = 'resource_filter'; $input->value = $this->response->html->request()->get('resource_filter'); $input->title = $this->lang['lang_filter_title']; $box2 = $this->response->html->box(); $box2->add($input); $box2->id = 'resource_filter'; $box2->css = 'htmlobject_box'; $box2->label = $this->lang['lang_filter']; $add = $this->response->html->a(); $add->title = $this->lang['action_add']; $add->label = $this->lang['action_add']; $add->handler = 'onclick="wait();"'; $add->css = 'add'; $add->href = $this->response->get_url($this->actions_name, "step1") . '' . $tp; $table->id = 'Tabelle'; $table->css = 'htmlobject_table'; $table->border = 1; $table->cellspacing = 0; $table->cellpadding = 3; $table->autosort = true; $table->sort_link = false; $table->max = count($b); $table->head = $h; $table->body = $b; #$table->form_action = $this->response->html->thisfile; $table->actions_name = $this->actions_name; $table->actions = array(array('start' => $this->lang['action_start']), array('stop' => $this->lang['action_stop']), array('remove' => $this->lang['action_remove'])); $table->identifier = 'appliance_id'; $table->identifier_name = $this->identifier_name; $table->identifier_disabled = $disabled; #$table->limit_select = array( # array("value" => 10, "text" => 10), # array("value" => 20, "text" => 20), # array("value" => 30, "text" => 30), # array("value" => 50, "text" => 50), # array("value" => 100, "text" => 100), #); $d['form'] = $this->response->get_form($this->actions_name, 'select', false)->get_elements(); $d['add'] = $add->get_string(); $d['table'] = $table; $d['resource_type_filter'] = $box1->get_string(); $d['resource_filter'] = $box2->get_string(); return $d; }