当前位置: 首页>>代码示例>>PHP>>正文


PHP image::add方法代码示例

本文整理汇总了PHP中image::add方法的典型用法代码示例。如果您正苦于以下问题:PHP image::add方法的具体用法?PHP image::add怎么用?PHP image::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在image的用法示例。


在下文中一共展示了image::add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: storage

 $storage_fields["storage_comment"] = "Local-server resource {$local_server_id}";
 $storage_fields["storage_capabilities"] = 'TYPE=local-server';
 $storage = new storage();
 $storage_fields["storage_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
 $storage->add($storage_fields);
 // create image
 $image_fields["image_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
 $image_fields["image_name"] = "resource{$local_server_id}";
 $image_fields["image_type"] = $deployment->type;
 $image_fields["image_rootdevice"] = $local_server_root_device;
 $image_fields["image_rootfstype"] = $local_server_root_device_type;
 $image_fields["image_storageid"] = $storage_fields["storage_id"];
 $image_fields["image_comment"] = "Local-server image resource {$local_server_id}";
 $image_fields["image_capabilities"] = 'TYPE=local-server';
 $image = new image();
 $image->add($image_fields);
 // create kernel
 $kernel_fields["kernel_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
 $kernel_fields["kernel_name"] = "resource{$local_server_id}";
 $kernel_fields["kernel_version"] = "{$local_server_kernel_version}";
 $kernel_fields["kernel_capabilities"] = 'TYPE=local-server';
 $kernel = new kernel();
 $kernel->add($kernel_fields);
 // create appliance
 $next_appliance_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
 $appliance_fields["appliance_id"] = $next_appliance_id;
 $appliance_fields["appliance_name"] = $local_server_name;
 $appliance_fields["appliance_kernelid"] = $kernel_fields["kernel_id"];
 $appliance_fields["appliance_imageid"] = $image_fields["image_id"];
 $appliance_fields["appliance_resources"] = "{$local_server_id}";
 $appliance_fields["appliance_capabilities"] = 'TYPE=local-server';
开发者ID:kelubo,项目名称:OpenQRM,代码行数:31,代码来源:local-server-action.php

示例2: image

 function image()
 {
     $response = '';
     $errors = array();
     $message = array();
     $image_command = $this->response->html->request()->get('image_command');
     if ($image_command !== '') {
         switch ($image_command) {
             case 'add':
                 $root_device = $this->response->html->request()->get('root_device');
                 if ($this->deployment->type == 'kvm-gluster-deployment') {
                     $image_name = $this->response->html->request()->get('image_name');
                 } else {
                     $image_name = basename($root_device);
                 }
                 // check if image name is not in use yet
                 $image = new image();
                 $image->get_instance_by_name($image_name);
                 if (strlen($image->id)) {
                     $errors[] = sprintf($this->lang['error_exists'], $image_name);
                 } else {
                     $tables = $this->openqrm->get('table');
                     $image_fields = array();
                     $image_fields["image_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                     $image_fields['image_name'] = $image_name;
                     $image_fields['image_type'] = $this->deployment->type;
                     $image_fields['image_rootfstype'] = 'local';
                     $image_fields['image_storageid'] = $this->storage->id;
                     $image_fields['image_comment'] = "Image Object for volume {$image_name}";
                     $image_fields['image_rootdevice'] = $root_device;
                     $image = new image();
                     $image->add($image_fields);
                     $message[] = sprintf($this->lang['msg_added_image'], $image_name);
                 }
                 break;
             case 'remove':
                 $image_id = $this->response->html->request()->get('image_id');
                 // check if image is not in use any more before removing
                 $remove_error = 0;
                 $appliance = new appliance();
                 $appliance_id_list = $appliance->get_all_ids();
                 foreach ($appliance_id_list as $appliance_list) {
                     $appliance_id = $appliance_list['appliance_id'];
                     $app_image_remove_check = new appliance();
                     $app_image_remove_check->get_instance_by_id($appliance_id);
                     if ($app_image_remove_check->imageid == $image_id) {
                         $image_is_used_by_appliance .= $appliance_id . " ";
                         $remove_error = 1;
                     }
                 }
                 if ($remove_error == 1) {
                     $errors[] = sprintf($this->lang['error_image_still_in_use'], $image_id, $image_is_used_by_appliance);
                 } else {
                     $image_remove = new image();
                     $image_remove->remove($image_id);
                     $message[] = sprintf($this->lang['msg_removed_image'], $image_id);
                 }
                 break;
         }
         if (count($errors) === 0) {
             $response = join('<br>', $message);
         } else {
             $msg = array_merge($errors, $message);
             $response = join('<br>', $msg);
         }
     } else {
         $response = '';
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:70,代码来源:kvm.image.class.php

示例3: duplicate

 function duplicate()
 {
     $response = $this->get_response();
     $form = $response->form;
     if (!$form->get_errors() && $this->response->submit()) {
         $storage_id = $this->response->html->request()->get('storage_id');
         $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);
         $name = $form->get_request('name');
         $command = $this->openqrm->get('basedir') . '/plugins/nfs-storage/bin/openqrm-nfs-storage clone';
         $command .= ' -n ' . $this->volume;
         $command .= ' -s ' . $name;
         $command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
         $command .= ' --openqrm-ui-user ' . $this->user->name;
         $command .= ' --openqrm-cmd-mode background';
         $statfile = $this->openqrm->get('basedir') . '/plugins/nfs-storage/web/storage/' . $storage->resource_id . '.nfs.stat';
         $origin_volume_path = '';
         $volume_path = "";
         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 = basename($line[1]);
                         if ($name === $check) {
                             $error = sprintf($this->lang['error_exists'], $name);
                         }
                         if ($this->volume === $check) {
                             $origin_volume_path = $line[1];
                         }
                     }
                 }
             }
         }
         if (!strlen($origin_volume_path)) {
             $error = sprintf($this->lang['msg_clone_failed'], $name);
         } else {
             $export_path = dirname($origin_volume_path);
             $volume_path = $export_path . '/' . $name;
         }
         if (isset($error)) {
             $response->error = $error;
         } else {
             $file = $this->openqrm->get('basedir') . '/plugins/nfs-storage/web/storage/' . $resource->id . '.nfs.' . $name . '.sync_progress';
             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();
             }
             $tables = $this->openqrm->get('table');
             $image_fields = array();
             $image_fields["image_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
             $image_fields['image_name'] = $name;
             $image_fields['image_type'] = $deployment->type;
             $image_fields['image_rootfstype'] = 'nfs';
             $image_fields['image_storageid'] = $storage->id;
             $image_fields['image_comment'] = "Image Object for volume {$name}";
             $image_fields['image_rootdevice'] = $volume_path;
             $image = new image();
             $image->add($image_fields);
             $response->msg = sprintf($this->lang['msg_cloned'], $this->volume, $name);
             // save image id in response for the wizard
             $response->image_id = $image_fields["image_id"];
         }
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:76,代码来源:nfs-storage.clone.class.php

示例4: openqrm_cloud_monitor

function openqrm_cloud_monitor()
{
    global $event;
    global $APPLIANCE_INFO_TABLE;
    global $IMAGE_INFO_TABLE;
    global $CLOUD_IMAGE_TABLE;
    global $CLOUD_APPLIANCE_TABLE;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $openqrm_server;
    global $BaseDir;
    global $RootDir;
    global $vm_create_timout;
    $vmware_mac_address_space = "00:50:56";
    $cloud_monitor_lock = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/web/action/cloud-conf/cloud-monitor.lock";
    $cloud_monitor_timeout = "600";
    $cloud_volume_clone_timeout = "4800";
    // lock to prevent running multiple times in parallel
    if (file_exists($cloud_monitor_lock)) {
        // check from when it is, if it is too old we remove it and start
        $cloud_monitor_lock_date = file_get_contents($cloud_monitor_lock);
        $now = $_SERVER['REQUEST_TIME'];
        if ($now - $cloud_monitor_lock_date > $cloud_monitor_timeout) {
            $event->log("cloud", $_SERVER['REQUEST_TIME'], 2, "monitor-hook", "Timeout for the cloud-monitor-lock reached, creating new lock", "", "", 0, 0, 0);
            $cloud_lock_fp = fopen($cloud_monitor_lock, 'w');
            fwrite($cloud_lock_fp, $now);
            fclose($cloud_lock_fp);
        } else {
            return 0;
        }
    } else {
        $now = $_SERVER['REQUEST_TIME'];
        $cloud_lock_fp = fopen($cloud_monitor_lock, 'w');
        fwrite($cloud_lock_fp, $now);
        fclose($cloud_lock_fp);
    }
    // prepare performance parameter
    $cloud_performance_config = new cloudconfig();
    $max_parallel_phase_one_actions = $cloud_performance_config->get_value(27);
    // 27 max-parallel-phase-one-actions
    $max_parallel_phase_two_actions = $cloud_performance_config->get_value(28);
    // 28 max-parallel-phase-two-actions
    $max_parallel_phase_three_actions = $cloud_performance_config->get_value(29);
    // 29 max-parallel-phase-three-actions
    $max_parallel_phase_four_actions = $cloud_performance_config->get_value(30);
    // 30 max-parallel-phase-four-actions
    $max_parallel_phase_five_actions = $cloud_performance_config->get_value(31);
    // 31 max-parallel-phase-five-actions
    $max_parallel_phase_six_actions = $cloud_performance_config->get_value(32);
    // 32 max-parallel-phase-six-actions
    $max_parallel_phase_seven_actions = $cloud_performance_config->get_value(33);
    // 33 max-parallel-phase-seven-actions
    $parallel_phase_one_actions = 0;
    $parallel_phase_two_actions = 0;
    $parallel_phase_three_actions = 0;
    $parallel_phase_four_actions = 0;
    $parallel_phase_five_actions = 0;
    $parallel_phase_six_actions = 0;
    $parallel_phase_seven_actions = 0;
    // appliance hostname
    $cloud_appliance_hostname_enabled = $cloud_performance_config->get_value(34);
    // 34 appliance-hostname
    // $event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "monitor-hook", "Cloud Phase I - Image actions, VM-removal", "", "", 0, 0, 0);
    // #################### clone-on-deploy image resize / remove ################################
    // here we check if we have any clone-on-deploy images to resize or to remove
    // get cloudimage ids
    $cil = new cloudimage();
    $cloud_image_list = $cil->get_all_ids();
    foreach ($cloud_image_list as $ci_list) {
        $phase_one_actions = 0;
        $ci_id = $ci_list['ci_id'];
        $ci = new cloudimage();
        $ci->get_instance_by_id($ci_id);
        $ci_state = $ci->state;
        $ci_image_id = $ci->image_id;
        $ci_appliance_id = $ci->appliance_id;
        $ci_resource_id = $ci->resource_id;
        $ci_cr_id = $ci->cr_id;
        $ci_resource = new resource();
        $ci_resource->get_instance_by_id($ci_resource_id);
        $ci_appliance = new appliance();
        $ci_appliance->get_instance_by_id($ci->appliance_id);
        // not the openQRM server resource, accept 0 only for private image remove
        if ($ci_cr_id != 0) {
            if ($ci_resource_id == 0) {
                continue;
            }
            // not when the cr is in starting phase
            $ci_request = new cloudrequest();
            $ci_request->get_instance_by_id($ci_cr_id);
            if ($ci_request->status == 8) {
                continue;
            }
        }
        // image still in use ?
        if ($ci_state == 1) {
            // its resource its active with the idle image ? sounds like pause
            if (!strcmp($ci_resource->state, "active") && $ci_resource->imageid == 1) {
                // ####################### remove auto createed vm #################
//.........这里部分代码省略.........
开发者ID:kelubo,项目名称:OpenQRM,代码行数:101,代码来源:openqrm-cloud-monitor-hook.php

示例5: 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/kvm/bin/openqrm-kvm add';
             $command .= ' -n ' . $name . ' -m ' . $form->get_request('size');
             $command .= ' -o ' . $form->get_request('type');
             $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';
             $statfile = $this->openqrm->get('basedir') . '/plugins/kvm/web/storage/' . $this->resource->id . '.' . $this->volgroup . '.lv.stat';
             if ($this->file->exists($statfile)) {
                 $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) {
                                 $error = sprintf($this->lang['error_exists'], $name);
                             }
                         }
                     }
                 }
             }
             // check for image name
             $image = new image();
             $image->get_instance_by_name($name);
             if (isset($image->id) && $image->id > 1) {
                 $error = sprintf($this->lang['error_exists'], $name);
             }
             if (isset($error)) {
                 $response->error = $error;
             } else {
                 if ($this->file->exists($statfile)) {
                     $this->file->remove($statfile);
                 }
                 $this->resource->send_command($this->resource->ip, $command);
                 while (!$this->file->exists($statfile)) {
                     usleep(10000);
                     // sleep 10ms to unload the CPU
                     clearstatcache();
                 }
                 // add check that volume $name is now in the statfile
                 $created = false;
                 $bf_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;
                                 $bf_volume_path = $line[2];
                                 break;
                             }
                         }
                     }
                 }
                 if ($created) {
                     $tables = $this->openqrm->get('table');
                     $image_fields = array();
                     $image_fields["image_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                     $image_fields['image_name'] = $name;
                     $image_fields['image_type'] = $this->deployment->type;
                     $image_fields['image_rootfstype'] = 'local';
                     $image_fields['image_storageid'] = $this->storage->id;
                     $image_fields['image_comment'] = "Image Object for volume {$name}";
                     switch ($this->deployment->type) {
                         case 'kvm-lvm-deployment':
                             $image_fields['image_rootdevice'] = '/dev/' . $this->volgroup . '/' . $name;
                             break;
                         case 'kvm-bf-deployment':
                             $image_fields['image_rootdevice'] = $bf_volume_path;
                             break;
                         case 'kvm-gluster-deployment':
                             $image_fields['image_rootdevice'] = "gluster://" . $this->resource->ip . "/" . $this->volgroup . "/" . $name;
                             break;
                     }
                     $image = new image();
                     $image->add($image_fields);
                     $response->msg = sprintf($this->lang['msg_added'], $name);
                     // save image id in response for the wizard
                     $response->image_id = $image_fields["image_id"];
                 } else {
                     $response->msg = sprintf($this->lang['msg_add_failed'], $name);
                 }
             }
         }
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:100,代码来源:kvm.add.class.php

