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


PHP openqrm_server::send_command方法代码示例

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


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

示例1: openqrm_dhcpd_appliance

function openqrm_dhcpd_appliance($cmd, $appliance_fields)
{
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_EXEC_PORT;
    $openqrm_server = new openqrm_server();
    $OPENQRM_SERVER_IP_ADDRESS = $openqrm_server->get_ip_address();
    $event = new event();
    $appliance_id = $appliance_fields["appliance_id"];
    $appliance_name = $appliance_fields["appliance_name"];
    $resource = new resource();
    $resource->get_instance_by_id($appliance_fields["appliance_resources"]);
    $resource_mac = $resource->mac;
    $resource_ip = $resource->ip;
    $appliance = new appliance();
    $appliance->get_instance_by_id($appliance_id);
    if ($resource->id == "-1" || $resource->id == "") {
        return;
    }
    $event->log("openqrm_dhcpd_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-dhcpd-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$resource_ip}/{$resource_mac}", "", "", 0, 0, $resource->id);
    switch ($cmd) {
        case "start":
            $event->log("openqrm_dhcpd_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-dhcpd-appliance-hook.php", "Adding hostname " . $appliance->name . " from resource " . $resource->id . ".", "", "", 0, 0, $resource->id);
            $dhcpd_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/dhcpd/bin/openqrm-dhcpd-appliance add_hostname -m " . $resource_mac . " -n " . $appliance->name . " -d " . $resource->id . " --openqrm-cmd-mode background";
            $openqrm_server->send_command($dhcpd_command);
            break;
        case "stop":
            $event->log("openqrm_dhcpd_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-dhcpd-appliance-hook.php", "Removing hostname " . $appliance->name . " from resource " . $resource->id . ".", "", "", 0, 0, $resource->id);
            $dhcpd_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/dhcpd/bin/openqrm-dhcpd-appliance remove_hostname -m " . $resource_mac . " -n " . $appliance->name . " -d " . $resource->id . " --openqrm-cmd-mode background";
            $openqrm_server->send_command($dhcpd_command);
            break;
    }
}
开发者ID:kelubo,项目名称:OpenQRM,代码行数:32,代码来源:openqrm-dhcpd-appliance-hook.php

示例2: openqrm_dhcpd_resource

function openqrm_dhcpd_resource($cmd, $resource_fields)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $resource_id = $resource_fields["resource_id"];
    $resource_ip = $resource_fields["resource_ip"];
    $resource_mac = $resource_fields["resource_mac"];
    if (isset($resource_fields["resource_subnet"])) {
        $resource_subnet = $resource_fields["resource_subnet"];
    } else {
        $resource_subnet = "0.0.0.0";
    }
    $openqrm_admin_user = new user("openqrm");
    $openqrm_admin_user->set_user();
    $openqrm_server = new openqrm_server();
    $event->log("openqrm_new_resource", $_SERVER['REQUEST_TIME'], 5, "openqrm-dhcpd-resource-hook.php", "Handling {$cmd} event {$resource_id}/{$resource_ip}/{$resource_subnet}/{$resource_mac}", "", "", 0, 0, $resource_id);
    switch ($cmd) {
        case "add":
            $openqrm_server->send_command($OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/dhcpd/bin/openqrm-dhcpd-manager add -d " . $resource_id . " -m " . $resource_mac . " -i " . $resource_ip . " -s " . $resource_subnet . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background");
            break;
        case "remove":
            $openqrm_server->send_command("{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/dhcpd/bin/openqrm-dhcpd-manager remove -d " . $resource_id . " -m " . $resource_mac . " -i " . $resource_ip . " -s " . $resource_subnet . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background");
            break;
    }
}
开发者ID:kelubo,项目名称:OpenQRM,代码行数:27,代码来源:openqrm-dhcpd-resource-hook.php

示例3: openqrm_template_appliance

