本文整理汇总了PHP中resource::send_command方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::send_command方法的具体用法?PHP resource::send_command怎么用?PHP resource::send_command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource::send_command方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_lvm_iscsi_deployment_image_rootdevice_identifier
function get_lvm_iscsi_deployment_image_rootdevice_identifier($lvm_iscsi_storage_id)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_ADMIN;
global $event;
// place for the storage stat files
$StorageDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/plugins/lvm-storage/storage';
$rootdevice_identifier_array = array();
$storage = new storage();
$storage->get_instance_by_id($lvm_iscsi_storage_id);
$storage_resource = new resource();
$storage_resource->get_instance_by_id($storage->resource_id);
$storage_resource_id = $storage_resource->id;
$ident_file = "{$StorageDir}/{$storage_resource_id}.lv.lvm-iscsi-deployment.ident";
if (file_exists($ident_file)) {
unlink($ident_file);
}
// send command
$resource_command = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/lvm-storage/bin/openqrm-lvm-storage post_identifier -t lvm-iscsi-deployment -u {$OPENQRM_ADMIN->name} -p {$OPENQRM_ADMIN->password}";
$storage_resource->send_command($storage_resource->ip, $resource_command);
if (!lvm_iscsi_deployment_wait_for_identfile($ident_file)) {
$event->log("get_image_rootdevice_identifier", $_SERVER['REQUEST_TIME'], 2, "image.lvm-iscsi-deployment", "Timeout while requesting image identifier from storage id {$storage->id}", "", "", 0, 0, 0);
return;
}
$fcontent = file($ident_file);
foreach ($fcontent as $lun_info) {
$tpos = strpos($lun_info, ",");
$timage_name = trim(substr($lun_info, 0, $tpos));
$troot_device = trim(substr($lun_info, $tpos + 1));
$rootdevice_identifier_array[] = array("value" => "{$troot_device}", "label" => "{$timage_name}");
}
return $rootdevice_identifier_array;
}
示例2: openqrm_template_deployment_resource_virtual_command
function openqrm_template_deployment_resource_virtual_command($cmd, $resource_fields)
{
global $event;
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
$resource_id = $resource_fields["resource_id"];
$resource = new resource();
$resource->get_instance_by_id($resource_id);
$host_resource = new resource();
$host_resource->get_instance_by_id($resource->vhostid);
$event->log("openqrm_template_deployment_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-template_deployment-resource-virtual-command-hook.php", "Handling {$cmd} command of resource {$resource->id} on host {$host_resource->id}", "", "", 0, 0, 0);
switch ($cmd) {
case "reboot":
$event->log("openqrm_template_deployment_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-template_deployment-resource-virtual-command-hook.php", "Handling {$cmd} command", "", "", 0, 0, 0);
$virtual_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template_deployment/bin/openqrm-template_deployment-vm restart_by_mac -m " . $resource->mac . " -d noop --openqrm-cmd-mode background";
// reboot conflicts with appliance stop, commented out for now
//$host_resource->send_command($host_resource->ip, $virtual_command);
break;
case "halt":
$event->log("openqrm_template_deployment_resource_virtual_command", $_SERVER['REQUEST_TIME'], 5, "openqrm-template_deployment-resource-virtual-command-hook.php", "Handling {$cmd} command", "", "", 0, 0, 0);
$virtual_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template_deployment/bin/openqrm-template_deployment-vm stop_by_mac -m " . $resource->mac . " --openqrm-cmd-mode background";
$host_resource->send_command($host_resource->ip, $virtual_command);
break;
}
}
示例3: remove_template_vm
function remove_template_vm($host_resource_id, $name, $mac)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
// remove the vm from host
$host_resource = new resource();
$host_resource->get_instance_by_id($host_resource_id);
$event->log("remove_template_vm", $_SERVER['REQUEST_TIME'], 5, "template-cloud-hook", "Removing OpenVZ VM {$name}/{$mac} from Host resource {$host_resource_id}", "", "", 0, 0, 0);
// we need to have an openQRM server object too since some of the
// virtualization commands are sent from openQRM directly
$openqrm = new openqrm_server();
// send command to create the vm on the host
$vm_remove_cmd = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/template/bin/openqrm-template-vm delete -n " . $name . " --openqrm-cmd-mode background";
$event->log("remove_template_vm", $_SERVER['REQUEST_TIME'], 5, "template-cloud-hook", "Running {$vm_remove_cmd}", "", "", 0, 0, 0);
$host_resource->send_command($host_resource->ip, $vm_remove_cmd);
}
示例4: get_nfs_deployment_image_rootdevice_identifier
function get_nfs_deployment_image_rootdevice_identifier($nfs_storage_id)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_ADMIN;
global $event;
// place for the storage stat files
$StorageDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/plugins/nfs-storage/storage';
$rootdevice_identifier_array = array();
$storage = new storage();
$storage->get_instance_by_id($nfs_storage_id);
$storage_resource = new resource();
$storage_resource->get_instance_by_id($storage->resource_id);
$storage_resource_id = $storage_resource->id;
$ident_file = "{$StorageDir}/{$storage_resource_id}.nfs.ident";
$statfile_manual = "{$StorageDir}/" . $storage_resource_id . ".nfs.stat.manual";
// manual configured ?
if (file_exists($statfile_manual)) {
$fcontent = file($statfile_manual);
foreach ($fcontent as $lun_info) {
$troot_device = trim($lun_info);
$rootdevice_identifier_array[] = array("value" => "{$troot_device}", "label" => "{$troot_device}");
}
} else {
if (file_exists($ident_file)) {
unlink($ident_file);
}
// send command
$resource_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nfs-storage/bin/openqrm-nfs-storage post_identifier -u " . $OPENQRM_ADMIN->name . " -p " . $OPENQRM_ADMIN->password . " --openqrm-cmd-mode background";
$storage_resource->send_command($storage_resource->ip, $resource_command);
if (!nfs_deployment_wait_for_identfile($ident_file)) {
$event->log("get_image_rootdevice_identifier", $_SERVER['REQUEST_TIME'], 2, "image.nfs-deployment", "Timeout while requesting image identifier from storage id {$storage->id}", "", "", 0, 0, 0);
return;
}
$fcontent = file($ident_file);
foreach ($fcontent as $lun_info) {
$tpos = strpos($lun_info, ",");
$timage_name = trim(substr($lun_info, 0, $tpos));
$troot_device = trim(substr($lun_info, $tpos + 1));
$rootdevice_identifier_array[] = array("value" => "{$troot_device}", "label" => "{$timage_name}");
}
}
return $rootdevice_identifier_array;
}
示例5: fence_template_deployment_vm
function fence_template_deployment_vm($host_resource_id, $mac)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
// fences the vm on its host
$host_resource = new resource();
$host_resource->get_instance_by_id($host_resource_id);
$event->log("fence_template_deployment_vm", $_SERVER['REQUEST_TIME'], 5, "template_deployment-ha-hook", "Fencing OpenVZ VM {$mac} from Host resource {$host_resource_id}", "", "", 0, 0, 0);
// we need to have an openQRM server object too since some of the
// virtualization commands are sent from openQRM directly
$openqrm = new openqrm_server();
// send command to fence the vm on the host
$vm_fence_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template_deployment/bin/openqrm-template_deployment-vm fence -m " . $mac . " --openqrm-cmd-mode background";
$event->log("fence_template_deployment_vm", $_SERVER['REQUEST_TIME'], 5, "template_deployment-ha-hook", "Running {$vm_fence_cmd}", "", "", 0, 0, 0);
$host_resource->send_command($host_resource->ip, $vm_fence_cmd);
}
示例6: get_kvm_lvm_deployment_image_rootdevice_identifier
function get_kvm_lvm_deployment_image_rootdevice_identifier($kvm_lvm_id)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_ADMIN;
global $event;
// place for the storage stat files
$StorageDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/plugins/kvm/storage';
$rootdevice_identifier_array = array();
$storage = new storage();
$storage->get_instance_by_id($kvm_lvm_id);
// get deployment type
$deployment = new deployment();
$deployment->get_instance_by_id($storage->type);
// get storage resource
$storage_resource = new resource();
$storage_resource->get_instance_by_id($storage->resource_id);
$storage_resource_id = $storage_resource->id;
$ident_file = $StorageDir . "/" . $storage_resource_id . ".lv.kvm-lvm-deployment.ident";
if (file_exists($ident_file)) {
unlink($ident_file);
}
// send command
$resource_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm post_identifier -u " . $OPENQRM_ADMIN->name . " -p " . $OPENQRM_ADMIN->password . " -t " . $deployment->type;
$storage_resource->send_command($storage_resource->ip, $resource_command);
if (!kvm_lvm_deployment_wait_for_identfile($ident_file)) {
$event->log("get_image_rootdevice_identifier", $_SERVER['REQUEST_TIME'], 2, "image.kvm-lvm-deployment", "Timeout while requesting image identifier from storage id {$storage->id}", "", "", 0, 0, 0);
return;
}
$fcontent = file($ident_file);
foreach ($fcontent as $lun_info) {
$tpos = strpos($lun_info, ":");
$timage_name = trim(substr($lun_info, 0, $tpos));
$troot_device = trim(substr($lun_info, $tpos + 1));
$rootdevice_identifier_array[] = array("value" => "{$troot_device}", "label" => "{$timage_name}");
}
return $rootdevice_identifier_array;
}
示例7: create_private_lvm_nfs_deployment
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;
}
示例8: openqrm_kvm_appliance
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
//.........这里部分代码省略.........
示例9: storage
function __reload($mode)
{
$OPENQRM_SERVER_BASE_DIR = $this->openqrm->get('basedir');
$storage_id = $this->response->html->request()->get('storage_id');
$volgroup = $this->response->html->request()->get('volgroup');
$storage = new storage();
$resource = new resource();
$deployment = new deployment();
$storage->get_instance_by_id($storage_id);
$resource->get_instance_by_id($storage->resource_id);
$deployment->get_instance_by_id($storage->type);
$command = '';
$file = '';
// reload volume group
if ($mode === 'vg') {
$file = $OPENQRM_SERVER_BASE_DIR . '/plugins/kvm/web/storage/' . $resource->id . '.vg.stat';
$command .= $OPENQRM_SERVER_BASE_DIR . '/plugins/kvm/bin/openqrm-kvm post_vg -t ' . $deployment->type;
}
// reload logical volumes
if ($mode === 'lv') {
$file = $OPENQRM_SERVER_BASE_DIR . '/plugins/kvm/web/storage/' . $resource->id . '.' . $volgroup . '.lv.stat';
$command .= $OPENQRM_SERVER_BASE_DIR . '/plugins/kvm/bin/openqrm-kvm post_lv';
$command .= ' -v ' . $volgroup . ' -t ' . $deployment->type;
}
$command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
$command .= ' --openqrm-ui-user ' . $this->user->name;
$command .= ' --openqrm-cmd-mode background';
if ($this->file->exists($file)) {
$this->file->remove($file);
}
$resource->send_command($resource->ip, $command);
while (!$this->file->exists($file)) {
usleep(10000);
// sleep 10ms to unload the CPU
clearstatcache();
}
return true;
}
示例10: remove
function remove()
{
$response = $this->get_response();
$lvols = $response->html->request()->get($this->identifier_name);
$form = $response->form;
if ($lvols !== '') {
$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 ($lvols as $ex) {
$d['param_f' . $i]['label'] = $ex;
$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'] = $ex;
$d['param_f' . $i]['object']['attrib']['checked'] = true;
$i++;
}
$form->add($d);
if (!$form->get_errors() && $response->submit()) {
$name = $this->openqrm->admin()->name;
$pass = $this->openqrm->admin()->password;
$storage = new storage();
$resource = new resource();
$deployment = new deployment();
$storage->get_instance_by_id($this->response->html->request()->get('storage_id'));
$resource->get_instance_by_id($storage->resource_id);
$deployment->get_instance_by_id($storage->type);
$errors = array();
$message = array();
foreach ($lvols as $key => $lvol) {
// check if an appliance is still using the volume as an image
$image = new image();
$image->get_instance_by_name($lvol);
// check if it is still in use
$appliance = new appliance();
$appliances_using_resource = $appliance->get_ids_per_image($image->id);
if (count($appliances_using_resource) > 0) {
$appliances_using_resource_str = implode(",", $appliances_using_resource[0]);
$errors[] = sprintf($this->lang['msg_vm_image_still_in_use'], $lvol, $image->id, $appliances_using_resource_str);
} else {
$command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm remove';
$command .= ' -n ' . $lvol;
$command .= ' -v ' . $this->volgroup;
$command .= ' -t ' . $deployment->type;
$command .= ' -u ' . $name . ' -p ' . $pass;
$command .= ' --openqrm-ui-user ' . $this->user->name;
$command .= ' --openqrm-cmd-mode background';
$file = $this->openqrm->get('basedir') . '/plugins/kvm/web/storage/' . $resource->id . '.' . $this->volgroup . '.lv.stat';
if ($this->file->exists($file)) {
$this->file->remove($file);
}
$resource->send_command($resource->ip, $command);
while (!$this->file->exists($file)) {
usleep(10000);
// sleep 10ms to unload the CPU
clearstatcache();
}
$form->remove($this->identifier_name . '[' . $key . ']');
$message[] = sprintf($this->lang['msg_removed'], $lvol);
// remove the image of the volume
$image->remove_by_name($lvol);
}
}
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;
}
示例11: remove_nfs_deployment
function remove_nfs_deployment($cloud_image_id)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
$event->log("remove_nfs_deployment", $_SERVER['REQUEST_TIME'], 5, "nfs-deployment-cloud-hook", "Removing 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;
// nfs-storage
$image_location_name = basename($image_rootdevice);
$image_remove_clone_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nfs-storage/bin/openqrm-nfs-storage remove -n " . $image_location_name . " --openqrm-cmd-mode background";
$event->log("remove_nfs_deployment", $_SERVER['REQUEST_TIME'], 5, "nfs-deployment-cloud-hook", "Running : {$image_remove_clone_cmd}", "", "", 0, 0, 0);
$resource->send_command($resource_ip, $image_remove_clone_cmd);
}
示例12: openqrm_kvm_resource_virtual_command
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;
}
}
示例13: reload
function reload()
{
$command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm-vm post_vm_config';
$command .= ' -n ' . $this->vm;
$command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
$id = $this->response->html->request()->get('appliance_id');
$appliance = new appliance();
$appliance->get_instance_by_id($id);
$resource = new resource();
$resource->get_instance_by_id($appliance->resources);
$file = $this->openqrm->get('basedir') . '/plugins/kvm/web/kvm-stat/' . $resource->id . '.' . $this->vm . '.vm_config';
if ($this->file->exists($file)) {
$this->file->remove($file);
}
$resource->send_command($resource->ip, $command);
while (!$this->file->exists($file)) {
usleep(10000);
// sleep 10ms to unload the CPU
clearstatcache();
}
return true;
}
示例14: stop
function stop()
{
$response = $this->get_response();
$appliances = $response->html->request()->get($this->identifier_name);
$form = $response->form;
$appliance = new appliance();
if ($appliances !== '') {
$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 ($appliances as $id) {
$appliance = $appliance->get_instance_by_id($id);
$d['param_f' . $i]['label'] = $appliance->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 ($appliances as $key => $id) {
$appliance = $appliance->get_instance_by_id($id);
$resource = new resource();
$resource->get_instance_by_id($appliance->resources);
if ($appliance->resources == 0) {
$errors[] = sprintf($this->lang['msg_always_active'], $id);
continue;
}
// if no errors then we stop the appliance
$kernel = new kernel();
$kernel->get_instance_by_id($appliance->kernelid);
// send command to the openQRM-server
$resource->send_command("127.0.0.1", "openqrm_assign_kernel " . $resource->id . " " . $resource->mac . " default");
$appliance->stop();
$form->remove($this->identifier_name . '[' . $key . ']');
$message[] = sprintf($this->lang['msg'], $id);
}
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;
}
示例15: auth
function auth()
{
$response = $this->get_response();
$export = $response->html->request()->get('volume');
$form = $response->form;
if ($export !== '') {
if (!$form->get_errors() && $response->submit()) {
// set ENV
$storage_id = $this->response->html->request()->get('storage_id');
$storage = new storage();
$resource = new resource();
$storage->get_instance_by_id($storage_id);
$resource->get_instance_by_id($storage->resource_id);
$errors = array();
$message = array();
$auths = $form->get_request('ip');
$statfile = $this->openqrm->get('basedir') . '/plugins/nfs-storage/web/storage/' . $resource->id . '.nfs.stat';
$error = '';
$command = $this->openqrm->get('basedir') . '/plugins/nfs-storage/bin/openqrm-nfs-storage auth';
$command .= ' -n ' . $export . ' -i ' . $auths;
$command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
$command .= ' --openqrm-ui-user ' . $this->user->name;
$command .= ' --openqrm-cmd-mode background';
if ($this->file->exists($statfile)) {
$this->file->remove($statfile);
}
$resource->send_command($resource->ip, $command);
while (!$this->file->exists($statfile)) {
usleep(10000);
// sleep 10ms to unload the CPU
clearstatcache();
}
$message[] = sprintf($this->lang['msg_authd'], $export);
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;
}