function get_template_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); $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects'); $a = $html->a(); $a->label = 'Template'; $a->css = 'badge'; $a->href = '#'; $a->handler = 'onclick="window.open(\'Template-URL\',\'\', \'location=0,status=0,scrollbars=1,width=1150,height=800,left=50,top=50,screenX=50,screenY=50\');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_template_deployment_resource_virtual_command($cmd, $resource_fields) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; $resource_id = $resource_fields["resource_id"]; $resource = new resource(); $resource->get_instance_by_id($resource_id); $host_resource = new resource(); $host_resource->get_instance_by_id($resource->vhostid); $event->log("openqrm_template_deployment_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-template_deployment-resource-virtual-command-hook.php", "Handling {$cmd} command of resource {$resource->id} on host {$host_resource->id}", "", "", 0, 0, 0); switch ($cmd) { case "reboot": $event->log("openqrm_template_deployment_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-template_deployment-resource-virtual-command-hook.php", "Handling {$cmd} command", "", "", 0, 0, 0); $virtual_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template_deployment/bin/openqrm-template_deployment-vm restart_by_mac -m " . $resource->mac . " -d noop --openqrm-cmd-mode background"; // reboot conflicts with appliance stop, commented out for now //$host_resource->send_command($host_resource->ip, $virtual_command); break; case "halt": $event->log("openqrm_template_deployment_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-template_deployment-resource-virtual-command-hook.php", "Handling {$cmd} command", "", "", 0, 0, 0); $virtual_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template_deployment/bin/openqrm-template_deployment-vm stop_by_mac -m " . $resource->mac . " --openqrm-cmd-mode background"; $host_resource->send_command($host_resource->ip, $virtual_command); break; } }
function get_lcmc_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); $lcmc_gui = "/openqrm/base/plugins/lcmc/lcmc-gui.php"; $icon_size = "width='24' height='24'"; $icon_title = "Configure appliaction highavailability"; $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects'); $a = $html->a(); $a->label = 'LCMC'; //'<img title="'.$icon_title.'" alt="'.$icon_title.'" $icon_size src="/openqrm/base/plugins/lcmc/img/plugin.png" border=0>'; $a->css = 'badge'; $a->href = '#'; $a->handler = 'onclick="window.open(\'' . $lcmc_gui . '\',\'\', \'location=0,status=0,scrollbars=1,width=1150,height=800,left=50,top=50,screenX=50,screenY=50\');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_template_appliance($cmd, $appliance_fields) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; $appliance_id = $appliance_fields["appliance_id"]; $appliance_name = $appliance_fields["appliance_name"]; $resource = new resource(); $resource->get_instance_by_id($appliance_fields["appliance_resources"]); $appliance_ip = $resource->ip; // check appliance values, maybe we are in update and they are incomplete if ($resource->id == "-1" || $resource->id == "") { return; } $event->log("openqrm_new_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-template-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id); switch ($cmd) { case "start": $openqrm_server = new openqrm_server(); $openqrm_server->send_command($OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template/bin/openqrm-template-manager start " . $appliance_id . " " . $appliance_name . " " . $appliance_ip . " --openqrm-cmd-mode background"); break; case "stop": $openqrm_server = new openqrm_server(); $openqrm_server->send_command($OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template/bin/openqrm-template-manager stop " . $appliance_id . " " . $appliance_name . " " . $appliance_ip . " --openqrm-cmd-mode background"); break; } }
function get_novnc_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); $virtualization = new virtualization(); $virtualization->get_instance_by_id($p_appliance->virtualization); $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects'); $a = $html->a(); $a->label = 'noVNC'; $a->css = 'badge'; $a->handler = 'onclick="wait();"'; $plugin_link = ''; if (strstr($p_appliance->state, "active")) { if (strstr($virtualization->type, '-vm-')) { $a->href = '/openqrm/base/index.php?plugin=novnc&controller=novnc&novnc_action=console&appliance_id=' . $p_appliance->id; } else { $a->href = '/openqrm/base/index.php?plugin=novnc&controller=novnc&novnc_action=login&appliance_id=' . $p_appliance->id; } $plugin_link = $a; } else { if ($p_resource->id === '0') { $a->href = '/openqrm/base/index.php?plugin=novnc&controller=novnc&novnc_action=login&appliance_id=' . $p_appliance->id; $plugin_link = $a; } } return $plugin_link; }
function openqrm_dhcpd_appliance($cmd, $appliance_fields) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_EXEC_PORT; $openqrm_server = new openqrm_server(); $OPENQRM_SERVER_IP_ADDRESS = $openqrm_server->get_ip_address(); $event = new event(); $appliance_id = $appliance_fields["appliance_id"]; $appliance_name = $appliance_fields["appliance_name"]; $resource = new resource(); $resource->get_instance_by_id($appliance_fields["appliance_resources"]); $resource_mac = $resource->mac; $resource_ip = $resource->ip; $appliance = new appliance(); $appliance->get_instance_by_id($appliance_id); if ($resource->id == "-1" || $resource->id == "") { return; } $event->log("openqrm_dhcpd_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-dhcpd-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$resource_ip}/{$resource_mac}", "", "", 0, 0, $resource->id); switch ($cmd) { case "start": $event->log("openqrm_dhcpd_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-dhcpd-appliance-hook.php", "Adding hostname " . $appliance->name . " from resource " . $resource->id . ".", "", "", 0, 0, $resource->id); $dhcpd_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/dhcpd/bin/openqrm-dhcpd-appliance add_hostname -m " . $resource_mac . " -n " . $appliance->name . " -d " . $resource->id . " --openqrm-cmd-mode background"; $openqrm_server->send_command($dhcpd_command); break; case "stop": $event->log("openqrm_dhcpd_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-dhcpd-appliance-hook.php", "Removing hostname " . $appliance->name . " from resource " . $resource->id . ".", "", "", 0, 0, $resource->id); $dhcpd_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/dhcpd/bin/openqrm-dhcpd-appliance remove_hostname -m " . $resource_mac . " -n " . $appliance->name . " -d " . $resource->id . " --openqrm-cmd-mode background"; $openqrm_server->send_command($dhcpd_command); break; } }
function get_nagios3_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); $nagios_link = "/openqrm/base/index.php?name=Nagios3&iframe=/cgi-bin/nagios3/status.cgi?host=" . $p_appliance->name; $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects'); $a = $html->a(); // $a->label = '<img title="Service monitoring" alt="Service monitoring" height="24" width="24" src="/openqrm/base/plugins/nagios3/img/plugin.png" border=0>'; $a->label = 'nagios'; $a->css = 'badge'; $a->href = $nagios_link; $a->handler = ''; $plugin_link = $a; if ($p_resource->id == 0) { $plugin_link = $a; } if ($p_resource->id == '') { $plugin_link = ""; } return $plugin_link; }
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 get_lvm_iscsi_deployment_image_rootdevice_identifier($lvm_iscsi_storage_id) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_ADMIN; global $event; // place for the storage stat files $StorageDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/plugins/lvm-storage/storage'; $rootdevice_identifier_array = array(); $storage = new storage(); $storage->get_instance_by_id($lvm_iscsi_storage_id); $storage_resource = new resource(); $storage_resource->get_instance_by_id($storage->resource_id); $storage_resource_id = $storage_resource->id; $ident_file = "{$StorageDir}/{$storage_resource_id}.lv.lvm-iscsi-deployment.ident"; if (file_exists($ident_file)) { unlink($ident_file); } // send command $resource_command = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/lvm-storage/bin/openqrm-lvm-storage post_identifier -t lvm-iscsi-deployment -u {$OPENQRM_ADMIN->name} -p {$OPENQRM_ADMIN->password}"; $storage_resource->send_command($storage_resource->ip, $resource_command); if (!lvm_iscsi_deployment_wait_for_identfile($ident_file)) { $event->log("get_image_rootdevice_identifier", $_SERVER['REQUEST_TIME'], 2, "image.lvm-iscsi-deployment", "Timeout while requesting image identifier from storage id {$storage->id}", "", "", 0, 0, 0); return; } $fcontent = file($ident_file); foreach ($fcontent as $lun_info) { $tpos = strpos($lun_info, ","); $timage_name = trim(substr($lun_info, 0, $tpos)); $troot_device = trim(substr($lun_info, $tpos + 1)); $rootdevice_identifier_array[] = array("value" => "{$troot_device}", "label" => "{$timage_name}"); } return $rootdevice_identifier_array; }
function openqrm_nagios3_appliance($cmd, $appliance_fields) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; $appliance_id = $appliance_fields["appliance_id"]; $appliance = new appliance(); $appliance->get_instance_by_id($appliance_id); $appliance_name = $appliance_fields["appliance_name"]; $resource = new resource(); $resource->get_instance_by_id($appliance_fields["appliance_resources"]); $appliance_ip = $resource->ip; // check appliance values, maybe we are in update and they are incomplete if ($appliance->imageid == 1) { return; } if ($resource->id == "-1" || $resource->id == "") { return; } // get the nagios service checks $nagios_host = new nagios3_host(); $nagios_host->get_instance_by_appliance_id($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)) { $event->log("openqrm_new_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-nagios3-appliance-hook.php", "Appliance {$appliance_id} has no configured nagios services, skipping...", "", "", 0, 0, $appliance_id); return 0; } $event->log("openqrm_new_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-nagios3-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id); switch ($cmd) { case "start": $nagios_appliance_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nagios3/bin/openqrm-nagios-manager add -n " . $appliance_name . " -i " . $resource->ip . " -p " . $nagios_service_list . " --openqrm-cmd-mode background"; $openqrm_server = new openqrm_server(); $openqrm_server->send_command($nagios_appliance_start_cmd, NULL, true); break; case "stop": $nagios_appliance_stop_cmd = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/nagios3/bin/openqrm-nagios-manager remove_host -n " . $appliance_name . " --openqrm-cmd-mode background"; $openqrm_server = new openqrm_server(); $openqrm_server->send_command($nagios_appliance_stop_cmd, NULL, true); break; case "remove": $nagios_appliance_stop_cmd = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/nagios3/bin/openqrm-nagios-manager remove_host -n " . $appliance_name . " --openqrm-cmd-mode background"; $openqrm_server = new openqrm_server(); $openqrm_server->send_command($nagios_appliance_stop_cmd, NULL, true); // remove nagios_host from the db $nagios_host->remove_by_appliance_id($appliance_id); break; } }
function get_nagios3_appliance_edit($appliance_id, $openqrm, $response) { $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); if ($p_resource->id !== '') { $a = $response->html->a(); $a->label = '<img title="Service monitoring" alt="Service monitoring" height="24" width="24" src="' . $openqrm->get('baseurl') . '/plugins/nagios3/img/plugin.png" border=0>'; $a->href = $openqrm->get('baseurl') . '/index.php?base=appliance&appliance_action=load_edit&aplugin=nagios3&appliance_id=' . $appliance_id . '&nagios3_action=edit'; return $a; } }
function action() { $resource = new resource(); $resource->get_instance_by_id(0); $t = $this->response->html->template($this->tpldir . '/local-server-about-usage.tpl.php'); $t->add($this->response->html->thisfile, "thisfile"); $t->add($this->lang['label'], 'label'); $t->add($this->lang['usage_integrate_title'], 'usage_integrate_title'); $t->add($this->lang['usage_remove_title'], 'usage_remove_title'); $t->add(sprintf($this->lang['usage_integrate_content'], $this->basedir, $resource->ip), 'usage_integrate_content'); $t->add(sprintf($this->lang['usage_remove_content'], $resource->ip), 'usage_remove_content'); $t->add($this->openqrm->get('baseurl'), 'baseurl'); return $t; }
function __construct($openqrm, $response) { $this->response = $response; $this->openqrm = $openqrm; $this->file = $openqrm->file(); $this->user = $openqrm->user(); $id = $this->response->html->request()->get('appliance_id'); $this->response->add('appliance_id', $id); $this->response->add($this->identifier_name . '[]', ''); $appliance = new appliance(); $this->appliance = $appliance->get_instance_by_id($id); $resource = new resource(); $this->resource = $resource->get_instance_by_id($this->appliance->resources); $this->statfile = $this->openqrm->get('basedir') . '/plugins/network-manager/web/storage/' . $this->resource->id . '.network_stat'; }
function __construct($openqrm, $response) { $this->response = $response; $this->openqrm = $openqrm; $this->file = $this->openqrm->file(); $this->openqrm = $openqrm; $this->user = $openqrm->user(); $storage_id = $this->response->html->request()->get('storage_id'); $storage = new storage(); $resource = new resource(); $deployment = new deployment(); $this->storage = $storage->get_instance_by_id($storage_id); $this->resource = $resource->get_instance_by_id($storage->resource_id); $this->deployment = $deployment->get_instance_by_id($storage->type); $this->response->add('storage_id', $storage_id); }
function __construct($openqrm, $response) { $this->openqrm = $openqrm; $this->user = $this->openqrm->user(); $this->rootdir = $this->openqrm->get('webdir'); $this->response = $response; $this->file = $this->openqrm->file(); $this->tpldir = $this->rootdir . '/plugins/device-manager/tpl'; $id = $this->response->html->request()->get('storage_id'); $this->response->add('storage_id', $id); $this->response->add('volgroup', $this->response->html->request()->get('volgroup')); $storage = new storage(); $this->storage = $storage->get_instance_by_id($id); $resource = new resource(); $this->resource = $resource->get_instance_by_id($this->storage->resource_id); $this->statfile = $this->openqrm->get('basedir') . '/plugins/device-manager/web/storage/' . $this->resource->id . '.device.stat'; }
function __construct($openqrm, $response) { $this->response = $response; $this->file = $openqrm->file(); $this->openqrm = $openqrm; $this->user = $openqrm->user(); $id = $this->response->html->request()->get('appliance_id'); if ($id === '') { return false; } $appliance = new appliance(); $resource = new resource(); $appliance->get_instance_by_id($id); $resource->get_instance_by_id($appliance->resources); $this->resource = $resource; $this->appliance = $appliance; $this->statfile = $this->openqrm->get('basedir') . '/plugins/kvm/web/kvm-stat/' . $resource->id . '.pick_iso_config'; }
function remove_template_vm($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; // remove the vm from host $host_resource = new resource(); $host_resource->get_instance_by_id($host_resource_id); $event->log("remove_template_vm", $_SERVER['REQUEST_TIME'], 5, "template-cloud-hook", "Removing OpenVZ VM {$name}/{$mac} from Host resource {$host_resource_id}", "", "", 0, 0, 0); // we need to have an openQRM server object too since some of the // virtualization commands are sent from openQRM directly $openqrm = new openqrm_server(); // send command to create the vm on the host $vm_remove_cmd = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/template/bin/openqrm-template-vm delete -n " . $name . " --openqrm-cmd-mode background"; $event->log("remove_template_vm", $_SERVER['REQUEST_TIME'], 5, "template-cloud-hook", "Running {$vm_remove_cmd}", "", "", 0, 0, 0); $host_resource->send_command($host_resource->ip, $vm_remove_cmd); }
function openqrm_puppet_resource($cmd, $resource_fields) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; $resource_id = $resource_fields["resource_id"]; $resource = new resource(); $resource->get_instance_by_id($resource_id); $resource_ip = $resource->ip; $resource_name = $resource->hostname; $event->log("openqrm_puppet_resource", $_SERVER['REQUEST_TIME'], 5, "openqrm-puppet-resource-hook.php", "Handling {$cmd} event {$resource_id}/{$resource_name}/{$resource_ip}", "", "", 0, 0, $resource_id); // we do only care if we serving an appliance $appliance = new appliance(); $appliance_record_set = array(); $appliance_id_array = array(); $appliance_record_set = $appliance->get_all_ids(); // the appliance_array from getlist is a 2-dimensional array foreach ($appliance_record_set as $index => $appliance_id_array) { foreach ($appliance_id_array as $index => $id) { $tapp = new appliance(); $tapp->get_instance_by_id($id); $tapp_state = $tapp->state; $tapp_resources = $tapp->resources; if (!strcmp($tapp_state, "active")) { if ($tapp_resources == $resource_id) { // we found the resources active appliance, running the cmd $appliance_name = $tapp->name; switch ($cmd) { case "start": $openqrm_server = new openqrm_server(); $openqrm_server->send_command("{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/puppet/bin/openqrm-puppet-manager start {$id} {$appliance_name} {$resource_ip} --openqrm-cmd-mode background"); break; case "stop": $openqrm_server = new openqrm_server(); $openqrm_server->send_command("{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/puppet/bin/openqrm-puppet-manager stop {$id} {$appliance_name} {$resource_ip} --openqrm-cmd-mode background"); break; } } } } } }
function fence_template_deployment_vm($host_resource_id, $mac) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; // fences the vm on its host $host_resource = new resource(); $host_resource->get_instance_by_id($host_resource_id); $event->log("fence_template_deployment_vm", $_SERVER['REQUEST_TIME'], 5, "template_deployment-ha-hook", "Fencing OpenVZ VM {$mac} from Host resource {$host_resource_id}", "", "", 0, 0, 0); // we need to have an openQRM server object too since some of the // virtualization commands are sent from openQRM directly $openqrm = new openqrm_server(); // send command to fence the vm on the host $vm_fence_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template_deployment/bin/openqrm-template_deployment-vm fence -m " . $mac . " --openqrm-cmd-mode background"; $event->log("fence_template_deployment_vm", $_SERVER['REQUEST_TIME'], 5, "template_deployment-ha-hook", "Running {$vm_fence_cmd}", "", "", 0, 0, 0); $host_resource->send_command($host_resource->ip, $vm_fence_cmd); }
function get_nfs_deployment_image_rootdevice_identifier($nfs_storage_id) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_ADMIN; global $event; // place for the storage stat files $StorageDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/plugins/nfs-storage/storage'; $rootdevice_identifier_array = array(); $storage = new storage(); $storage->get_instance_by_id($nfs_storage_id); $storage_resource = new resource(); $storage_resource->get_instance_by_id($storage->resource_id); $storage_resource_id = $storage_resource->id; $ident_file = "{$StorageDir}/{$storage_resource_id}.nfs.ident"; $statfile_manual = "{$StorageDir}/" . $storage_resource_id . ".nfs.stat.manual"; // manual configured ? if (file_exists($statfile_manual)) { $fcontent = file($statfile_manual); foreach ($fcontent as $lun_info) { $troot_device = trim($lun_info); $rootdevice_identifier_array[] = array("value" => "{$troot_device}", "label" => "{$troot_device}"); } } else { if (file_exists($ident_file)) { unlink($ident_file); } // send command $resource_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nfs-storage/bin/openqrm-nfs-storage post_identifier -u " . $OPENQRM_ADMIN->name . " -p " . $OPENQRM_ADMIN->password . " --openqrm-cmd-mode background"; $storage_resource->send_command($storage_resource->ip, $resource_command); if (!nfs_deployment_wait_for_identfile($ident_file)) { $event->log("get_image_rootdevice_identifier", $_SERVER['REQUEST_TIME'], 2, "image.nfs-deployment", "Timeout while requesting image identifier from storage id {$storage->id}", "", "", 0, 0, 0); return; } $fcontent = file($ident_file); foreach ($fcontent as $lun_info) { $tpos = strpos($lun_info, ","); $timage_name = trim(substr($lun_info, 0, $tpos)); $troot_device = trim(substr($lun_info, $tpos + 1)); $rootdevice_identifier_array[] = array("value" => "{$troot_device}", "label" => "{$timage_name}"); } } return $rootdevice_identifier_array; }
function __construct($controller) { $this->controller = $controller; $this->user = $this->controller->user; $this->html = $this->controller->response->html; $this->response = $this->html->response(); $this->file = $this->controller->file; $this->admin = $this->controller->openqrm->admin(); $id = $this->response->html->request()->get('appliance_id'); if ($id === '') { return false; } // set ENV $this->response->params['appliance_id'] = $id; $appliance = new appliance(); $resource = new resource(); $appliance->get_instance_by_id($id); $resource->get_instance_by_id($appliance->resources); $this->resource = $resource; $this->appliance = $appliance; #$this->statfile = 'kvm-stat/'.$resource->id.'.pick_iso_config'; }
function get_hybrid_cloud_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); $virtualization = new virtualization(); $virtualization->get_instance_by_id($p_appliance->virtualization); if ($virtualization->type != "hybrid-cloud-vm-local") { return; } // get hybrid-cloud account $hybrid_cloud_acl_id = $p_resource->get_resource_capabilities("HCACL"); if ($hybrid_cloud_acl_id == '') { $event->log("get_hybrid_cloud_appliance_link", $_SERVER['REQUEST_TIME'], 2, "openqrm-hybrid-cloud-appliance-link-hook.php", "Could not find Hybrid-Cloud Account for resource " . $p_resource->id, "", "", 0, 0, $appliance_id); return; } $hc = new hybrid_cloud(); $hc->get_instance_by_id($hybrid_cloud_acl_id); $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects'); $a = $html->a(); $a->label = 'Dashboard'; $a->css = 'badge'; $a->target = '_BLANK'; if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $a->href = 'https://console.aws.amazon.com/ec2/'; } if ($hc->account_type == 'lc-openstack') { $a->href = 'http://' . $hc->host . '/project/instances/'; } $plugin_link = $a->get_string(); return $plugin_link; }
function get_kvm_lvm_deployment_image_rootdevice_identifier($kvm_lvm_id) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_ADMIN; global $event; // place for the storage stat files $StorageDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/plugins/kvm/storage'; $rootdevice_identifier_array = array(); $storage = new storage(); $storage->get_instance_by_id($kvm_lvm_id); // get deployment type $deployment = new deployment(); $deployment->get_instance_by_id($storage->type); // get storage resource $storage_resource = new resource(); $storage_resource->get_instance_by_id($storage->resource_id); $storage_resource_id = $storage_resource->id; $ident_file = $StorageDir . "/" . $storage_resource_id . ".lv.kvm-lvm-deployment.ident"; if (file_exists($ident_file)) { unlink($ident_file); } // send command $resource_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm post_identifier -u " . $OPENQRM_ADMIN->name . " -p " . $OPENQRM_ADMIN->password . " -t " . $deployment->type; $storage_resource->send_command($storage_resource->ip, $resource_command); if (!kvm_lvm_deployment_wait_for_identfile($ident_file)) { $event->log("get_image_rootdevice_identifier", $_SERVER['REQUEST_TIME'], 2, "image.kvm-lvm-deployment", "Timeout while requesting image identifier from storage id {$storage->id}", "", "", 0, 0, 0); return; } $fcontent = file($ident_file); foreach ($fcontent as $lun_info) { $tpos = strpos($lun_info, ":"); $timage_name = trim(substr($lun_info, 0, $tpos)); $troot_device = trim(substr($lun_info, $tpos + 1)); $rootdevice_identifier_array[] = array("value" => "{$troot_device}", "label" => "{$timage_name}"); } return $rootdevice_identifier_array; }
function openqrm_collectd_appliance($cmd, $appliance_fields) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; $appliance_id = $appliance_fields["appliance_id"]; $appliance_name = $appliance_fields["appliance_name"]; $resource = new resource(); $resource->get_instance_by_id($appliance_fields["appliance_resources"]); $appliance_ip = $resource->ip; $event->log("openqrm_new_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-collectd-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id); // we remove the stats on add and remove switch ($cmd) { case "add": $openqrm_server = new openqrm_server(); $openqrm_server->send_command($OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/collectd/bin/openqrm-collectd-manager remove " . $appliance_name . " now --openqrm-cmd-mode background"); break; case "remove": $openqrm_server = new openqrm_server(); $openqrm_server->send_command($OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/collectd/bin/openqrm-collectd-manager remove " . $appliance_name . " now --openqrm-cmd-mode background"); break; } }
function get_collectd_appliance_link($appliance_id) { global $event; global $OPENQRM_SERVER_BASE_DIR; $appliance_name = ''; $appliance = new appliance(); $appliance->get_instance_by_id($appliance_id); $resource = new resource(); $resource->get_instance_by_id($appliance->resources); $hostname = $appliance->name; if ($resource->id == 0) { $hostname = 'openqrm'; } $a = ''; if (file_exists('/usr/share/openqrm/plugins/collectd/data/' . $hostname)) { $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects'); $a = $html->a(); $a->label = 'collectd'; $a->css = 'badge'; $a->handler = 'onclick="wait();"'; $a->href = '/openqrm/base/index.php?plugin=collectd&controller=collectd&collectd_action=statistics&appliance_id=' . $appliance->id; } return $a; }
function upload() { $response = $this->response; $form = $response->get_form('upload', 'true'); $form->box_css = 'htmlobject_box'; $form->display_errors = false; $submit = $form->get_elements('submit'); $submit->handler = 'onclick="wait();"'; $form->add($submit, 'submit'); $d['upload_1']['label'] = $this->lang['public_key']; $d['upload_1']['object']['type'] = 'input'; $d['upload_1']['object']['attrib']['type'] = 'file'; $d['upload_1']['object']['attrib']['name'] = 'upload_1'; $d['upload_1']['object']['attrib']['size'] = 30; $d['upload_2']['label'] = $this->lang['server_license']; $d['upload_2']['object']['type'] = 'input'; $d['upload_2']['object']['attrib']['type'] = 'file'; $d['upload_2']['object']['attrib']['name'] = 'upload_2'; $d['upload_2']['object']['attrib']['size'] = 30; $d['upload_3']['label'] = $this->lang['client_license']; $d['upload_3']['object']['type'] = 'input'; $d['upload_3']['object']['attrib']['type'] = 'file'; $d['upload_3']['object']['attrib']['name'] = 'upload_3'; $d['upload_3']['object']['attrib']['size'] = 30; $form->add($d); if (!$form->get_errors() && $response->submit()) { $upload = new file_upload($this->openqrm->file()); $upload->lang = $this->openqrm->user()->translate($upload->lang, $this->openqrm->get('basedir') . "/web/base/lang", 'file.upload.ini'); $error = ''; for ($i = 1; $i < 4; $i++) { if ($_FILES['upload_' . $i]['name'] !== '') { $msg = $upload->upload('upload_' . $i, $this->openqrm->get('webdir') . '/tmp/', '', true); if ($msg !== '') { $error .= $msg['msg'] . '<br>'; } } } if ($error !== '') { $_REQUEST['upload_msg'] = $error; } else { $response_msg = array(); for ($i = 1; $i < 4; $i++) { if ($_FILES['upload_' . $i]['name'] !== '') { $command = $this->openqrm->get('basedir') . "/bin/openqrm license -l " . $this->openqrm->get('webdir') . "/tmp/" . $_FILES['upload_' . $i]['name'] . " --openqrm-cmd-mode background"; $resource = new resource(); $resource->get_instance_by_id(0); $resource->send_command($resource->ip, $command); $response_msg[] = sprintf($this->lang['msg'], $_FILES['upload_' . $i]['name']); sleep(4); } } $response_msg = implode('<br>', $response_msg); $response->redirect($this->openqrm->get('baseurl') . '/index.php?datacenter_msg=' . $response_msg . '&upload_msg=' . $response_msg); } } $t = $this->response->html->template($this->openqrm->get('webdir') . '/tpl/upload.tpl.php'); $t->add($response->html->thisfile, 'thisfile'); $t->add($this->lang['label'], 'label'); $t->add($this->lang['welcome'], 'welcome'); $t->add($this->lang['explanation'], 'explanation'); $t->add($form->get_elements()); $t->group_elements(array('param_' => 'form')); $content['label'] = $this->lang['tab']; $content['value'] = $t; $content['target'] = $this->response->html->thisfile; $content['request'] = $this->response->get_array('upload', 'true'); $content['onclick'] = false; $content['active'] = true; return $content; }
function __reload($mode) { $OPENQRM_SERVER_BASE_DIR = $this->openqrm->get('basedir'); $storage_id = $this->response->html->request()->get('storage_id'); $volgroup = $this->response->html->request()->get('volgroup'); $storage = new storage(); $resource = new resource(); $deployment = new deployment(); $storage->get_instance_by_id($storage_id); $resource->get_instance_by_id($storage->resource_id); $deployment->get_instance_by_id($storage->type); $command = ''; $file = ''; // reload volume group if ($mode === 'vg') { $file = $OPENQRM_SERVER_BASE_DIR . '/plugins/kvm/web/storage/' . $resource->id . '.vg.stat'; $command .= $OPENQRM_SERVER_BASE_DIR . '/plugins/kvm/bin/openqrm-kvm post_vg -t ' . $deployment->type; } // reload logical volumes if ($mode === 'lv') { $file = $OPENQRM_SERVER_BASE_DIR . '/plugins/kvm/web/storage/' . $resource->id . '.' . $volgroup . '.lv.stat'; $command .= $OPENQRM_SERVER_BASE_DIR . '/plugins/kvm/bin/openqrm-kvm post_lv'; $command .= ' -v ' . $volgroup . ' -t ' . $deployment->type; } $command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; if ($this->file->exists($file)) { $this->file->remove($file); } $resource->send_command($resource->ip, $command); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } return true; }
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); } }
$appliance_fields["appliance_resources"] = "{$local_server_id}"; $appliance_fields["appliance_capabilities"] = 'TYPE=local-server'; $appliance_fields["appliance_comment"] = "Local-server appliance resource {$local_server_id}"; $appliance = new appliance(); $appliance->add($appliance_fields); // set start time, reset stoptime, set state $now = $_SERVER['REQUEST_TIME']; $appliance_fields["appliance_starttime"] = $now; $appliance_fields["appliance_stoptime"] = 0; $appliance_fields['appliance_state'] = 'active'; // set resource type to physical $appliance_fields['appliance_virtualization'] = 1; $appliance->update($next_appliance_id, $appliance_fields); // set resource to localboot $resource = new resource(); $resource->get_instance_by_id($local_server_id); $openqrm_server->send_command("openqrm_server_set_boot local {$local_server_id} {$resource->mac} 0.0.0.0"); $resource->set_localboot($local_server_id, 1); // update resource fields with kernel + image $kernel->get_instance_by_id($kernel_fields["kernel_id"]); $resource_fields["resource_kernel"] = $kernel->name; $resource_fields["resource_kernelid"] = $kernel_fields["kernel_id"]; $image->get_instance_by_id($image_fields["image_id"]); $resource_fields["resource_image"] = $image->name; $resource_fields["resource_imageid"] = $image_fields["image_id"]; // set capabilites $resource_fields["resource_capabilities"] = 'TYPE=local-server'; $resource->update_info($local_server_id, $resource_fields); // add + start hook $appliance->get_instance_by_id($next_appliance_id); $now = $_SERVER['REQUEST_TIME'];
function storage_auth_deployment_stop($image_id) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; $image = new image(); $image->get_instance_by_id($image_id); $image_name = $image->name; $image_rootdevice = $image->rootdevice; $storage = new storage(); $storage->get_instance_by_id($image->storageid); $storage_resource = new resource(); $storage_resource->get_instance_by_id($storage->resource_id); $storage_ip = $storage_resource->ip; $deployment = new deployment(); $deployment->get_instance_by_type($image->type); $deployment_type = $deployment->type; $deployment_plugin_name = $deployment->storagetype; // just for sending the commands $resource = new resource(); // get install deployment params $install_from_nfs_param = trim($image->get_deployment_parameter("IMAGE_INSTALL_FROM_NFS")); if (strlen($install_from_nfs_param)) { // storage -> resource -> auth $ip_storage_id = $deployment->parse_deployment_parameter("id", $install_from_nfs_param); $ip_storage_ip = $deployment->parse_deployment_parameter("ip", $install_from_nfs_param); $ip_image_rootdevice = $deployment->parse_deployment_parameter("path", $install_from_nfs_param); $ip_storage = new storage(); $ip_storage->get_instance_by_id($ip_storage_id); $ip_storage_resource = new resource(); $ip_storage_resource->get_instance_by_id($ip_storage->resource_id); $op_storage_ip = $ip_storage_resource->ip; $ip_deployment = new deployment(); $ip_deployment->get_instance_by_id($ip_storage->type); $ip_deployment_type = $ip_deployment->type; $ip_deployment_plugin_name = $ip_deployment->storagetype; $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Install-from-NFS: Authenticating {$resource_ip} on storage id {$ip_storage_id}:{$ip_storage_ip}:{$ip_image_rootdevice}", "", "", 0, 0, $resource_id); $auth_install_from_nfs_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $ip_deployment_plugin_name . "/bin/openqrm-" . $ip_deployment_plugin_name . " auth -r " . $ip_image_rootdevice . " -i " . $OPENQRM_SERVER_IP_ADDRESS . " -t " . $ip_deployment_type . " --openqrm-cmd-mode background"; $resource->send_command($ip_storage_ip, $auth_install_from_nfs_start_cmd); } // get transfer deployment params $transfer_from_nfs_param = trim($image->get_deployment_parameter("IMAGE_TRANSFER_TO_NFS")); if (strlen($transfer_from_nfs_param)) { // storage -> resource -> auth $tp_storage_id = $deployment->parse_deployment_parameter("id", $transfer_from_nfs_param); $tp_storage_ip = $deployment->parse_deployment_parameter("ip", $transfer_from_nfs_param); $tp_image_rootdevice = $deployment->parse_deployment_parameter("path", $transfer_from_nfs_param); $tp_storage = new storage(); $tp_storage->get_instance_by_id($tp_storage_id); $tp_storage_resource = new resource(); $tp_storage_resource->get_instance_by_id($tp_storage->resource_id); $op_storage_ip = $tp_storage_resource->ip; $tp_deployment = new deployment(); $tp_deployment->get_instance_by_id($tp_storage->type); $tp_deployment_type = $tp_deployment->type; $tp_deployment_plugin_name = $tp_deployment->storagetype; $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Install-from-NFS: Authenticating {$resource_ip} on storage id {$tp_storage_id}:{$tp_storage_ip}:{$tp_image_rootdevice}", "", "", 0, 0, $resource_id); $auth_install_from_nfs_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $tp_deployment_plugin_name . "/bin/openqrm-" . $tp_deployment_plugin_name . " auth -r " . $tp_image_rootdevice . " -i " . $OPENQRM_SERVER_IP_ADDRESS . " -t " . $tp_deployment_type . " --openqrm-cmd-mode background"; $resource->send_command($tp_storage_ip, $auth_install_from_nfs_start_cmd); } }