本文整理汇总了PHP中image::update方法的典型用法代码示例。如果您正苦于以下问题:PHP image::update方法的具体用法?PHP image::update怎么用?PHP image::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image
的用法示例。
在下文中一共展示了image::update方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_clone_lvm_nfs_deployment
function create_clone_lvm_nfs_deployment($cloud_image_id, $image_clone_name, $disk_size)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
$event->log("create_clone", $_SERVER['REQUEST_TIME'], 5, "lvm-nfs-deployment-cloud-hook", "Creating clone of 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, this is already the new logical clone
// we just need to physical snapshot it and update the rootdevice
$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;
$full_vol_name = $image_rootdevice;
$vol_dir = dirname($full_vol_name);
$vol = str_replace("/", "", $vol_dir);
$image_location_name = basename($full_vol_name);
// set default snapshot size
if (!strlen($disk_size)) {
$disk_size = 5000;
}
// update the image rootdevice parameter
$image->get_instance_by_id($image_id);
$ar_image_update = array('image_rootdevice' => "/{$vol}/{$image_clone_name}");
$image->update($image_id, $ar_image_update);
$event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "lvm-nfs-deployment-cloud-hook", "Updating rootdevice of image {$image_id} / {$image_name} with /{$vol}/{$image_clone_name}", "", "", 0, 0, 0);
$image_clone_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/lvm-storage/bin/openqrm-lvm-storage snap -n " . $image_location_name . " -v " . $vol . " -t lvm-nfs-deployment -s " . $image_clone_name . " -m " . $disk_size . " --openqrm-cmd-mode background";
$event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "lvm-nfs-deployment-cloud-hook", "Running : {$image_clone_cmd}", "", "", 0, 0, 0);
$resource->send_command($resource_ip, $image_clone_cmd);
}
示例2: create_clone_iscsi_deployment
function create_clone_iscsi_deployment($cloud_image_id, $image_clone_name, $disk_size)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
$event->log("create_clone", $_SERVER['REQUEST_TIME'], 5, "iscsi-deployment-cloud-hook", "Creating clone of 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, this is already the new logical clone
// we just need to physical snapshot it and update the rootdevice
$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;
// generate a new image password for the clone
$image->get_instance_by_id($image_id);
$image_password = $image->generatePassword(12);
$image->set_deployment_parameters("IMAGE_ISCSI_AUTH", $image_password);
$image_location = dirname($image_rootdevice);
$image_location_name = basename($image_location);
// update the image rootdevice parameter
$ar_image_update = array('image_rootdevice' => "/dev/{$image_clone_name}/1");
$event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "iscsi-deployment-cloud-hook", "Updating rootdevice of image {$image_id} / {$image_name} with /dev/{$image_clone_name}/1", "", "", 0, 0, 0);
$image->update($image_id, $ar_image_update);
$image_clone_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/iscsi-storage/bin/openqrm-iscsi-storage snap -n " . $image_location_name . " -s " . $image_clone_name . " -i " . $image_password . " --openqrm-cmd-mode background";
$event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "iscsi-deployment-cloud-hook", "Running : {$image_clone_cmd}", "", "", 0, 0, 0);
$resource->send_command($resource_ip, $image_clone_cmd);
}
示例3: create_clone_kvm_gluster_deployment
function create_clone_kvm_gluster_deployment($cloud_image_id, $image_clone_name, $disk_size)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
// we got the cloudimage id here, get the image out of it
$cloudimage = new cloudimage();
$cloudimage->get_instance_by_id($cloud_image_id);
$event->log("create_clone_kvm_gluster_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-gluster-deployment-cloud-hook.php", "Creating clone " . $image_clone_name . " of image " . $cloudimage->image_id . " on the storage", "", "", 0, 0, 0);
// get image, this is already the new logical clone
// we just need to physical snapshot it and update the rootdevice
$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;
// kvm-gluster-deployment
$image->get_instance_by_id($image_id);
$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']));
// set default snapshot size
if (!strlen($disk_size)) {
$disk_size = 5000;
}
// update the image rootdevice parameter
$ar_image_update = array('image_rootdevice' => "gluster:" . $resource->ip . "//" . $image_location_name . "/" . $image_clone_name);
// get the vm resource
$vm_resource = new resource();
$vm_resource->get_instance_by_id($cloudimage->resource_id);
// get the VM host
$vm_host_resource = new resource();
$vm_host_resource->get_instance_by_id($vm_resource->vhostid);
$event->log("create_clone_kvm_gluster_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-gluster-deployment-cloud-hook.php", "Updating rootdevice of image " . $image_id . " / " . $image_name . " with " . $image_location_name . "/" . $image_clone_name, "", "", 0, 0, 0);
$image->update($image_id, $ar_image_update);
$image_clone_cmd = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/kvm/bin/openqrm-kvm snap -n " . $origin_volume_name . " -v " . $image_location_name . " -s " . $image_clone_name . " -m " . $disk_size . " -t " . $deployment->type . " --openqrm-cmd-mode background";
$event->log("create_clone_kvm_gluster_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-gluster-deployment-cloud-hook.php", "Running : " . $image_clone_cmd, "", "", 0, 0, 0);
$resource->send_command($resource->ip, $image_clone_cmd);
}
示例4: stripslashes
$deployment_switch->get_instance_by_id($image_type);
$image_fields["image_type"] = $deployment_switch->type;
// unquote
$image_deployment_parameter = $image_fields["image_deployment_parameter"];
$image_fields["image_deployment_parameter"] = stripslashes($image_deployment_parameter);
$image->add($image_fields);
break;
case 'update_image':
$image = new image();
if (!strlen($image_fields["image_isshared"])) {
$image_fields["image_isshared"] = "0";
}
// unquote
$image_deployment_parameter = $image_fields["image_deployment_parameter"];
$image_fields["image_deployment_parameter"] = stripslashes($image_deployment_parameter);
$image->update($image_id, $image_fields);
break;
case 'remove':
$image = new image();
$image->remove($image_id);
break;
case 'remove_by_name':
$image = new image();
$image->remove_by_name($image_name);
break;
case 'add_deployment_type':
$deployment = new deployment();
$deployment_fields["deployment_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
$deployment->add($deployment_fields);
break;
case 'remove_deployment_type':
示例5: create_clone_template_deployment
function create_clone_template_deployment($cloud_image_id, $image_clone_name, $disk_size)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
$event->log("create_clone", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Creating clone of 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, this is already the new logical clone
// we just need to physical snapshot it and update the rootdevice
$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;
// template_deployment
$image->get_instance_by_id($image_id);
// 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);
// set default snapshot size
if (!strlen($disk_size)) {
$disk_size = 5000;
}
// update the image rootdevice parameter
$ar_image_update = array('image_rootdevice' => "/dev/{$volume_group}/{$image_clone_name}");
// 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
// get the vm resource
$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_clone_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);
// update the image storage id with the vm-host-resource
$image_deployment = new deployment();
$image_deployment->get_instance_by_type($image_type);
// loop over all storage id from type $image_type
$found_image_storage = 0;
$storage_list_by_type = new storage();
$storage_id_list_by_type = $storage_list_by_type->get_ids_by_storage_type($image_deployment->id);
foreach ($storage_id_list_by_type as $storage_id_list) {
$storage_id = $storage_id_list['storage_id'];
$tstorage = new storage();
$tstorage->get_instance_by_id($storage_id);
if ($tstorage->resource_id == $vm_host_resource->id) {
// re-create update array + new storage id
$ar_image_update = array('image_rootdevice' => "/dev/{$volume_group}/{$image_clone_name}", 'image_storageid' => $tstorage->id);
$event->log("create_clone_template_deployment", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Updating Image {$image_id} / {$image_name} with storage id {$tstorage->id}", "", "", 0, 0, $appliance_id);
$found_image_storage = 1;
break;
}
}
if ($found_image_storage == 0) {
$event->log("create_clone_template_deployment", $_SERVER['REQUEST_TIME'], 2, "template_deployment-cloud-hook", "SETUP ERROR: Could not find a storage server type {$image_type} using resource {$vm_host_resource->id}. Please create one!", "", "", 0, 0, $appliance_id);
$event->log("create_clone_template_deployment", $_SERVER['REQUEST_TIME'], 2, "template_deployment-cloud-hook", "SETUP ERROR: Not cloning image {$image_id}", "", "", 0, 0, $appliance_id);
return;
}
} else {
$event->log("create_clone_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);
}
$event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Updating rootdevice of image {$image_id} / {$image_name} with /dev/{$volume_group}/{$image_clone_name}", "", "", 0, 0, 0);
$image->update($image_id, $ar_image_update);
$image_clone_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template/bin/openqrm-template snap -n " . $image_location_name . " -v " . $volume_group . " -s " . $image_clone_name . " -m " . $disk_size . " --openqrm-cmd-mode background";
$event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "template_deployment-cloud-hook", "Running on {$vm_host_resource->ip} : {$image_clone_cmd}", "", "", 0, 0, 0);
$resource->send_command($vm_host_resource->ip, $image_clone_cmd);
}
示例6: edit
function edit()
{
$response = $this->get_response();
$form = $response->form;
$id = $this->response->html->request()->get('image_id');
if ($id !== '') {
// check password
$pass = $form->get_request('image_password');
if ($pass !== '' && $pass !== $form->get_request('image_password_2')) {
$form->set_error('image_password_2', $this->lang['error_password']);
}
$image = new image();
$image->get_instance_by_id($id);
if (!$form->get_errors() && $this->response->submit()) {
$image_password = $this->response->html->request()->get('image_password');
$install_from_local = $this->response->html->request()->get('install_from_local');
$transfer_to_local = $this->response->html->request()->get('transfer_to_local');
$install_from_nfs = $this->response->html->request()->get('install_from_nfs');
$transfer_to_nfs = $this->response->html->request()->get('transfer_to_nfs');
$install_from_template = $this->response->html->request()->get('install_from_template');
$image_comment = $this->response->html->request()->get('image_comment');
$image_version = $this->response->html->request()->get('image_version');
// update image
$fields['image_comment'] = $image_comment;
$fields['image_version'] = $image_version;
$image->update($id, $fields);
$image->get_instance_by_id($id);
# set password if given
if (strlen($image_password)) {
$image->set_root_password($id, $image_password);
} else {
$CMD = "rm -f " . $this->openqrm->get('basedir') . "/web/action/image-auth/iauth." . $id . ".php";
exec($CMD);
}
// install-from-nfs
if (strlen($install_from_nfs)) {
$install_from_nfs_image = new image();
$install_from_nfs_image->get_instance_by_id($install_from_nfs);
$install_from_nfs_storage = new storage();
$install_from_nfs_storage->get_instance_by_id($install_from_nfs_image->storageid);
$install_from_nfs_storage_resource = new resource();
$install_from_nfs_storage_resource->get_instance_by_id($install_from_nfs_storage->resource_id);
$install_from_nfs_storage_ip = $install_from_nfs_storage_resource->ip;
$install_from_nfs_storage_path = $install_from_nfs_image->rootdevice;
$install_from_nfs_path = $install_from_nfs_image->storageid . ":" . $install_from_nfs_storage_ip . ":" . $install_from_nfs_storage_path;
$image->set_deployment_parameters("IMAGE_INSTALL_FROM_NFS", $install_from_nfs_path);
} else {
$image->set_deployment_parameters("IMAGE_INSTALL_FROM_NFS", "");
}
// transfer-to-nfs, we have to refresh the image object here
$image->get_instance_by_id($id);
if (strlen($transfer_to_nfs)) {
$transfer_to_nfs_image = new image();
$transfer_to_nfs_image->get_instance_by_id($transfer_to_nfs);
$transfer_to_nfs_storage = new storage();
$transfer_to_nfs_storage->get_instance_by_id($transfer_to_nfs_image->storageid);
$transfer_to_nfs_storage_resource = new resource();
$transfer_to_nfs_storage_resource->get_instance_by_id($transfer_to_nfs_storage->resource_id);
$transfer_to_nfs_storage_ip = $transfer_to_nfs_storage_resource->ip;
$transfer_to_nfs_storage_path = $transfer_to_nfs_image->rootdevice;
$transfer_to_nfs_path = $transfer_to_nfs_image->storageid . ":" . $transfer_to_nfs_storage_ip . ":" . $transfer_to_nfs_storage_path;
$image->set_deployment_parameters("IMAGE_TRANSFER_TO_NFS", $transfer_to_nfs_path);
} else {
$image->set_deployment_parameters("IMAGE_TRANSFER_TO_NFS", "");
}
// install-from-local, we have to refresh the image object again
$image->get_instance_by_id($id);
if (strlen($install_from_local)) {
$image->set_deployment_parameters("IMAGE_INSTALL_FROM_LOCAL", $install_from_local);
} else {
$image->set_deployment_parameters("IMAGE_INSTALL_FROM_LOCAL", "");
}
// transfer-to-local, we have to refresh the image object again
$image->get_instance_by_id($id);
if (strlen($transfer_to_local)) {
$image->set_deployment_parameters("IMAGE_TRANSFER_TO_LOCAL", $transfer_to_local);
} else {
$image->set_deployment_parameters("IMAGE_TRANSFER_TO_LOCAL", "");
}
// reset deployment parameter INSTALL_CONFIG
$image->set_deployment_parameters("INSTALL_CONFIG", "");
if (strlen($install_from_template)) {
// redirect to install-from-template step1
$response->msg = 'install-from-template';
$response->install_from_template = $install_from_template;
} else {
$response->msg = sprintf($this->lang['msg'], $image->name);
}
$response->image_id = $id;
}
$response->name = $image->name;
} else {
$response->msg = '';
}
return $response;
}
示例7: header
$uploadOk1 = 1;
} else {
echo "File is not an image.";
$uploadOk1 = 0;
}
if (!in_array($type1, $allowed_types1)) {
$error[] = 'plz, upload image type';
} else {
if ($size1 > 42565433) {
$error[] = 'plz, dun exceed the max limit of size';
} else {
move_uploaded_file($tmp_name1, 'images/' . $name1);
}
}
if (!isset($_POST['option'])) {
$error[] = 'plz , select a product';
}
if (!empty($error)) {
$_SESSION['errors'] = $error;
header('location: update_image.php?id=' . $_POST['id'] . '&p_id=' . $_POST['p_id']);
} else {
$img->image_path = $name;
$img->image_path_1 = $name1;
$img->product_id = $_POST['option'];
$img->update();
header('location: image_control.php');
}
} else {
echo "you must submit the form";
}
}
示例8: create_clone_kvm_lvm_deployment
function create_clone_kvm_lvm_deployment($cloud_image_id, $image_clone_name, $disk_size)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
// clone or snap cloud action
$kvm_plugin_config = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/etc/openqrm-plugin-kvm.conf";
$store = openqrm_parse_conf($kvm_plugin_config);
$kvm_plugin_cloud_create_volume_action = "snap";
if (isset($store['OPENQRM_PLUGIN_KVM_CLOUD_CREATE_VOLUME_ACTION'])) {
if ($store['OPENQRM_PLUGIN_KVM_CLOUD_CREATE_VOLUME_ACTION'] == 'clone') {
$kvm_plugin_cloud_create_volume_action = "clone";
}
}
// we got the cloudimage id here, get the image out of it
$cloudimage = new cloudimage();
$cloudimage->get_instance_by_id($cloud_image_id);
$event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Creating clone " . $image_clone_name . " of image " . $cloudimage->image_id . " on the storage", "", "", 0, 0, 0);
// get image, this is already the new logical clone
// we just need to physical snapshot it and update the rootdevice
$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;
$openqrm_admin_user = new user("openqrm");
$openqrm_admin_user->set_user();
// 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;
// kvm-lvm-deployment
$image->get_instance_by_id($image_id);
// 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);
// set default snapshot size
if (!strlen($disk_size)) {
$disk_size = 5000;
}
// update the image rootdevice parameter
$ar_image_update = array('image_rootdevice' => "/dev/" . $volume_group . "/" . $image_clone_name);
// 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
// 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_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-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);
// update the image storage id with the vm-host-resource
$image_deployment = new deployment();
$image_deployment->get_instance_by_type($image_type);
// loop over all storage id from type $image_type
$found_image = 0;
$storage_list_by_type = new storage();
$storage_id_list_by_type = $storage_list_by_type->get_ids_by_storage_type($image_deployment->id);
foreach ($storage_id_list_by_type as $storage_id_list) {
$storage_id = $storage_id_list['storage_id'];
$tstorage = new storage();
$tstorage->get_instance_by_id($storage_id);
if ($tstorage->resource_id == $vm_host_resource->id) {
// re-create update array + new storage id
$ar_image_update = array('image_rootdevice' => "/dev/" . $volume_group . "/" . $image_clone_name, 'image_storageid' => $tstorage->id);
$event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-cloud-hook.php", "Updating Image " . $image_id . " / " . $image_name . " with storage id " . $tstorage->id . ".", "", "", 0, 0, 0);
$found_image = 1;
break;
}
}
if ($found_image == 0) {
$event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 2, "openqrm-kvm-lvm-deployment-cloud-hook.php", "SETUP ERROR: Could not find a storage server type " . $image_type . " using resource " . $vm_host_resource->id . ". Please create one!", "", "", 0, 0, 0);
$event->log("create_clone_kvm_lvm_deployment", $_SERVER['REQUEST_TIME'], 2, "openqrm-kvm-lvm-deployment-cloud-hook.php", "SETUP ERROR: Not cloning image " . $image_id . ".", "", "", 0, 0, 0);
return;
}
} else {
//.........这里部分代码省略.........
示例9: add
function add()
{
$response = $this->get_response();
$form = $response->form;
$errors = array();
if (!$form->get_errors() && $this->response->submit()) {
$image_id = $form->get_request('ami_image_id');
$image = new image();
if (isset($image_id) && $image_id !== '') {
$image->get_instance_by_id($image_id);
} else {
$errors[] = $this->lang['error_boot'];
}
if (count($errors) > 0 || $form->get_errors()) {
$response->error = join('<br>', $errors);
} else {
$tables = $this->openqrm->get('table');
$custom_script_parameter = '';
$custom_script = $form->get_request('custom_script');
if (strlen($custom_script)) {
$custom_script_parameter = ' -ic ' . $custom_script;
}
$custom_name = $form->get_request('name');
$resource = new resource();
$id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
if (strlen($custom_name)) {
$name = $custom_name;
} else {
$name = $this->hc->account_type . $id;
}
$ip = "0.0.0.0";
$resource->generate_mac();
$mac = $resource->mac;
// send command to the openQRM-server
$openqrm = new openqrm_server();
$openqrm->send_command('openqrm_server_add_resource ' . $id . ' ' . $mac . ' ' . $ip);
// set resource type
$virtualization = new virtualization();
$virtualization->get_instance_by_type("hybrid-cloud-vm-local");
// add to openQRM database
$fields["resource_id"] = $id;
$fields["resource_ip"] = $ip;
$fields["resource_mac"] = $mac;
$fields["resource_hostname"] = $name;
$fields["resource_localboot"] = 0;
$fields["resource_vtype"] = $virtualization->id;
$fields["resource_vhostid"] = 0;
$fields["resource_image"] = $image->name;
$fields["resource_imageid"] = $image->id;
$rfields["resource_kernel"] = 'default';
$rfields["resource_kernelid"] = 1;
$resource->add($fields);
$resource->get_instance_by_mac($mac);
// set account id in resource capabilities
$resource->set_resource_capabilities("HCACL", $this->hc->id);
$hc_authentication = '';
if ($this->hc->account_type == 'aws' || $this->hc->account_type == 'euca') {
$hc_authentication .= ' -O ' . $this->hc->access_key;
$hc_authentication .= ' -W ' . $this->hc->secret_key;
$hc_authentication .= ' -ir ' . $this->region;
$hc_authentication .= ' -iz ' . $form->get_request('availability_zone');
}
if ($this->hc->account_type == 'lc-openstack') {
$hc_authentication .= ' -u ' . $this->hc->username;
$hc_authentication .= ' -p ' . $this->hc->password;
$hc_authentication .= ' -q ' . $this->hc->host;
$hc_authentication .= ' -x ' . $this->hc->port;
$hc_authentication .= ' -g ' . $this->hc->tenant;
$hc_authentication .= ' -e ' . $this->hc->endpoint;
}
$command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm create';
$command .= ' -i ' . $this->hc->id;
$command .= ' -n ' . $this->hc->account_name;
$command .= ' -t ' . $this->hc->account_type;
$command .= $hc_authentication;
$command .= ' -in ' . $name;
$command .= ' -im ' . $mac;
$command .= ' -a ' . $image->name;
$command .= ' -it ' . $form->get_request('type');
$command .= ' -ik ' . $form->get_request('keypair');
if ($this->hc->account_type == 'aws') {
$command .= ' -subnet ' . $form->get_request('subnet');
} else {
$command .= ' -ig ' . $form->get_request('group');
}
$command .= ' --openqrm-ui-user ' . $this->user->name;
$command .= ' --openqrm-cmd-mode background';
$command .= $custom_script_parameter;
$openqrm->send_command($command, NULL, true);
// check to have a ip from the dhcpd-resource hook
while ($resource->ip == "0.0.0.0") {
sleep(1);
clearstatcache();
$resource->get_instance_by_mac($mac);
}
// save the mgmt ip in the resource network field
$rufields["resource_network"] = $resource->ip;
$resource->update_info($resource->id, $rufields);
$response->resource_id = $id;
$response->msg = sprintf($this->lang['msg_added'], $name);
//.........这里部分代码省略.........
示例10: create_clone_kvm_bf_deployment
function create_clone_kvm_bf_deployment($cloud_image_id, $image_clone_name, $disk_size)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
// we got the cloudimage id here, get the image out of it
$cloudimage = new cloudimage();
$cloudimage->get_instance_by_id($cloud_image_id);
$event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Creating clone " . $image_clone_name . " of image " . $cloudimage->image_id . " on the storage", "", "", 0, 0, 0);
// get image, this is already the new logical clone
// we just need to physical snapshot it and update the rootdevice
$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;
$openqrm_admin_user = new user("openqrm");
$openqrm_admin_user->set_user();
// 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;
// kvm-bf-deployment
$image->get_instance_by_id($image_id);
// parse the identifiers
// origin image volume name
$origin_volume_name = basename($image_rootdevice);
// location of the volume (path)
$image_location_name = dirname($image_rootdevice);
// set default snapshot size
if (!strlen($disk_size)) {
$disk_size = 5000;
}
// update the image rootdevice parameter
$ar_image_update = array('image_rootdevice' => $image_location_name . "/" . $image_clone_name);
// 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
// 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_clone_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);
// update the image storage id with the vm-host-resource
$image_deployment = new deployment();
$image_deployment->get_instance_by_type($image_type);
// loop over all storage id from type $image_type
$found_image = 0;
$storage_list_by_type = new storage();
$storage_id_list_by_type = $storage_list_by_type->get_ids_by_storage_type($image_deployment->id);
foreach ($storage_id_list_by_type as $storage_id_list) {
$storage_id = $storage_id_list['storage_id'];
$tstorage = new storage();
$tstorage->get_instance_by_id($storage_id);
if ($tstorage->resource_id == $vm_host_resource->id) {
// re-create update array + new storage id
$ar_image_update = array('image_rootdevice' => $image_location_name . "/" . $image_clone_name, 'image_storageid' => $tstorage->id);
$event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Updating Image " . $image_id . " / " . $image_name . " with storage id " . $tstorage->id . ".", "", "", 0, 0, 0);
$found_image = 1;
break;
}
}
if ($found_image == 0) {
$event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 2, "openqrm-kvm-bf-deployment-cloud-hook.php", "SETUP ERROR: Could not find a storage server type " . $image_type . " using resource " . $vm_host_resource->id . ". Please create one!", "", "", 0, 0, 0);
$event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 2, "openqrm-kvm-bf-deployment-cloud-hook.php", "SETUP ERROR: Not cloning image " . $image_id . ".", "", "", 0, 0, 0);
return;
}
} else {
$event->log("create_clone_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);
}
$event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Updating rootdevice of image " . $image_id . " / " . $image_name . " with " . $image_location_name . "/" . $image_clone_name, "", "", 0, 0, 0);
$image->update($image_id, $ar_image_update);
$image_clone_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/kvm/bin/openqrm-kvm snap -n " . $origin_volume_name . " -v " . $image_location_name . " -s " . $image_clone_name . " -m " . $disk_size . " -t " . $deployment->type . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background";
$event->log("create_clone_kvm_bf_deployment", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-bf-deployment-cloud-hook.php", "Running : " . $image_clone_cmd, "", "", 0, 0, 0);
$resource->send_command($vm_host_resource->ip, $image_clone_cmd);
}
示例11: create_clone_lvm_aoe_deployment
function create_clone_lvm_aoe_deployment($cloud_image_id, $image_clone_name, $disk_size)
{
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
global $RESOURCE_INFO_TABLE;
global $event;
global $BaseDir;
$event->log("create_clone", $_SERVER['REQUEST_TIME'], 5, "lvm-aoe-deployment-cloud-hook", "Creating clone of 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, this is already the new logical clone
// we just need to physical snapshot it and update the rootdevice
$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;
// parse the volume group info in the identifier
$ident_separate = strpos($image_rootdevice, ":");
$volume_group = substr($image_rootdevice, 0, $ident_separate);
$image_rootdevice_rest = substr($image_rootdevice, $ident_separate + 1);
$ident_separate2 = strpos($image_rootdevice_rest, ":");
$image_location_name = substr($image_rootdevice_rest, 0, $ident_separate2);
$root_device = substr($image_rootdevice_rest, $ident_separate2 + 1);
// set default snapshot size
if (!strlen($disk_size)) {
$disk_size = 5000;
}
$image_clone_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/lvm-storage/bin/openqrm-lvm-storage snap -n " . $image_location_name . " -v " . $volume_group . " -t lvm-aoe-deployment -s " . $image_clone_name . " -m " . $disk_size . " --openqrm-cmd-mode background";
$event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "lvm-aoe-deployment-cloud-hook", "Running : {$image_clone_cmd}", "", "", 0, 0, 0);
$resource->send_command($resource_ip, $image_clone_cmd);
// wait for clone
sleep(4);
// find the new rootdevice of the snapshot, get it via the storage-ident hook
$rootdevice_identifier_hook = "{$BaseDir}/boot-service/image.lvm-aoe-deployment.php";
// require once
require_once "{$rootdevice_identifier_hook}";
$rootdevice_identifier_arr = array();
$rootdevice_identifier_arr = get_lvm_aoe_deployment_image_rootdevice_identifier($image->storageid);
foreach ($rootdevice_identifier_arr as $id) {
foreach ($id as $aoe_identifier_string) {
if (strstr($aoe_identifier_string, $image_clone_name)) {
$aoe_clone_rootdevice_tmp = strrchr($aoe_identifier_string, ":");
$aoe_clone_rootdevice = trim(str_replace(":", "", $aoe_clone_rootdevice_tmp));
break;
}
}
}
// update the image rootdevice parameter
$ar_image_update = array('image_rootdevice' => "{$volume_group}:{$image_clone_name}:{$aoe_clone_rootdevice}");
$image->update($image_id, $ar_image_update);
$event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "lvm-aoe-deployment-cloud-hook", "Updating rootdevice of image {$image_id} / {$image_name} with {$volume_group}:{$image_clone_name}:{$aoe_clone_rootdevice}", "", "", 0, 0, 0);
}