function openqrm_template_appliance($cmd, $appliance_fields)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $appliance_id = $appliance_fields["appliance_id"];
    $appliance_name = $appliance_fields["appliance_name"];
    $resource = new resource();
    $resource->get_instance_by_id($appliance_fields["appliance_resources"]);
    $appliance_ip = $resource->ip;
    // check appliance values, maybe we are in update and they are incomplete
    if ($resource->id == "-1" || $resource->id == "") {
        return;
    }
    $event->log("openqrm_new_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-template-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id);
    switch ($cmd) {
        case "start":
            $openqrm_server = new openqrm_server();
            $openqrm_server->send_command($OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template/bin/openqrm-template-manager start " . $appliance_id . " " . $appliance_name . " " . $appliance_ip . " --openqrm-cmd-mode background");
            break;
        case "stop":
            $openqrm_server = new openqrm_server();
            $openqrm_server->send_command($OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/template/bin/openqrm-template-manager stop " . $appliance_id . " " . $appliance_name . " " . $appliance_ip . " --openqrm-cmd-mode background");
            break;
    }
}
开发者ID:kelubo,项目名称:OpenQRM,代码行数:27,代码来源:openqrm-template-appliance-hook.php

示例4: openqrm_nagios3_appliance

function openqrm_nagios3_appliance($cmd, $appliance_fields)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $appliance_id = $appliance_fields["appliance_id"];
    $appliance = new appliance();
    $appliance->get_instance_by_id($appliance_id);
    $appliance_name = $appliance_fields["appliance_name"];
    $resource = new resource();
    $resource->get_instance_by_id($appliance_fields["appliance_resources"]);
    $appliance_ip = $resource->ip;
    // check appliance values, maybe we are in update and they are incomplete
    if ($appliance->imageid == 1) {
        return;
    }
    if ($resource->id == "-1" || $resource->id == "") {
        return;
    }
    // get the nagios service checks
    $nagios_host = new nagios3_host();
    $nagios_host->get_instance_by_appliance_id($appliance_id);
    $active_nagios_services = explode(',', $nagios_host->appliance_services);
    $nagios_service_list = '';
    foreach ($active_nagios_services as $service_id) {
        $nagios_service = new nagios3_service();
        $nagios_service->get_instance_by_id($service_id);
        $nagios_service_list = $nagios_service_list . "," . $nagios_service->port;
    }
    $nagios_service_list = substr($nagios_service_list, 1);
    if (!strlen($nagios_service_list)) {
        $event->log("openqrm_new_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-nagios3-appliance-hook.php", "Appliance {$appliance_id} has no configured nagios services, skipping...", "", "", 0, 0, $appliance_id);
        return 0;
    }
    $event->log("openqrm_new_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-nagios3-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id);
    switch ($cmd) {
        case "start":
            $nagios_appliance_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nagios3/bin/openqrm-nagios-manager add -n " . $appliance_name . " -i " . $resource->ip . " -p " . $nagios_service_list . " --openqrm-cmd-mode background";
            $openqrm_server = new openqrm_server();
            $openqrm_server->send_command($nagios_appliance_start_cmd, NULL, true);
            break;
        case "stop":
            $nagios_appliance_stop_cmd = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/nagios3/bin/openqrm-nagios-manager remove_host -n " . $appliance_name . " --openqrm-cmd-mode background";
            $openqrm_server = new openqrm_server();
            $openqrm_server->send_command($nagios_appliance_stop_cmd, NULL, true);
            break;
        case "remove":
            $nagios_appliance_stop_cmd = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/nagios3/bin/openqrm-nagios-manager remove_host -n " . $appliance_name . " --openqrm-cmd-mode background";
            $openqrm_server = new openqrm_server();
            $openqrm_server->send_command($nagios_appliance_stop_cmd, NULL, true);
            // remove nagios_host from the db
            $nagios_host->remove_by_appliance_id($appliance_id);
            break;
    }
}
开发者ID:kelubo,项目名称:OpenQRM,代码行数:56,代码来源:openqrm-nagios3-appliance-hook.php

示例5: openqrm_tftpd_resource

function openqrm_tftpd_resource($cmd, $resource_fields)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $resource_id = $resource_fields["resource_id"];
    $resource_ip = $resource_fields["resource_ip"];
    $resource_mac = $resource_fields["resource_mac"];
    $event->log("openqrm_new_resource", $_SERVER['REQUEST_TIME'], 5, "openqrm-tftpd-resource-hook.php", "Handling {$cmd} event {$resource_id}/{$resource_ip}/{$resource_mac}", "", "", 0, 0, $resource_id);
    switch ($cmd) {
        case "remove":
            // we remove the pxe config file; the database removal is handled in the resource class
            $openqrm_server = new openqrm_server();
            $openqrm_server->send_command("openqrm_remove_resource {$resource_id} {$resource_mac}");
            break;
    }
}
开发者ID:kelubo,项目名称:OpenQRM,代码行数:18,代码来源:openqrm-tftpd-resource-hook.php

示例6: openqrm_puppet_resource

function openqrm_puppet_resource($cmd, $resource_fields)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $resource_id = $resource_fields["resource_id"];
    $resource = new resource();
    $resource->get_instance_by_id($resource_id);
    $resource_ip = $resource->ip;
    $resource_name = $resource->hostname;
    $event->log("openqrm_puppet_resource", $_SERVER['REQUEST_TIME'], 5, "openqrm-puppet-resource-hook.php", "Handling {$cmd} event {$resource_id}/{$resource_name}/{$resource_ip}", "", "", 0, 0, $resource_id);
    // we do only care if we serving an appliance
    $appliance = new appliance();
    $appliance_record_set = array();
    $appliance_id_array = array();
    $appliance_record_set = $appliance->get_all_ids();
    // the appliance_array from getlist is a 2-dimensional array
    foreach ($appliance_record_set as $index => $appliance_id_array) {
        foreach ($appliance_id_array as $index => $id) {
            $tapp = new appliance();
            $tapp->get_instance_by_id($id);
            $tapp_state = $tapp->state;
            $tapp_resources = $tapp->resources;
            if (!strcmp($tapp_state, "active")) {
                if ($tapp_resources == $resource_id) {
                    // we found the resources active appliance, running the cmd
                    $appliance_name = $tapp->name;
                    switch ($cmd) {
                        case "start":
                            $openqrm_server = new openqrm_server();
                            $openqrm_server->send_command("{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/puppet/bin/openqrm-puppet-manager start {$id} {$appliance_name} {$resource_ip} --openqrm-cmd-mode background");
                            break;
                        case "stop":
                            $openqrm_server = new openqrm_server();
                            $openqrm_server->send_command("{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/puppet/bin/openqrm-puppet-manager stop {$id} {$appliance_name} {$resource_ip} --openqrm-cmd-mode background");
                            break;
                    }
                }
            }
        }
    }
}
开发者ID:kelubo,项目名称:OpenQRM,代码行数:43,代码来源:openqrm-puppet-resource-hook.php

