本文整理汇总了PHP中image::generatePassword方法的典型用法代码示例。如果您正苦于以下问题:PHP image::generatePassword方法的具体用法?PHP image::generatePassword怎么用?PHP image::generatePassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image
的用法示例。
在下文中一共展示了image::generatePassword方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_clone_lvm_iscsi_deployment
function create_clone_lvm_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, "lvm-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_password = $image->generatePassword(12);
$image->set_deployment_parameters("IMAGE_ISCSI_AUTH", $image_password);
// parse the volume group info in the identifier
$ident_separate = strpos($image_rootdevice, ":");
$volume_group = substr($image_rootdevice, 0, $ident_separate);
$root_device = substr($image_rootdevice, $ident_separate);
$image_location = dirname($root_device);
$image_location_name = basename($image_location);
// set default snapshot size
if (!strlen($disk_size)) {
$disk_size = 5000;
}
// update the image rootdevice parameter
$ar_image_update = array('image_rootdevice' => "{$volume_group}:/dev/{$image_clone_name}/1");
$event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "lvm-iscsi-deployment-cloud-hook", "Updating rootdevice of image {$image_id} / {$image_name} with {$volume_group}:/dev/{$image_clone_name}/1", "", "", 0, 0, 0);
$image->update($image_id, $ar_image_update);
// send command
$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-iscsi-deployment -s " . $image_clone_name . " -m " . $disk_size . " -i " . $image_password . " --openqrm-cmd-mode background";
$event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "lvm-iscsi-deployment-cloud-hook", "Running : {$image_clone_cmd}", "", "", 0, 0, 0);
$resource->send_command($resource_ip, $image_clone_cmd);
}
示例2: openqrm_cloud_monitor
//.........这里部分代码省略.........
$vm_virt->get_instance_by_id($cr->resource_type_req);
$virt_name = $vm_virt->get_plugin_name();
switch ($virt_name) {
case 'vmware-esx':
case 'vmware-server':
case 'vmware-server2':
$mac_res->generate_mac();
$suggested_mac = $mac_res->mac;
$new_forth_byte_first_bit = rand(1, 3);
$new_vm_mac = strtolower($vmware_mac_address_space . ":" . substr($suggested_mac, 9));
$new_vm_mac = substr_replace($new_vm_mac, $new_forth_byte_first_bit, 9, 1);
break;
default:
$mac_res->generate_mac();
$new_vm_mac = $mac_res->mac;
break;
}
// additional_nics
$new_additional_nics = $cr->network_req;
// cpu
$new_vm_cpu = $cr->cpu_req;
// memory
$new_vm_memory = 256;
if ($cr->ram_req != 0) {
$new_vm_memory = $cr->ram_req;
}
// disk size
$new_vm_disk = 5000;
if ($cr->disk_req != 0) {
$new_vm_disk = $cr->disk_req;
}
// here we generate the password for the Image and optional vnc of the VM resource
$image = new image();
$vm_vnc_password = trim($image->generatePassword(12));
// put the password in the cr for the image later
$cr_update_fields = array();
$cr_update_fields['cr_image_password'] = $vm_vnc_password;
$cr->update($cr_id, $cr_update_fields);
// Create VM
// here we start the new vm !
$cloudvm = new cloudvm();
// this method returns the resource-id
$cloudvm->create($cr_cu_id, $appliance_virtualization, $appliance_name, $new_vm_mac, $new_additional_nics, $new_vm_cpu, $new_vm_memory, $new_vm_disk, $vm_create_timout, $vm_vnc_password, $SOURCE_IMAGE_ID);
$new_vm_resource_id = $cloudvm->resource_id;
// check if creating the new VM resource failed
if ($new_vm_resource_id == 0) {
$event->log("cloud", $_SERVER['REQUEST_TIME'], 2, "cloud-monitor", "Failed creating a new resource for request ID {$cr_id}!", "", "", 0, 0, 0);
$cr->setstatus($cr_id, 'no-res');
// send mail to user
$rmail = new cloudmailer();
$rmail->to = "{$cu_email}";
$rmail->from = "{$cc_acr_admin_email}";
$rmail->subject = "openQRM Cloud: Not enough resources to provision a system for request " . $cr_id;
$rmail->template = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/cloud/etc/mail/not_enough_resources.mail.tmpl";
$arr = array('@@ID@@' => "{$cr_id}", '@@FORENAME@@' => "{$cu_forename}", '@@LASTNAME@@' => "{$cu_lastname}", '@@RESNUMBER@@' => "{$cr_resource_number}", '@@YOUR@@' => "your", '@@CLOUDADMIN@@' => $cc_acr_admin_email);
$rmail->var_array = $arr;
$rmail->send();
// send mail to admin
$rmail_admin = new cloudmailer();
$rmail_admin->to = "{$cc_acr_admin_email}";
$rmail_admin->from = "{$cc_acr_admin_email}";
$rmail_admin->subject = "openQRM Cloud: Error creating new resource for request " . $cr_id;
$rmail_admin->template = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/cloud/etc/mail/not_enough_resources.mail.tmpl";
$arr = array('@@ID@@' => "{$cr_id}", '@@FORENAME@@' => "Cloudadmin", '@@LASTNAME@@' => "", '@@RESNUMBER@@' => "{$cr_resource_number}", '@@YOUR@@' => "the", '@@CLOUDADMIN@@' => $cc_acr_admin_email);
$rmail_admin->var_array = $arr;
$rmail_admin->send();
示例3: resize
function resize()
{
$this->set_max();
$response = $this->get_response();
$form = $response->form;
if (!$form->get_errors() && $this->response->submit()) {
if ($form->get_request('size') > $this->max) {
$form->set_error('size', sprintf($this->lang['error_size_exeeded'], number_format($this->max, 0, '', '')));
}
if ($form->get_request('size') < $this->min) {
$form->set_error('size', sprintf($this->lang['error_size_undercut'], number_format($this->min, 0, '', '')));
}
if (!$form->get_errors()) {
$name = $form->get_request('name');
$command = $this->openqrm->get('basedir') . '/plugins/lvm-storage/bin/openqrm-lvm-storage resize';
$command .= ' -t ' . $this->deployment->type;
$command .= ' -v ' . $this->volgroup;
$command .= ' -n ' . $this->lvol;
$command .= ' -m ' . ($form->get_request('size') - $this->min);
$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->deployment->type === 'lvm-iscsi-deployment') {
$image = new image();
$command .= ' -i ' . $image->generatePassword(12);
}
$statfile = $this->openqrm->get('basedir') . '/plugins/lvm-storage/web/storage/' . $this->resource->id . '.' . $this->volgroup . '.lv.stat';
if (file_exists($statfile)) {
unlink($statfile);
}
$this->resource->send_command($this->resource->ip, $command);
while (!file_exists($statfile)) {
usleep(10000);
// sleep 10ms to unload the CPU
clearstatcache();
}
$response->msg = sprintf($this->lang['msg_resized'], $this->lvol);
}
}
return $response;
}
示例4: add
function add()
{
$response = $this->get_response();
$form = $response->form;
if (!$form->get_errors() && $this->response->submit()) {
if ($form->get_request('size') > $this->max) {
$form->set_error('size', sprintf($this->lang['error_size_exeeded'], $this->max));
}
if (!$form->get_errors()) {
$name = $form->get_request('name');
$command = $this->openqrm->get('basedir') . '/plugins/lvm-storage/bin/openqrm-lvm-storage add';
$command .= ' -n ' . $name . ' -m ' . $form->get_request('size');
$command .= ' -t ' . $this->deployment->type . ' -v ' . $this->volgroup;
$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->deployment->type === 'lvm-iscsi-deployment') {
$image = new image();
$command .= ' -i ' . $image->generatePassword(12);
}
$statfile = $this->openqrm->get('basedir') . '/plugins/lvm-storage/web/storage/' . $this->resource->id . '.' . $this->volgroup . '.lv.stat';
if (file_exists($statfile)) {
$lines = explode("\n", file_get_contents($statfile));
if (count($lines) >= 1) {
foreach ($lines as $line) {
if ($line !== '') {
$line = explode('@', $line);
$check = $line[1];
if ($name === $check) {
$error = sprintf($this->lang['error_exists'], $name);
}
}
}
}
}
if (isset($error)) {
$response->error = $error;
} else {
if (file_exists($statfile)) {
unlink($statfile);
}
$this->resource->send_command($this->resource->ip, $command);
while (!file_exists($statfile)) {
usleep(10000);
// sleep 10ms to unload the CPU
clearstatcache();
}
// add check that volume $name is now in the statfile
$created = false;
$volume_path = "";
$lines = explode("\n", $this->file->get_contents($statfile));
if (count($lines) >= 1) {
foreach ($lines as $line) {
if ($line !== '') {
$line = explode('@', $line);
$check = $line[1];
if ($name === $check) {
$created = true;
switch ($this->deployment->type) {
case 'lvm-aoe-deployment':
// for lvm-aoe deployment we need to get the shelf + slot from get_root_identifiert
$ident_file = $this->openqrm->get('basedir') . '/plugins/lvm-storage/web/storage/' . $this->resource->id . '.lv.lvm-aoe-deployment.ident';
$get_ident_command = $this->openqrm->get('basedir') . '/plugins/lvm-storage/bin/openqrm-lvm-storage post_identifier';
$get_ident_command .= ' -t ' . $this->deployment->type . ' -v ' . $this->volgroup;
$get_ident_command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
$ident_file = $this->openqrm->get('basedir') . '/plugins/lvm-storage/web/storage/' . $this->resource->id . '.lv.lvm-aoe-deployment.ident';
if (file_exists($ident_file)) {
unlink($ident_file);
}
$this->resource->send_command($this->resource->ip, $get_ident_command);
while (!file_exists($ident_file)) {
usleep(10000);
// sleep 10ms to unload the CPU
clearstatcache();
}
$ident_lines = explode("\n", file_get_contents($ident_file));
if (count($ident_lines) >= 1) {
foreach ($ident_lines as $ident_line) {
if ($ident_line !== '') {
$ident_line = explode(',', $ident_line);
$ident_root_path = explode(':', $ident_line[1]);
$ident_check = $ident_root_path[1];
if ($name === $ident_check) {
$volume_path = $ident_line[1];
$rootfstype = 'ext3';
break;
}
}
}
}
break;
case 'lvm-nfs-deployment':
$volume_path = '/' . $line[2] . '/' . $line[1];
$rootfstype = 'nfs';
break;
case 'lvm-iscsi-deployment':
$volume_path = $line[2] . ':/dev/' . $line[1] . '/1';
$rootfstype = 'ext3';
break;
}
//.........这里部分代码省略.........
示例5: storage_auth_stop
function storage_auth_stop($image_id)
{
global $event;
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
$image = new image();
$image->get_instance_by_id($image_id);
$image_name = $image->name;
$image_rootdevice = $image->rootdevice;
// generate a password for the image
$image_password = $image->generatePassword(12);
$image_deployment_parameter = $image->deployment_parameter;
$storage = new storage();
$storage->get_instance_by_id($image->storageid);
$storage_resource = new resource();
$storage_resource->get_instance_by_id($storage->resource_id);
$storage_ip = $storage_resource->ip;
$deployment = new deployment();
$deployment->get_instance_by_type($image->type);
$deployment_type = $deployment->type;
$deployment_plugin_name = $deployment->storagetype;
$event->log("storage_auth_stop_in_background", $_SERVER['REQUEST_TIME'], 5, "openqrm-iscsi-deployment-auth-hook.php", "Authenticating {$image_name} / {$image_rootdevice} with password {$image_password}", "", "", 0, 0, $appliance_id);
$auth_stop_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $deployment_plugin_name . "/bin/openqrm-" . $deployment_plugin_name . " auth -r " . $image_rootdevice . " -i " . $image_password . " --openqrm-cmd-mode background";
$resource = new resource();
$resource->send_command($storage_ip, $auth_stop_cmd);
// and update the image params
$image->set_deployment_parameters("IMAGE_ISCSI_AUTH", $image_password);
}
示例6: storage_auth_stop
function storage_auth_stop($image_id)
{
global $event;
global $OPENQRM_SERVER_BASE_DIR;
global $OPENQRM_SERVER_IP_ADDRESS;
global $OPENQRM_EXEC_PORT;
$image = new image();
$image->get_instance_by_id($image_id);
$image_name = $image->name;
$image_rootdevice = $image->rootdevice;
// generate a password for the image
$image_password = $image->generatePassword(12);
$image_deployment_parameter = $image->deployment_parameter;
// parse the volume group info in the identifier
$ident_separate = strpos($image_rootdevice, ":");
$volume_group = substr($image_rootdevice, 0, $ident_separate);
$root_device = substr($image_rootdevice, $ident_separate);
$image_location = dirname($root_device);
$image_location_name = basename($image_location);
$storage = new storage();
$storage->get_instance_by_id($image->storageid);
$storage_resource = new resource();
$storage_resource->get_instance_by_id($storage->resource_id);
$storage_ip = $storage_resource->ip;
$deployment = new deployment();
$deployment->get_instance_by_type($image->type);
$deployment_type = $deployment->type;
$deployment_plugin_name = $deployment->storagetype;
$auth_stop_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $deployment_plugin_name . "/bin/openqrm-" . $deployment_plugin_name . " auth -r /dev/" . $volume_group . "/" . $image_location_name . " -i " . $image_password . " -t lvm-iscsi-deployment --openqrm-cmd-mode background";
$resource = new resource();
$resource->send_command($storage_ip, $auth_stop_cmd);
// and update the image params
$image->set_deployment_parameters("IMAGE_ISCSI_AUTH", $image_password);
}