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


PHP resource::get_instance_by_mac方法代码示例

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


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

示例1: edit

 function edit()
 {
     $resource_icon_default = "/img/resource.png";
     $storage_icon = "/plugins/kvm/img/plugin.png";
     //$state_icon = $this->openqrm->get('baseurl')."/img/".$this->resource->state.".png";
     if ($this->file->exists($this->openqrm->get('webdir') . $storage_icon)) {
         $resource_icon_default = $storage_icon;
     }
     $resource_icon_default = $this->openqrm->get('baseurl') . $resource_icon_default;
     // check if we have a plugin implementing the remote console
     $remote_console = false;
     $plugin = new plugin();
     $enabled_plugins = $plugin->enabled();
     foreach ($enabled_plugins as $index => $plugin_name) {
         //$plugin_remote_console_running = $this->openqrm->get('webdir')."/plugins/".$plugin_name."/.running";
         $plugin_remote_console_hook = $this->openqrm->get('webdir') . "/plugins/" . $plugin_name . "/openqrm-" . $plugin_name . "-remote-console-hook.php";
         if ($this->file->exists($plugin_remote_console_hook)) {
             require_once "{$plugin_remote_console_hook}";
             $link_function = str_replace("-", "_", "openqrm_" . "{$plugin_name}" . "_remote_console");
             if (function_exists($link_function)) {
                 $remote_functions[] = $link_function;
                 $remote_console = true;
             }
         }
     }
     // prepare list of all Host resource id for the migration select
     // we need a select with the ids/ips from all resources which
     // are used by appliances with kvm capabilities
     $kvm_hosts = array();
     $appliance_list = new appliance();
     $appliance_list_array = $appliance_list->get_list();
     foreach ($appliance_list_array as $index => $app) {
         $appliance_kvm_host_check = new appliance();
         $appliance_kvm_host_check->get_instance_by_id($app["value"]);
         // only active appliances
         if (!strcmp($appliance_kvm_host_check->state, "active") || $appliance_kvm_host_check->resources == 0) {
             $virtualization = new virtualization();
             $virtualization->get_instance_by_id($appliance_kvm_host_check->virtualization);
             if (!strcmp($virtualization->type, "kvm") && !strstr($virtualization->type, "kvm-vm")) {
                 $kvm_host_resource = new resource();
                 $kvm_host_resource->get_instance_by_id($appliance_kvm_host_check->resources);
                 // exclude source host
                 #if ($kvm_host_resource->id == $this->resource->id) {
                 #	continue;
                 #}
                 // only active appliances
                 if (!strcmp($kvm_host_resource->state, "active")) {
                     $migration_select_label = "Res. " . $kvm_host_resource->id . "/" . $kvm_host_resource->ip;
                     $kvm_hosts[] = array("value" => $kvm_host_resource->id, "label" => $migration_select_label);
                 }
             }
         }
     }
     $d['state'] = '<span class="pill ' . $this->resource->state . '">' . $this->resource->state . '</span>';
     $d['resource'] = $this->resource->id . ' / ' . $this->resource->ip;
     $d['name'] = $this->appliance->name;
     $d['id'] = $this->appliance->id;
     $a = $this->response->html->a();
     $a->label = $this->lang['action_add_local_vm'];
     $a->css = 'add';
     $a->handler = 'onclick="wait();"';
     $a->href = $this->response->get_url($this->actions_name, "add") . '&vmtype=kvm-vm-local';
     $d['add_local_vm'] = $a->get_string();
     $a = $this->response->html->a();
     $a->label = $this->lang['action_add_network_vm'];
     $a->css = 'add';
     $a->handler = 'onclick="wait();"';
     $a->href = $this->response->get_url($this->actions_name, "add") . '&vmtype=kvm-vm-net';
     $d['add_network_vm'] = $a->get_string();
     $body = array();
     $identifier_disabled = array();
     $file = $this->statfile;
     if ($this->file->exists($file)) {
         $lines = explode("\n", $this->file->get_contents($file));
         if (count($lines) >= 1) {
             $i = 0;
             foreach ($lines as $line) {
                 if ($line !== '') {
                     $line = explode('@', $line);
                     $state = $line[0];
                     $name = $line[1];
                     $mac = $line[2];
                     $resource = new resource();
                     $resource->get_instance_by_mac($mac);
                     if ($resource->vhostid != $this->resource->id) {
                         continue;
                     }
                     $res_virtualization = new virtualization();
                     $res_virtualization->get_instance_by_id($resource->vtype);
                     $update = '';
                     $a = $this->response->html->a();
                     $a->title = $this->lang['action_update'];
                     $a->label = $this->lang['action_update'];
                     $a->handler = 'onclick="wait();"';
                     $a->css = 'edit';
                     $a->href = $this->response->get_url($this->actions_name, "update") . '&vm=' . $name . '&vmtype=' . $res_virtualization->type;
                     $update_link = $a->get_string();
                     $clone = '';
                     $a = $this->response->html->a();
                     $a->title = $this->lang['action_clone'];
//.........这里部分代码省略.........
开发者ID:kelubo,项目名称:OpenQRM,代码行数:101,代码来源:kvm-vm.edit.class.php

示例2: openqrm_hybrid_cloud_monitor

function openqrm_hybrid_cloud_monitor()
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $openqrm_server;
    global $BaseDir;
    global $RootDir;
    $now = $_SERVER['REQUEST_TIME'];
    // $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-monitor-hook", "Hybrid Cloud monitor hook DISABLED for now!!!", "", "", 0, 0, 0);
    // return;
    // $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-monitor-hook", "Hybrid Cloud monitor hook", "", "", 0, 0, 0);
    $last_stats = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/web/hybrid-cloud-stat/last_statistics";
    if (file_exists($last_stats)) {
        $last_host_stats = file_get_contents($last_stats);
        $secs_after_last_host_stat = $now - $last_host_stats;
        if ($secs_after_last_host_stat > 35) {
            file_put_contents($last_stats, $now);
            $server = new openqrm_server();
            $hc = new hybrid_cloud();
            $hc_account_arr = $hc->get_ids();
            foreach ($hc_account_arr as $id) {
                $hc_account_id = $id['hybrid_cloud_id'];
                $hc->get_instance_by_id($hc_account_id);
                $hc_authentication = '';
                // for every ec2/euca cloud account monitor every configured region
                if ($hc->account_type == 'aws' || $hc->account_type == 'euca') {
                    $hybrid_cloud_conf = $OPENQRM_SERVER_BASE_DIR . '/openqrm/plugins/hybrid-cloud/etc/openqrm-plugin-hybrid-cloud.conf';
                    $hybrid_cloud_conf_arr = openqrm_parse_conf($hybrid_cloud_conf);
                    $region_arr = explode(",", $hybrid_cloud_conf_arr['OPENQRM_PLUGIN_HYBRID_CLOUD_REGIONS']);
                    $hc_authentication .= ' -O ' . $hc->access_key;
                    $hc_authentication .= ' -W ' . $hc->secret_key;
                }
                // one region for openstack
                if ($hc->account_type == 'lc-openstack') {
                    $region_arr = array("OpenStack");
                    $hc_authentication .= ' -u ' . $hc->username;
                    $hc_authentication .= ' -p ' . $hc->password;
                    $hc_authentication .= ' -q ' . $hc->host;
                    $hc_authentication .= ' -x ' . $hc->port;
                    $hc_authentication .= ' -g ' . $hc->tenant;
                    $hc_authentication .= ' -e ' . $hc->endpoint;
                }
                foreach ($region_arr as $region) {
                    $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-monitor-hook", "Hybrid Cloud monitor - checking Cloud statistics for Account " . $hc->account_name . " - " . $region, "", "", 0, 0, 0);
                    $statfile = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/web/hybrid-cloud-stat/" . $hc_account_id . ".instances_statistics.log";
                    $command = $OPENQRM_SERVER_BASE_DIR . '/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm describe --statistics true';
                    $command .= ' -i ' . $hc->id;
                    $command .= ' -n ' . $hc->account_name;
                    $command .= ' -t ' . $hc->account_type;
                    $command .= ' -ir ' . $region;
                    $command .= $hc_authentication;
                    $command .= ' --openqrm-cmd-mode background';
                    if (file_exists($statfile)) {
                        unlink($statfile);
                    }
                    $server->send_command($command, NULL, true);
                    while (!file_exists($statfile)) {
                        usleep(10000);
                        clearstatcache();
                    }
                    $content = file_get_contents($statfile);
                    $content = explode("\n", $content);
                    $b = array();
                    foreach ($content as $k => $v) {
                        if ($v !== '') {
                            $tmp = explode('@', $v);
                            $name = $tmp[1];
                            $ami = $tmp[2];
                            $public_hostname = $tmp[3];
                            $private_hostname = $tmp[4];
                            $state = $tmp[5];
                            $keypair = $tmp[6];
                            $unknown1 = $tmp[7];
                            $unknown2 = $tmp[8];
                            $type = $tmp[9];
                            $date = $tmp[10];
                            $region = $tmp[11];
                            $unknown4 = $tmp[12];
                            $unknown5 = $tmp[13];
                            $unknown6 = $tmp[14];
                            $monitoring = $tmp[15];
                            $public_ip = $hc->format_ip_address($tmp[16]);
                            $private_ip = $hc->format_ip_address($tmp[17]);
                            $unknown7 = $tmp[18];
                            $unknown8 = $tmp[19];
                            $store = $tmp[20];
                            $unknown9 = $tmp[21];
                            $unknown10 = $tmp[22];
                            $unknown11 = $tmp[23];
                            $unknown12 = $tmp[24];
                            $hvm = $tmp[25];
                            $virt_type = $tmp[26];
                            $mac = '';
                            // check for idle instances
                            $resource = new resource();
                            if ($state == 'idle') {
                                $mac = $tmp[30];
                                $resource->get_instance_by_mac($mac);
//.........这里部分代码省略.........
开发者ID:kelubo,项目名称:OpenQRM,代码行数:101,代码来源:openqrm-hybrid-cloud-monitor-hook.php

示例3: fence_hybrid_cloud_vm_local

function fence_hybrid_cloud_vm_local($host_resource_id, $mac)
{
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $RESOURCE_INFO_TABLE;
    global $event;
    $event->log("fence_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-ha-hook", "Fencing Cloud VM " . $mac, "", "", 0, 0, 0);
    $origin_resource = new resource();
    $origin_resource->get_instance_by_mac($mac);
    // get hybrid-cloud account from origin resource
    $hybrid_acl_id = $origin_resource->get_resource_capabilities("HCACL");
    $hc = new hybrid_cloud();
    $hc->get_instance_by_id($hybrid_acl_id);
    $hc_authentication = '';
    if ($hc->account_type == 'aws' || $hc->account_type == 'euca') {
        $hc_authentication .= ' -O ' . $hc->access_key;
        $hc_authentication .= ' -W ' . $hc->secret_key;
    }
    if ($hc->account_type == 'lc-openstack') {
        $hc_authentication .= ' -u ' . $hc->username;
        $hc_authentication .= ' -p ' . $hc->password;
        $hc_authentication .= ' -q ' . $hc->host;
        $hc_authentication .= ' -x ' . $hc->port;
        $hc_authentication .= ' -g ' . $hc->tenant;
        $hc_authentication .= ' -e ' . $hc->endpoint;
    }
    $openqrm = new openqrm_server();
    $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm fence ";
    $command .= ' -i ' . $hc->id;
    $command .= ' -n ' . $hc->account_name;
    $command .= ' -t ' . $hc->account_type;
    $command .= $hc_authentication;
    $command .= ' -im ' . $mac;
    $command .= ' --openqrm-cmd-mode background';
    $event->log("fence_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-ha-hook", "Running {$command}", "", "", 0, 0, 0);
    $openqrm->send_command($command, NULL, true);
    $rufields["resource_hostname"] = $hc->account_type . $origin_resource->id;
    $origin_resource->update_info($origin_resource->id, $rufields);
    // debug
    // echo "1:".$command;
}
开发者ID:kelubo,项目名称:OpenQRM,代码行数:42,代码来源:openqrm-hybrid-cloud-ha-cmd-hook.php

示例4: remove

 function remove()
 {
     $response = $this->get_response();
     $instance_name = $response->html->request()->get('instance_name');
     $form = $response->form;
     $submit = $form->get_elements('submit');
     $submit->handler = 'onclick="wait();"';
     $form->add($submit, 'submit');
     $submit = $form->get_elements('cancel');
     $submit->handler = 'onclick="cancel();"';
     $form->add($submit, 'cancel');
     $d['param_f']['label'] = $instance_name;
     $d['param_f']['object']['type'] = 'htmlobject_input';
     $d['param_f']['object']['attrib']['type'] = 'checkbox';
     $d['param_f']['object']['attrib']['name'] = 'instance_name';
     $d['param_f']['object']['attrib']['value'] = $instance_name;
     $d['param_f']['object']['attrib']['checked'] = true;
     $form->add($d);
     if (!$form->get_errors() && $response->submit()) {
         $errors = array();
         $message = array();
         $resource = new resource();
         $resource->get_instance_by_mac($this->instance_mac);
         $appliance = new appliance();
         $appliances_using_resource = $appliance->get_ids_per_resource($resource->id);
         if (count($appliances_using_resource) > 0) {
             $appliances_using_resource_str = implode(",", $appliances_using_resource[0]);
             $errors[] = sprintf($this->lang['msg_vm_resource_still_in_use'], $instance_name, $resource->id, $appliances_using_resource_str);
         } else {
             $resource->remove($resource->id, $this->instance_mac);
             $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;
             }
             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 remove';
             $command .= ' -i ' . $this->hc->id;
             $command .= ' -n ' . $this->hc->account_name;
             $command .= ' -t ' . $this->hc->account_type;
             $command .= ' -in ' . $instance_name;
             $command .= $hc_authentication;
             $command .= ' --openqrm-ui-user ' . $this->user->name;
             $command .= ' --openqrm-cmd-mode background';
             $openqrm = new openqrm_server();
             $openqrm->send_command($command, NULL, true);
             $message[] = sprintf($this->lang['msg_removed'], $instance_name);
         }
         if (count($errors) === 0) {
             $response->msg = join('<br>', $message);
         } else {
             $msg = array_merge($errors, $message);
             $response->error = join('<br>', $msg);
         }
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:65,代码来源:hybrid-cloud-vm.remove.class.php

示例5: stop

 function stop()
 {
     $response = '';
     $vms = $this->response->html->request()->get($this->identifier_name);
     if ($vms !== '') {
         $appliance_id = $this->response->html->request()->get('appliance_id');
         $appliance = new appliance();
         $resource = new resource();
         $errors = array();
         $message = array();
         foreach ($vms as $key => $vm) {
             $appliance->get_instance_by_id($appliance_id);
             $resource->get_instance_by_id($appliance->resources);
             $file = $this->openqrm->get('basedir') . '/plugins/kvm/web/kvm-stat/' . $resource->id . '.vm_list';
             $command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm-vm stop -n ' . $vm;
             $command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
             $command .= ' --openqrm-ui-user ' . $this->user->name;
             $command .= ' --openqrm-cmd-mode background';
             $resource->send_command($resource->ip, $command);
             $message[] = sprintf($this->lang['msg_stoped'], $vm);
             $file = $this->openqrm->get('basedir') . '/plugins/kvm/web/kvm-stat/' . $resource->id . '.vm_list';
             if ($this->file->exists($file)) {
                 $lines = explode("\n", $this->file->get_contents($file));
                 foreach ($lines as $line) {
                     if ($line !== '') {
                         $line = explode('@', $line);
                         if ($line[1] === $vm) {
                             $tmp = explode(':', $line[5]);
                             $server = $tmp[0];
                             $port = $tmp[1];
                             $mac = $line[2];
                             $resource->get_instance_by_mac($mac);
                             $rid = $resource->id;
                         }
                     }
                     $event = new event();
                     $plugin = new plugin();
                     $enabled = $plugin->enabled();
                     foreach ($enabled as $index => $name) {
                         $running = $this->openqrm->get('webdir') . '/plugins/' . $name . '/.running';
                         $hook = $this->openqrm->get('webdir') . '/plugins/' . $name . '/openqrm-' . $name . '-remote-console-hook.php';
                         if (file_exists($hook)) {
                             if (file_exists($running)) {
                                 $event->log("console", $_SERVER['REQUEST_TIME'], 5, "kvm-vm.console.class.php", 'Found plugin ' . $name . ' providing a remote console.', "", "", 0, 0, $resource->id);
                                 require_once $hook;
                                 $console_function = 'openqrm_' . $name . '_disable_remote_console';
                                 $console_function = str_replace("-", "_", $console_function);
                                 $console_function($server, $port, $rid, $mac, $vm);
                             }
                         }
                     }
                 }
             }
         }
         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,代码行数:65,代码来源:kvm-vm.stop.class.php

示例6: resource

         }
         $event->log("get_parameter", $_SERVER['REQUEST_TIME'], 5, "resource-monitor", "Adding new resource {$new_resource_id} ({$resource_mac})", "", "", 0, 1, $resource->id);
         # send add resource to openQRM-server
         $openqrm_server->send_command("openqrm_server_add_resource {$new_resource_id} {$resource_mac} {$resource_ip}");
         # add resource to db
         $resource_fields["resource_id"] = $new_resource_id;
         $resource_fields["resource_localboot"] = 0;
         $resource_fields["resource_vtype"] = 1;
         $resource_fields["resource_vhostid"] = $new_resource_id;
         $resource_fields["resource_subnet"] = $resource_subnet;
         $resource->add($resource_fields);
     }
 }
 if (strlen($resource_mac)) {
     $resource = new resource();
     $resource->get_instance_by_mac("{$resource_mac}");
     // update the resource parameter in any way
     $resource->update_info($resource->id, $resource_fields);
     $resource->get_parameter($resource->id);
 } else {
     if (strlen($resource_id)) {
         $resource = new resource();
         $resource->get_instance_by_id($resource_id);
         // update the resource parameter in any way
         $resource->update_info($resource->id, $resource_fields);
         $resource->get_parameter($resource->id);
     }
 }
 exit;
 break;
 // update_info requires :
开发者ID:kelubo,项目名称:OpenQRM,代码行数:31,代码来源:resource-monitor.php

示例7: migrate

 function migrate()
 {
     $response = $this->get_response();
     if (isset($response->msg)) {
         return $response;
     }
     $form = $response->form;
     if (!$form->get_errors() && $this->response->submit()) {
         $target = $form->get_request('target');
         $vm_resource = new resource();
         $vm_resource->get_instance_by_mac($this->mac);
         $dest_host_resource = new resource();
         $dest_host_resource->get_instance_by_id($target);
         $source_host_resource = new resource();
         $source_host_resource->get_instance_by_id($vm_resource->vhostid);
         // first transfer the VM config from source to destination
         $tstatfile = $this->openqrm->get('basedir') . '/plugins/kvm/web/kvm-stat/' . $this->vm . '.transfer_status';
         if ($this->file->exists($tstatfile)) {
             $this->file->remove($tstatfile);
         }
         $t_command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm-vm transfer_vm_config';
         $t_command .= ' -n ' . $this->vm;
         $t_command .= ' -k ' . $dest_host_resource->ip;
         $t_command .= ' -k1 ' . $source_host_resource->ip;
         $t_command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
         $t_command .= ' --openqrm-ui-user ' . $this->user->name;
         $t_command .= ' --openqrm-cmd-mode background';
         $openqrm = new openqrm_server();
         $openqrm->send_command($t_command, NULL, true);
         while (!$this->file->exists($tstatfile)) {
             usleep(10000);
             // sleep 10ms to unload the CPU
             clearstatcache();
         }
         $msg = trim($this->file->get_contents($tstatfile));
         if ($msg !== "ok") {
             $response->error = $msg;
             return $response;
         }
         // calcuate the migration port
         list($o1, $o2, $o3, $o4) = explode(".", $vm_resource->ip, 4);
         $kvm_vm_migration_port = $o4 + 6000;
         // start as incoming on destination
         $s_command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm-vm start_as_incoming';
         $s_command .= ' -n ' . $this->vm;
         $s_command .= ' -j ' . $kvm_vm_migration_port;
         $s_command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
         $s_command .= ' --openqrm-ui-user ' . $this->user->name;
         $s_command .= ' --openqrm-cmd-mode background';
         $statfile = $this->openqrm->get('basedir') . '/plugins/kvm/web/kvm-stat/' . $this->vm . '.vm_migrated_successfully';
         if ($this->file->exists($statfile)) {
             $this->file->remove($statfile);
         }
         $dest_host_resource->send_command($dest_host_resource->ip, $s_command);
         sleep(5);
         $m_command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm-vm migrate';
         $m_command .= ' -n ' . $this->vm;
         $m_command .= ' -k ' . $dest_host_resource->ip;
         $m_command .= ' -j ' . $kvm_vm_migration_port;
         $m_command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
         $m_command .= ' --openqrm-ui-user ' . $this->user->name;
         $m_command .= ' --openqrm-cmd-mode background';
         $this->resource->send_command($this->resource->ip, $m_command);
         $fields = array();
         $fields["resource_vhostid"] = $dest_host_resource->id;
         $vm_resource->update_info($vm_resource->id, $fields);
         $response->msg = sprintf($this->lang['msg_migrated'], $this->vm, $dest_host_resource->id . ' / ' . $dest_host_resource->ip);
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:70,代码来源:kvm-vm.migrate.class.php

示例8: remove_hybrid_cloud_vm_local

function remove_hybrid_cloud_vm_local($host_resource_id, $name, $mac)
{
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $RESOURCE_INFO_TABLE;
    global $event;
    $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-cloud-hook", "Removing Cloud VM {$name}/{$mac} from Host resource {$host_resource_id}", "", "", 0, 0, 0);
    $openqrm = new openqrm_server();
    $cloud_resource = new resource();
    $cloud_resource->get_instance_by_mac($mac);
    $hc_default_account_id = $cloud_resource->get_resource_capabilities("HCACL");
    $cloud_resource_hostname = $cloud_resource->hostname;
    if (strlen($hc_default_account_id)) {
        // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "!!! found Cloud Account ".$hc_default_account_id." from resource config", "", "", 0, 0, 0);
    } else {
        $file = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/etc/openqrm-plugin-hybrid-cloud.conf";
        $ini = openqrm_parse_conf($file);
        $hc_default_account_id = $ini['OPENQRM_PLUGIN_HYBRID_CLOUD_DEFAULT_ACCOUNT'];
        // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "!!! got Cloud Account ".$hc_default_account_id." from plugin config", "", "", 0, 0, 0);
    }
    $hc = new hybrid_cloud();
    $hc->get_instance_by_id($hc_default_account_id);
    $hc_authentication = '';
    if ($hc->account_type == 'aws' || $hc->account_type == 'euca') {
        $hc_authentication .= ' -O ' . $hc->access_key;
        $hc_authentication .= ' -W ' . $hc->secret_key;
    }
    if ($hc->account_type == 'lc-openstack') {
        $hc_authentication .= ' -u ' . $hc->username;
        $hc_authentication .= ' -p ' . $hc->password;
        $hc_authentication .= ' -q ' . $hc->host;
        $hc_authentication .= ' -x ' . $hc->port;
        $hc_authentication .= ' -g ' . $hc->tenant;
        $hc_authentication .= ' -e ' . $hc->endpoint;
    }
    $openqrm = new openqrm_server();
    $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm remove ";
    $command .= ' -i ' . $hc->id;
    $command .= ' -n ' . $hc->account_name;
    $command .= ' -t ' . $hc->account_type;
    $command .= $hc_authentication;
    $command .= ' -in ' . $cloud_resource_hostname;
    $command .= ' --openqrm-cmd-mode background';
    // $event->log("remove_hybrid_cloud_vm_local", $_SERVER['REQUEST_TIME'], 2, "hybrid-cloud-cloud-hook", "Running $command", "", "", 0, 0, 0);
    $openqrm->send_command($command, NULL, true);
}
开发者ID:kelubo,项目名称:OpenQRM,代码行数:47,代码来源:openqrm-hybrid-cloud-cloud-hook.php

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

示例10: 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

示例11: resource

 function resource_new()
 {
     $response = $this->get_response();
     $form = $response->form;
     $name = $form->get_request('name');
     $ip = $form->get_request('ip');
     $mac = $form->get_request('mac');
     if (strlen($name)) {
         if (!$form->get_errors() && $this->response->submit()) {
             // check that mac adress + ip does not yet exists
             $resource = new resource();
             $resource->get_instance_by_mac($mac);
             if (strlen($resource->id)) {
                 $response->error = sprintf($this->lang['msg_mac_in_use']);
                 return $response;
             }
             $resource->get_instance_by_ip($ip);
             if (strlen($resource->id)) {
                 $response->error = sprintf($this->lang['msg_ip_in_use']);
                 return $response;
             }
             $tables = $this->openqrm->get('table');
             $id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
             $mac = strtolower($mac);
             // send command to the openQRM-server
             $openqrm = new openqrm_server();
             $openqrm->send_command('openqrm_server_add_resource ' . $id . ' ' . $mac . ' ' . $ip);
             // add to openQRM database
             $fields["resource_id"] = $id;
             $fields["resource_hostname"] = $name;
             $fields["resource_ip"] = $ip;
             $fields["resource_mac"] = $mac;
             $fields["resource_localboot"] = 0;
             $fields["resource_vtype"] = 1;
             $fields["resource_vhostid"] = $id;
             $fields["resource_state"] = 'unknown';
             $fields["resource_lastgood"] = '-1';
             $resource->add($fields);
             // set lastgood to -1 to prevent automatic checking the state
             $resource->update_info($id, $fields);
             $response->msg = sprintf($this->lang['msg'], $name);
             $response->resource_id = $id;
         } else {
             $response->error = sprintf($this->lang['msg_add_failed']);
         }
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:48,代码来源:resource.new.class.php

示例12: remove

 function remove()
 {
     $response = $this->get_response();
     $vms = $response->html->request()->get($this->identifier_name);
     $form = $response->form;
     if ($vms !== '') {
         $submit = $form->get_elements('submit');
         $submit->handler = 'onclick="wait();"';
         $form->add($submit, 'submit');
         $submit = $form->get_elements('cancel');
         $submit->handler = 'onclick="cancel();"';
         $form->add($submit, 'cancel');
         $i = 0;
         foreach ($vms as $ex) {
             $d['param_f' . $i]['label'] = $ex;
             $d['param_f' . $i]['object']['type'] = 'htmlobject_input';
             $d['param_f' . $i]['object']['attrib']['type'] = 'checkbox';
             $d['param_f' . $i]['object']['attrib']['name'] = $this->identifier_name . '[' . $i . ']';
             $d['param_f' . $i]['object']['attrib']['value'] = $ex;
             $d['param_f' . $i]['object']['attrib']['checked'] = true;
             $i++;
         }
         $form->add($d);
         if (!$form->get_errors() && $response->submit()) {
             $appliance_id = $this->response->html->request()->get('appliance_id');
             $appliance = new appliance();
             $resource = new resource();
             $errors = array();
             $message = array();
             foreach ($vms as $key => $vm) {
                 $appliance->get_instance_by_id($appliance_id);
                 $resource->get_instance_by_id($appliance->resources);
                 $file = $this->openqrm->get('basedir') . '/plugins/kvm/web/kvm-stat/' . $resource->id . '.vm_list';
                 if ($this->file->exists($file)) {
                     $lines = explode("\n", $this->file->get_contents($file));
                     if (count($lines) >= 1) {
                         foreach ($lines as $line) {
                             if ($line !== '') {
                                 $line = explode('@', $line);
                                 if ($vm === $line[1]) {
                                     $kvm = new resource();
                                     $kvm->get_instance_by_mac($line[2]);
                                     // check if it is still in use
                                     $appliances_using_resource = $appliance->get_ids_per_resource($kvm->id);
                                     if (count($appliances_using_resource) > 0) {
                                         $appliances_using_resource_str = implode(",", $appliances_using_resource[0]);
                                         $errors[] = sprintf($this->lang['msg_vm_resource_still_in_use'], $vm, $kvm->id, $appliances_using_resource_str);
                                     } else {
                                         $kvm->remove($kvm->id, $line[2]);
                                         $command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm-vm delete -n ' . $vm;
                                         $command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
                                         $command .= ' --openqrm-ui-user ' . $this->user->name;
                                         $command .= ' --openqrm-cmd-mode background';
                                         $resource->send_command($resource->ip, $command);
                                         $form->remove($this->identifier_name . '[' . $key . ']');
                                         $message[] = sprintf($this->lang['msg_removed'], $vm);
                                         // stop remote console
                                         $tmp = explode(':', $line[5]);
                                         $server = $tmp[0];
                                         $port = $tmp[1];
                                         $mac = $line[2];
                                         $rid = $kvm->id;
                                         $event = new event();
                                         $plugin = new plugin();
                                         $enabled = $plugin->enabled();
                                         foreach ($enabled as $index => $name) {
                                             $running = $this->openqrm->get('webdir') . '/plugins/' . $name . '/.running';
                                             $hook = $this->openqrm->get('webdir') . '/plugins/' . $name . '/openqrm-' . $name . '-remote-console-hook.php';
                                             if (file_exists($hook)) {
                                                 if (file_exists($running)) {
                                                     $event->log("console", $_SERVER['REQUEST_TIME'], 5, "kvm-storge-vm.remove.class.php", 'Stopping ' . $name . ' remote console.', "", "", 0, 0, $kvm->id);
                                                     require_once $hook;
                                                     $console_function = 'openqrm_' . $name . '_disable_remote_console';
                                                     $console_function = str_replace("-", "_", $console_function);
                                                     $console_function($server, $port, $rid, $mac, $vm);
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (count($errors) === 0) {
                 $response->msg = join('<br>', $message);
             } else {
                 $msg = array_merge($errors, $message);
                 $response->error = join('<br>', $msg);
             }
         }
     } else {
         $response->msg = '';
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:97,代码来源:kvm-vm.remove.class.php

示例13: duplicate

 function duplicate()
 {
     $response = $this->get_response();
     $form = $response->form;
     if (!$form->get_errors() && $this->response->submit()) {
         $mac_gen_resource = new resource();
         $mac_gen_resource->generate_mac();
         $name = $form->get_request('name');
         $command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm-vm clone';
         $command .= ' -n ' . $this->vm;
         $command .= ' -w ' . $name;
         $command .= ' -m ' . $mac_gen_resource->mac;
         $command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
         $command .= ' --openqrm-ui-user ' . $this->user->name;
         $command .= ' --openqrm-cmd-mode regular';
         $statfile = $this->statfile;
         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);
                         }
                     }
                 }
             }
         }
         if (isset($error)) {
             $response->error = $error;
         } else {
             $tables = $this->openqrm->get('table');
             $id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
             $ip = "0.0.0.0";
             $mac = $mac_gen_resource->mac;
             // set resource type, get virt type from origin vm
             $mac_gen_resource->get_instance_by_mac($this->vm_mac);
             $virtualization = new virtualization();
             $virtualization->get_instance_by_id($mac_gen_resource->vtype);
             // send command to the openQRM-server
             $openqrm = new openqrm_server();
             $openqrm->send_command('openqrm_server_add_resource ' . $id . ' ' . $mac . ' ' . $ip);
             // add to openQRM database
             $fields["resource_id"] = $id;
             $fields["resource_ip"] = $ip;
             $fields["resource_mac"] = $mac;
             $fields["resource_localboot"] = 0;
             $fields["resource_vtype"] = $virtualization->id;
             $fields["resource_vhostid"] = $this->resource->id;
             $this->resource->add($fields);
             $this->resource->send_command($this->resource->ip, $command);
             $response->resource_id = $id;
             $response->msg = sprintf($this->lang['msg_cloned'], $this->vm, $name);
         }
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:59,代码来源:kvm-vm.clone.class.php


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