示例7: openqrm_collectd_appliance

function openqrm_collectd_appliance($cmd, $appliance_fields)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $appliance_id = $appliance_fields["appliance_id"];
    $appliance_name = $appliance_fields["appliance_name"];
    $resource = new resource();
    $resource->get_instance_by_id($appliance_fields["appliance_resources"]);
    $appliance_ip = $resource->ip;
    $event->log("openqrm_new_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-collectd-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$appliance_ip}", "", "", 0, 0, $appliance_id);
    // we remove the stats on add and remove
    switch ($cmd) {
        case "add":
            $openqrm_server = new openqrm_server();
            $openqrm_server->send_command($OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/collectd/bin/openqrm-collectd-manager remove " . $appliance_name . " now --openqrm-cmd-mode background");
            break;
        case "remove":
            $openqrm_server = new openqrm_server();
            $openqrm_server->send_command($OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/collectd/bin/openqrm-collectd-manager remove " . $appliance_name . " now --openqrm-cmd-mode background");
            break;
    }
}
开发者ID:kelubo,项目名称:OpenQRM,代码行数:24,代码来源:openqrm-collectd-appliance-hook.php

示例8: action

 function action()
 {
     $msg = '';
     $event = new event();
     $server = new openqrm_server();
     $plugin = new plugin();
     $identifier = $this->response->html->request()->get($this->identifier_name);
     $enabled = $plugin->enabled();
     if ($identifier !== '') {
         foreach ($identifier as $id) {
             if (in_array($id, $enabled)) {
                 $error = false;
                 // check dependencies
                 foreach ($enabled as $v) {
                     if ($v !== $id) {
                         $tmp = $plugin->get_dependencies($v);
                         if ($tmp !== '' && isset($tmp['dependencies']) && $tmp['dependencies'] !== '') {
                             if (strpos($tmp['dependencies'], $id) !== false) {
                                 $msg .= sprintf($this->lang['error_dependencies'], $id, $v) . '<br>';
                                 $error = true;
                             }
                         }
                     }
                 }
                 // handle plugin type
                 if ($error === false) {
                     $tmp = $plugin->get_config($id);
                     switch ($tmp['type']) {
                         case 'storage':
                             $storage = new storage();
                             $types = $storage->get_storage_types();
                             $deployment = new deployment();
                             $dep = $deployment->get_id_by_storagetype($id);
                             foreach ($dep as $val) {
                                 if (in_array($val['value'], $types)) {
                                     $msg .= sprintf($this->lang['error_in_use'], $id) . '<br>';
                                     $error = true;
                                 }
                             }
                             break;
                     }
                 }
                 if ($error === false) {
                     $return = $server->send_command("openqrm_server_plugin_command " . $id . " uninstall " . $GLOBALS['OPENQRM_ADMIN']->name . ' ' . $GLOBALS['OPENQRM_ADMIN']->password);
                     if ($return === true) {
                         if ($this->__check($id)) {
                             $msg .= sprintf($this->lang['msg'], $id) . '<br>';
                         } else {
                             $msg .= sprintf($this->lang['error_timeout'], $id) . '<br>';
                         }
                     } else {
                         $msg .= sprintf($this->lang['error_disable'], $id) . '<br>';
                     }
                 }
             }
         }
     }
     $this->response->redirect($this->response->get_url($this->actions_name, 'select', $this->message_param, $msg));
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:59,代码来源:aa_plugins.disable.class.php

示例9: remove

 function remove()
 {
     $response = $this->get_response();
     $group_name = $response->html->request()->get('group_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'] = $group_name;
     $d['param_f']['object']['type'] = 'htmlobject_input';
     $d['param_f']['object']['attrib']['type'] = 'checkbox';
     $d['param_f']['object']['attrib']['name'] = 'group_name';
     $d['param_f']['object']['attrib']['value'] = $group_name;
     $d['param_f']['object']['attrib']['checked'] = true;
     $form->add($d);
     if (!$form->get_errors() && $response->submit()) {
         $errors = array();
         $message = array();
         require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php';
         $hc = new hybrid_cloud();
         $hc->get_instance_by_id($this->id);
         $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-group remove';
         $command .= ' -i ' . $hc->id;
         $command .= ' -n ' . $hc->account_name;
         $command .= ' -O ' . $hc->access_key;
         $command .= ' -W ' . $hc->secret_key;
         $command .= ' -t ' . $hc->account_type;
         $command .= ' -ar ' . $this->region;
         $command .= ' -gn ' . $group_name;
         $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'], $group_name);
         if (count($errors) === 0) {
             $response->msg = join('<br>', $message);
         } else {
             $msg = array_merge($errors, $message);
             $response->error = join('<br>', $msg);
         }
         sleep(4);
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:47,代码来源:hybrid-cloud-group.remove.class.php

示例10: appliance

 $appliance_fields["appliance_capabilities"] = 'TYPE=local-server';
 $appliance_fields["appliance_comment"] = "Local-server appliance resource {$local_server_id}";
 $appliance = new appliance();
 $appliance->add($appliance_fields);
 // set start time, reset stoptime, set state
 $now = $_SERVER['REQUEST_TIME'];
 $appliance_fields["appliance_starttime"] = $now;
 $appliance_fields["appliance_stoptime"] = 0;
 $appliance_fields['appliance_state'] = 'active';
 // set resource type to physical
 $appliance_fields['appliance_virtualization'] = 1;
 $appliance->update($next_appliance_id, $appliance_fields);
 // set resource to localboot
 $resource = new resource();
 $resource->get_instance_by_id($local_server_id);
 $openqrm_server->send_command("openqrm_server_set_boot local {$local_server_id} {$resource->mac} 0.0.0.0");
 $resource->set_localboot($local_server_id, 1);
 // update resource fields with kernel + image
 $kernel->get_instance_by_id($kernel_fields["kernel_id"]);
 $resource_fields["resource_kernel"] = $kernel->name;
 $resource_fields["resource_kernelid"] = $kernel_fields["kernel_id"];
 $image->get_instance_by_id($image_fields["image_id"]);
 $resource_fields["resource_image"] = $image->name;
 $resource_fields["resource_imageid"] = $image_fields["image_id"];
 // set capabilites
 $resource_fields["resource_capabilities"] = 'TYPE=local-server';
 $resource->update_info($local_server_id, $resource_fields);
 // add + start hook
 $appliance->get_instance_by_id($next_appliance_id);
 $now = $_SERVER['REQUEST_TIME'];
 $appliance_fields = array();
开发者ID:kelubo,项目名称:OpenQRM,代码行数:31,代码来源:local-server-action.php

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

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

示例13: create


//.........这里部分代码省略.........
                 $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
     $vm_resource_fields["resource_ip"] = $vm_resource_ip;
     $vm_resource_fields["resource_mac"] = $mac;
     $vm_resource_fields["resource_localboot"] = 0;
     $vm_resource_fields["resource_vtype"] = $vtype->id;
     $vm_resource_fields["resource_vhostid"] = $less_load_resource_id;
     $vm_resource_fields["resource_vname"] = $name;
     $new_resource_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
     $vm_resource_fields["resource_id"] = $new_resource_id;
     $host_resource->add($vm_resource_fields);
     // send new-resource command now after the resource is created logically
     $openqrm->send_command("openqrm_server_add_resource {$new_resource_id} {$mac} {$vm_resource_ip}");
     // let the new resource commands settle
     sleep(10);
     // plug in the virtualization cloud hook
     $virtualization_cloud_hook = "{$RootDir}/plugins/{$virtualization_plugin_name}/openqrm-{$virtualization_plugin_name}-cloud-hook.php";
     if (file_exists($virtualization_cloud_hook)) {
         $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class", "Found plugin {$virtualization_plugin_name} handling to create the VM.", "", "", 0, 0, $new_resource_id);
         require_once "{$virtualization_cloud_hook}";
         $virtualization_method = "create_" . $vtype->type;
         $virtualization_method = str_replace("-", "_", $virtualization_method);
         $virtualization_method($less_load_resource_id, $name, $mac, $memory, $cpu, $swap, $additional_nic_str, $vncpassword, $source_image_id);
     } else {
         $event->log("cloud", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class", "Do not know how to create VM from type {$virtualization_plugin_name}.", "", "", 0, 0, 0);
         // remove resource object
         $vm_resource = new resource();
         $vm_resource->get_instance_by_id($new_resource_id);
         $vm_resource->remove($new_resource_id, $mac);
         return false;
     }
     // update hostlimits quite early to avoid overloading a Host with non-starting VMs
     // add or update hostlimits
     $res_hostlimit = new cloudhostlimit();
     $res_hostlimit->get_instance_by_resource($host_resource->id);
     if (strlen($res_hostlimit->id)) {
         // update
         $current_vms = $res_hostlimit->current_vms + 1;
         $cloud_hostlimit_fields["hl_current_vms"] = $current_vms;
         $res_hostlimit->update($res_hostlimit->id, $cloud_hostlimit_fields);
     } else {
         // add
         $cloud_hostlimit_fields["hl_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
         $cloud_hostlimit_fields["hl_resource_id"] = $host_resource->id;
         $cloud_hostlimit_fields["hl_max_vms"] = -1;
         $cloud_hostlimit_fields["hl_current_vms"] = 1;
         $res_hostlimit->add($cloud_hostlimit_fields);
     }
     $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "New VM created with resource id " . $new_resource_id . " and started. Waiting now until it is active/idle", "", "", 0, 0, 0);
     if ($vm_provision_delay > 0) {
         $event->log("create", $_SERVER['REQUEST_TIME'], 5, "cloudvm.class.php", "Delaying the provisioning of resource id " . $new_resource_id . " for " . $vm_provision_delay . " seconds.", "", "", 0, 0, 0);
         sleep($vm_provision_delay);
     }
     // setting this object resource id as return state
     $this->resource_id = $new_resource_id;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:101,代码来源:cloudvm.class.php

示例14: add

 function add()
 {
     $response = $this->get_response();
     $form = $response->form;
     $errors = array();
     if (!$form->get_errors() && $this->response->submit()) {
         $keypair_name = $form->get_request('name');
         if (!strlen($keypair_name)) {
             $errors[] = $this->lang['error_name'];
         }
         if (count($errors) > 0 || $form->get_errors()) {
             $response->error = join('<br>', $errors);
         } else {
             $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') {
                 $keypair_content = $form->get_request('keypair_content');
                 if (!strlen($keypair_content)) {
                     $errors[] = $this->lang['error_keypair_content'];
                 }
                 $keypair_content = str_replace(' ', '%', $keypair_content);
                 $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;
                 $hc_authentication .= ' -c ' . $keypair_content;
             }
             $openqrm = new openqrm_server();
             $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-keypair create';
             $command .= ' -i ' . $this->hc->id;
             $command .= ' -n ' . $this->hc->account_name;
             $command .= ' -t ' . $this->hc->account_type;
             $command .= $hc_authentication;
             $command .= ' -k ' . $keypair_name;
             $command .= ' --openqrm-ui-user ' . $this->user->name;
             $command .= ' --openqrm-cmd-mode background';
             $openqrm->send_command($command, NULL, true);
             sleep(4);
             $response->msg = sprintf($this->lang['msg_added'], $keypair_name);
         }
     }
     return $response;
 }
开发者ID:kelubo,项目名称:OpenQRM,代码行数:49,代码来源:hybrid-cloud-keypair.add.class.php

示例15: select

 function select()
 {
     $h = array();
     $h['state']['title'] = $this->lang['table_state'];
     $h['name']['title'] = $this->lang['table_name'];
     $h['region']['title'] = $this->lang['table_region'];
     $h['ami']['title'] = $this->lang['table_ami'];
     $h['type']['title'] = $this->lang['table_type'];
     $h['public']['title'] = $this->lang['table_public_ip'];
     $h['private']['title'] = $this->lang['table_private_ip'];
     $h['import']['title'] = '&#160;';
     $h['import']['sortable'] = false;
     $content = array();
     $file = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/hybrid-cloud-stat/' . $this->id . '.describe_instances.log';
     if ($this->file->exists($file)) {
         $this->file->remove($file);
     }
     require_once $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/web/class/hybrid-cloud.class.php';
     $hc = new hybrid_cloud();
     $hc->get_instance_by_id($this->id);
     $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm describe';
     $command .= ' -i ' . $hc->id;
     $command .= ' -n ' . $hc->account_name;
     $command .= ' -O ' . $hc->access_key;
     $command .= ' -W ' . $hc->secret_key;
     $command .= ' -t ' . $hc->account_type;
     $command .= ' -ir ' . $this->region;
     $command .= ' --openqrm-ui-user ' . $this->user->name;
     $command .= ' --openqrm-cmd-mode background';
     $server = new openqrm_server();
     $server->send_command($command, NULL, true);
     while (!$this->file->exists($file)) {
         usleep(10000);
         // sleep 10ms to unload the CPU
         clearstatcache();
     }
     $content = $this->file->get_contents($file);
     $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 = $tmp[16];
             $private_ip = $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 = '';
             $select_for_import = '';
             if ($state == 'idle') {
                 $state_icon = "/openqrm/base/img/idle.png";
             } else {
                 if ($state == 'running') {
                     $state_icon = "/openqrm/base/img/active.png";
                     // select for import
                     $a = $this->response->html->a();
                     $a->label = $this->lang['action_import'];
                     $a->title = $this->lang['action_import'];
                     $a->handler = 'onclick="wait();"';
                     $a->css = 'edit';
                     $a->href = $this->response->get_url($this->actions_name, 'imtarget') . '&instance_name=' . $name . '&instance_public_ip=' . $public_ip . '&instance_public_hostname=' . $public_hostname . '&instance_keypair=' . $keypair;
                     $select_for_import = $a->get_string();
                 } else {
                     $state_icon = "/openqrm/base/img/error.png";
                 }
             }
             $b[] = array('state' => "<img width=24 height=24 src=" . $state_icon . ">", 'name' => $name, 'region' => $region, 'ami' => $ami, 'type' => $type, 'public' => $public_hostname, 'private' => $private_ip, 'import' => $select_for_import);
         }
     }
     $params = $this->response->get_array($this->actions_name, 'import');
     $table = $this->response->html->tablebuilder('hybridcloud_import', $params);
     $table->offset = 0;
     $table->sort = 'id';
     $table->limit = 10;
     $table->order = 'ASC';
     $table->id = 'Tabelle';
     $table->css = 'htmlobject_table';
     $table->border = 1;
     $table->cellspacing = 0;
//.........这里部分代码省略.........
开发者ID:kelubo,项目名称:OpenQRM,代码行数:101,代码来源:hybrid-cloud.import.class.php


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