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 create_kvm_vm($host_resource_id, $name, $mac, $memory, $cpu, $swap, $additional_nic_str, $vm_type, $vncpassword) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; $event->log("create_kvm_vm_local", $_SERVER['REQUEST_TIME'], 5, "kvm-cloud-hook", "Creating KVM VM {$name} on Host resource {$host_resource_id}", "", "", 0, 0, 0); // start the vm on the host $host_resource = new resource(); $host_resource->get_instance_by_id($host_resource_id); // we need to have an openQRM server object too since some of the // virtualization commands are sent from openQRM directly $openqrm = new openqrm_server(); $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); $vncpassword_parameter = ""; if ($vncpassword != '') { $vncpassword_parameter = " -v " . $vncpassword; } // send command to create vm $vm_create_cmd = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/kvm/bin/openqrm-kvm-vm create -n " . $name . " -y " . $vm_type . " -m " . $mac . " -r " . $memory . " -c " . $cpu . " -b local " . $additional_nic_str . " " . $vncpassword_parameter . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password; $host_resource->send_command($host_resource->ip, $vm_create_cmd); $event->log("create_kvm_vm_local", $_SERVER['REQUEST_TIME'], 5, "kvm-cloud-hook", "Running {$vm_create_cmd}", "", "", 0, 0, 0); }
function set_env() { // auth user if (isset($_SERVER['PHP_AUTH_USER'])) { $OPENQRM_USER = new user($_SERVER['PHP_AUTH_USER']); if ($OPENQRM_USER->check_user_exists()) { $OPENQRM_USER->set_user(); $GLOBALS['OPENQRM_USER'] = $OPENQRM_USER; define('OPENQRM_USER_NAME', $OPENQRM_USER->name); define('OPENQRM_USER_ROLE_NAME', $OPENQRM_USER->role); } } // admin user for running commands $OPENQRM_ADMIN = new user('openqrm'); $OPENQRM_ADMIN->set_user(); $GLOBALS['OPENQRM_ADMIN'] = $OPENQRM_ADMIN; }
function __construct() { // handle timezone needed since php 5.3 if (function_exists('ini_get')) { if (ini_get('date.timezone') === '') { date_default_timezone_set('Europe/Berlin'); } } $this->rootdir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base'; $this->tpldir = $this->rootdir . '/tpl'; require_once $this->rootdir . '/class/file.handler.class.php'; $file = new file_handler(); require_once $this->rootdir . '/class/htmlobjects/htmlobject.class.php'; require_once $this->rootdir . '/class/openqrm.htmlobjects.class.php'; $html = new openqrm_htmlobject(); // if openQRM is unconfigured, set openqrm empty if ($file->exists($this->rootdir . '/unconfigured')) { $this->openqrm = ''; $this->webdir = $this->rootdir; $this->baseurl = $html->thisurl; } else { require_once $this->rootdir . '/class/user.class.php'; $user = new user($_SERVER['PHP_AUTH_USER']); $user->set_user(); require_once $this->rootdir . '/class/openqrm.class.php'; $this->openqrm = new openqrm($file, $user, $html->response()); $this->webdir = $this->openqrm->get('webdir'); $this->baseurl = $this->openqrm->get('baseurl'); } // only translate if openqrm is not empty (configure mode) if ($this->openqrm !== '') { $html->lang = $user->translate($html->lang, $this->rootdir . "/lang", 'htmlobjects.ini'); $file->lang = $user->translate($file->lang, $this->rootdir . "/lang", 'file.handler.ini'); $this->lang = $user->translate($this->lang, $this->rootdir . "/lang", 'openqrm.controller.ini'); } require_once $this->rootdir . '/include/requestfilter.inc.php'; $request = $html->request(); $request->filter = $requestfilter; $this->response = $html->response(); $this->request = $this->response->html->request(); $this->file = $file; }
function storage_auth_function($cmd, $appliance_id) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $IMAGE_AUTHENTICATION_TABLE; global $openqrm_server; global $RootDir; $appliance = new appliance(); $appliance->get_instance_by_id($appliance_id); $image = new image(); $image->get_instance_by_id($appliance->imageid); $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; $resource = new resource(); $resource->get_instance_by_id($appliance->resources); $resource_mac = $resource->mac; $resource_ip = $resource->ip; // For kvm vms we assume that the image is located on the vm-host // so we send the auth command to the vm-host instead of the image storage. // This enables using a SAN backend with dedicated volumes per vm-host which all // contain all "golden-images" which are used for snapshotting. // We do this to overcome the current lvm limitation of not supporting cluster-wide snapshots $vm_host_resource = new resource(); $vm_host_resource->get_instance_by_id($resource->vhostid); if ($vm_host_resource->id != $storage_resource->id) { $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-auth-hook.php", "Appliance " . $appliance_id . " image IS NOT available on this kvm host, " . $storage_resource->id . " not equal " . $vm_host_resource->id . " !! Assuming SAN Backend", "", "", 0, 0, $appliance_id); } else { $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-auth-hook.php", "Appliance " . $appliance_id . " image IS available on this kvm host, " . $storage_resource->id . " equal " . $vm_host_resource->id . ".", "", "", 0, 0, $appliance_id); } switch ($cmd) { case "start": // authenticate the rootfs / needs openqrm user + pass $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); // generate a password for the image $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-auth-hook.php", "Authenticating " . $image_name . " / " . $image_rootdevice . " to resource " . $resource_mac . ".", "", "", 0, 0, $appliance_id); $auth_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $deployment_plugin_name . "/bin/openqrm-" . $deployment_plugin_name . " auth -n " . $image_name . " -r " . $image_rootdevice . " -i " . $image_name . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " -t " . $deployment->type . " --openqrm-cmd-mode background"; $resource->send_command($vm_host_resource->ip, $auth_start_cmd); break; } }
function delete() { $response = $this->get_response('delete'); $folders = $response->html->request()->get($this->identifier_name); $form = $response->form; if ($folders !== '') { $i = 0; foreach ($folders as $folder) { $d['param_f' . $i]['label'] = $folder; $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 . '[]'; $d['param_f' . $i]['object']['attrib']['value'] = $folder; $d['param_f' . $i]['object']['attrib']['checked'] = true; $i++; } $form->add($d); if (!$form->get_errors() && $response->submit()) { $errors = array(); $message = array(); foreach ($folders as $key => $user) { // protect user openqrm if ($user !== 'openqrm') { $del = new user($user); $del->set_user(); $error = $del->query_delete(); if (is_array($error) && count($error) > 1) { $errors[] = $error; } else { $form->remove($this->identifier_name . '[' . $key . ']'); $message[] = sprintf($this->lang['msg_deleted'], $user); } } else { if ($user === 'openqrm') { $form->remove($this->identifier_name . '[' . $key . ']'); } } } if (count($errors) === 0) { $response->msg = join('<br>', $message); } else { $msg = array_merge($errors, $message); $response->error = join('<br>', $msg); } } if ($form->get_errors()) { $response->error = join('<br>', $form->get_errors()); } } else { $response->msg = ''; } return $response; }
function check_user($mode, $username, $password) { global $RootDir; global $event; switch ($mode) { case 'admin': $OPENQRM_USER = new user($username); if ($OPENQRM_USER->check_user_exists()) { $OPENQRM_USER->set_user(); if (!strcmp($OPENQRM_USER->password, $password)) { return true; } else { $event->log("cloudsoap->check_user", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Got a wrong password from openQRM User name {$username}!", "", "", 0, 0, 0); return false; } } else { $event->log("cloudsoap->check_user", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "User name {$username} does not exists in openQRM !", "", "", 0, 0, 0); return false; } break; case 'user': $cl_user = new clouduser(); // check that the user exists if ($cl_user->is_name_free($username)) { $event->log("cloudsoap->check_user", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud User name {$username} does not exists in the Cloud!", "", "", 0, 0, 0); return false; } // check users password, only if ldap is not enabled if (!file_exists($RootDir . "/plugins/ldap/.running")) { $cl_user->get_instance_by_name($username); if (strcmp($cl_user->password, $password)) { $event->log("cloudsoap->check_user", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Got a wrong password from Cloud User name {$username}!", "", "", 0, 0, 0); return false; } } return true; break; default: return false; break; } }
function sync($ct_id, $insert_into_failed) { $openqrm_server = new openqrm_server(); $OPENQRM_SERVER_IP_ADDRESS = $openqrm_server->get_ip_address(); $this->get_instance_by_id($ct_id); // get cloud user $local_transaction_cloud_user = new clouduser(); $local_transaction_cloud_user->get_instance_by_id($this->cu_id); // get cloud-zones config parameters from main config $cz_conf = new cloudconfig(); $cloud_zones_master_ip = $cz_conf->get_value(36); // 36 is cloud_zones_master_ip // check if cloud_external_ip is set $cloud_external_ip = $cz_conf->get_value(37); // 37 is cloud_external_ip if (!strlen($cloud_external_ip)) { $cloud_external_ip = $openqrm_server->get_ip_address(); } // get the admin user, the zone master will automatically authenticate against this user $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); // url for the wdsl $url = "https://" . $cloud_zones_master_ip . "/openqrm/boot-service/cloud-zones-soap.wsdl"; // turn off the WSDL cache ini_set("soap.wsdl_cache_enabled", "0"); // create the soap-client $client = new SoapClient($url, array('soap_version' => SOAP_1_2, 'trace' => 1, 'login' => $openqrm_admin_user->name, 'password' => $openqrm_admin_user->password)); // var_dump($client->__getFunctions()); try { $send_transaction_parameters = $openqrm_admin_user->name . "," . $openqrm_admin_user->password . "," . $cloud_external_ip . "," . $local_transaction_cloud_user->name . "," . $this->id . "," . $this->time . "," . $this->cr_id . "," . $this->ccu_charge . "," . $this->reason . "," . $this->comment; $new_local_ccu_value = $client->CloudZonesSync($send_transaction_parameters); // update users ccus values with return from master $local_transaction_cloud_user->set_users_ccunits($this->cu_id, $new_local_ccu_value); $this->_event->log("push", $_SERVER['REQUEST_TIME'], 5, "cloudtransaction.class.php", "Synced transaction! User:"******"/CR:" . $this->cr_id . "/Global CCU:" . $new_local_ccu_value, "", "", 0, 0, 0); return true; } catch (Exception $e) { $soap_error_msg = $e->getMessage(); $this->_event->log("push", $_SERVER['REQUEST_TIME'], 2, "cloudtransaction.class.php", "Could not sync transaction! User:"******"/CR:" . $this->cr_id . "/Charge:" . $this->ccu_charge . "/" . $soap_error_msg, "", "", 0, 0, 0); if ($insert_into_failed) { // add to failed transactions $cloudtransactionfailed = new cloudtransactionfailed(); $failed_transaction_fields['tf_id'] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $failed_transaction_fields['tf_ct_id'] = $ct_id; $cloudtransactionfailed->add($failed_transaction_fields); } return false; } }
function create_private_kvm_gluster_deployment($cloud_image_id, $private_disk, $private_image_name) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; $cloudimage = new cloudimage(); $cloudimage->get_instance_by_id($cloud_image_id); $event->log("create_private_kvm_gluster_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-gluster-deployment-cloud-hook.php", "Creating private image " . $cloudimage->image_id . " on storage.", "", "", 0, 0, 0); // get image $image = new image(); $image->get_instance_by_id($cloudimage->image_id); $image_id = $image->id; $image_name = $image->name; $image_type = $image->type; $image_version = $image->version; $image_rootdevice = $image->rootdevice; $image_rootfstype = $image->rootfstype; $imageid = $image->storageid; $image_isshared = $image->isshared; $image_comment = $image->comment; $image_capabilities = $image->capabilities; $image_deployment_parameter = $image->deployment_parameter; // get image storage $storage = new storage(); $storage->get_instance_by_id($imageid); $storage_resource_id = $storage->resource_id; // get deployment type $deployment = new deployment(); $deployment->get_instance_by_id($storage->type); // get storage resource $resource = new resource(); $resource->get_instance_by_id($storage_resource_id); $resource_id = $resource->id; $resource_ip = $resource->ip; // create an admin user to post when cloning has finished $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); $gluster_uri_arr = parse_url($image_rootdevice); // origin image volume name $origin_volume_name = basename($gluster_uri_arr['path']); // location of the volume (path) $image_location_name = str_replace('/', '', dirname($gluster_uri_arr['path'])); $image_clone_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm clone -n " . $origin_volume_name . " -s " . $private_image_name . " -v " . $image_location_name . " -m " . $private_disk . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " -t " . $deployment->type . " --openqrm-cmd-mode background"; $event->log("create_private_kvm_gluster_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-gluster-deployment-cloud-hook.php", "Running : {$image_resize_cmd}", "", "", 0, 0, 0); $resource->send_command($resource->ip, $image_clone_cmd); // set the storage specific image root_device parameter $new_rootdevice = "gluster:" . $resource->ip . "//" . $image_location_name . "/" . $private_image_name; return $new_rootdevice; }
function openqrm_kvm_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; $appliance = new appliance(); $appliance->get_instance_by_id($appliance_id); // check appliance values, maybe we are in update and they are incomplete if ($appliance->imageid == 1) { return; } if ($resource->id == "-1" || $resource->id == "" || !isset($resource->vtype)) { return; } $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id); switch ($cmd) { case "start": // send command to assign image and start vm // NOTICE : please enable this hook only if you are using the ip-mgmt plugin with vlans // check if resource type -> kvm-vm-net // $virtualization = new virtualization(); // $virtualization->get_instance_by_type("kvm-vm-net"); // $kvm_host_resource = new resource(); // $kvm_host_resource->get_instance_by_id($resource->vhostid); // if ($resource->vtype != $virtualization->id) { // $kvm_command="$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/kvm/bin/openqrm-kvm-vm reset_vlans_by_mac -b start -m $resource->mac"; // $kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command); // return; // } // check resource type -> kvm-vm-local $virtualization = new virtualization(); $virtualization->get_instance_by_type("kvm-vm-local"); if ($resource->vtype != $virtualization->id) { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "{$appliance_id} is not from type kvm-vm, skipping .. {$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id); return; } // check image is on the same storage server // get the kvm host resource $kvm_host_resource = new resource(); $kvm_host_resource->get_instance_by_id($resource->vhostid); // get the kvm resource $image = new image(); $image->get_instance_by_id($appliance->imageid); $storage = new storage(); $storage->get_instance_by_id($image->storageid); $kvm_resource = new resource(); $kvm_resource->get_instance_by_id($storage->resource_id); if ($kvm_host_resource->id != $kvm_resource->id) { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Appliance {$appliance_id} image is not available on this kvm host. Assuming SAN-Backend", "", "", 0, 0, $appliance_id); } $kvm_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm-vm start_by_mac -m " . $resource->mac . " -d " . $image->rootdevice . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password; $kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command); break; case "stop": // send command to stop the vm and deassign image // NOTICE : please enable this hook only if you are using the ip-mgmt plugin with vlans // check if resource type -> kvm-vm-net // $virtualization = new virtualization(); // $virtualization->get_instance_by_type("kvm-vm-net"); // $kvm_host_resource = new resource(); // $kvm_host_resource->get_instance_by_id($resource->vhostid); // if ($resource->vtype != $virtualization->id) { // $kvm_command="$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/kvm/bin/openqrm-kvm reset_vlans_by_mac -b stop -m $resource->mac"; // $kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command); // return; // } // check resource type -> kvm-vm-local $virtualization = new virtualization(); $virtualization->get_instance_by_type("kvm-vm-local"); if ($resource->vtype != $virtualization->id) { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "{$appliance_id} is not from type kvm-vm, skipping .. {$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id); return; } // check image is on the same storage server // get the kvm host resource $kvm_host_resource = new resource(); $kvm_host_resource->get_instance_by_id($resource->vhostid); // get the kvm resource $image = new image(); $image->get_instance_by_id($appliance->imageid); $storage = new storage(); $storage->get_instance_by_id($image->storageid); $kvm_resource = new resource(); $kvm_resource->get_instance_by_id($storage->resource_id); if ($kvm_host_resource->id != $kvm_resource->id) { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Appliance {$appliance_id} image is not available on this kvm host. Assuming SAN-Backend", "", "", 0, 0, $appliance_id); } $kvm_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm-vm restart_by_mac -m " . $resource->mac . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background"; $kvm_host_resource->send_command($kvm_host_resource->ip, $kvm_command); break; case "update": // check if the appliance was set to a kvm Host, if yes, auto-create the storage objects $virtualization = new virtualization(); $virtualization->get_instance_by_type("kvm"); if ($appliance->virtualization == $virtualization->id) { // KVM LVM Storage $deployment = new deployment(); $deployment->get_instance_by_name('kvm-lvm-deployment'); $storage = new storage(); $kvm_id_list = $storage->get_ids_by_storage_type($deployment->id); $found_kvm = false; $found_kvm_id = -1; foreach ($kvm_id_list as $list) { foreach ($list as $kvm_id) { $storage->get_instance_by_id($kvm_id); if ($storage->resource_id == $appliance->resources) { $found_kvm = true; $found_kvm_id = $storage->id; break; } } } if (!$found_kvm) { $found_kvm_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $storage_fields['storage_id'] = $found_kvm_id; $storage_fields['storage_name'] = $appliance->name . "-lvm"; $storage_fields['storage_type'] = $deployment->id; $storage_fields['storage_comment'] = 'KVM LVM Storage Object for Appliance ' . $appliance->name; $storage_fields['storage_resource_id'] = $appliance->resources; $storage_fields['storage_capabilities'] = ''; $storage->add($storage_fields); $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Created KVM LVM Storage Object for Appliance " . $appliance_id . "!", "", "", 0, 0, $appliance_id); } else { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "KVM LVM Storage Object for Appliance " . $appliance_id . " already existing.", "", "", 0, 0, $appliance_id); } // KVM Blockfile Storage $deployment = new deployment(); $deployment->get_instance_by_name('kvm-bf-deployment'); $storage = new storage(); $kvm_id_list = $storage->get_ids_by_storage_type($deployment->id); $found_kvm = false; $found_kvm_id = -1; foreach ($kvm_id_list as $list) { foreach ($list as $kvm_id) { $storage->get_instance_by_id($kvm_id); if ($storage->resource_id == $appliance->resources) { $found_kvm = true; $found_kvm_id = $storage->id; break; } } } if (!$found_kvm) { $found_kvm_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $storage_fields['storage_id'] = $found_kvm_id; $storage_fields['storage_name'] = $appliance->name . "-bf"; $storage_fields['storage_type'] = $deployment->id; $storage_fields['storage_comment'] = 'KVM Blockfile Storage Object for Appliance ' . $appliance->name; $storage_fields['storage_resource_id'] = $appliance->resources; $storage_fields['storage_capabilities'] = ''; $storage->add($storage_fields); $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "Created KVM Blockfile Storage Object for Appliance " . $appliance_id . "!", "", "", 0, 0, $appliance_id); } else { $event->log("openqrm_kvm_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-appliance-hook.php", "KVM Blockfile Storage Object for Appliance " . $appliance_id . " already existing.", "", "", 0, 0, $appliance_id); } } break; } }
function storage_auth_function($cmd, $appliance_id) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $IMAGE_AUTHENTICATION_TABLE; global $openqrm_server; global $RootDir; $appliance = new appliance(); $appliance->get_instance_by_id($appliance_id); $image = new image(); $image->get_instance_by_id($appliance->imageid); $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; $resource = new resource(); $resource->get_instance_by_id($appliance->resources); $resource_mac = $resource->mac; $resource_ip = $resource->ip; $vm_host_resource = new resource(); $vm_host_resource->get_instance_by_id($resource->vhostid); switch ($cmd) { case "start": // authenticate the rootfs / needs openqrm user + pass $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); // generate a password for the image $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-auth-hook.php", "Authenticating " . $image_name . " / " . $image_rootdevice . " to resource " . $resource_mac . ".", "", "", 0, 0, $appliance_id); $auth_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $deployment_plugin_name . "/bin/openqrm-" . $deployment_plugin_name . " auth -n " . $image_name . " -r " . $image_rootdevice . " -i " . $image_name . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " -t " . $deployment->type . " --openqrm-cmd-mode background"; $resource->send_command($storage_resource->ip, $auth_start_cmd); break; } }
function storage_auth_function($cmd, $appliance_id) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $IMAGE_AUTHENTICATION_TABLE; global $openqrm_server; $appliance = new appliance(); $appliance->get_instance_by_id($appliance_id); $image = new image(); $image->get_instance_by_id($appliance->imageid); $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; $resource = new resource(); $resource->get_instance_by_id($appliance->resources); $resource_mac = $resource->mac; $resource_ip = $resource->ip; switch ($cmd) { case "start": // authenticate the rootfs / needs openqrm user + pass $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); // generate a password for the image $image_password = $image->generatePassword(12); $image_deployment_parameter = $image->deployment_parameter; $image->set_deployment_parameters("IMAGE_ISCSI_AUTH", $image_password); $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-iscsi-deployment-auth-hook.php", "Authenticating {$image_name} / {$image_rootdevice} to resource {$resource_mac} with password {$image_password}", "", "", 0, 0, $appliance_id); $auth_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $deployment_plugin_name . "/bin/openqrm-" . $deployment_plugin_name . " auth -n " . $image_name . " -r " . $image_rootdevice . " -i " . $image_password . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background"; $resource->send_command($storage_ip, $auth_start_cmd); // authenticate the install-from-nfs export $run_disable_deployment_export = 0; $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-iscsi-deployment-auth-hook.php", "Install-from-NFS: Authenticating {$resource_ip} on storage id {$ip_storage_id}:{$ip_storage_ip}:{$ip_image_rootdevice}", "", "", 0, 0, $appliance_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 " . $resource_ip . " -t " . $ip_deployment_type . " --openqrm-cmd-mode background"; $resource->send_command($ip_storage_ip, $auth_install_from_nfs_start_cmd); $run_disable_deployment_export = 1; } // authenticate the transfer-to-nfs export $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-iscsi-deployment-auth-hook.php", "Transfer-to-NFS: Authenticating {$resource_ip} on storage id {$tp_storage_id}:{$tp_storage_ip}:{$tp_image_rootdevice}", "", "", 0, 0, $appliance_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 " . $resource_ip . " -t " . $tp_deployment_type . " --openqrm-cmd-mode background"; $resource->send_command($tp_storage_ip, $auth_install_from_nfs_start_cmd); $run_disable_deployment_export = 1; } // do we need to disable the install-from/transfer-to-nfs exports ? if ($run_disable_deployment_export == 1) { $image_authentication = new image_authentication(); $ia_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $image_auth_ar = array('ia_id' => $ia_id, 'ia_image_id' => $appliance->imageid, 'ia_resource_id' => $appliance->resources, 'ia_auth_type' => 1); $image_authentication->add($image_auth_ar); $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-iscsi-deployment-auth-hook.php", "Registered image {$appliance->imageid} for de-authentication the deployment exports when resource {$appliance->resources} is fully up.", "", "", 0, 0, $appliance_id); } break; case "stop": $image_authentication = new image_authentication(); $ia_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $image_auth_ar = array('ia_id' => $ia_id, 'ia_image_id' => $appliance->imageid, 'ia_resource_id' => $appliance->resources, 'ia_auth_type' => 0); $image_authentication->add($image_auth_ar); $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-iscsi-deployment-auth-hook.php", "Registered image {$appliance->imageid} for de-authentication the root-fs exports when resource {$appliance->resources} is idle again.", "", "", 0, 0, $appliance_id); break; } }
function create_private_kvm_bf_deployment($cloud_image_id, $private_disk, $private_image_name) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; $cloudimage = new cloudimage(); $cloudimage->get_instance_by_id($cloud_image_id); $event->log("create_private_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Creating private image " . $cloudimage->image_id . " on storage.", "", "", 0, 0, 0); // get image $image = new image(); $image->get_instance_by_id($cloudimage->image_id); $image_id = $image->id; $image_name = $image->name; $image_type = $image->type; $image_version = $image->version; $image_rootdevice = $image->rootdevice; $image_rootfstype = $image->rootfstype; $imageid = $image->storageid; $image_isshared = $image->isshared; $image_comment = $image->comment; $image_capabilities = $image->capabilities; $image_deployment_parameter = $image->deployment_parameter; // get image storage $storage = new storage(); $storage->get_instance_by_id($imageid); $storage_resource_id = $storage->resource_id; // get deployment type $deployment = new deployment(); $deployment->get_instance_by_id($storage->type); // get storage resource $resource = new resource(); $resource->get_instance_by_id($storage_resource_id); $resource_id = $resource->id; $resource_ip = $resource->ip; // create an admin user to post when cloning has finished $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); // parse the identifiers // origin image volume name $origin_volume_name = basename($image_rootdevice); // location of the volume (path) $image_location_name = dirname($image_rootdevice); // For kvm vms we assume that the image is located on the vm-host // so we send the auth command to the vm-host instead of the image storage. // This enables using a NAS/Glusterfs backend with all volumes accessible for all hosts // // Still we need to send the remove command to the storage resource since the // create-phase automatically adapted the image->storageid, we cannot use the vm-resource here // because cloudimage->resource_id will be set to -1 when the cloudapp is in paused/resize/private state // if ($cloudimage->resource_id > 0) { // try to get the vm resource $vm_resource = new resource(); $vm_resource->get_instance_by_id($cloudimage->resource_id); // get the lxc host $vm_host_resource = new resource(); $vm_host_resource->get_instance_by_id($vm_resource->vhostid); // san backend ? if ($vm_host_resource->id != $resource->id) { $event->log("create_private_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Image " . $image_id . " IS NOT available on this kvm host, " . $resource->id . " not equal " . $vm_host_resource->id . " !! Assuming SAN Backend", "", "", 0, 0, 0); } else { $event->log("create_private_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Image " . $image_id . " IS available on this kvm host, " . $resource->id . " equal " . $vm_host_resource->id . ".", "", "", 0, 0, 0); } } $image_resize_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm clone -n " . $origin_volume_name . " -s " . $private_image_name . " -v " . $image_location_name . " -m " . $private_disk . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " -t " . $deployment->type . " --openqrm-cmd-mode background"; $event->log("create_private_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Running : {$image_resize_cmd}", "", "", 0, 0, 0); $resource->send_command($resource_ip, $image_resize_cmd); // set the storage specific image root_device parameter $new_rootdevice = str_replace($origin_volume_name, $private_image_name, $image->rootdevice); return $new_rootdevice; }
/* openQRM Enterprise developed by openQRM Enterprise GmbH. All source code and content (c) Copyright 2014, openQRM Enterprise GmbH unless specifically noted otherwise. This source code is released under the GNU General Public License version 2, unless otherwise agreed with openQRM Enterprise GmbH. The latest version of this license can be found here: src/doc/LICENSE.txt By using this software, you acknowledge having read this license and agree to be bound thereby. http://openqrm-enterprise.com Copyright 2014, openQRM Enterprise GmbH <*****@*****.**> */ $RootDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/'; require_once $RootDir . "/include/user.inc.php"; require_once $RootDir . "/class/openqrm.class.php"; require_once $RootDir . "/plugins/hybrid-cloud/class/hybrid-cloud.controller.class.php"; require_once $RootDir . "/class/htmlobjects/htmlobject.class.php"; $html = new htmlobject($RootDir . "/class/htmlobjects/"); $response = $html->response(); require_once $RootDir . '/class/file.handler.class.php'; $file = new file_handler(); require_once $RootDir . '/class/user.class.php'; $user = new user($_SERVER['PHP_AUTH_USER']); $user->set_user(); $openqrm = new openqrm($file, $user); $openqrm->init(); $controller = new hybrid_cloud_controller($openqrm, $response); $controller->api();
function create_private_template_deployment($cloud_image_id, $private_disk, $private_image_name) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; $event->log("create_private_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Creating private image on storage", "", "", 0, 0, 0); // we got the cloudimage id here, get the image out of it $cloudimage = new cloudimage(); $cloudimage->get_instance_by_id($cloud_image_id); // get image $image = new image(); $image->get_instance_by_id($cloudimage->image_id); $image_id = $image->id; $image_name = $image->name; $image_type = $image->type; $image_version = $image->version; $image_rootdevice = $image->rootdevice; $image_rootfstype = $image->rootfstype; $image_storageid = $image->storageid; $image_isshared = $image->isshared; $image_comment = $image->comment; $image_capabilities = $image->capabilities; $image_deployment_parameter = $image->deployment_parameter; // get image storage $storage = new storage(); $storage->get_instance_by_id($image_storageid); $storage_resource_id = $storage->resource_id; // get storage resource $resource = new resource(); $resource->get_instance_by_id($storage_resource_id); $resource_id = $resource->id; $resource_ip = $resource->ip; // create an admin user to post when cloning has finished $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); // parse the volume group info in the identifier $volume_group_location = dirname($image_rootdevice); $volume_group = basename($volume_group_location); $image_location_name = basename($image_rootdevice); // For template vms we assume that the image is located on the vm-host // so we send the auth command to the vm-host instead of the image storage. // This enables using a SAN backend with dedicated volumes per vm-host which all // contain all "golden-images" which are used for snapshotting. // We do this to overcome the current lvm limitation of not supporting cluster-wide snapshots // // Still we need to send the remove command to the storage resource since the // create-phase automatically adapted the image->storageid, we cannot use the vm-resource here // because cloudimage->resource_id will be set to -1 when the cloudapp is in paused/resize/private state // if ($cloudimage->resource_id > 0) { $vm_resource = new resource(); $vm_resource->get_instance_by_id($cloudimage->resource_id); // get the openvz host $vm_host_resource = new resource(); $vm_host_resource->get_instance_by_id($vm_resource->vhostid); // san backend ? if ($vm_host_resource->id != $resource->id) { $event->log("create_private_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Image {$image_id} IS NOT available on this template host, {$resource->id} not equal {$vm_host_resource->id} !! Assuming SAN Backend", "", "", 0, 0, $appliance_id); } else { $event->log("create_private_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Image {$image_id} IS available on this template host, {$resource->id} equal {$vm_host_resource->id}", "", "", 0, 0, $appliance_id); } } $image_resize_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template/bin/openqrm-template clone -n " . $image_location_name . " -s " . $private_image_name . " -v " . $volume_group . " -m " . $private_disk . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background"; $event->log("create_private_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Running : {$image_resize_cmd}", "", "", 0, 0, 0); $resource->send_command($resource_ip, $image_resize_cmd); // set the storage specific image root_device parameter $new_rootdevice = str_replace($image_location_name, $private_image_name, $image->rootdevice); return $new_rootdevice; }
function create_private_lvm_nfs_deployment($cloud_image_id, $private_disk, $private_image_name) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; $event->log("create_private_lvm_nfs_deployment", $_SERVER['REQUEST_TIME'], 5, "lvm-nfs-deployment-cloud-hook", "Creating private image on storage", "", "", 0, 0, 0); $cloudimage = new cloudimage(); $cloudimage->get_instance_by_id($cloud_image_id); // get image $image = new image(); $image->get_instance_by_id($cloudimage->image_id); $image_id = $image->id; $image_name = $image->name; $image_type = $image->type; $image_version = $image->version; $image_rootdevice = $image->rootdevice; $image_rootfstype = $image->rootfstype; $image_storageid = $image->storageid; $image_isshared = $image->isshared; $image_comment = $image->comment; $image_capabilities = $image->capabilities; $image_deployment_parameter = $image->deployment_parameter; // get image storage $storage = new storage(); $storage->get_instance_by_id($image_storageid); $storage_resource_id = $storage->resource_id; // get storage resource $resource = new resource(); $resource->get_instance_by_id($storage_resource_id); $resource_id = $resource->id; $resource_ip = $resource->ip; // create an admin user to post when cloning has finished $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); $full_vol_name = $image_rootdevice; $vol_dir = dirname($full_vol_name); $vol = str_replace("/", "", $vol_dir); $image_location_name = basename($full_vol_name); $image_resize_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/lvm-storage/bin/openqrm-lvm-storage clone -n " . $image_location_name . " -s " . $private_image_name . " -v " . $vol . " -m " . $private_disk . " -t lvm-nfs-deployment -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background"; $event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "lvm-nfs-deployment-cloud-hook", "Running : {$image_resize_cmd}", "", "", 0, 0, 0); $resource->send_command($resource_ip, $image_resize_cmd); // set the storage specific image root_device parameter $new_rootdevice = "/" . $vol . "/" . $private_image_name; return $new_rootdevice; }
$create_kernel_cloudselector_config = "insert into cloud_selector (id, type, sort_id, quantity, price, name, description, state) VALUES (" . $cloud_product_id . ", 'kernel', " . $next_sort_id . ", '" . $kernel->id . "', 1, '" . $kernel->name . "', '" . $kernel->version . "', 1);"; $recordSet = $db->Execute($create_kernel_cloudselector_config); $next_sort_id++; } } // create default projects $cloud_hook_config = array(); $cloud_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $create_default_usergroup = "insert into cloud_usergroups VALUES (" . $cloud_id . ",'Default'," . $cloud_id . ",'The Default Cloud Project');"; $recordSet = $db->Execute($create_default_usergroup); $cloud_admin_usergroup_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $create_default_usergroup = "insert into cloud_usergroups VALUES (" . $cloud_admin_usergroup_id . ",'Admin'," . $cloud_admin_usergroup_id . ",'The Admin Cloud Project');"; $recordSet = $db->Execute($create_default_usergroup); // create openqrm admin user $OPENQRM_ADMIN = new user('openqrm'); $OPENQRM_ADMIN->set_user(); $cloud_user = new clouduser(); $cloud_user_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $clouduser_fields["cu_id"] = $cloud_user_id; $clouduser_fields["cu_cg_id"] = $cloud_admin_usergroup_id; $clouduser_fields["cu_name"] = 'openqrm'; $clouduser_fields["cu_password"] = $OPENQRM_ADMIN->password; $clouduser_fields["cu_forename"] = 'openQRM'; $clouduser_fields["cu_lastname"] = 'Adminstrator'; $clouduser_fields["cu_email"] = 'root@localhost'; $clouduser_fields["cu_street"] = '-'; $clouduser_fields["cu_city"] = '-'; $clouduser_fields["cu_country"] = '-'; $clouduser_fields["cu_phone"] = '-'; $clouduser_fields["cu_status"] = 1; $clouduser_fields["cu_ccunits"] = 1000;
function storage_auth_function($cmd, $appliance_id) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $IMAGE_AUTHENTICATION_TABLE; global $openqrm_server; global $RootDir; $appliance = new appliance(); $appliance->get_instance_by_id($appliance_id); $image = new image(); $image->get_instance_by_id($appliance->imageid); $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; $resource = new resource(); $resource->get_instance_by_id($appliance->resources); $resource_mac = $resource->mac; $resource_ip = $resource->ip; // this is a hook for the cloud-plugin to be able // to translate the internal to the external ip address // for the nfs-mount authentication /* if (file_exists("$RootDir/plugins/cloud/.running")) { $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Found Cloud enabled and running. Checking for CloudNAT", "", "", 0, 0, $appliance_id); // special clouduser class require_once "$RootDir/plugins/cloud/class/cloudconfig.class.php"; require_once "$RootDir/plugins/cloud/class/cloudnat.class.php"; // check if we have to cloudnat the ip address $cn_conf = new cloudconfig(); $cn_nat_enabled = $cn_conf->get_value(18); // 18 is cloud_nat if (!strcmp($cn_nat_enabled, "true")) { $cn = new cloudnat(); $internal_resource_ip=$resource_ip; $resource_ip = $cn->translate($resource_ip); $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Found CloudNAT enabled, translated $internal_resource_ip to $resource_ip", "", "", 0, 0, $appliance_id); } else { $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Cloudnat is disabled, keeping $resource_ip", "", "", 0, 0, $appliance_id); } } else { $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Cloud is not enabled/running. Not checking for CloudNAT", "", "", 0, 0, $appliance_id); } */ switch ($cmd) { case "start": // authenticate the rootfs / needs openqrm user + pass $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Authenticating {$image_name} / {$image_rootdevice} to resource {$resource_ip}", "", "", 0, 0, $appliance_id); $auth_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $deployment_plugin_name . "/bin/openqrm-" . $deployment_plugin_name . " auth -n " . $image_name . " -r " . $image_rootdevice . " -i " . $resource_ip . " -t lvm-nfs-deployment -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background"; $resource->send_command($storage_ip, $auth_start_cmd); // authenticate the install-from-nfs export $run_disable_deployment_export = 0; $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, $appliance_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 " . $resource_ip . " -t " . $ip_deployment_type . " --openqrm-cmd-mode background"; $resource->send_command($ip_storage_ip, $auth_install_from_nfs_start_cmd); $run_disable_deployment_export = 1; } // authenticate the transfer-to-nfs export $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", "Transfer-to-NFS: Authenticating {$resource_ip} on storage id {$tp_storage_id}:{$tp_storage_ip}:{$tp_image_rootdevice}", "", "", 0, 0, $appliance_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 " . $resource_ip . " -t " . $tp_deployment_type . " --openqrm-cmd-mode background"; $resource->send_command($tp_storage_ip, $auth_install_from_nfs_start_cmd); $run_disable_deployment_export = 1; } // do we need to disable the install-from/transfer-to-nfs exports ? if ($run_disable_deployment_export == 1) { $image_authentication = new image_authentication(); $ia_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $image_auth_ar = array('ia_id' => $ia_id, 'ia_image_id' => $appliance->imageid, 'ia_resource_id' => $appliance->resources, 'ia_auth_type' => 1); $image_authentication->add($image_auth_ar); $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Registered image {$appliance->imageid} for de-authentication the deployment exports when resource {$appliance->resources} is fully up.", "", "", 0, 0, $appliance_id); } break; case "stop": $image_authentication = new image_authentication(); $ia_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $image_auth_ar = array('ia_id' => $ia_id, 'ia_image_id' => $appliance->imageid, 'ia_resource_id' => $appliance->resources, 'ia_auth_type' => 0); $image_authentication->add($image_auth_ar); $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Registered image {$appliance->imageid} for de-authentication the root-fs exports when resource {$appliance->resources} is idle again.", "", "", 0, 0, $appliance_id); break; } }
function openqrm_kvm_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); $virtualization = new virtualization(); $virtualization->get_instance_by_id($resource->vtype); $openqrm_admin_user = new user("openqrm"); $openqrm_admin_user->set_user(); switch ($cmd) { case "reboot": $event->log("openqrm_kvm_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-resource-virtual-command-hook.php", "Handling {$cmd} command", "", "", 0, 0, 0); if ($virtualization->type == "kvm-vm-local") { $virtual_command = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/kvm/bin/openqrm-kvm-vm restart_by_mac -m " . $resource->mac . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " -d noop --openqrm-cmd-mode background"; $host_resource->send_command($host_resource->ip, $virtual_command); } if ($virtualization->type == "kvm-vm-net") { // simply add to cmd queue. do not use resource->send_command(ip, reboot) since this will re-trigger this hook $cmd_token = md5(uniqid(rand(), true)); $resource_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/sbin/openqrm-exec -i " . $resource->ip . " -t " . $cmd_token . " -c reboot"; shell_exec($resource_command); } if ($virtualization->type == "kvm") { $cmd_token = md5(uniqid(rand(), true)); $resource_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/sbin/openqrm-exec -i " . $resource->ip . " -t " . $cmd_token . " -c reboot"; shell_exec($resource_command); } $resource_reboot_fields = array(); $resource_reboot_fields["resource_state"] = "transition"; $resource_reboot_fields["resource_event"] = "reboot"; $resource->update_info($resource->id, $resource_reboot_fields); break; case "halt": $event->log("openqrm_kvm_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-resource-virtual-command-hook.php", "Handling {$cmd} command", "", "", 0, 0, 0); if ($virtualization->type == "kvm-vm-local") { $virtual_command = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/kvm/bin/openqrm-kvm-vm stop_by_mac -m " . $resource->mac . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background"; $host_resource->send_command($host_resource->ip, $virtual_command); } if ($virtualization->type == "kvm-vm-net") { // simply add to cmd queue. do not use resource->send_command(ip, reboot) since this will re-trigger this hook $cmd_token = md5(uniqid(rand(), true)); $resource_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/sbin/openqrm-exec -i " . $resource->ip . " -t " . $cmd_token . " -c halt"; shell_exec($resource_command); } if ($virtualization->type == "kvm") { // simply add to cmd queue. do not use resource->send_command(ip, reboot) since this will re-trigger this hook $cmd_token = md5(uniqid(rand(), true)); $resource_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/sbin/openqrm-exec -i " . $resource->ip . " -t " . $cmd_token . " -c halt"; shell_exec($resource_command); } $resource_reboot_fields = array(); $resource_reboot_fields["resource_state"] = "off"; $resource_reboot_fields["resource_event"] = "reboot"; $resource->update_info($resource->id, $resource_reboot_fields); break; } }