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


PHP resource::generate_mac方法代码示例

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


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

示例1: openqrm_cloud_monitor


//.........这里部分代码省略.........
                $rmail_admin->template = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/cloud/etc/mail/not_enough_resources.mail.tmpl";
                $arr = array('@@ID@@' => "{$cr_id}", '@@FORENAME@@' => "Cloudadmin", '@@LASTNAME@@' => "", '@@RESNUMBER@@' => "{$cr_resource_number}", '@@YOUR@@' => "the", '@@CLOUDADMIN@@' => $cc_acr_admin_email);
                $rmail_admin->var_array = $arr;
                $rmail_admin->send();
                continue;
            }
            // we have a phys. resource, update object
            $appliance->get_instance_by_id($appliance_id);
        } else {
            // ################################## auto create vm ###############################
            // check if we should try to create one
            // request type vm
            $cc_autovm_conf = new cloudconfig();
            $cc_auto_create_vms = $cc_autovm_conf->get_value(7);
            // 7 is auto_create_vms
            if (!strcmp($cc_auto_create_vms, "true")) {
                // check if createvmlc exists for this cr + res-quantity
                unset($cvmlc);
                $cvmlc = new cloudcreatevmlc();
                $cvmlc->get_instance_by_cr_details($cr_id, $cr_resource_number);
                if (!strlen($cvmlc->request_time)) {
                    // if no createvmlc exists so far create it and the vm
                    // generate a mac address
                    $mac_res = new resource();
                    // check if we need to generate the first nics mac address in the vmware address space
                    $new_vm_mac = "";
                    $vm_virt = new virtualization();
                    $vm_virt->get_instance_by_id($cr->resource_type_req);
                    $virt_name = $vm_virt->get_plugin_name();
                    switch ($virt_name) {
                        case 'vmware-esx':
                        case 'vmware-server':
                        case 'vmware-server2':
                            $mac_res->generate_mac();
                            $suggested_mac = $mac_res->mac;
                            $new_forth_byte_first_bit = rand(1, 3);
                            $new_vm_mac = strtolower($vmware_mac_address_space . ":" . substr($suggested_mac, 9));
                            $new_vm_mac = substr_replace($new_vm_mac, $new_forth_byte_first_bit, 9, 1);
                            break;
                        default:
                            $mac_res->generate_mac();
                            $new_vm_mac = $mac_res->mac;
                            break;
                    }
                    // additional_nics
                    $new_additional_nics = $cr->network_req;
                    // cpu
                    $new_vm_cpu = $cr->cpu_req;
                    // memory
                    $new_vm_memory = 256;
                    if ($cr->ram_req != 0) {
                        $new_vm_memory = $cr->ram_req;
                    }
                    // disk size
                    $new_vm_disk = 5000;
                    if ($cr->disk_req != 0) {
                        $new_vm_disk = $cr->disk_req;
                    }
                    // here we generate the password for the Image and optional vnc of the VM resource
                    $image = new image();
                    $vm_vnc_password = trim($image->generatePassword(12));
                    // put the password in the cr for the image later
                    $cr_update_fields = array();
                    $cr_update_fields['cr_image_password'] = $vm_vnc_password;
                    $cr->update($cr_id, $cr_update_fields);
                    // Create VM
开发者ID:kelubo,项目名称:OpenQRM,代码行数:67,代码来源:openqrm-cloud-monitor-hook.php

示例2: create


//.........这里部分代码省略.........
                     $less_load_resource_id = $this->vm_balance_load($active_appliance_list);
                     break;
             }
         }
     } else {
         $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Using Loadbalancing Algorithm " . $vm_loadbalance_algorithm . " for creating the new VM", "", "", 0, 0, 0);
         switch ($vm_loadbalance_algorithm) {
             case '0':
                 $less_load_resource_id = $this->vm_balance_load($active_appliance_list);
                 break;
             case '1':
                 $less_load_resource_id = $this->vm_balance_memory($active_appliance_list, $memory);
                 break;
             case '2':
                 $less_load_resource_id = $this->vm_balance_random($active_appliance_list);
                 break;
             case '3':
                 $less_load_resource_id = $this->vm_balance_first_available($active_appliance_list);
                 break;
             default:
                 $less_load_resource_id = $this->vm_balance_load($active_appliance_list);
                 break;
         }
     }
     if ($less_load_resource_id >= 0) {
         $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Found Virtualization host resource {$less_load_resource_id} as the target for the new VM ", "", "", 0, 0, 0);
     }
     // additional network cards
     if ($additional_nics > 0) {
         $anic = 1;
         $additional_nic_str = "";
         $mac_gen_res = new resource();
         while ($anic <= $additional_nics) {
             $mac_gen_res->generate_mac();
             switch ($virtualization_plugin_name) {
                 # VMware VMs need to get special macs
                 case 'vmware-esx':
                     $nic_nr = $anic;
                     $suggested_mac = $mac_gen_res->mac;
                     $new_forth_byte_first_bit = rand(1, 3);
                     $mac_gen_res_vmw = strtolower($vmware_mac_address_space . ":" . substr($suggested_mac, 9));
                     $mac_gen_res_vmw = substr_replace($mac_gen_res_vmw, $new_forth_byte_first_bit, 9, 1);
                     $additional_nic_str .= " -m" . $nic_nr . " " . $mac_gen_res_vmw;
                     break;
                     # VMs network parameter starts with -m1
                 # VMs network parameter starts with -m1
                 default:
                     $nic_nr = $anic;
                     $additional_nic_str .= " -m" . $nic_nr . " " . $mac_gen_res->mac;
                     break;
             }
             $anic++;
         }
     }
     // swap, for the cloud VMs we simply calculate memory * 2
     $swap = $memory * 2;
     // start the VM on the appliance resource
     $host_resource = new resource();
     $host_resource->get_instance_by_id($less_load_resource_id);
     $host_resource_ip = $host_resource->ip;
     // we need to have an openQRM server object too since some of the
     // virtualization commands are sent from openQRM directly
     $openqrm = new openqrm_server();
     // create the new resource + setting the virtualization type
     $vm_resource_ip = "0.0.0.0";
     // add to openQRM database