示例6: add

 function add()
 {
     $response = $this->get_response();
     $form = $response->form;
     if (!$form->get_errors() && $this->response->submit()) {
         $config = $form->get_request('config');
         $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);
         $file = $this->openqrm->get('basedir') . "/plugins/nfs-storage/web/storage/" . $resource->id . ".nfs.stat.manual";
         $image = new image();
         $error = '';
         // get old data
         $old = array();
         if ($this->file->exists($file)) {
             $old = $this->file->get_contents($file);
             $old = str_replace("\r\n", "\n", $old);
             $old = explode("\n", $old);
         }
         if (isset($config) && $config !== '') {
             $new = str_replace("\r\n", "\n", $config);
             $new = explode("\n", $new);
             $new = array_unique($new);
             // sync old and new values
             foreach ($old as $v) {
                 if (!in_array($v, $new)) {
                     $name = substr($v, strrpos($v, '/') + 1);
                     if (isset($name) && $name !== '' && $name !== false) {
                         $current = $image->get_instance_by_name($name);
                         if (isset($current) && $current->name === $name) {
                             $image->remove($current->id);
                         }
                     }
                 } else {
                     if (in_array($v, $new)) {
                         unset($new[array_search($v, $new)]);
                     }
                 }
             }
             // add new values to images
             foreach ($new as $v) {
                 $name = substr($v, strrpos($v, '/') + 1);
                 if (isset($name) && $name !== '' && $name !== false) {
                     $current = $image->get_instance_by_name($name);
                     if (isset($current) && $current->name === $name) {
                         $error[] = sprintf($this->lang['error_image_in_use'], $name, $v);
                     } else {
                         if ($v !== '') {
                             $tables = $this->openqrm->get('table');
                             $f['image_id'] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                             $f['image_name'] = $name;
                             $f['image_type'] = 'nfs-deployment';
                             $f['image_rootfstype'] = 'nfs';
                             $f['image_rootdevice'] = $v;
                             $f['image_storageid'] = $this->storage;
                             $f['image_comment'] = 'Manually added nfs export';
                             $image->add($f);
                         }
                     }
                 } else {
                     if ((!isset($name) || $name === '' || $name === false) && $v !== '') {
                         $error[] = $this->lang['error_name_empty'];
                     }
                 }
             }
             // handle config file
             if ($error === '') {
                 if (!($handle = fopen($file, 'w+'))) {
                     $error = "Cannot open file ({$file})";
                 }
                 if (fwrite($handle, $config) === FALSE) {
                     $error = "Cannot write to file ({$file})";
                 }
                 if ($error !== '') {
                     $response->error = $error;
                 } else {
                     $response->msg = $this->lang['saved'];
                 }
             } else {
                 if (is_array($error)) {
                     $response->error = implode('<br>', $error);
                 } else {
                     if (is_string($error)) {
                         $response->error = $error;
                     }
                 }
             }
         } else {
             // remove old values from image table
             foreach ($old as $v) {
                 if (!in_array($v, $new)) {
                     $name = substr($v, strrpos($v, '/') + 1);
                     if (isset($name) && $name !== '' && $name !== false) {
                         $current = $image->get_instance_by_name($name);
                         if (isset($current) && $current->name === $name) {
                             $image->remove($current->id);
                         }
                     }
//.........这里部分代码省略.........
开发者ID:kelubo,项目名称:OpenQRM,代码行数:101,代码来源:nfs-storage.manual.class.php

示例7: image

 function image()
 {
     $response = '';
     $errors = array();
     $message = array();
     $image_command = $this->response->html->request()->get('image_command');
     if ($image_command !== '') {
         switch ($image_command) {
             case 'add':
                 $root_device = $this->response->html->request()->get('root_device');
                 $image_name = $this->response->html->request()->get('image_name');
                 // check if image name is not in use yet
                 $image = new image();
                 $image->get_instance_by_name($image_name);
                 if (strlen($image->id)) {
                     $errors[] = sprintf($this->lang['error_exists'], $image_name);
                 } else {
                     $image_rootfstype = '';
                     // 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 . '.lvm.' . $image_name . '.adapt';
                     $get_ident_command = $this->openqrm->get('basedir') . '/plugins/lvm-storage/bin/openqrm-lvm-storage adapt';
                     $get_ident_command .= ' -n ' . $image_name;
                     $get_ident_command .= ' -t ' . $this->deployment->type . ' -v ' . $this->volgroup;
                     $get_ident_command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
                     $get_ident_command .= ' --openqrm-ui-user ' . $this->user->name;
                     $get_ident_command .= ' --openqrm-cmd-mode background';
                     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();
                     }
                     $found = false;
                     if ($this->deployment->type == 'lvm-aoe-deployment') {
                         $name = $root_device;
                         $root_device = '';
                         $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) {
                                         $root_device = $ident_line[1];
                                         $image_rootfstype = 'ext3';
                                         $found = true;
                                         break;
                                     }
                                 }
                             }
                         }
                     } else {
                         if ($this->deployment->type == 'lvm-iscsi-deployment') {
                             $image_rootfstype = 'ext3';
                             $found = true;
                         } else {
                             if ($this->deployment->type == 'lvm-nfs-deployment') {
                                 $image_rootfstype = 'nfs';
                                 $found = true;
                             }
                         }
                     }
                     if ($found) {
                         $tables = $this->openqrm->get('table');
                         $image_fields = array();
                         $image_fields["image_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                         $image_fields['image_name'] = $image_name;
                         $image_fields['image_type'] = $this->deployment->type;
                         $image_fields['image_rootfstype'] = $image_rootfstype;
                         $image_fields['image_storageid'] = $this->storage->id;
                         $image_fields['image_comment'] = "Image Object for volume {$image_name}";
                         $image_fields['image_rootdevice'] = $root_device;
                         $image = new image();
                         $image->add($image_fields);
                         $message[] = sprintf($this->lang['msg_added_image'], $image_name);
                     } else {
                         $message[] = sprintf($this->lang['msg_add_failed'], $image_name);
                     }
                 }
                 break;
             case 'remove':
                 $image_id = $this->response->html->request()->get('image_id');
                 // check if image is not in use any more before removing
                 $remove_error = 0;
                 $appliance = new appliance();
                 $appliance_id_list = $appliance->get_all_ids();
                 foreach ($appliance_id_list as $appliance_list) {
                     $appliance_id = $appliance_list['appliance_id'];
                     $app_image_remove_check = new appliance();
                     $app_image_remove_check->get_instance_by_id($appliance_id);
                     if ($app_image_remove_check->imageid == $image_id) {
                         $image_is_used_by_appliance .= $appliance_id . " ";
                         $remove_error = 1;
                     }
                 }
                 if ($remove_error == 1) {
//.........这里部分代码省略.........
开发者ID:kelubo,项目名称:OpenQRM,代码行数:101,代码来源:lvm-storage.image.class.php

示例8: duplicate

 function duplicate()
 {
     $response = $this->get_response();
     $form = $response->form;
     if (!$form->get_errors() && $this->response->submit()) {
         $storage_id = $this->response->html->request()->get('storage_id');
         $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);
         $name = $form->get_request('name');
         // check if volume / image name is aleady existing
         $image_check = new image();
         $image_check->get_instance_by_name($name);
         if (isset($image_check->id) && $image_check->id > 0) {
             $error = sprintf($this->lang['error_image_exists'], $name);
         }
         $linuxcoe_volume = new linuxcoe_volume();
         $linuxcoe_volume->get_instance_by_name($name);
         if (isset($linuxcoe_volume->id) && $linuxcoe_volume->id > 0) {
             $error = sprintf($this->lang['error_exists'], $name);
         }
         if (isset($error)) {
             $response->error = $error;
         } else {
             // add volume
             $linuxcoe_volume->get_instance_by_name($this->volume);
             $volume_fields = array();
             $volume_fields["linuxcoe_volume_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
             $volume_fields['linuxcoe_volume_name'] = $name;
             $volume_fields['linuxcoe_volume_root'] = $linuxcoe_volume->root;
             $volume_fields['linuxcoe_volume_description'] = $linuxcoe_volume->description;
             $linuxcoe_volume->add($volume_fields);
             // add image
             $tables = $this->openqrm->get('table');
             $image_fields = array();
             $image_fields["image_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
             $image_fields['image_name'] = $name;
             $image_fields['image_type'] = $deployment->type;
             $image_fields['image_rootfstype'] = 'local';
             $image_fields['image_storageid'] = $storage->id;
             $image_fields['image_comment'] = "Image Object for volume {$name}";
             $image_fields['image_rootdevice'] = 'local';
             $image = new image();
             $image->add($image_fields);
             $response->msg = sprintf($this->lang['msg_cloned'], $this->volume, $name);
             // save image id in response for the wizard
             $response->image_id = $image_fields["image_id"];
         }
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:54,代码来源:linuxcoe.clone.class.php

示例9: 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'], number_format($this->max, 0, '', '') . ' MB'));
         }
         if (!$form->get_errors()) {
             $name = $form->get_request('name');
             $size = $form->get_request('size');
             $command = $this->openqrm->get('basedir') . "/plugins/iscsi-storage/bin/openqrm-iscsi-storage add -n " . $name . " -m " . $size;
             $command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
             $command .= ' --openqrm-ui-user ' . $this->user->name;
             $command .= ' --openqrm-cmd-mode background';
             $storage_id = $this->response->html->request()->get('storage_id');
             $storage = $this->storage;
             $resource = $this->resource;
             $storage->get_instance_by_id($storage_id);
             $resource->get_instance_by_id($storage->resource_id);
             $statfile = $this->openqrm->get('basedir') . '/plugins/iscsi-storage/web/storage/' . $storage->resource_id . '.iscsi.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[2];
                             if ($name === $check) {
                                 $error = sprintf($this->lang['error_exists'], $name);
                             }
                         }
                     }
                 }
             }
             if (isset($error)) {
                 $response->error = $error;
             } else {
                 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();
                 }
                 // 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[2];
                             if ($name === $check) {
                                 $created = true;
                                 $volume_path = '/dev/' . $name . '/1';
                                 break;
                             }
                         }
                     }
                 }
                 if ($created) {
                     $tables = $this->openqrm->get('table');
                     $image_fields = array();
                     $image_fields["image_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                     $image_fields['image_name'] = $name;
                     $image_fields['image_type'] = $this->deployment->type;
                     $image_fields['image_rootfstype'] = 'ext3';
                     $image_fields['image_storageid'] = $this->storage->id;
                     $image_fields['image_comment'] = "Image Object for volume {$name}";
                     $image_fields['image_rootdevice'] = $volume_path;
                     $image = new image();
                     $image->add($image_fields);
                     $response->msg = sprintf($this->lang['msg_added'], $name);
                     // save image id in response for the wizard
                     $response->image_id = $image_fields["image_id"];
                 } else {
                     $response->msg = sprintf($this->lang['msg_add_failed'], $name);
                 }
             }
         }
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:87,代码来源:iscsi-storage.add.class.php

