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 openqrm_dhcpd_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_ip = $resource_fields["resource_ip"]; $resource_mac = $resource_fields["resource_mac"]; if (isset($resource_fields["resource_subnet"])) { $resource_subnet = $resource_fields["resource_subnet"]; } else { $resource_subnet = "0.0.0.0"; } $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); $openqrm_server = new openqrm_server(); $event->log("openqrm_new_resource", $_SERVER['REQUEST_TIME'], 5, "openqrm-dhcpd-resource-hook.php", "Handling {$cmd} event {$resource_id}/{$resource_ip}/{$resource_subnet}/{$resource_mac}", "", "", 0, 0, $resource_id); switch ($cmd) { case "add": $openqrm_server->send_command($OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/dhcpd/bin/openqrm-dhcpd-manager add -d " . $resource_id . " -m " . $resource_mac . " -i " . $resource_ip . " -s " . $resource_subnet . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background"); break; case "remove": $openqrm_server->send_command("{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/dhcpd/bin/openqrm-dhcpd-manager remove -d " . $resource_id . " -m " . $resource_mac . " -i " . $resource_ip . " -s " . $resource_subnet . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background"); break; } }
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 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 openqrm_tftpd_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_ip = $resource_fields["resource_ip"]; $resource_mac = $resource_fields["resource_mac"]; $event->log("openqrm_new_resource", $_SERVER['REQUEST_TIME'], 5, "openqrm-tftpd-resource-hook.php", "Handling {$cmd} event {$resource_id}/{$resource_ip}/{$resource_mac}", "", "", 0, 0, $resource_id); switch ($cmd) { case "remove": // we remove the pxe config file; the database removal is handled in the resource class $openqrm_server = new openqrm_server(); $openqrm_server->send_command("openqrm_remove_resource {$resource_id} {$resource_mac}"); break; } }
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 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 action() { $msg = ''; $event = new event(); $server = new openqrm_server(); $plugin = new plugin(); $identifier = $this->response->html->request()->get($this->identifier_name); $enabled = $plugin->enabled(); if ($identifier !== '') { foreach ($identifier as $id) { if (in_array($id, $enabled)) { $error = false; // check dependencies foreach ($enabled as $v) { if ($v !== $id) { $tmp = $plugin->get_dependencies($v); if ($tmp !== '' && isset($tmp['dependencies']) && $tmp['dependencies'] !== '') { if (strpos($tmp['dependencies'], $id) !== false) { $msg .= sprintf($this->lang['error_dependencies'], $id, $v) . '<br>'; $error = true; } } } } // handle plugin type if ($error === false) { $tmp = $plugin->get_config($id); switch ($tmp['type']) { case 'storage': $storage = new storage(); $types = $storage->get_storage_types(); $deployment = new deployment(); $dep = $deployment->get_id_by_storagetype($id); foreach ($dep as $val) { if (in_array($val['value'], $types)) { $msg .= sprintf($this->lang['error_in_use'], $id) . '<br>'; $error = true; } } break; } } if ($error === false) { $return = $server->send_command("openqrm_server_plugin_command " . $id . " uninstall " . $GLOBALS['OPENQRM_ADMIN']->name . ' ' . $GLOBALS['OPENQRM_ADMIN']->password); if ($return === true) { if ($this->__check($id)) { $msg .= sprintf($this->lang['msg'], $id) . '<br>'; } else { $msg .= sprintf($this->lang['error_timeout'], $id) . '<br>'; } } else { $msg .= sprintf($this->lang['error_disable'], $id) . '<br>'; } } } } } $this->response->redirect($this->response->get_url($this->actions_name, 'select', $this->message_param, $msg)); }
function remove() { $response = $this->get_response(); $group_name = $response->html->request()->get('group_name'); $form = $response->form; $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['param_f']['label'] = $group_name; $d['param_f']['object']['type'] = 'htmlobject_input'; $d['param_f']['object']['attrib']['type'] = 'checkbox'; $d['param_f']['object']['attrib']['name'] = 'group_name'; $d['param_f']['object']['attrib']['value'] = $group_name; $d['param_f']['object']['attrib']['checked'] = true; $form->add($d); if (!$form->get_errors() && $response->submit()) { $errors = array(); $message = array(); require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-group remove'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -ar ' . $this->region; $command .= ' -gn ' . $group_name; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $openqrm = new openqrm_server(); $openqrm->send_command($command, NULL, true); $message[] = sprintf($this->lang['msg_removed'], $group_name); if (count($errors) === 0) { $response->msg = join('<br>', $message); } else { $msg = array_merge($errors, $message); $response->error = join('<br>', $msg); } sleep(4); } return $response; }
$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']; $appliance_fields = array();
function remove() { $response = $this->get_response(); $instance_name = $response->html->request()->get('instance_name'); $form = $response->form; $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['param_f']['label'] = $instance_name; $d['param_f']['object']['type'] = 'htmlobject_input'; $d['param_f']['object']['attrib']['type'] = 'checkbox'; $d['param_f']['object']['attrib']['name'] = 'instance_name'; $d['param_f']['object']['attrib']['value'] = $instance_name; $d['param_f']['object']['attrib']['checked'] = true; $form->add($d); if (!$form->get_errors() && $response->submit()) { $errors = array(); $message = array(); $resource = new resource(); $resource->get_instance_by_mac($this->instance_mac); $appliance = new appliance(); $appliances_using_resource = $appliance->get_ids_per_resource($resource->id); if (count($appliances_using_resource) > 0) { $appliances_using_resource_str = implode(",", $appliances_using_resource[0]); $errors[] = sprintf($this->lang['msg_vm_resource_still_in_use'], $instance_name, $resource->id, $appliances_using_resource_str); } else { $resource->remove($resource->id, $this->instance_mac); $hc_authentication = ''; if ($this->hc->account_type == 'aws' || $this->hc->account_type == 'euca') { $hc_authentication .= ' -O ' . $this->hc->access_key; $hc_authentication .= ' -W ' . $this->hc->secret_key; $hc_authentication .= ' -ir ' . $this->region; } if ($this->hc->account_type == 'lc-openstack') { $hc_authentication .= ' -u ' . $this->hc->username; $hc_authentication .= ' -p ' . $this->hc->password; $hc_authentication .= ' -q ' . $this->hc->host; $hc_authentication .= ' -x ' . $this->hc->port; $hc_authentication .= ' -g ' . $this->hc->tenant; $hc_authentication .= ' -e ' . $this->hc->endpoint; } $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm remove'; $command .= ' -i ' . $this->hc->id; $command .= ' -n ' . $this->hc->account_name; $command .= ' -t ' . $this->hc->account_type; $command .= ' -in ' . $instance_name; $command .= $hc_authentication; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $openqrm = new openqrm_server(); $openqrm->send_command($command, NULL, true); $message[] = sprintf($this->lang['msg_removed'], $instance_name); } if (count($errors) === 0) { $response->msg = join('<br>', $message); } else { $msg = array_merge($errors, $message); $response->error = join('<br>', $msg); } } return $response; }
function fence_hybrid_cloud_vm_local($host_resource_id, $mac) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; $event->log("fence_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-ha-hook", "Fencing Cloud VM " . $mac, "", "", 0, 0, 0); $origin_resource = new resource(); $origin_resource->get_instance_by_mac($mac); // 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; } $openqrm = new openqrm_server(); $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm fence "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= $hc_authentication; $command .= ' -im ' . $mac; $command .= ' --openqrm-cmd-mode background'; $event->log("fence_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-ha-hook", "Running {$command}", "", "", 0, 0, 0); $openqrm->send_command($command, NULL, true); $rufields["resource_hostname"] = $hc->account_type . $origin_resource->id; $origin_resource->update_info($origin_resource->id, $rufields); // debug // echo "1:".$command; }
function create($cu_id, $virtualization_type, $name, $mac, $additional_nics, $cpu, $memory, $disk, $timeout, $vncpassword, $source_image_id = null) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $host_start_from_off_timeout; global $RootDir; $this->init($timeout); global $event; $vmware_mac_address_space = "00:50:56"; $vtype = new virtualization(); $vtype->get_instance_by_id($virtualization_type); $virtualization_plugin_name = $vtype->get_plugin_name(); $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Trying to create new VM type {$virtualization_type} ({$virtualization_plugin_name}) {$mac}/{$cpu}/{$memory}/{$disk}", "", "", 0, 0, 0); // here we need to find out if we have a virtualization host providing the type of VMs as requested // find out the host virtualization type via the plugin name $vhost_type = new virtualization(); $vhost_type->get_instance_by_type($virtualization_plugin_name); $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Trying to find a virtualization host from type {$vhost_type->type} {$vhost_type->name}", "", "", 0, 0, 0); // check if resource-pooling is enabled $cp_conf = new cloudconfig(); $show_resource_pools = $cp_conf->get_value(25); // resource_pools enabled ? $vm_provision_delay = $cp_conf->get_value(40); // delay provisioning of VMs ? $vm_loadbalance_algorithm = $cp_conf->get_value(41); // which LB to select ? // for all in appliance list, find virtualization host appliances $appliance_tmp = new appliance(); $appliance_id_list = $appliance_tmp->get_all_ids(); $active_appliance_list = array(); $active_appliance_resource_list = array(); foreach ($appliance_id_list as $id_arr) { foreach ($id_arr as $id) { $appliance = new appliance(); $appliance->get_instance_by_id($id); // active ? if ($appliance->stoptime == 0 || $appliance->resources == 0) { if ($appliance->virtualization == $vhost_type->id) { // we have found an active appliance from the right virtualization type // Now we check that its resource is active and not in error $cvm_resource = new resource(); $cvm_resource->get_instance_by_id($appliance->resources); if (strcmp($cvm_resource->state, "active")) { continue; } // here we check if there is still enough space // to create the new VM -> max_vm setting per resource $res_hostlimit = new cloudhostlimit(); $res_hostlimit->get_instance_by_resource($appliance->resources); if (strlen($res_hostlimit->id)) { if ($res_hostlimit->max_vms >= 0) { $new_current_vms = $res_hostlimit->current_vms + 1; if ($new_current_vms > $res_hostlimit->max_vms) { $event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "Hostlimit max_vm is reached for resource {$appliance->resources}", "", "", 0, 0, $appliance->resources); continue; } } } // resource pooling enabled ? if (strcmp($show_resource_pools, "true")) { // disabled, add any appliance from the right virtualization type $active_appliance_list[] .= $id; $active_appliance_resource_list[] .= $appliance->resources; //$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- resource pooling is disabled", "", "", 0, 0, 0); } else { //$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- resource pooling is enabled $appliance->resources", "", "", 0, 0, 0); // resource pooling enabled, check to which user group the resource belongs to $private_resource = new cloudrespool(); $private_resource->get_instance_by_resource($appliance->resources); // is this resource configured in the resource pools ? //$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- resource pool id $private_resource->id !", "", "", 0, 0, 0); if (strlen($private_resource->id)) { //$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- resource $appliance->resources is in a resource pool", "", "", 0, 0, 0); // is it hidden ? if ($private_resource->cg_id >= 0) { //$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- resource $appliance->resources is also configured in resource pool (not hidden)", "", "", 0, 0, 0); $cloud_user = new clouduser(); $cloud_user->get_instance_by_id($cu_id); $cloud_user_group = new cloudusergroup(); $cloud_user_group->get_instance_by_id($cloud_user->cg_id); //$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- we have found the users group $cloud_user_group->id", "", "", 0, 0, 0); // does it really belongs to the users group ? if ($private_resource->cg_id == $cloud_user_group->id) { // resource belongs to the users group, add appliance to list //$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- adding appliance $id ", "", "", 0, 0, 0); $active_appliance_list[] .= $id; $active_appliance_resource_list[] .= $appliance->resources; //} else { // $event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "Appliance $id (resource $appliance->resources) is NOT in dedicated for the users group", "", "", 0, 0, 0); } //} else { // $event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "Appliance $id (resource $appliance->resources) is marked as hidden", "", "", 0, 0, 0); } } } } } } } // did we found any active host ? if (count($active_appliance_list) < 1) { $event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "Warning ! There is no active virtualization host type {$vhost_type->name} available to bring up a new VM", "", "", 0, 0, 0); $event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "Notice : Trying to find a Host which can start-from-off .....", "", "", 0, 0, 0); // if this method finds a host it will block until the host is up + active $cloud_host_start_from_off = new cloudhoststartfromoff(); $start_from_off_appliance_id = $cloud_host_start_from_off->find_host_to_start_from_off($vhost_type->id, $show_resource_pools, $cu_id, $host_start_from_off_timeout); if ($start_from_off_appliance_id > 0) { //$event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "------- adding appliance $id ", "", "", 0, 0, 0); $active_appliance_list[] .= $start_from_off_appliance_id; // add to active resource list $start_from_off_appliance = new appliance(); $start_from_off_appliance->get_instance_by_id($start_from_off_appliance_id); $active_appliance_resource_list[] .= $start_from_off_appliance->resources; } else { // here we did not found any host to start-from-off $event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "Warning ! Could not find any virtualization host type {$vhost_type->name} to start-from-off", "", "", 0, 0, 0); $event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "Warning ! Giving up trying to start a new VM type {$vhost_type->name}", "", "", 0, 0, 0); return false; } } // ! for all virt-localboot VMs we need to make sure the VM is created on // ! the same host as the image is located, for all others we try to lb $less_load_resource_id = -1; if (strstr($vtype->type, "-vm-local")) { $origin_appliance = new appliance(); $origin_appliance->get_instance_by_name($name); // if we have a cloudappliance already this create is coming from unpause // The host to create the new VM on must be the image storage resource $vstorage_cloud_app = new cloudappliance(); $vstorage_cloud_app->get_instance_by_appliance_id($origin_appliance->id); if (strlen($vstorage_cloud_app->id)) { $vstorage_image = new image(); $vstorage_image->get_instance_by_id($origin_appliance->imageid); $vstorage = new storage(); $vstorage->get_instance_by_id($vstorage_image->storageid); $vstorage_host_res_id = $vstorage->resource_id; // check if the origin host is in the active appliances we have found if (in_array($vstorage_host_res_id, $active_appliance_resource_list)) { $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Origin host {$vstorage_host_res_id} is active. Creating the new VM", "", "", 0, 0, 0); $resource = new resource(); $resource->get_instance_by_id($vstorage_host_res_id); $less_load_resource_id = $vstorage_host_res_id; } else { $event->log("create", $_SERVER['REQUEST_TIME'], 2, "cloudvm.class.php", "Origin host {$vstorage_host_res_id} is not active. Not creating the new VM", "", "", 0, 0, 0); } } else { // if we do not have a cloudappliance yet we can (should) loadbalance the create VM request $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Using Loadbalancing Algorithm " . $vm_loadbalance_algorithm . " for creating the new VM", "", "", 0, 0, 0); // the cloud-deployment hook of the virt-localboot VM will adapt the image storage id to the host id switch ($vm_loadbalance_algorithm) { case '0': $less_load_resource_id = $this->vm_balance_load($active_appliance_list); break; case '1': $less_load_resource_id = $this->vm_balance_memory($active_appliance_list, $memory); break; case '2': $less_load_resource_id = $this->vm_balance_random($active_appliance_list); break; case '3': $less_load_resource_id = $this->vm_balance_first_available($active_appliance_list); break; default: $less_load_resource_id = $this->vm_balance_load($active_appliance_list); break; } } } else { $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Using Loadbalancing Algorithm " . $vm_loadbalance_algorithm . " for creating the new VM", "", "", 0, 0, 0); switch ($vm_loadbalance_algorithm) { case '0': $less_load_resource_id = $this->vm_balance_load($active_appliance_list); break; case '1': $less_load_resource_id = $this->vm_balance_memory($active_appliance_list, $memory); break; case '2': $less_load_resource_id = $this->vm_balance_random($active_appliance_list); break; case '3': $less_load_resource_id = $this->vm_balance_first_available($active_appliance_list); break; default: $less_load_resource_id = $this->vm_balance_load($active_appliance_list); break; } } if ($less_load_resource_id >= 0) { $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Found Virtualization host resource {$less_load_resource_id} as the target for the new VM ", "", "", 0, 0, 0); } // additional network cards if ($additional_nics > 0) { $anic = 1; $additional_nic_str = ""; $mac_gen_res = new resource(); while ($anic <= $additional_nics) { $mac_gen_res->generate_mac(); switch ($virtualization_plugin_name) { # VMware VMs need to get special macs case 'vmware-esx': $nic_nr = $anic; $suggested_mac = $mac_gen_res->mac; $new_forth_byte_first_bit = rand(1, 3); $mac_gen_res_vmw = strtolower($vmware_mac_address_space . ":" . substr($suggested_mac, 9)); $mac_gen_res_vmw = substr_replace($mac_gen_res_vmw, $new_forth_byte_first_bit, 9, 1); $additional_nic_str .= " -m" . $nic_nr . " " . $mac_gen_res_vmw; break; # VMs network parameter starts with -m1 # VMs network parameter starts with -m1 default: $nic_nr = $anic; $additional_nic_str .= " -m" . $nic_nr . " " . $mac_gen_res->mac; break; } $anic++; } } // swap, for the cloud VMs we simply calculate memory * 2 $swap = $memory * 2; // start the VM on the appliance resource $host_resource = new resource(); $host_resource->get_instance_by_id($less_load_resource_id); $host_resource_ip = $host_resource->ip; // we need to have an openQRM server object too since some of the // virtualization commands are sent from openQRM directly $openqrm = new openqrm_server(); // create the new resource + setting the virtualization type $vm_resource_ip = "0.0.0.0"; // add to openQRM database $vm_resource_fields["resource_ip"] = $vm_resource_ip; $vm_resource_fields["resource_mac"] = $mac; $vm_resource_fields["resource_localboot"] = 0; $vm_resource_fields["resource_vtype"] = $vtype->id; $vm_resource_fields["resource_vhostid"] = $less_load_resource_id; $vm_resource_fields["resource_vname"] = $name; $new_resource_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $vm_resource_fields["resource_id"] = $new_resource_id; $host_resource->add($vm_resource_fields); // send new-resource command now after the resource is created logically $openqrm->send_command("openqrm_server_add_resource {$new_resource_id} {$mac} {$vm_resource_ip}"); // let the new resource commands settle sleep(10); // plug in the virtualization cloud hook $virtualization_cloud_hook = "{$RootDir}/plugins/{$virtualization_plugin_name}/openqrm-{$virtualization_plugin_name}-cloud-hook.php"; if (file_exists($virtualization_cloud_hook)) { $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class", "Found plugin {$virtualization_plugin_name} handling to create the VM.", "", "", 0, 0, $new_resource_id); require_once "{$virtualization_cloud_hook}"; $virtualization_method = "create_" . $vtype->type; $virtualization_method = str_replace("-", "_", $virtualization_method); $virtualization_method($less_load_resource_id, $name, $mac, $memory, $cpu, $swap, $additional_nic_str, $vncpassword, $source_image_id); } else { $event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class", "Do not know how to create VM from type {$virtualization_plugin_name}.", "", "", 0, 0, 0); // remove resource object $vm_resource = new resource(); $vm_resource->get_instance_by_id($new_resource_id); $vm_resource->remove($new_resource_id, $mac); return false; } // update hostlimits quite early to avoid overloading a Host with non-starting VMs // add or update hostlimits $res_hostlimit = new cloudhostlimit(); $res_hostlimit->get_instance_by_resource($host_resource->id); if (strlen($res_hostlimit->id)) { // update $current_vms = $res_hostlimit->current_vms + 1; $cloud_hostlimit_fields["hl_current_vms"] = $current_vms; $res_hostlimit->update($res_hostlimit->id, $cloud_hostlimit_fields); } else { // add $cloud_hostlimit_fields["hl_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $cloud_hostlimit_fields["hl_resource_id"] = $host_resource->id; $cloud_hostlimit_fields["hl_max_vms"] = -1; $cloud_hostlimit_fields["hl_current_vms"] = 1; $res_hostlimit->add($cloud_hostlimit_fields); } $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "New VM created with resource id " . $new_resource_id . " and started. Waiting now until it is active/idle", "", "", 0, 0, 0); if ($vm_provision_delay > 0) { $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Delaying the provisioning of resource id " . $new_resource_id . " for " . $vm_provision_delay . " seconds.", "", "", 0, 0, 0); sleep($vm_provision_delay); } // setting this object resource id as return state $this->resource_id = $new_resource_id; }
function add() { $response = $this->get_response(); $form = $response->form; $errors = array(); if (!$form->get_errors() && $this->response->submit()) { $keypair_name = $form->get_request('name'); if (!strlen($keypair_name)) { $errors[] = $this->lang['error_name']; } if (count($errors) > 0 || $form->get_errors()) { $response->error = join('<br>', $errors); } else { $hc_authentication = ''; if ($this->hc->account_type == 'aws' || $this->hc->account_type == 'euca') { $hc_authentication .= ' -O ' . $this->hc->access_key; $hc_authentication .= ' -W ' . $this->hc->secret_key; $hc_authentication .= ' -ir ' . $this->region; } if ($this->hc->account_type == 'lc-openstack') { $keypair_content = $form->get_request('keypair_content'); if (!strlen($keypair_content)) { $errors[] = $this->lang['error_keypair_content']; } $keypair_content = str_replace(' ', '%', $keypair_content); $hc_authentication .= ' -u ' . $this->hc->username; $hc_authentication .= ' -p ' . $this->hc->password; $hc_authentication .= ' -q ' . $this->hc->host; $hc_authentication .= ' -x ' . $this->hc->port; $hc_authentication .= ' -g ' . $this->hc->tenant; $hc_authentication .= ' -e ' . $this->hc->endpoint; $hc_authentication .= ' -c ' . $keypair_content; } $openqrm = new openqrm_server(); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-keypair create'; $command .= ' -i ' . $this->hc->id; $command .= ' -n ' . $this->hc->account_name; $command .= ' -t ' . $this->hc->account_type; $command .= $hc_authentication; $command .= ' -k ' . $keypair_name; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $openqrm->send_command($command, NULL, true); sleep(4); $response->msg = sprintf($this->lang['msg_added'], $keypair_name); } } return $response; }
function select() { $h = array(); $h['state']['title'] = $this->lang['table_state']; $h['name']['title'] = $this->lang['table_name']; $h['region']['title'] = $this->lang['table_region']; $h['ami']['title'] = $this->lang['table_ami']; $h['type']['title'] = $this->lang['table_type']; $h['public']['title'] = $this->lang['table_public_ip']; $h['private']['title'] = $this->lang['table_private_ip']; $h['import']['title'] = ' '; $h['import']['sortable'] = false; $content = array(); $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $this->id . '.describe_instances.log'; if ($this->file->exists($file)) { $this->file->remove($file); } require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm describe'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -ir ' . $this->region; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $server = new openqrm_server(); $server->send_command($command, NULL, true); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } $content = $this->file->get_contents($file); $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 = $tmp[16]; $private_ip = $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 = ''; $select_for_import = ''; if ($state == 'idle') { $state_icon = "/openqrm/base/img/idle.png"; } else { if ($state == 'running') { $state_icon = "/openqrm/base/img/active.png"; // select for import $a = $this->response->html->a(); $a->label = $this->lang['action_import']; $a->title = $this->lang['action_import']; $a->handler = 'onclick="wait();"'; $a->css = 'edit'; $a->href = $this->response->get_url($this->actions_name, 'imtarget') . '&instance_name=' . $name . '&instance_public_ip=' . $public_ip . '&instance_public_hostname=' . $public_hostname . '&instance_keypair=' . $keypair; $select_for_import = $a->get_string(); } else { $state_icon = "/openqrm/base/img/error.png"; } } $b[] = array('state' => "<img width=24 height=24 src=" . $state_icon . ">", 'name' => $name, 'region' => $region, 'ami' => $ami, 'type' => $type, 'public' => $public_hostname, 'private' => $private_ip, 'import' => $select_for_import); } } $params = $this->response->get_array($this->actions_name, 'import'); $table = $this->response->html->tablebuilder('hybridcloud_import', $params); $table->offset = 0; $table->sort = 'id'; $table->limit = 10; $table->order = 'ASC'; $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; // handle account name require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $d['name'] = $hc->account_name; $d['form'] = $this->response->get_form($this->actions_name, 'import', false)->get_elements(); $d['table'] = $table; return $d; }
function edit() { $response = $this->get_response(); $form = $response->form; if (!$form->get_errors() && $response->submit()) { $playbooks = $form->get_request('playbooks'); $this->ansible->remove_appliance($this->appliance->name); if (!in_array('{empty}', $playbooks)) { $this->ansible->set_playbooks($this->appliance->name, $playbooks); } // apply directly $apply = $form->get_request('apply'); if ($apply == '1') { $command = $this->openqrm->get('basedir') . "/plugins/ansible/bin/openqrm-ansible-manager apply " . $this->appliance->id . " " . $this->appliance->name . " " . $this->resource->ip; $openqrm_server = new openqrm_server(); $openqrm_server->send_command($command, NULL, true); } $response->msg = sprintf($this->lang['msg_updated'], $this->appliance->name); } return $response; }
function openqrm_linuxcoe_appliance($cmd, $appliance_fields) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; $openqrm_server = new openqrm_server(); $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); $linuxcoe_install_timeout = 240; // check appliance values, maybe we are in update and they are incomplete if ($appliance->imageid == 1) { return; } if ($resource->id == "-1" || $resource->id == "") { return; } // check if image is type linuxcoe-deployment $image = new image(); $image->get_instance_by_id($appliance->imageid); // linuxcoe configured in image deployment parameters ? $linuxcoe_auto_install_enabled = false; $linuxcoe_deployment_parameters = trim($image->get_deployment_parameter("INSTALL_CONFIG")); if (strlen($linuxcoe_deployment_parameters)) { $linuxcoe_deployment_parameter_arr = explode(":", $linuxcoe_deployment_parameters); $local_deployment_persistent = $linuxcoe_deployment_parameter_arr[0]; $local_deployment_type = $linuxcoe_deployment_parameter_arr[1]; if (strcmp($local_deployment_type, "linuxcoe-deployment")) { $event->log("openqrm_linuxcoe_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-linuxcoe-appliance-hook.php", "Appliance " . $appliance_id . "/" . $appliance_name . " image is not from type linuxcoe-deployment", "", "", 0, 0, $resource->id); return; } $linuxcoe_server_storage_id = $linuxcoe_deployment_parameter_arr[2]; $linuxcoe_install_profile = $linuxcoe_deployment_parameter_arr[3]; $linuxcoe_auto_install_enabled = true; } $event->log("openqrm_linuxcoe_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-linuxcoe-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_linuxcoe_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-linuxcoe-appliance-hook.php", "START event {$appliance_id}/{$appliance_name}/{$resource_ip}/{$resource_mac}", "", "", 0, 0, $resource->id); if ($linuxcoe_auto_install_enabled) { // prepare automatic-installation / transfer client to linuxcoe server $linuxcoe_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/linuxcoe/bin/openqrm-linuxcoe-manager transfer_to_linuxcoe -x " . $resource->id . " -i " . $resource_ip . " -m " . $resource_mac . " -n " . $linuxcoe_install_profile . " --openqrm-cmd-mode background"; $event->log("openqrm_linuxcoe_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-linuxcoe-appliance-hook.php", "transfer_to_linuxcoe {$resource_ip} / {$linuxcoe_install_profile}", "", "", 0, 0, $resource->id); $openqrm_server->send_command($linuxcoe_command, NULL, true); // Remove image-deployment paramters, if auto-install is a single-shot actions if (!strcmp($local_deployment_persistent, "0")) { $image->set_deployment_parameters("INSTALL_CONFIG", ""); } // create linuxcoestate-state object to allow to run a late setboot to local command on the vm host $linuxcoe_state = new linuxcoestate(); $linuxcoe_state->remove_by_resource_id($resource->id); $linuxcoe_state_fields = array(); $linuxcoe_state_fields["linuxcoe_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $linuxcoe_state_fields["linuxcoe_resource_id"] = $resource->id; $linuxcoe_state_fields["linuxcoe_install_start"] = $_SERVER['REQUEST_TIME']; $linuxcoe_state_fields["linuxcoe_timeout"] = $linuxcoe_install_timeout; $linuxcoe_state->add($linuxcoe_state_fields); } else { if (strcmp($image->type, "linuxcoe-deployment")) { $event->log("openqrm_linuxcoe_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-linuxcoe-appliance-hook.php", "Appliance {$appliance_id}/{$appliance_name} image is not from type linuxcoe-deployment", "", "", 0, 0, $resource->id); } else { // we have auto-installed already, if it is VM the linuxcoeresource object will care to set the boot-sequence on the VM Host to local boot $linuxcoeresource = new linuxcoeresource(); $linuxcoeresource->set_boot($resource->id, 1); // set pxe config to local-boot $event->log("openqrm_linuxcoe_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-linuxcoe-appliance-hook.php", "Setting resource {$resource_ip} to local-boot", "", "", 0, 0, $resource->id); $linuxcoe_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/linuxcoe/bin/openqrm-linuxcoe-manager set_linuxcoe_client_to_local_boot -m " . $resource_mac . " --openqrm-cmd-mode background"; $openqrm_server->send_command($linuxcoe_command, NULL, true); } } break; case "stop": if (strcmp($image->type, "linuxcoe-deployment")) { $event->log("stop", $_SERVER['REQUEST_TIME'], 5, "openqrm-linuxcoe-appliance-hook.php", "Appliance {$appliance_id}/{$appliance_name} image is not from type linuxcoe-deployment", "", "", 0, 0, $resource->id); } else { $event->log("stop", $_SERVER['REQUEST_TIME'], 5, "openqrm-linuxcoe-appliance-hook.php", "Stop event for appliance " . $appliance_id . "/" . $appliance->name . ".", "", "", 0, 0, $resource->id); // remove linuxcoestate-state object if existing $local_storage_state = new linuxcoestate(); $local_storage_state->remove_by_resource_id($resource->id); // if it is VM the linuxcoeresource object will care to set the boot-sequence on the VM Host to network boot $linuxcoeresource = new linuxcoeresource(); $linuxcoeresource->set_boot($resource->id, 0); } break; } }
function get_sizes() { $hc_authentication = $this->get_authentication(); $file = $this->_web_dir . '/openqrm/base/plugins/hybrid-cloud/hybrid-cloud-stat/' . $this->id . '.describe_sizes.log'; if (file_exists($file)) { unlink($file); } $openqrm = new openqrm_server(); $command = $this->_base_dir . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-sizes describe_sizes "; $command .= ' -i ' . $this->id; $command .= ' -n ' . $this->account_name; $command .= ' -t ' . $this->account_type; $command .= $hc_authentication; $command .= ' --openqrm-cmd-mode background'; $openqrm = new openqrm_server(); $openqrm->send_command($command, NULL, true); while (!file_exists($file)) { usleep(10000); clearstatcache(); } $hc_sizes = array(); $content = file_get_contents($file); $content = explode("\n", $content); foreach ($content as $k => $v) { if ($v !== '') { $tmp = explode('@', $v); $id = $tmp[1]; $name = $tmp[2]; $memory = $tmp[3]; $cpu = $tmp[4]; // echo "id :".$id." - name: ".$name." - mem: ".$memory." - cpus: ".$cpu."<br>"; $hc_sizes[] = array('id' => $id, 'name' => $name, 'memory' => $memory, 'cpu' => $cpu); } } return $hc_sizes; }
function __reload() { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->response->html->request()->get('hybrid_cloud_id')); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-keypair describe'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -c ' . $hc->rc_config; $command .= ' -t ' . $hc->account_type; $command .= ' -ir ' . $this->response->html->request()->get('region'); $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $hc->id . '.describe_keypair.log'; if ($this->file->exists($file)) { $this->file->remove($file); } $openqrm = new openqrm_server(); $openqrm->send_command($command); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } return true; }
function setdefault() { $response = $this->get_response(); $kernels = $response->html->request()->get($this->identifier_name); $form = $response->form; $kernel = new kernel(); if ($kernels !== '') { $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'); $i = 0; foreach ($kernels as $id) { $kernel = $kernel->get_instance_by_id($id); $d['param_f' . $i]['label'] = $kernel->name; $d['param_f' . $i]['object']['type'] = 'htmlobject_input'; $d['param_f' . $i]['object']['attrib']['type'] = 'checkbox'; $d['param_f' . $i]['object']['attrib']['name'] = $this->identifier_name . '[' . $i . ']'; $d['param_f' . $i]['object']['attrib']['value'] = $id; $d['param_f' . $i]['object']['attrib']['checked'] = true; $i++; } $form->add($d); if (!$form->get_errors() && $response->submit()) { $errors = array(); $message = array(); foreach ($kernels as $id) { $kernel = $kernel->get_instance_by_id($id); $kernel_name = $kernel->name; $ar_kernel_update = array('kernel_name' => "default", 'kernel_version' => $kernel->version, 'kernel_capabilities' => $kernel->capabilities); $kernel->update(1, $ar_kernel_update); // send set-default kernel command to openQRM $openqrm_server = new openqrm_server(); $openqrm_server->send_command("openqrm_server_set_default_kernel {$kernel->name}"); $form->remove($this->identifier_name . '[' . $id . ']'); $message[] = sprintf($this->lang['msg'], $kernel_name); // exit after the first kernel break; } if (count($errors) === 0) { $response->msg = join('<br>', $message); } else { $msg = array_merge($errors, $message); $response->error = join('<br>', $msg); } } } else { $response->msg = ''; } return $response; }
function edit() { $h = array(); $h['state']['title'] = $this->lang['table_state']; $h['state']['sortable'] = false; $h['name']['title'] = $this->lang['table_name']; $h['name']['hidden'] = true; $h['region']['title'] = $this->lang['table_region']; $h['region']['hidden'] = true; $h['ami']['title'] = $this->lang['table_ami']; $h['ami']['hidden'] = true; $h['type']['title'] = $this->lang['table_type']; $h['type']['hidden'] = true; $h['data']['title'] = ' '; $h['data']['sortable'] = false; $h['public']['title'] = $this->lang['table_public_ip']; $h['private']['title'] = $this->lang['table_private_ip']; $h['remove']['title'] = ' '; $h['remove']['sortable'] = false; $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"); $d['add_local_vm'] = $a->get_string(); $content = array(); $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $this->id . '.describe_instances.log'; if ($this->file->exists($file)) { $this->file->remove($file); } $hc_authentication = ''; if ($this->hc->account_type == 'aws' || $this->hc->account_type == 'euca') { $hc_authentication .= ' -O ' . $this->hc->access_key; $hc_authentication .= ' -W ' . $this->hc->secret_key; $hc_authentication .= ' -ir ' . $this->region; } if ($this->hc->account_type == 'lc-openstack') { $hc_authentication .= ' -u ' . $this->hc->username; $hc_authentication .= ' -p ' . $this->hc->password; $hc_authentication .= ' -q ' . $this->hc->host; $hc_authentication .= ' -x ' . $this->hc->port; $hc_authentication .= ' -g ' . $this->hc->tenant; $hc_authentication .= ' -e ' . $this->hc->endpoint; } $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm describe'; $command .= ' -i ' . $this->hc->id; $command .= ' -n ' . $this->hc->account_name; $command .= ' -t ' . $this->hc->account_type; $command .= $hc_authentication; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $server = new openqrm_server(); $server->send_command($command, NULL, true); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } $content = $this->file->get_contents($file); $content = explode("\n", $content); $b = array(); foreach ($content as $k => $v) { if ($v !== '') { // e.g. INSTANCE@i-ec3667a1@ami-02f4fe76@ec2-54-216-10-23.eu-west-1.compute.amazonaws.com@ip-10-234-109-57.eu-west-1.compute.internal@running@home@0@@m1.small@2013-06-25T16:58:30+0000@eu-west-1a@aki-71665e05@@@monitoring-disabled@54.216.10.23@10.234.109.57@@@instance-store@@@@@paravirtual@xen@@sg-9d664de9@default@false@ $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 = $this->hc->format_ip_address($tmp[16]); $private_ip = $this->hc->format_ip_address($tmp[17]); $vpc = $tmp[18]; $subnet = $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 = ''; // remove $remove_instance = ''; $import_str = ''; if ($state == 'idle') { $mac = $tmp[30]; $a = $this->response->html->a(); $a->label = $this->lang['action_remove_vm']; $a->css = 'remove'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "remove") . '&instance_name=' . $name . '&instance_mac=' . $mac; $remove_instance = $a->get_string(); $state_icon = '<span class="pill idle">idle</span>'; } else { if ($state == 'running') { $state_icon = '<span class="pill active">active</span>'; // import $import_resource = new resource(); $import_resource->get_instance_id_by_hostname($name); if ($import_resource->id == '') { // import add if (!strlen($mac)) { $import_resource->generate_mac(); $mac = $import_resource->mac; } $link = $this->response->get_url($this->actions_name, "import"); $link .= '&instance_command=add&instance_name=' . $name; $link .= '&instance_mac=' . $mac; $link .= '&instance_public_ip=' . $public_ip; $link .= '&instance_type=' . $type; $link .= '&instance_keypair=' . $keypair; $link .= '&instance_region=' . $region; $link .= '&instance_ami=' . $ami; $link .= '&instance_subnet=' . $subnet; $a = $this->response->html->a(); $a->label = $this->lang['action_import_instance']; $a->title = $this->lang['action_import_instance_title']; $a->css = 'add'; $a->handler = 'onclick="wait();"'; $a->href = $link; $import_str = $a->get_string(); } } else { $state_icon = '<span class="pill ' . $state . '">' . $state . '</span>'; } } $remove = $remove_instance . $import_str; $data = '<b>' . $this->lang['table_name'] . '</b>: ' . $name . '<br>'; $data .= '<b>' . $this->lang['table_region'] . '</b>: ' . $region . '<br>'; $data .= '<b>' . $this->lang['table_ami'] . '</b>: ' . $ami . '<br>'; $data .= '<b>' . $this->lang['table_type'] . '</b>: ' . $type; $b[] = array('state' => $state_icon, 'name' => $name, 'region' => $region, 'ami' => $ami, 'type' => $type, 'data' => $data, 'public' => $public_ip, 'private' => $private_ip, 'remove' => $remove); } } $params = $this->response->get_array($this->actions_name, 'edit'); $table = $this->response->html->tablebuilder('hybridcloud_vm_edit', $params); $table->form_action = $this->response->html->thisfile; $table->offset = 0; $table->sort = 'name'; $table->limit = 10; $table->order = 'ASC'; $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; $d['name'] = $this->hc->account_name; $d['form'] = $this->response->get_form($this->actions_name, 'import', false)->get_elements(); $d['table'] = $table; return $d; }
function __reload_instance_configuration() { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->response->html->request()->get('hybrid_cloud_id')); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-ebs instance_configuration'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -ar ' . $this->response->html->request()->get('region'); $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $hc->id . '.attach_volume_configuration.log'; if ($this->file->exists($file)) { $this->file->remove($file); } $openqrm = new openqrm_server(); $openqrm->send_command($command, NULL, true); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } return true; }
function add() { $response = $this->get_response(); $form = $response->form; $errors = array(); if (!$form->get_errors() && $this->response->submit()) { $group_name = $form->get_request('name'); if (!strlen($group_name)) { $errors[] = $this->lang['error_name']; } $group_description = $form->get_request('description'); if (!strlen($group_description)) { $errors[] = $this->lang['error_description']; } $group_vpc_parameter = ''; $group_vpc = $form->get_request('vpc'); if (strlen($group_vpc)) { $group_vpc_parameter = ' -c ' . $group_vpc; } if (count($errors) > 0 || $form->get_errors()) { $response->error = join('<br>', $errors); } else { require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $openqrm = new openqrm_server(); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-group create'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -ar ' . $this->region; $command .= ' -gn ' . $group_name; $command .= ' -gd ' . $group_description; $command .= $group_vpc_parameter; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $openqrm->send_command($command, NULL, true); sleep(4); $response->msg = sprintf($this->lang['msg_added_group'], $group_name); //$ev = new event(); //$ev->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-monitor-hook", $command, "", "", 0, 0, 0); } } return $response; }
function edit() { // filter $alphabet = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"; $alphabet_arr = explode(",", $alphabet); $form = $this->response->get_form($this->actions_name, 'edit'); unset($form->__data['submit']); $d = array(); $d['submit'] = ''; $form->add($d); unset($form->__data['cancel']); $d = array(); $d['cancel'] = ''; $form->add($d); $filter = $this->response->html->select(); $filter->name = 'hybrid_cloud_ami_filter'; $filter->handler = 'onchange="wait();this.form.submit();return false;"'; $filter->add(array('private', $this->lang['table_private_ami']), array(0, 1)); foreach ($alphabet_arr as $index => $character) { $filter->add(array($character), array(0, 0)); } if ($this->filter == 'private') { $ami_type_switch_cmd_parameter = ' -ap private'; } else { $ami_type_switch_cmd_parameter = ' -ap public'; } $filter->selected = array($this->filter); $box = $this->response->html->box(); $box->label = "Filter"; $box->add($filter); $box->id = "amifilter"; $box->css = "htmlobject_box"; $form->add($box); $this->response->add('hybrid_cloud_ami_filter', $this->filter); $d['filter'] = $form->get_string(); $h = array(); $h['ami']['title'] = $this->lang['table_ami']; $h['path']['title'] = $this->lang['table_path']; $h['perm']['title'] = $this->lang['table_permission']; $h['arch']['title'] = $this->lang['table_arch']; $h['type']['title'] = $this->lang['table_type']; $h['virt']['title'] = $this->lang['table_virt_type']; $h['image']['title'] = ' '; $h['image']['sortable'] = false; $content = array(); $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $this->id . '.describe_images.log'; if ($this->file->exists($file)) { $this->file->remove($file); } $hc_authentication = ''; if ($this->hc->account_type == 'aws' || $this->hc->account_type == 'euca') { $hc_authentication .= ' -O ' . $this->hc->access_key; $hc_authentication .= ' -W ' . $this->hc->secret_key; $hc_authentication .= ' -f ' . $this->filter; $hc_authentication .= ' -ar ' . $this->region; $hc_authentication .= $ami_type_switch_cmd_parameter; #$d['ami_type_switch'] = $ami_type_switch; } if ($this->hc->account_type == 'lc-openstack') { $hc_authentication .= ' -u ' . $this->hc->username; $hc_authentication .= ' -p ' . $this->hc->password; $hc_authentication .= ' -q ' . $this->hc->host; $hc_authentication .= ' -x ' . $this->hc->port; $hc_authentication .= ' -g ' . $this->hc->tenant; $hc_authentication .= ' -e ' . $this->hc->endpoint; $hc_authentication .= ' -f ' . $this->filter; #$d['ami_type_switch'] = ''; } $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-ami describe_images'; $command .= ' -i ' . $this->hc->id; $command .= ' -t ' . $this->hc->account_type; $command .= ' -n ' . $this->hc->account_name; $command .= $hc_authentication; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $server = new openqrm_server(); $server->send_command($command, NULL, true); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } $content = $this->file->get_contents($file); $content = explode("\n", $content); $b = array(); foreach ($content as $k => $v) { if ($v !== '') { // e.g. IMAGE@ami-25f9c051@021471307000/ami_hapx_ubuntu_10_04@021471307000@available@public@@i386@machine@aki-4deec439@@@ebs@paravirtual@xen $tmp = explode('@', $v); $ami = $tmp[1]; $path = $tmp[2]; if ($this->hc->account_type == 'aws' || $this->hc->account_type == 'euca') { $state = $tmp[4]; $perm = $tmp[5]; $arch = $tmp[7]; $type = $tmp[13]; $virt = $tmp[14]; } if ($this->hc->account_type == 'lc-openstack') { $state = ''; $perm = ''; $arch = ''; $type = ''; $virt = ''; } if ($arch != "i386" && $arch != "x86_64") { $arch = ''; } $image_add_remove = ''; $deployment_type = ''; $image = new image(); $image->get_instance_by_name($ami); if (strlen($image->id)) { if ($image->type != $this->deployment->type) { $deployment_type = $image->type; $disabled[] = $ami; } else { $i = $this->response->html->a(); $i->title = $this->lang['action_remove_image']; $i->label = $this->lang['action_remove_image']; $i->handler = 'onclick="wait();"'; $i->css = 'edit'; $i->href = $this->response->get_url($this->actions_name, "image") . '&image_id=' . $image->id . '&image_command=remove'; $image_add_remove = $i; } } else { $i = $this->response->html->a(); $i->title = $this->lang['action_add_image']; $i->label = $this->lang['action_add_image']; $i->handler = 'onclick="wait();"'; $i->css = 'edit'; $i->href = $this->response->get_url($this->actions_name, "image") . '&image_name=' . $ami . '&image_rootdevice=' . $ami . '&image_comment=' . basename($path) . '&image_command=add'; $disabled[] = $ami; $image_add_remove = $i; } $b[] = array('ami' => $ami, 'path' => basename($path), 'perm' => $perm, 'arch' => $arch, 'type' => $type, 'virt' => $virt, 'state' => $arch, 'image' => $image_add_remove); } } $params = $this->response->get_array($this->actions_name, 'edit'); $table = $this->response->html->tablebuilder('hybridcloud_ami_edit', $params); $table->offset = 0; $table->sort = 'ami'; $table->limit = 200; $table->order = 'ASC'; $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->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), array("value" => 200, "text" => 200)); $d['name'] = $this->hc->account_name; $d['form'] = $this->response->get_form($this->actions_name, 'edit', false)->get_elements(); $d['table'] = $table; return $d; }
function edit() { $h = array(); $h['volume']['title'] = $this->lang['table_volume']; $h['id']['title'] = $this->lang['table_id']; $h['snapshot']['title'] = $this->lang['table_snapshot']; $h['zone']['title'] = $this->lang['table_zone']; $h['state']['title'] = $this->lang['table_state']; $h['date']['title'] = $this->lang['table_date']; $h['type']['title'] = $this->lang['table_type']; $h['snap']['title'] = ' '; $h['snap']['sortable'] = false; $h['attach']['title'] = ' '; $h['attach']['sortable'] = false; $h['detach']['title'] = ' '; $h['detach']['sortable'] = false; $h['remove']['title'] = ' '; $h['remove']['sortable'] = false; $content = array(); $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $this->id . '.describe_volumes.log'; if ($this->file->exists($file)) { $this->file->remove($file); } $a = $this->response->html->a(); $a->label = $this->lang['action_add_volume']; $a->css = 'add'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "add"); $d['add_volume'] = $a->get_string(); require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-ebs describe_volumes'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -ar ' . $this->region; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $server = new openqrm_server(); $server->send_command($command, NULL, true); while (!$this->file->exists($file)) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); } $content = $this->file->get_contents($file); $content = explode("\n", $content); $b = array(); foreach ($content as $k => $v) { if ($v !== '') { // e.g. VOLUME vol-1a2b3c4d 30 snap-1a2b3c4d us-west-2a available YYYY-MM-DDTHH:MM:SS+0000 standard $tmp = explode('@', $v); $volume = $tmp[1]; $id = $tmp[2]; $snapshot = $tmp[3]; $zone = $tmp[4]; $state = $tmp[5]; $date = $tmp[6]; $type = $tmp[7]; $a = $this->response->html->a(); $a->label = $this->lang['action_snap_volume']; $a->css = 'edit'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "snap", "volume_name", $volume); $a->css = 'edit'; $snap = $a->get_string(); if ($state == 'available') { $a = $this->response->html->a(); $a->label = $this->lang['action_attach_volume']; $a->css = 'remove'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "attach", "volume_name", $volume); $a->css = 'edit'; $attach = $a->get_string(); $a = $this->response->html->a(); $a->label = $this->lang['action_remove_volume']; $a->css = 'remove'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "remove", "volume_name", $volume); $a->css = 'edit'; $remove = $a->get_string(); } else { $a = $this->response->html->a(); $a->label = $this->lang['action_detach_volume']; $a->css = 'remove'; $a->handler = 'onclick="wait();"'; $a->href = $this->response->get_url($this->actions_name, "detach", "volume_name", $volume); $a->css = 'edit'; $attach = $a->get_string(); $remove = ''; } $b[] = array('volume' => $volume, 'id' => $id, 'snapshot' => $snapshot, 'zone' => $zone, 'state' => $state, 'date' => $date, 'type' => $type, 'snap' => $snap, 'attach' => $attach, 'remove' => $remove); } } $params = $this->response->get_array($this->actions_name, 'edit'); $table = $this->response->html->tablebuilder('hybridcloud_import_edit', $params); $table->offset = 0; $table->sort = 'volume'; $table->limit = 200; $table->order = 'ASC'; $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; // handle account name require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php'; $hc = new hybrid_cloud(); $hc->get_instance_by_id($this->id); $d['name'] = $hc->account_name; $d['form'] = $this->response->get_form($this->actions_name, 'edit', false)->get_elements(); $d['table'] = $table; return $d; }
function select() { $response = $this->get_response(); $form = $response->form; if (!$form->get_errors() && $this->response->submit()) { $request = $form->get_request(); $hc = $response->hc; $image = $response->image; $storage = new storage(); $storage->get_instance_by_id($image->storageid); $resource = new resource(); $resource->get_instance_by_id($storage->resource_id); $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-migration export_image'; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -O ' . $hc->access_key; $command .= ' -W ' . $hc->secret_key; $command .= ' -t ' . $hc->account_type; $command .= ' -s ' . $resource->ip . ":" . $image->rootdevice; $command .= ' -m ' . $request['size']; $command .= ' -a ' . $request['name']; $command .= ' -r ' . $request['arch']; $command .= ' -u ' . $request['user_id']; $command .= ' -y ' . $request['private_key_file']; $command .= ' -z ' . $request['public_key_file']; $command .= ' -l ' . $this->region; $command .= ' --openqrm-ui-user ' . $this->user->name; $command .= ' --openqrm-cmd-mode background'; $server = new openqrm_server(); $server->send_command($command, NULL, true); $response->msg = sprintf($this->lang['msg_exported'], $image->name, $hc->account_name); // $ev = new event(); // $ev->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-monitor-hook", $command, "", "", 0, 0, 0); } return $response; }
function edit() { $response = $this->get_response(); $form = $response->form; $appliance_id = $response->html->request()->get('appliance_id'); if ($appliance_id !== '') { if (!$form->get_errors() && $response->submit()) { $host = new nagios3_host(); $host = $host->get_instance_by_appliance_id($appliance_id); $old = explode(',', $host->appliance_services); $new = $form->get_request('services'); if (isset($new[0]) && $new[0] !== '{empty}') { $fields['nagios3_appliance_services'] = implode(',', $new); } else { $fields['nagios3_appliance_services'] = 'false'; } // if nagios3_host id is set -> update or remove if ($host->id !== '') { // if no services -> remove if ($fields['nagios3_appliance_services'] === 'false') { $error = $this->nagios3h->remove($host->id); } else { $error = $this->nagios3h->update($host->id, $fields); } } else { if ($fields['nagios3_appliance_services'] !== 'false') { $fields['nagios3_host_id'] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $fields['nagios3_appliance_id'] = $appliance_id; $error = $this->nagios3h->add($fields); } } // remove new ports from old foreach ($new as $id) { if ($id !== '{empty}') { if (in_array($id, $old)) { $key = array_search($id, $old); unset($old[$key]); } } } // handle ports to set $set = array(); foreach ($new as $id) { if ($id !== '{empty}') { $set[] = $this->nagios3s->get_instance_by_id($id)->port; } } // handle ports to unset $unset = array(); foreach ($old as $id) { if ($id !== 'false') { $unset[] = $this->nagios3s->get_instance_by_id($id)->port; } } // autoselect? active? if ($response->appliance->state == "active" || $response->appliance->resources == 0) { // unset if (count($unset) >= 1) { $res = new resource(); $cmd = $this->openqrm->get('basedir') . '/plugins/nagios3/bin/openqrm-nagios-manager remove_service'; $cmd .= ' -n ' . $response->appliance->name; $cmd .= ' -i ' . $res->get_instance_by_id($response->appliance->resources)->ip; $cmd .= ' -p ' . implode(',', $unset); $cmd .= ' --openqrm-ui-user ' . $this->user->name; $cmd .= ' --openqrm-cmd-mode fork'; $oqs = new openqrm_server(); $oqs->send_command($cmd, NULL, true); } // set if (count($set) >= 1) { $res = new resource(); $cmd = $this->openqrm->get('basedir') . '/plugins/nagios3/bin/openqrm-nagios-manager add'; $cmd .= ' -n ' . $response->appliance->name; $cmd .= ' -i ' . $res->get_instance_by_id($response->appliance->resources)->ip; $cmd .= ' -p ' . implode(',', $set); $cmd .= ' --openqrm-ui-user ' . $this->user->name; $cmd .= ' --openqrm-cmd-mode fork'; $oqs = new openqrm_server(); $oqs->send_command($cmd, NULL, true); } } $response->msg = sprintf($this->lang['msg_updated'], $response->appliance->name); } } else { $response->msg = ''; } return $response; }
if ($resource_id == "-1") { // check if resource already exists $resource = new resource(); if (!$resource->exists($resource_mac)) { // add resource $new_resource_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $resource->id = $new_resource_id; // check if resource_id is free if (!$resource->is_id_free($resource->id)) { $event->log("get_parameter", $_SERVER['REQUEST_TIME'], 3, "resource-monitor", "Given resource id {$resource->id} is already in use!", "", "", 0, 1, $resource->id); echo "Given resource id {$resource->id} is already in use!"; exit; } $event->log("get_parameter", $_SERVER['REQUEST_TIME'], 5, "resource-monitor", "Adding new resource {$new_resource_id} ({$resource_mac})", "", "", 0, 1, $resource->id); # send add resource to openQRM-server $openqrm_server->send_command("openqrm_server_add_resource {$new_resource_id} {$resource_mac} {$resource_ip}"); # add resource to db $resource_fields["resource_id"] = $new_resource_id; $resource_fields["resource_localboot"] = 0; $resource_fields["resource_vtype"] = 1; $resource_fields["resource_vhostid"] = $new_resource_id; $resource_fields["resource_subnet"] = $resource_subnet; $resource->add($resource_fields); } } if (strlen($resource_mac)) { $resource = new resource(); $resource->get_instance_by_mac("{$resource_mac}"); // update the resource parameter in any way $resource->update_info($resource->id, $resource_fields); $resource->get_parameter($resource->id);
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); } }
$ansible_server_ip = $request->get('ansible_ip'); global $OPENQRM_SERVER_BASE_DIR; $event = new event(); $openqrm_server = new openqrm_server(); $OPENQRM_SERVER_IP_ADDRESS = $openqrm_server->get_ip_address(); global $OPENQRM_SERVER_IP_ADDRESS; global $event; // main $event->log($ansible_command, $_SERVER['REQUEST_TIME'], 5, "ansible-apply", "Processing ansible command " . $ansible_command, "", "", 0, 0, 0); switch ($ansible_command) { case 'apply': $appliance = new appliance(); $appliance->get_instance_by_id($ansible_server_id); if ($ansible_server_name == $appliance->name) { $resource = new resource(); $resource->get_instance_by_id($appliance->resources); if ($ansible_server_mac == $resource->mac && $ansible_server_ip == $resource->ip) { $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/ansible/bin/openqrm-ansible-manager apply " . $appliance->id . " " . $appliance->name . " " . $resource->ip . " --openqrm-cmd-mode background"; $openqrm_server = new openqrm_server(); $openqrm_server->send_command($command, NULL, true); } else { $event->log($ansible_command, $_SERVER['REQUEST_TIME'], 3, "ansible-apply", "Request for Ansible apply for server id " . $ansible_server_id . " with wrong resource " . $resource->id, "", "", 0, 0, 0); } } else { $event->log($ansible_command, $_SERVER['REQUEST_TIME'], 3, "ansible-apply", "Request for Ansible apply for server id " . $ansible_server_id . " with wrong name " . $ansible_server_name, "", "", 0, 0, 0); } break; default: $event->log($ansible_command, $_SERVER['REQUEST_TIME'], 3, "ansible-apply", "No such command " . $ansible_command, "", "", 0, 0, 0); break; }