开发者ID:kelubo,项目名称:OpenQRM,代码行数:67,代码来源:cloudvm.class.php

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

示例4: edit


//.........这里部分代码省略.........
             $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 = $this->hc->format_ip_address($tmp[16]);
             $private_ip = $this->hc->format_ip_address($tmp[17]);
             $vpc = $tmp[18];
             $subnet = $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 = '';
             // remove
             $remove_instance = '';
             $import_str = '';
             if ($state == 'idle') {
                 $mac = $tmp[30];
                 $a = $this->response->html->a();
                 $a->label = $this->lang['action_remove_vm'];
                 $a->css = 'remove';
                 $a->handler = 'onclick="wait();"';
                 $a->href = $this->response->get_url($this->actions_name, "remove") . '&instance_name=' . $name . '&instance_mac=' . $mac;
                 $remove_instance = $a->get_string();
                 $state_icon = '<span class="pill idle">idle</span>';
             } else {
                 if ($state == 'running') {
                     $state_icon = '<span class="pill active">active</span>';
                     // import
                     $import_resource = new resource();
                     $import_resource->get_instance_id_by_hostname($name);
                     if ($import_resource->id == '') {
                         // import add
                         if (!strlen($mac)) {
                             $import_resource->generate_mac();
                             $mac = $import_resource->mac;
                         }
                         $link = $this->response->get_url($this->actions_name, "import");
                         $link .= '&instance_command=add&instance_name=' . $name;
                         $link .= '&instance_mac=' . $mac;
                         $link .= '&instance_public_ip=' . $public_ip;
                         $link .= '&instance_type=' . $type;
                         $link .= '&instance_keypair=' . $keypair;
                         $link .= '&instance_region=' . $region;
                         $link .= '&instance_ami=' . $ami;
                         $link .= '&instance_subnet=' . $subnet;
                         $a = $this->response->html->a();
                         $a->label = $this->lang['action_import_instance'];
                         $a->title = $this->lang['action_import_instance_title'];
                         $a->css = 'add';
                         $a->handler = 'onclick="wait();"';
                         $a->href = $link;
                         $import_str = $a->get_string();
                     }
                 } else {
                     $state_icon = '<span class="pill ' . $state . '">' . $state . '</span>';
                 }
             }
             $remove = $remove_instance . $import_str;
             $data = '<b>' . $this->lang['table_name'] . '</b>: ' . $name . '<br>';
             $data .= '<b>' . $this->lang['table_region'] . '</b>: ' . $region . '<br>';
             $data .= '<b>' . $this->lang['table_ami'] . '</b>: ' . $ami . '<br>';
             $data .= '<b>' . $this->lang['table_type'] . '</b>: ' . $type;
             $b[] = array('state' => $state_icon, 'name' => $name, 'region' => $region, 'ami' => $ami, 'type' => $type, 'data' => $data, 'public' => $public_ip, 'private' => $private_ip, 'remove' => $remove);
         }
     }
     $params = $this->response->get_array($this->actions_name, 'edit');
     $table = $this->response->html->tablebuilder('hybridcloud_vm_edit', $params);
     $table->form_action = $this->response->html->thisfile;
     $table->offset = 0;
     $table->sort = 'name';
     $table->limit = 10;
     $table->order = 'ASC';
     $table->id = 'Tabelle';
     $table->css = 'htmlobject_table';
     $table->border = 1;
     $table->cellspacing = 0;
     $table->cellpadding = 3;
     $table->autosort = true;
     $table->sort_link = false;
     $table->max = count($b);
     $table->head = $h;
     $table->body = $b;
     $d['name'] = $this->hc->account_name;
     $d['form'] = $this->response->get_form($this->actions_name, 'import', false)->get_elements();
     $d['table'] = $table;
     return $d;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:101,代码来源:hybrid-cloud-vm.edit.class.php

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