function get_hybrid_cloud_appliance_link($appliance_id) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; $p_appliance = new appliance(); $p_appliance->get_instance_by_id($appliance_id); $p_resource = new resource(); $p_resource->get_instance_by_id($p_appliance->resources); $virtualization = new virtualization(); $virtualization->get_instance_by_id($p_appliance->virtualization); if ($virtualization->type != "hybrid-cloud-vm-local") { return; } // get hybrid-cloud account $hybrid_cloud_acl_id = $p_resource->get_resource_capabilities("HCACL"); if ($hybrid_cloud_acl_id == '') { $event->log("get_hybrid_cloud_appliance_link", $_SERVER['REQUEST_TIME'], 2, "openqrm-hybrid-cloud-appliance-link-hook.php", "Could not find Hybrid-Cloud Account for resource " . $p_resource->id, "", "", 0, 0, $appliance_id); return; } $hc = new hybrid_cloud(); $hc->get_instance_by_id($hybrid_cloud_acl_id); $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects'); $a = $html->a(); $a->label = 'Dashboard'; $a->css = 'badge'; $a->target = '_BLANK'; if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $a->href = 'https://console.aws.amazon.com/ec2/'; } if ($hc->account_type == 'lc-openstack') { $a->href = 'http://' . $hc->host . '/project/instances/'; } $plugin_link = $a->get_string(); return $plugin_link; }
function 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 remove_hybrid_cloud_vm_local($host_resource_id, $name, $mac) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $event; $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-cloud-hook", "Removing Cloud VM {$name}/{$mac} from Host resource {$host_resource_id}", "", "", 0, 0, 0); $openqrm = new openqrm_server(); $cloud_resource = new resource(); $cloud_resource->get_instance_by_mac($mac); $hc_default_account_id = $cloud_resource->get_resource_capabilities("HCACL"); $cloud_resource_hostname = $cloud_resource->hostname; if (strlen($hc_default_account_id)) { // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "!!! found Cloud Account ".$hc_default_account_id." from resource config", "", "", 0, 0, 0); } else { $file = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/etc/openqrm-plugin-hybrid-cloud.conf"; $ini = openqrm_parse_conf($file); $hc_default_account_id = $ini['OPENQRM_PLUGIN_HYBRID_CLOUD_DEFAULT_ACCOUNT']; // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "!!! got Cloud Account ".$hc_default_account_id." from plugin config", "", "", 0, 0, 0); } $hc = new hybrid_cloud(); $hc->get_instance_by_id($hc_default_account_id); $hc_authentication = ''; if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $hc_authentication .= ' -O ' . $hc->access_key; $hc_authentication .= ' -W ' . $hc->secret_key; } if ($hc->account_type == 'lc-openstack') { $hc_authentication .= ' -u ' . $hc->username; $hc_authentication .= ' -p ' . $hc->password; $hc_authentication .= ' -q ' . $hc->host; $hc_authentication .= ' -x ' . $hc->port; $hc_authentication .= ' -g ' . $hc->tenant; $hc_authentication .= ' -e ' . $hc->endpoint; } $openqrm = new openqrm_server(); $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm remove "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= $hc_authentication; $command .= ' -in ' . $cloud_resource_hostname; $command .= ' --openqrm-cmd-mode background'; // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "Running $command", "", "", 0, 0, 0); $openqrm->send_command($command, NULL, true); }
function openqrm_hybrid_cloud_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); $virtualization = new virtualization(); $virtualization->get_instance_by_id($resource->vtype); switch ($virtualization->type) { case "hybrid-cloud": $event->log("openqrm_hybrid_cloud_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-resource-virtual-command-hook.php", "Handling " . $cmd . " command of resource " . $resource->id, "", "", 0, 0, 0); // noop break; case "hybrid-cloud-vm-local": $event->log("openqrm_hybrid_cloud_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-resource-virtual-command-hook.php", "Handling " . $cmd . " command of resource " . $resource->id, "", "", 0, 0, 0); $openqrm_server = new openqrm_server(); // get hybrid-cloud account $hybrid_cloud_acl_id = $resource->get_resource_capabilities("HCACL"); if ($hybrid_cloud_acl_id == '') { $event->log("openqrm_hybrid_cloud_resource_virtual_command", $_SERVER['REQUEST_TIME'], 2, "openqrm-hybrid-cloud-resource-virtual-command-hook.php", "Could not find Hybrid-Cloud Account for resource " . $resource->id, "", "", 0, 0, $appliance_id); return; } $hc = new hybrid_cloud(); $hc->get_instance_by_id($hybrid_cloud_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; } switch ($cmd) { case "reboot": $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm restart "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= ' -in ' . $resource->hostname; $command .= $hc_authentication; $command .= ' --openqrm-cmd-mode background'; $openqrm_server->send_command($command, NULL, true); break; case "halt": $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm stop "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= ' -in ' . $resource->hostname; $command .= $hc_authentication; $command .= ' --openqrm-cmd-mode background'; $openqrm_server->send_command($command, NULL, true); break; } break; } }
function check_all_states() { global $RESOURCE_INFO_TABLE; global $RESOURCE_TIME_OUT; global $RootDir; global $event; $resource_list = array(); $db = openqrm_get_db_connection(); $rs = $db->Execute("select resource_id, resource_lastgood, resource_state from {$RESOURCE_INFO_TABLE}"); if (!$rs) { $event->log("check_all_states", $_SERVER['REQUEST_TIME'], 2, "resource.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$rs->EOF) { $resource_id = $rs->fields['resource_id']; $resource_lastgood = $rs->fields['resource_lastgood']; $resource_state = $rs->fields['resource_state']; $check_time = $_SERVER['REQUEST_TIME']; // get the HA-timeout per resource from the capabilites $custom_resource_ha_timeout = ""; $resource_hat = new resource(); $resource_hat->get_instance_by_id($resource_id); $custom_resource_ha_timeout = $resource_hat->get_resource_capabilities("HAT"); if (strlen($custom_resource_ha_timeout)) { $RESOURCE_TIME_OUT = $custom_resource_ha_timeout; } // resolve errors for all active resources if ("{$resource_state}" == "active" && $resource_id != 0) { if ($check_time - $resource_lastgood < $RESOURCE_TIME_OUT) { // resolve error event $event->resolve_by_resource("check_all_states", $resource_id); } } // check for statistics (errors) for all resources which are not offline // exclude manual added resources from the check ! if ("{$resource_state}" != "off" && "{$resource_lastgood}" != "-1") { if ($check_time - $resource_lastgood > $RESOURCE_TIME_OUT) { $resource_fields = array(); $resource_fields["resource_state"] = "error"; $resource_error = new resource(); $resource_error->update_info($resource_id, $resource_fields); // log error event $event->log("check_all_states", $_SERVER['REQUEST_TIME'], 1, "resource.class.php", "Resource {$resource_id} is in error state", "", "", 0, 0, $resource_id); // check for plugin which may want to handle the error event $plugin = new plugin(); $enabled_plugins = $plugin->enabled(); foreach ($enabled_plugins as $index => $plugin_name) { $plugin_ha_hook = "{$RootDir}/plugins/{$plugin_name}/openqrm-{$plugin_name}-ha-hook.php"; if (file_exists($plugin_ha_hook)) { $event->log("check_all_states", $_SERVER['REQUEST_TIME'], 1, "resource.class.php", "Found {$plugin_name} handling the resource error.", "", "", 0, 0, $resource_id); require_once "{$plugin_ha_hook}"; $ha_function = "openqrm_" . "{$plugin_name}" . "_ha_hook"; $ha_function = str_replace("-", "_", $ha_function); $ha_function($resource_id); } } } } $rs->MoveNext(); } } }
function find_host_to_start_from_off($virtualization_type_id, $resource_pools_enabled, $cu_id, $timeout) { global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $RESOURCE_INFO_TABLE; global $vmware_mac_address_space; global $RootDir; $this->init($timeout); global $event; // find out the host virtualization type via the plugin name $vhost_type = new virtualization(); $vhost_type->get_instance_by_id($virtualization_type_id); $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 5, "cloudhoststartfromoff.class.php", "Trying to find a powered-off virtualization host from type {$vhost_type->type} {$vhost_type->name}", "", "", 0, 0, 0); // for all in appliance list, find virtualization host appliances $appliance_tmp = new appliance(); $appliance_id_list = $appliance_tmp->get_all_ids(); $in_active_appliance_list = array(); foreach ($appliance_id_list as $id_arr) { foreach ($id_arr as $id) { $appliance = new appliance(); $appliance->get_instance_by_id($id); $sfo_resource = new resource(); $sfo_resource->get_instance_by_id($appliance->resources); // state off ? if (!strcmp($appliance->state, "stopped") && !strcmp($sfo_resource->state, "off")) { if ($appliance->virtualization == $virtualization_type_id) { // we have found an active appliance from the right virtualization type // // 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("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.class.php", "Hostlimit max_vm is reached for resource {$appliance->resources}", "", "", 0, 0, $appliance->resources); continue; } } } // resource pooling enabled ? if (strcmp($resource_pools_enabled, "true")) { // disabled, add any appliance from the right virtualization type // $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 5, "cloudhoststartfromoff.class.php", "resource pooling is disabled", "", "", 0, 0, 0); // check if the resource can start-from-off $can_start_from_off = $sfo_resource->get_resource_capabilities('SFO'); if ($can_start_from_off == 1) { $in_active_appliance_list[] .= $id; $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 5, "cloudhoststartfromoff.class.php", "Resource pooling is disabled, adding appliance {$id}", "", "", 0, 0, 0); } else { $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.class.php", "Resource pooling is disabled, resource of appliance {$id} cannot start-from-off", "", "", 0, 0, 0); } } else { // $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.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("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.class.php", "resource pool id $private_resource->id ", "", "", 0, 0, 0); if (strlen($private_resource->id)) { // $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.class.php", "resource $appliance->resources is in a resource pool", "", "", 0, 0, 0); // is it hidden ? if ($private_resource->cg_id >= 0) { // $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.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("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.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 // check if the resource can start-from-off $sfo_resource = new resource(); $sfo_resource->get_instance_by_id($appliance->resources); $can_start_from_off = $sfo_resource->get_resource_capabilities('SFO'); if ($can_start_from_off == 1) { $in_active_appliance_list[] .= $id; $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 5, "cloudhoststartfromoff.class.php", "Adding appliance {$id}", "", "", 0, 0, 0); } else { $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.class.php", "Resource of appliance {$id} cannot start-from-off", "", "", 0, 0, 0); } } else { $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.class.php", "Appliance {$id} (resource {$appliance->resources}) is NOT in dedicated for the users group", "", "", 0, 0, 0); } } else { $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.class.php", "Appliance {$id} (resource {$appliance->resources}) is marked as hidden", "", "", 0, 0, 0); } } else { $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.class.php", "Appliance {$id} (resource {$appliance->resources}) is NOT member of any resource pools", "", "", 0, 0, 0); } } } } } } // did we found any active host ? if (count($in_active_appliance_list) < 1) { $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.class.php", "Warning ! There is no virtualization host type {$vhost_type->name} available to start-from-off", "", "", 0, 0, 0); $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.class.php", "Warning : Giving up to start a virtualization host type {$vhost_type->name} from power-off state .....", "", "", 0, 0, 0); return 0; } // simply take the first one foreach ($in_active_appliance_list as $in_active_id) { $in_active_appliance = new appliance(); $in_active_appliance->get_instance_by_id($in_active_id); break; } // simply start the appliance, the rest will be done by the appliance start hook sending power-on // monitor until it is fully up or timeout $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 5, "cloudhoststartfromoff.class.php", "Notice: Starting host appliance {$in_active_id}, waiting until it is fully active ...", "", "", 0, 0, 0); $in_active_appliance->start(); // check until it is full up $in_active_resource = new resource(); $sec_loops = 0; while (0 == 0) { echo " "; flush(); sleep(2); $sec_loops++; $sec_loops++; // check if the resource is active $in_active_resource->get_instance_by_id($in_active_appliance->resources); if (!strcmp($in_active_resource->state, "active")) { // the host is up :) return the appliance id of the host $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 5, "cloudhoststartfromoff.class.php", "Notice: Host resource id {$in_active_resource->id} successfully started from power-off", "", "", 0, 0, 0); return $in_active_id; } if ($this->timeout <= $sec_loops) { $event->log("find_host_to_start_from_off", $_SERVER['REQUEST_TIME'], 2, "cloudhoststartfromoff.class.php", "Error:Timeout while waiting for resource id {$in_active_resource->id} to start-from-off", "", "", 0, 0, 0); return 0; } } }
function openqrm_hybrid_cloud_appliance($cmd, $appliance_fields) { global $event; global $OPENQRM_SERVER_BASE_DIR; global $OPENQRM_SERVER_IP_ADDRESS; global $OPENQRM_EXEC_PORT; global $IMAGE_AUTHENTICATION_TABLE; global $RootDir; $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"]); $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; } $event->log("openqrm_hybrid_cloud_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-appliance-hook.php", "Handling " . $cmd . " event " . $appliance_id . "/" . $appliance_name . "/" . $appliance_ip, "", "", 0, 0, $appliance_id); // check resource type -> hybrid-cloud-strorage-vm $virtualization = new virtualization(); $virtualization->get_instance_by_id($resource->vtype); switch ($virtualization->type) { case "hybrid-cloud-vm-local": $image = new image(); $image->get_instance_by_id($appliance->imageid); // get hybrid-cloud account $hybrid_cloud_acl_id = $resource->get_resource_capabilities("HCACL"); if ($hybrid_cloud_acl_id == '') { $event->log("openqrm_hybrid_cloud_appliance", $_SERVER['REQUEST_TIME'], 2, "openqrm-hybrid-cloud-appliance-hook.php", "Could not find Hybrid-Cloud Account for resource " . $resource->id, "", "", 0, 0, $appliance_id); return; } $hc = new hybrid_cloud(); $hc->get_instance_by_id($hybrid_cloud_acl_id); $hc_authentication = ''; if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $hc_authentication .= ' -O ' . $hc->access_key; $hc_authentication .= ' -W ' . $hc->secret_key; } if ($hc->account_type == 'lc-openstack') { $hc_authentication .= ' -u ' . $hc->username; $hc_authentication .= ' -p ' . $hc->password; $hc_authentication .= ' -q ' . $hc->host; $hc_authentication .= ' -x ' . $hc->port; $hc_authentication .= ' -g ' . $hc->tenant; $hc_authentication .= ' -e ' . $hc->endpoint; } $statfile = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/web/hybrid-cloud-stat/" . $hybrid_cloud_acl_id . ".run_instances.hostname"; switch ($cmd) { case "start": // send command to assign image and start instance $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm run "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= $hc_authentication; $command .= ' -in ' . $resource->hostname; $command .= ' -a ' . $image->rootdevice; $command .= ' -ii ' . $image->id; $command .= ' -ia ' . $appliance->name; $command .= ' --openqrm-cmd-mode background'; // wait for hostname statfile if (file_exists($statfile)) { unlink($statfile); } $openqrm_server->send_command($command, NULL, true); while (!file_exists($statfile)) { usleep(10000); clearstatcache(); } // special hostname handling for aws + euca if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $resource_new_hostname = file_get_contents($statfile); $resource_new_hostname = trim($resource_new_hostname); unlink($statfile); // update hostname in resource $resource_fields["resource_hostname"] = $resource_new_hostname; $resource->update_info($resource->id, $resource_fields); } // reset image_isactive -> AMI are cloned anyway $image->set_active(1); break; case "stop": // send command to stop the vm and deassign image $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm terminate "; $command .= ' -i ' . $hc->id; $command .= ' -n ' . $hc->account_name; $command .= ' -t ' . $hc->account_type; $command .= $hc_authentication; $command .= ' -in ' . $resource->hostname; $command .= ' --openqrm-cmd-mode background'; $openqrm_server->send_command($command, NULL, true); // special hostname handling for aws + euca if ($hc->account_type == 'aws' || $hc->account_type == 'euca') { $resource_new_hostname = $hc->account_type . $resource->id; // update hostname in resource $resource_fields["resource_hostname"] = $resource_new_hostname; $resource->update_info($resource->id, $resource_fields); } break; } break; } }