示例10: 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;
                                 }
//.........这里部分代码省略.........
开发者ID:kelubo,项目名称:OpenQRM,代码行数:101,代码来源:lvm-storage.add.class.php

示例11: import

 function import()
 {
     $response = '';
     $errors = array();
     $message = array();
     $event = new event();
     $instance_command = $this->response->html->request()->get('instance_command');
     if ($instance_command !== '') {
         switch ($instance_command) {
             case 'add':
                 // instance_command=add
                 // &instance_name='.$name.'
                 // &instance_mac='.$mac.'
                 // &instance_public_ip='.$public_ip.'
                 // &instance_type='.$type.'
                 // &instance_keypair='.$keypair.'
                 // &instance_region='.$region.'
                 // &instance_ami='.$ami;
                 $now = $_SERVER['REQUEST_TIME'];
                 $openqrm = new openqrm_server();
                 $instance_name = $this->response->html->request()->get('instance_name');
                 $instance_mac = $this->response->html->request()->get('instance_mac');
                 $instance_public_ip = $this->response->html->request()->get('instance_public_ip');
                 $instance_type = $this->response->html->request()->get('instance_type');
                 $instance_keypair = $this->response->html->request()->get('instance_keypair');
                 $instance_region = $this->response->html->request()->get('instance_region');
                 $instance_ami = $this->response->html->request()->get('instance_ami');
                 // create resource, image and appliance
                 $event->log("import", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-vm-import", "Importing " . $instance_name . " - " . $instance_mac . " - " . $instance_public_ip . " - " . $instance_type . " - " . $instance_keypair . " - " . $instance_region . " - " . $instance_ami . ".", "", "", 0, 0, 0);
                 $import_resource = new resource();
                 $deployment = new deployment();
                 $deployment->get_instance_by_name('ami-deployment');
                 $virtualization = new virtualization();
                 $virtualization->get_instance_by_type("hybrid-cloud-vm-local");
                 // create resource
                 $resid = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                 // send command to the openQRM-server
                 $openqrm->send_command('openqrm_server_add_resource ' . $resid . ' ' . $instance_mac . ' ' . $instance_public_ip);
                 // add to openQRM database
                 $resource_fields["resource_id"] = $resid;
                 $resource_fields["resource_ip"] = $instance_public_ip;
                 $resource_fields["resource_mac"] = $instance_mac;
                 $resource_fields["resource_kernel"] = 'local';
                 $resource_fields["resource_kernelid"] = 0;
                 $resource_fields["resource_localboot"] = 0;
                 $resource_fields["resource_hostname"] = $this->hc->account_type . $resid;
                 $resource_fields["resource_vtype"] = $virtualization->id;
                 $resource_fields["resource_vhostid"] = 0;
                 $import_resource->add($resource_fields);
                 $import_resource->get_instance_by_mac($instance_mac);
                 // update stats
                 #if ($state == 'running') {
                 $rfields["resource_state"] = 'idle';
                 #$rfields["resource_lastgood"]=$now;
                 #} else {
                 #	$rfields["resource_state"]='off';
                 #}
                 #$import_resource->update_info($import_resource->id, $rfields);
                 // set account id in resource capabilities
                 $import_resource->set_resource_capabilities("HCACL", $this->id);
                 // auto create image object
                 $storage = new storage();
                 $storage->get_instance_by_name('ami-image-storage');
                 $image = new image();
                 $image->get_instance_by_name($instance_ami);
                 if (isset($image->id) && $image->id > 0) {
                     $image_exists = true;
                 } else {
                     $image_fields = array();
                     $vm_image_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                     $image_fields["image_id"] = $vm_image_id;
                     $image_fields['image_name'] = $instance_ami;
                     $image_fields['image_type'] = 'ami-deployment';
                     $image_fields['image_rootfstype'] = 'local';
                     $image_fields['image_isactive'] = 0;
                     $image_fields['image_storageid'] = $storage->id;
                     $image_fields['image_comment'] = "Image Object for AMI {$instance_ami}";
                     $image_fields['image_rootdevice'] = $instance_ami;
                     $image->add($image_fields);
                     # update image object
                     $image->get_instance_by_id($vm_image_id);
                     // update resource with image infos
                     $rfields["resource_id"] = $resid;
                     $rfields["resource_image"] = $image->name;
                     $rfields["resource_imageid"] = $image->id;
                     $import_resource->update_info($import_resource->id, $rfields);
                     $import_resource->get_instance_by_mac($instance_mac);
                 }
                 // create the appliance
                 $appliance = new appliance();
                 $appliance->get_instance_by_name($instance_name);
                 if (isset($appliance->id) && $appliance->id > 0) {
                     $appliance_exists = true;
                 } else {
                     $new_appliance_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                     $afields['appliance_id'] = $new_appliance_id;
                     $afields['appliance_name'] = $this->hc->account_type . $resid;
                     $afields['appliance_resources'] = $resid;
                     $afields['appliance_kernelid'] = '1';
                     $afields['appliance_imageid'] = $image->id;
//.........这里部分代码省略.........
开发者ID:kelubo,项目名称:OpenQRM,代码行数:101,代码来源:hybrid-cloud-vm.import.class.php

示例12: duplicate

 function duplicate()
 {
     $response = $this->get_response();
     $form = $response->form;
     if (!$form->get_errors() && $this->response->submit()) {
         $name = $form->get_request('name');
         $command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm clone';
         $command .= ' -t ' . $this->deployment->type;
         $command .= ' -v ' . $this->volgroup;
         $command .= ' -n ' . $this->lvol;
         $command .= ' -s ' . $name;
         $command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
         $command .= ' --caching false';
         $command .= ' --openqrm-ui-user ' . $this->user->name;
         $command .= ' --openqrm-cmd-mode background';
         $statfile = $this->openqrm->get('basedir') . '/plugins/kvm/web/storage/' . $this->resource->id . '.' . $this->volgroup . '.lv.stat';
         if ($this->file->exists($statfile)) {
             $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) {
                             $error = sprintf($this->lang['error_exists'], $name);
                         }
                     }
                 }
             }
         }
         // check for image name
         $image = new image();
         $image->get_instance_by_name($name);
         if (isset($image->id) && $image->id > 1) {
             $error = sprintf($this->lang['error_exists'], $name);
         }
         if (isset($error)) {
             $response->error = $error;
         } else {
             $file = $this->openqrm->get('basedir') . '/plugins/kvm/web/storage/' . $this->resource->id . '.lvm.' . $name . '.sync_progress';
             if ($this->file->exists($file)) {
                 $this->file->remove($file);
             }
             $root_device_ident = $this->openqrm->get('basedir') . '/plugins/kvm/web/storage/' . $this->resource->id . '.' . $name . '.root_device';
             if ($this->file->exists($root_device_ident)) {
                 $this->file->remove($root_device_ident);
             }
             $this->resource->send_command($this->resource->ip, $command);
             while (!$this->file->exists($file)) {
                 usleep(10000);
                 clearstatcache();
             }
             // wait for the root-device identifier
             while (!$this->file->exists($root_device_ident)) {
                 usleep(10000);
                 clearstatcache();
             }
             $root_device = trim($this->file->get_contents($root_device_ident));
             $this->file->remove($root_device_ident);
             $tables = $this->openqrm->get('table');
             $image_fields = array();
             $image_fields["image_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
             $image_fields['image_name'] = $name;
             $image_fields['image_type'] = $this->deployment->type;
             $image_fields['image_rootfstype'] = 'local';
             $image_fields['image_storageid'] = $this->storage->id;
             $image_fields['image_comment'] = "Image Object for volume {$name}";
             $image_fields['image_rootdevice'] = $root_device;
             $image = new image();
             $image->add($image_fields);
             $response->image_id = $image_fields["image_id"];
             $response->msg = sprintf($this->lang['msg_cloned'], $this->lvol, $name);
         }
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:76,代码来源:kvm.clone.class.php


注:本文中的image::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。