コード例 #1
0
function get_nagios3_appliance_link($appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $p_appliance = new appliance();
    $p_appliance->get_instance_by_id($appliance_id);
    $p_resource = new resource();
    $p_resource->get_instance_by_id($p_appliance->resources);
    $nagios_link = "/openqrm/base/index.php?name=Nagios3&iframe=/cgi-bin/nagios3/status.cgi?host=" . $p_appliance->name;
    $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects');
    $a = $html->a();
    //	$a->label = '<img title="Service monitoring" alt="Service monitoring" height="24" width="24" src="/openqrm/base/plugins/nagios3/img/plugin.png" border=0>';
    $a->label = 'nagios';
    $a->css = 'badge';
    $a->href = $nagios_link;
    $a->handler = '';
    $plugin_link = $a;
    if ($p_resource->id == 0) {
        $plugin_link = $a;
    }
    if ($p_resource->id == '') {
        $plugin_link = "";
    }
    return $plugin_link;
}
コード例 #2
0
function get_novnc_appliance_link($appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $p_appliance = new appliance();
    $p_appliance->get_instance_by_id($appliance_id);
    $p_resource = new resource();
    $p_resource->get_instance_by_id($p_appliance->resources);
    $virtualization = new virtualization();
    $virtualization->get_instance_by_id($p_appliance->virtualization);
    $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects');
    $a = $html->a();
    $a->label = 'noVNC';
    $a->css = 'badge';
    $a->handler = 'onclick="wait();"';
    $plugin_link = '';
    if (strstr($p_appliance->state, "active")) {
        if (strstr($virtualization->type, '-vm-')) {
            $a->href = '/openqrm/base/index.php?plugin=novnc&controller=novnc&novnc_action=console&appliance_id=' . $p_appliance->id;
        } else {
            $a->href = '/openqrm/base/index.php?plugin=novnc&controller=novnc&novnc_action=login&appliance_id=' . $p_appliance->id;
        }
        $plugin_link = $a;
    } else {
        if ($p_resource->id === '0') {
            $a->href = '/openqrm/base/index.php?plugin=novnc&controller=novnc&novnc_action=login&appliance_id=' . $p_appliance->id;
            $plugin_link = $a;
        }
    }
    return $plugin_link;
}
コード例 #3
0
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;
    }
}
コード例 #4
0
function get_template_appliance_link($appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $p_appliance = new appliance();
    $p_appliance->get_instance_by_id($appliance_id);
    $p_resource = new resource();
    $p_resource->get_instance_by_id($p_appliance->resources);
    $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects');
    $a = $html->a();
    $a->label = 'Template';
    $a->css = 'badge';
    $a->href = '#';
    $a->handler = 'onclick="window.open(\'Template-URL\',\'\', \'location=0,status=0,scrollbars=1,width=1150,height=800,left=50,top=50,screenX=50,screenY=50\');return false;"';
    $plugin_link = '';
    if (strstr($p_appliance->state, "active")) {
        $plugin_link = $a;
    }
    if ($p_resource->id == 0) {
        $plugin_link = $a;
    }
    if ($p_resource->id == '') {
        $plugin_link = "";
    }
    return $plugin_link;
}
コード例 #5
0
function get_sshterm_appliance_link($appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $p_appliance = new appliance();
    $p_appliance->get_instance_by_id($appliance_id);
    $p_resource = new resource();
    $p_resource->get_instance_by_id($p_appliance->resources);
    // get the parameters from the plugin config file
    $OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE = "{$OPENQRM_SERVER_BASE_DIR}/openqrm/plugins/sshterm/etc/openqrm-plugin-sshterm.conf";
    $store = openqrm_parse_conf($OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE);
    extract($store);
    $sshterm_login_ip = $p_resource->ip;
    $sshterm_window = 'window' . str_replace('.', '', $sshterm_login_ip);
    $sshterm_login_url = "https://{$sshterm_login_ip}:{$OPENQRM_PLUGIN_WEBSHELL_PORT}";
    $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects');
    $a = $html->a();
    $a->label = 'SSHTerm';
    $a->css = 'badge';
    $a->href = '#';
    $a->handler = 'onclick="sshwindow = window.open(\'' . $sshterm_login_url . '\',\'' . $sshterm_window . '\', \'location=0,status=0,scrollbars=yes,resizable=yes,width=972,height=500,left=100,top=100,screenX=400,screenY=100\'); sshwindow.focus(); return false;"';
    $plugin_link = '';
    if (strstr($p_appliance->state, "active")) {
        $plugin_link = $a;
    }
    if ($p_resource->id == 0) {
        $plugin_link = $a;
    }
    if ($p_resource->id == '') {
        $plugin_link = "";
    }
    return $plugin_link;
}
コード例 #6
0
function get_lcmc_appliance_link($appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $p_appliance = new appliance();
    $p_appliance->get_instance_by_id($appliance_id);
    $p_resource = new resource();
    $p_resource->get_instance_by_id($p_appliance->resources);
    $lcmc_gui = "/openqrm/base/plugins/lcmc/lcmc-gui.php";
    $icon_size = "width='24' height='24'";
    $icon_title = "Configure appliaction highavailability";
    $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects');
    $a = $html->a();
    $a->label = 'LCMC';
    //'<img title="'.$icon_title.'" alt="'.$icon_title.'" $icon_size src="/openqrm/base/plugins/lcmc/img/plugin.png" border=0>';
    $a->css = 'badge';
    $a->href = '#';
    $a->handler = 'onclick="window.open(\'' . $lcmc_gui . '\',\'\', \'location=0,status=0,scrollbars=1,width=1150,height=800,left=50,top=50,screenX=50,screenY=50\');return false;"';
    $plugin_link = '';
    if (strstr($p_appliance->state, "active")) {
        $plugin_link = $a;
    }
    if ($p_resource->id == 0) {
        $plugin_link = $a;
    }
    if ($p_resource->id == '') {
        $plugin_link = "";
    }
    return $plugin_link;
}
コード例 #7
0
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;
    }
}
コード例 #8
0
function get_puppet_appliance_edit($appliance_id, $openqrm, $response)
{
    $appliance = new appliance();
    $appliance->get_instance_by_id($appliance_id);
    $plugin_title = "Configure Application on Appliance " . $appliance->name;
    $a = $response->html->a();
    $a->label = '<image height="24" width="24" alt="' . $plugin_title . '" title="' . $plugin_title . '" src="' . $openqrm->get('baseurl') . '/plugins/puppet/img/plugin.png">';
    $a->href = $openqrm->get('baseurl') . '/index.php?base=appliance&appliance_action=load_edit&aplugin=puppet&puppet_action=edit&appliance_id=' . $appliance_id;
    return $a;
}
コード例 #9
0
function storage_auth_function($cmd, $appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $IMAGE_AUTHENTICATION_TABLE;
    global $openqrm_server;
    global $RootDir;
    $appliance = new appliance();
    $appliance->get_instance_by_id($appliance_id);
    $image = new image();
    $image->get_instance_by_id($appliance->imageid);
    $image_name = $image->name;
    $image_rootdevice = $image->rootdevice;
    $storage = new storage();
    $storage->get_instance_by_id($image->storageid);
    $storage_resource = new resource();
    $storage_resource->get_instance_by_id($storage->resource_id);
    $storage_ip = $storage_resource->ip;
    $deployment = new deployment();
    $deployment->get_instance_by_type($image->type);
    $deployment_type = $deployment->type;
    $deployment_plugin_name = $deployment->storagetype;
    $resource = new resource();
    $resource->get_instance_by_id($appliance->resources);
    $resource_mac = $resource->mac;
    $resource_ip = $resource->ip;
    // For kvm vms we assume that the image is located on the vm-host
    // so we send the auth command to the vm-host instead of the image storage.
    // This enables using a SAN backend with dedicated volumes per vm-host which all
    // contain all "golden-images" which are used for snapshotting.
    // We do this to overcome the current lvm limitation of not supporting cluster-wide snapshots
    $vm_host_resource = new resource();
    $vm_host_resource->get_instance_by_id($resource->vhostid);
    if ($vm_host_resource->id != $storage_resource->id) {
        $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-auth-hook.php", "Appliance " . $appliance_id . " image IS NOT available on this kvm host, " . $storage_resource->id . " not equal " . $vm_host_resource->id . " !! Assuming SAN Backend", "", "", 0, 0, $appliance_id);
    } else {
        $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-auth-hook.php", "Appliance " . $appliance_id . " image IS available on this kvm host, " . $storage_resource->id . " equal " . $vm_host_resource->id . ".", "", "", 0, 0, $appliance_id);
    }
    switch ($cmd) {
        case "start":
            // authenticate the rootfs / needs openqrm user + pass
            $openqrm_admin_user = new user("openqrm");
            $openqrm_admin_user->set_user();
            // generate a password for the image
            $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-auth-hook.php", "Authenticating " . $image_name . " / " . $image_rootdevice . " to resource " . $resource_mac . ".", "", "", 0, 0, $appliance_id);
            $auth_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $deployment_plugin_name . "/bin/openqrm-" . $deployment_plugin_name . " auth -n " . $image_name . " -r " . $image_rootdevice . " -i " . $image_name . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " -t " . $deployment->type . " --openqrm-cmd-mode background";
            $resource->send_command($vm_host_resource->ip, $auth_start_cmd);
            break;
    }
}
コード例 #10
0
function get_nagios3_appliance_edit($appliance_id, $openqrm, $response)
{
    $p_appliance = new appliance();
    $p_appliance->get_instance_by_id($appliance_id);
    $p_resource = new resource();
    $p_resource->get_instance_by_id($p_appliance->resources);
    if ($p_resource->id !== '') {
        $a = $response->html->a();
        $a->label = '<img title="Service monitoring" alt="Service monitoring" height="24" width="24" src="' . $openqrm->get('baseurl') . '/plugins/nagios3/img/plugin.png" border=0>';
        $a->href = $openqrm->get('baseurl') . '/index.php?base=appliance&appliance_action=load_edit&aplugin=nagios3&appliance_id=' . $appliance_id . '&nagios3_action=edit';
        return $a;
    }
}
コード例 #11
0
 function __construct($openqrm, $response)
 {
     $this->openqrm = $openqrm;
     $this->user = $this->openqrm->user();
     $this->rootdir = $this->openqrm->get('webdir');
     $this->response = $response;
     $this->file = $this->openqrm->file();
     $this->tpldir = $this->rootdir . '/plugins/template/tpl';
     require_once $this->openqrm->get('basedir') . '/plugins/template/web/class/template.class.php';
     $this->template = new template();
     $id = $this->response->html->request()->get('appliance_id');
     $this->response->add('appliance_id', $id);
     $appliance = new appliance();
     $this->appliance = $appliance->get_instance_by_id($id);
 }
コード例 #12
0
 function __construct($openqrm, $response)
 {
     $this->response = $response;
     $this->openqrm = $openqrm;
     $this->file = $openqrm->file();
     $this->user = $openqrm->user();
     $id = $this->response->html->request()->get('appliance_id');
     $this->response->add('appliance_id', $id);
     $this->response->add($this->identifier_name . '[]', '');
     $appliance = new appliance();
     $this->appliance = $appliance->get_instance_by_id($id);
     $resource = new resource();
     $this->resource = $resource->get_instance_by_id($this->appliance->resources);
     $this->statfile = $this->openqrm->get('basedir') . '/plugins/network-manager/web/storage/' . $this->resource->id . '.network_stat';
 }
コード例 #13
0
function get_network_manager_appliance_edit($appliance_id, $openqrm, $response)
{
    $appliance = new appliance();
    $appliance->get_instance_by_id($appliance_id);
    $virtualization = new virtualization();
    $virtualization->get_instance_by_id($appliance->virtualization);
    // choose only not vm
    if (stripos($virtualization->type, '-vm-') === false) {
        $plugin_title = "Network Manager on " . $appliance->name;
        $a = $response->html->a();
        $a->label = '<image height="24" width="24" alt="' . $plugin_title . '" title="' . $plugin_title . '" src="' . $openqrm->get('baseurl') . '/plugins/network-manager/img/plugin.png">';
        $a->href = $openqrm->get('baseurl') . '/index.php?base=appliance&appliance_action=load_edit&aplugin=network-manager&appliance_id=' . $appliance_id;
        return $a;
    }
}
コード例 #14
0
function get_template_appliance_edit($appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $appliance = new appliance();
    $appliance->get_instance_by_id($appliance_id);
    $plugin_title = "Configure Application on Appliance " . $appliance->name;
    $plugin_link = "/openqrm/base/index.php?plugin=template&appliance_id=" . $appliance_id . "&template_action=edit";
    $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects');
    $a = $html->a();
    $a->label = '<image height="24" width="24" alt="' . $plugin_title . '" title="' . $plugin_title . '" src="/openqrm/base/plugins/template/img/plugin.png">';
    $a->href = $plugin_link;
    $a->handler = '';
    return $a;
}
コード例 #15
0
ファイル: kvm-vm.iso.class.php プロジェクト: kelubo/OpenQRM
 function __construct($openqrm, $response)
 {
     $this->response = $response;
     $this->file = $openqrm->file();
     $this->openqrm = $openqrm;
     $this->user = $openqrm->user();
     $id = $this->response->html->request()->get('appliance_id');
     if ($id === '') {
         return false;
     }
     $appliance = new appliance();
     $resource = new resource();
     $appliance->get_instance_by_id($id);
     $resource->get_instance_by_id($appliance->resources);
     $this->resource = $resource;
     $this->appliance = $appliance;
     $this->statfile = $this->openqrm->get('basedir') . '/plugins/kvm/web/kvm-stat/' . $resource->id . '.pick_iso_config';
 }
コード例 #16
0
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;
                    }
                }
            }
        }
    }
}
コード例 #17
0
function storage_auth_function($cmd, $appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $IMAGE_AUTHENTICATION_TABLE;
    global $openqrm_server;
    global $RootDir;
    $appliance = new appliance();
    $appliance->get_instance_by_id($appliance_id);
    $image = new image();
    $image->get_instance_by_id($appliance->imageid);
    $image_name = $image->name;
    $image_rootdevice = $image->rootdevice;
    $storage = new storage();
    $storage->get_instance_by_id($image->storageid);
    $storage_resource = new resource();
    $storage_resource->get_instance_by_id($storage->resource_id);
    $storage_ip = $storage_resource->ip;
    $deployment = new deployment();
    $deployment->get_instance_by_type($image->type);
    $deployment_type = $deployment->type;
    $deployment_plugin_name = $deployment->storagetype;
    $resource = new resource();
    $resource->get_instance_by_id($appliance->resources);
    $resource_mac = $resource->mac;
    $resource_ip = $resource->ip;
    $vm_host_resource = new resource();
    $vm_host_resource->get_instance_by_id($resource->vhostid);
    switch ($cmd) {
        case "start":
            // authenticate the rootfs / needs openqrm user + pass
            $openqrm_admin_user = new user("openqrm");
            $openqrm_admin_user->set_user();
            // generate a password for the image
            $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-kvm-lvm-deployment-auth-hook.php", "Authenticating " . $image_name . " / " . $image_rootdevice . " to resource " . $resource_mac . ".", "", "", 0, 0, $appliance_id);
            $auth_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $deployment_plugin_name . "/bin/openqrm-" . $deployment_plugin_name . " auth -n " . $image_name . " -r " . $image_rootdevice . " -i " . $image_name . " -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " -t " . $deployment->type . " --openqrm-cmd-mode background";
            $resource->send_command($storage_resource->ip, $auth_start_cmd);
            break;
    }
}
コード例 #18
0
ファイル: kvm-vm.api.class.php プロジェクト: kelubo/OpenQRM
 function __construct($controller)
 {
     $this->controller = $controller;
     $this->user = $this->controller->user;
     $this->html = $this->controller->response->html;
     $this->response = $this->html->response();
     $this->file = $this->controller->file;
     $this->admin = $this->controller->openqrm->admin();
     $id = $this->response->html->request()->get('appliance_id');
     if ($id === '') {
         return false;
     }
     // set ENV
     $this->response->params['appliance_id'] = $id;
     $appliance = new appliance();
     $resource = new resource();
     $appliance->get_instance_by_id($id);
     $resource->get_instance_by_id($appliance->resources);
     $this->resource = $resource;
     $this->appliance = $appliance;
     #$this->statfile  = 'kvm-stat/'.$resource->id.'.pick_iso_config';
 }
コード例 #19
0
function get_hybrid_cloud_appliance_link($appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    $p_appliance = new appliance();
    $p_appliance->get_instance_by_id($appliance_id);
    $p_resource = new resource();
    $p_resource->get_instance_by_id($p_appliance->resources);
    $virtualization = new virtualization();
    $virtualization->get_instance_by_id($p_appliance->virtualization);
    if ($virtualization->type != "hybrid-cloud-vm-local") {
        return;
    }
    // get hybrid-cloud account
    $hybrid_cloud_acl_id = $p_resource->get_resource_capabilities("HCACL");
    if ($hybrid_cloud_acl_id == '') {
        $event->log("get_hybrid_cloud_appliance_link", $_SERVER['REQUEST_TIME'], 2, "openqrm-hybrid-cloud-appliance-link-hook.php", "Could not find Hybrid-Cloud Account for resource " . $p_resource->id, "", "", 0, 0, $appliance_id);
        return;
    }
    $hc = new hybrid_cloud();
    $hc->get_instance_by_id($hybrid_cloud_acl_id);
    $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects');
    $a = $html->a();
    $a->label = 'Dashboard';
    $a->css = 'badge';
    $a->target = '_BLANK';
    if ($hc->account_type == 'aws' || $hc->account_type == 'euca') {
        $a->href = 'https://console.aws.amazon.com/ec2/';
    }
    if ($hc->account_type == 'lc-openstack') {
        $a->href = 'http://' . $hc->host . '/project/instances/';
    }
    $plugin_link = $a->get_string();
    return $plugin_link;
}
コード例 #20
0
function get_collectd_appliance_link($appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    $appliance_name = '';
    $appliance = new appliance();
    $appliance->get_instance_by_id($appliance_id);
    $resource = new resource();
    $resource->get_instance_by_id($appliance->resources);
    $hostname = $appliance->name;
    if ($resource->id == 0) {
        $hostname = 'openqrm';
    }
    $a = '';
    if (file_exists('/usr/share/openqrm/plugins/collectd/data/' . $hostname)) {
        $html = new htmlobject($OPENQRM_SERVER_BASE_DIR . '/openqrm/web/base/class/htmlobjects');
        $a = $html->a();
        $a->label = 'collectd';
        $a->css = 'badge';
        $a->handler = 'onclick="wait();"';
        $a->href = '/openqrm/base/index.php?plugin=collectd&controller=collectd&collectd_action=statistics&appliance_id=' . $appliance->id;
    }
    return $a;
}
コード例 #21
0
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);
                                $resource_fields["resource_state"] = 'active';
                                $resource_fields["resource_lastgood"] = $now;
                                $resource_fields["resource_cpunumber"] = $hc->translate_resource_components('cpu', $type);
                                $resource_fields["resource_nics"] = $hc->translate_resource_components('net', $type);
                                $resource_fields["resource_memtotal"] = $hc->translate_resource_components('mem', $type);
                                $resource_fields["resource_memused"] = "0";
                                $resource_fields["resource_load"] = "0";
                                // restore mgmt ip
                                $resource_fields["resource_ip"] = $resource->network;
                                $resource->update_info($resource->id, $resource_fields);
                            } else {
                                if ($state == 'running') {
                                    // check if existing, if not auto-create resource, image and appliance
                                    if ($resource->exists_by_name($name)) {
                                        // update stats
                                        $resource->get_instance_id_by_hostname($name);
                                        $resource->get_instance_by_id($resource->id);
                                        $resource_fields["resource_state"] = 'active';
                                        $resource_fields["resource_lastgood"] = $now;
                                        $resource_fields["resource_cpunumber"] = $hc->translate_resource_components('cpu', $type);
                                        $resource_fields["resource_nics"] = $hc->translate_resource_components('net', $type);
                                        $resource_fields["resource_memtotal"] = $hc->translate_resource_components('mem', $type);
                                        $resource_fields["resource_memused"] = $resource_fields["resource_memtotal"];
                                        $resource_fields["resource_load"] = "1";
                                        if (strlen($public_ip) && $resource->ip != $public_ip) {
                                            // set public ip, update early and run nagios hook
                                            $resource_fields["resource_ip"] = $public_ip;
                                            $resource->update_info($resource->id, $resource_fields);
                                            // nagios enabled and started ?
                                            if (file_exists($RootDir . "/plugins/nagios3/.running")) {
                                                $virtualization = new virtualization();
                                                $virtualization->get_instance_by_type("hybrid-cloud-vm-local");
                                                $hc_appliance = new appliance();
                                                $hc_appliance->get_instance_by_virtualization_and_resource($virtualization->id, $resource->id);
                                                if (strlen($hc_appliance->name)) {
                                                    // special nagios classes
                                                    require_once $RootDir . "/plugins/nagios3/class/nagios3_service.class.php";
                                                    require_once $RootDir . "/plugins/nagios3/class/nagios3_host.class.php";
                                                    // get the nagios service checks
                                                    $nagios_host = new nagios3_host();
                                                    $nagios_host->get_instance_by_appliance_id($hc_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)) {
                                                        // appliance has nagios service checks configured
                                                        $nagios_appliance_stop_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nagios3/bin/openqrm-nagios-manager remove_host -n " . $hc_appliance->name . " --openqrm-cmd-mode background";
                                                        $server->send_command($nagios_appliance_stop_cmd, NULL, true);
                                                        sleep(2);
                                                        $nagios_appliance_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/nagios3/bin/openqrm-nagios-manager add -n " . $hc_appliance->name . " -i " . $public_ip . " -p " . $nagios_service_list . " --openqrm-cmd-mode background";
                                                        $server->send_command($nagios_appliance_start_cmd, NULL, true);
                                                    }
                                                }
                                            }
                                            // nagios finished
                                        }
                                        $resource->update_info($resource->id, $resource_fields);
                                    } else {
                                        // through error for now
                                        $event->log("hybrid_cloud_monitor", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-monitor-hook", "New Resource detected with name " . $name . "!", "", "", 0, 0, 0);
                                    }
                                }
                            }
                        }
                    }
                    unlink($statfile);
                }
            }
        }
    } else {
        file_put_contents($last_stats, $now);
    }
}
コード例 #22
0
 function action()
 {
     $response = $this->install2();
     if (isset($response->local_deployment_templates_select)) {
         // check if we are in the appliance wizard
         if (isset($this->user->wizard_name) && $this->user->wizard_name === 'appliance' && $this->user->wizard_step == 4) {
             // only if this is the image of the appliance in the wizard
             $wizard_appliance = new appliance();
             $wizard_appliance->get_instance_by_id($this->user->wizard_id);
             if ($wizard_appliance->imageid == $response->image_id) {
                 // this is our image
                 $this->response->redirect($this->response->html->thisfile . '?base=appliance&appliance_action=step' . $this->user->wizard_step . '&appliance_id=' . $this->user->wizard_id . '&image_id=' . $response->image_id);
             } else {
                 $this->response->redirect($this->response->get_url($this->actions_name, 'select', $this->message_param, $response->msg));
             }
         } else {
             $this->response->redirect($this->response->get_url($this->actions_name, 'select', $this->message_param, $response->msg));
         }
     }
     if (isset($response->error)) {
         $_REQUEST[$this->message_param] = $response->error;
     }
     $t = $this->response->html->template($this->tpldir . '/image-install2.tpl.php');
     $t->add(sprintf($this->lang['label'], $this->image->name, $this->image->storageid), 'label');
     $t->add($this->response->html->thisfile, "thisfile");
     $t->add($response->form);
     $t->add($this->openqrm->get('baseurl'), 'baseurl');
     $t->add($this->lang['please_wait'], 'please_wait');
     $t->add($this->lang['canceled'], 'canceled');
     $t->add($this->prefix_tab, 'prefix_tab');
     $t->group_elements(array('param_' => 'form'));
     return $t;
 }
コード例 #23
0
             // start
             $appliance_fields['appliance_stoptime'] = '';
             $appliance_fields['appliance_starttime'] = $now;
             $appliance_fields['appliance_state'] = 'active';
             $appliance->update($next_appliance_id, $appliance_fields);
             $appliance_function("start", $appliance_fields);
         }
     }
     break;
 case 'remove':
     // remove all appliance with resource set to localserver id
     $appliance = new appliance();
     $appliance_id_list = $appliance->get_all_ids();
     foreach ($appliance_id_list as $appliance_list) {
         $appliance_id = $appliance_list['appliance_id'];
         $app_resource_remove_check = new appliance();
         $app_resource_remove_check->get_instance_by_id($appliance_id);
         if ($app_resource_remove_check->resources == $local_server_id) {
             // stop + remove hooks
             $now = $_SERVER['REQUEST_TIME'];
             $appliance_fields = array();
             $appliance_fields['appliance_stoptime'] = $now;
             $appliance_fields['appliance_state'] = 'stopped';
             // fill in the rest of the appliance info in the array for the plugin hook
             $appliance_fields["appliance_id"] = $appliance_id;
             $appliance_fields["appliance_name"] = $app_resource_remove_check->name;
             $appliance_fields["appliance_kernelid"] = $app_resource_remove_check->kernelid;
             $appliance_fields["appliance_imageid"] = $app_resource_remove_check->imageid;
             $appliance_fields["appliance_cpunumber"] = $app_resource_remove_check->cpunumber;
             $appliance_fields["appliance_cpuspeed"] = $app_resource_remove_check->cpuspeed;
             $appliance_fields["appliance_cpumodel"] = $app_resource_remove_check->cpumodel;
コード例 #24
0
function openqrm_hybrid_cloud_cloud_product($cmd, $cloud_hook_config)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $RootDir;
    $openqrm_server = new openqrm_server();
    $event->log("openqrm_hybrid_cloud_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-cloud-product-hook.php", "Handling " . $cmd . " event", "", "", 0, 0, 0);
    switch ($cmd) {
        case "add":
            $event->log("openqrm_hybrid_cloud_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-cloud-product-hook.php", "Handling cloud-product " . $cmd . " event", "", "", 0, 0, 0);
            // create resource products
            $db = openqrm_get_db_connection();
            $image = new image();
            $checked_virtualization_plugins = array();
            $virtualization = new virtualization();
            $virtualization_id_ar = $virtualization->get_list();
            unset($virtualization_id_ar[0]);
            foreach ($virtualization_id_ar as $key => $value) {
                $next_sort_id = 0;
                $id = $value['value'];
                $virtualization->get_instance_by_id($id);
                $pos = strpos($virtualization->type, 'hybrid-cloud-vm-');
                if ($pos !== false) {
                    $event->log("openqrm_hybrid_cloud_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-cloud-product-hook.php", "Adding " . $virtualization->type . " as cloud-product", "", "", 0, 0, 0);
                    $cloud_product_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                    $create_resource_cloudselector_config = "insert into cloud_selector (id, type, sort_id, quantity, price, name, description, state) VALUES (" . $cloud_product_id . ", 'resource', " . $next_sort_id . ", '" . $virtualization->id . "', 1, '" . $virtualization->type . "', '" . $virtualization->name . "', 1);";
                    $recordSet = $db->Execute($create_resource_cloudselector_config);
                    $next_sort_id++;
                    // add all existing images for this virtualization type to private images
                    $virtualization_plugin_name = $virtualization->get_plugin_name();
                    if (!in_array($virtualization_plugin_name, $checked_virtualization_plugins)) {
                        $checked_virtualization_plugins[] = $virtualization_plugin_name;
                        $deployment = new deployment();
                        $deployment_id_ar = $deployment->get_id_by_storagetype($virtualization_plugin_name);
                        foreach ($deployment_id_ar as $key => $value) {
                            $did = $value['value'];
                            $deployment->get_instance_by_id($did);
                            $image_id_deployment_ar = $image->get_ids_by_type($deployment->type);
                            foreach ($image_id_deployment_ar as $iid_ar) {
                                // add to private images
                                $image_id = $iid_ar['image_id'];
                                $event->log("openqrm_hybrid_cloud_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-cloud-product-hook.php", "Adding Image " . $image_id . " as private image", "", "", 0, 0, 0);
                                $cloud_pr_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                                $create_private_image_config = "insert into cloud_private_image (co_id, co_image_id, co_cu_id, co_clone_on_deploy, co_state) VALUES (" . $cloud_pr_id . ", " . $image_id . ", 0, 1, 1);";
                                $recordSet = $db->Execute($create_private_image_config);
                            }
                        }
                    }
                }
            }
            // add host to admin resource pool
            $admin_project_id = $cloud_hook_config['cloud_admin_procect'];
            $virtualization->get_instance_by_type('hybrid-cloud');
            $appliance = new appliance();
            $appliance_id_ar = $appliance->get_ids_per_virtualization($virtualization->id);
            foreach ($appliance_id_ar as $key => $value) {
                $appliance_id = $value['appliance_id'];
                $appliance->get_instance_by_id($appliance_id);
                $cloud_respool_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                $create_default_resource_pool_config = "insert into cloud_respool(rp_id, rp_resource_id, rp_cg_id) values (" . $cloud_respool_id . ", " . $appliance->resources . ", " . $admin_project_id . ");";
                $recordSet = $db->Execute($create_default_resource_pool_config);
            }
            break;
        case "remove":
            $cloud_product_class = $RootDir . "/plugins/cloud/class/cloudselector.class.php";
            if (file_exists($cloud_product_class)) {
                require_once $cloud_product_class;
                $cloud_selector = new cloudselector();
                $virtualization = new virtualization();
                $virtualization->get_instance_by_type('hybrid-cloud-vm-local');
                $event->log("openqrm_hybrid_cloud_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-cloud-product-hook.php", "Removing resource type " . $virtualization->type . " from cloud-products", "", "", 0, 0, 0);
                $cloud_selector->remove_by_quantity($virtualization->id);
            }
            break;
    }
}
コード例 #25
0
function storage_auth_function($cmd, $appliance_id)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $IMAGE_AUTHENTICATION_TABLE;
    global $openqrm_server;
    global $RootDir;
    $appliance = new appliance();
    $appliance->get_instance_by_id($appliance_id);
    $image = new image();
    $image->get_instance_by_id($appliance->imageid);
    $image_name = $image->name;
    $image_rootdevice = $image->rootdevice;
    $storage = new storage();
    $storage->get_instance_by_id($image->storageid);
    $storage_resource = new resource();
    $storage_resource->get_instance_by_id($storage->resource_id);
    $storage_ip = $storage_resource->ip;
    $deployment = new deployment();
    $deployment->get_instance_by_type($image->type);
    $deployment_type = $deployment->type;
    $deployment_plugin_name = $deployment->storagetype;
    $resource = new resource();
    $resource->get_instance_by_id($appliance->resources);
    $resource_mac = $resource->mac;
    $resource_ip = $resource->ip;
    // this is a hook for the cloud-plugin to be able
    // to translate the internal to the external ip address
    // for the nfs-mount authentication
    /*        if (file_exists("$RootDir/plugins/cloud/.running")) {
    			$event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Found Cloud enabled and running. Checking for CloudNAT", "", "", 0, 0, $appliance_id);
    			// special clouduser class
    			require_once "$RootDir/plugins/cloud/class/cloudconfig.class.php";
    			require_once "$RootDir/plugins/cloud/class/cloudnat.class.php";
    			// check if we have to cloudnat the ip address
    			$cn_conf = new cloudconfig();
    			$cn_nat_enabled = $cn_conf->get_value(18);  // 18 is cloud_nat
    			if (!strcmp($cn_nat_enabled, "true")) {
    				$cn = new cloudnat();
    				$internal_resource_ip=$resource_ip;
    				$resource_ip = $cn->translate($resource_ip);
    				$event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Found CloudNAT enabled, translated $internal_resource_ip to $resource_ip", "", "", 0, 0, $appliance_id);
    			} else {
    				$event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Cloudnat is disabled, keeping $resource_ip", "", "", 0, 0, $appliance_id);
    			}
    		} else {
    			$event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Cloud is not enabled/running. Not checking for CloudNAT", "", "", 0, 0, $appliance_id);
    
    		}
    */
    switch ($cmd) {
        case "start":
            // authenticate the rootfs / needs openqrm user + pass
            $openqrm_admin_user = new user("openqrm");
            $openqrm_admin_user->set_user();
            $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Authenticating {$image_name} / {$image_rootdevice} to resource {$resource_ip}", "", "", 0, 0, $appliance_id);
            $auth_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $deployment_plugin_name . "/bin/openqrm-" . $deployment_plugin_name . " auth -n " . $image_name . " -r " . $image_rootdevice . " -i " . $resource_ip . " -t lvm-nfs-deployment -u " . $openqrm_admin_user->name . " -p " . $openqrm_admin_user->password . " --openqrm-cmd-mode background";
            $resource->send_command($storage_ip, $auth_start_cmd);
            // authenticate the install-from-nfs export
            $run_disable_deployment_export = 0;
            $install_from_nfs_param = trim($image->get_deployment_parameter("IMAGE_INSTALL_FROM_NFS"));
            if (strlen($install_from_nfs_param)) {
                // storage -> resource -> auth
                $ip_storage_id = $deployment->parse_deployment_parameter("id", $install_from_nfs_param);
                $ip_storage_ip = $deployment->parse_deployment_parameter("ip", $install_from_nfs_param);
                $ip_image_rootdevice = $deployment->parse_deployment_parameter("path", $install_from_nfs_param);
                $ip_storage = new storage();
                $ip_storage->get_instance_by_id($ip_storage_id);
                $ip_storage_resource = new resource();
                $ip_storage_resource->get_instance_by_id($ip_storage->resource_id);
                $op_storage_ip = $ip_storage_resource->ip;
                $ip_deployment = new deployment();
                $ip_deployment->get_instance_by_id($ip_storage->type);
                $ip_deployment_type = $ip_deployment->type;
                $ip_deployment_plugin_name = $ip_deployment->storagetype;
                $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Install-from-NFS: Authenticating {$resource_ip} on storage id {$ip_storage_id}:{$ip_storage_ip}:{$ip_image_rootdevice}", "", "", 0, 0, $appliance_id);
                $auth_install_from_nfs_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $ip_deployment_plugin_name . "/bin/openqrm-" . $ip_deployment_plugin_name . " auth -r " . $ip_image_rootdevice . " -i " . $resource_ip . " -t " . $ip_deployment_type . " --openqrm-cmd-mode background";
                $resource->send_command($ip_storage_ip, $auth_install_from_nfs_start_cmd);
                $run_disable_deployment_export = 1;
            }
            // authenticate the transfer-to-nfs export
            $transfer_from_nfs_param = trim($image->get_deployment_parameter("IMAGE_TRANSFER_TO_NFS"));
            if (strlen($transfer_from_nfs_param)) {
                // storage -> resource -> auth
                $tp_storage_id = $deployment->parse_deployment_parameter("id", $transfer_from_nfs_param);
                $tp_storage_ip = $deployment->parse_deployment_parameter("ip", $transfer_from_nfs_param);
                $tp_image_rootdevice = $deployment->parse_deployment_parameter("path", $transfer_from_nfs_param);
                $tp_storage = new storage();
                $tp_storage->get_instance_by_id($tp_storage_id);
                $tp_storage_resource = new resource();
                $tp_storage_resource->get_instance_by_id($tp_storage->resource_id);
                $op_storage_ip = $tp_storage_resource->ip;
                $tp_deployment = new deployment();
                $tp_deployment->get_instance_by_id($tp_storage->type);
                $tp_deployment_type = $tp_deployment->type;
                $tp_deployment_plugin_name = $tp_deployment->storagetype;
                $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Transfer-to-NFS: Authenticating {$resource_ip} on storage id {$tp_storage_id}:{$tp_storage_ip}:{$tp_image_rootdevice}", "", "", 0, 0, $appliance_id);
                $auth_install_from_nfs_start_cmd = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/" . $tp_deployment_plugin_name . "/bin/openqrm-" . $tp_deployment_plugin_name . " auth -r " . $tp_image_rootdevice . " -i " . $resource_ip . " -t " . $tp_deployment_type . " --openqrm-cmd-mode background";
                $resource->send_command($tp_storage_ip, $auth_install_from_nfs_start_cmd);
                $run_disable_deployment_export = 1;
            }
            // do we need to disable the install-from/transfer-to-nfs exports ?
            if ($run_disable_deployment_export == 1) {
                $image_authentication = new image_authentication();
                $ia_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                $image_auth_ar = array('ia_id' => $ia_id, 'ia_image_id' => $appliance->imageid, 'ia_resource_id' => $appliance->resources, 'ia_auth_type' => 1);
                $image_authentication->add($image_auth_ar);
                $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Registered image {$appliance->imageid} for de-authentication the deployment exports when resource {$appliance->resources} is fully up.", "", "", 0, 0, $appliance_id);
            }
            break;
        case "stop":
            $image_authentication = new image_authentication();
            $ia_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
            $image_auth_ar = array('ia_id' => $ia_id, 'ia_image_id' => $appliance->imageid, 'ia_resource_id' => $appliance->resources, 'ia_auth_type' => 0);
            $image_authentication->add($image_auth_ar);
            $event->log("storage_auth_function", $_SERVER['REQUEST_TIME'], 5, "openqrm-lvm-nfs-deployment-auth-hook.php", "Registered image {$appliance->imageid} for de-authentication the root-fs exports when resource {$appliance->resources} is idle again.", "", "", 0, 0, $appliance_id);
            break;
    }
}
コード例 #26
0
ファイル: kvm.add.class.php プロジェクト: kelubo/OpenQRM
 function get_response()
 {
     $response = $this->response;
     $form = $response->get_form($this->actions_name, 'add');
     $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');
     // create the image type select array
     switch ($this->deployment->type) {
         case 'kvm-lvm-deployment':
             $image_types[] = array('lvm2', 'lvm2');
             break;
         default:
             $image_types[] = array('qcow2', 'qcow2');
             $image_types[] = array('raw', 'raw');
             $image_types[] = array('qcow', 'qcow');
             $image_types[] = array('cow', 'cow');
             break;
     }
     // if we come from the wizard suggest the server name
     $vm_volume_name_suggestion = '';
     if (isset($this->user->wizard_name) && $this->user->wizard_name === 'appliance' && $this->user->wizard_step == 3) {
         $appliance = new appliance();
         $appliance->get_instance_by_id($this->user->wizard_id);
         $vm_volume_name_suggestion = $appliance->name;
     }
     $d['name']['label'] = $this->lang['form_name'];
     $d['name']['required'] = true;
     $d['name']['validate']['regex'] = '/^[a-z0-9._]+$/i';
     $d['name']['validate']['errormsg'] = sprintf($this->lang['error_name'], 'a-z0-9._');
     $d['name']['object']['type'] = 'htmlobject_input';
     $d['name']['object']['attrib']['id'] = 'name';
     $d['name']['object']['attrib']['name'] = 'name';
     $d['name']['object']['attrib']['type'] = 'text';
     $d['name']['object']['attrib']['css'] = 'namegen';
     $d['name']['object']['attrib']['customattribs'] = 'data-prefix="kvm" data-length="6"';
     $d['name']['object']['attrib']['value'] = $vm_volume_name_suggestion;
     $d['name']['object']['attrib']['maxlength'] = 50;
     $d['size']['label'] = sprintf($this->lang['form_size'], number_format($this->max, 0, '', ''));
     $d['size']['required'] = true;
     $d['size']['validate']['regex'] = '/^[0-9]+$/i';
     $d['size']['validate']['errormsg'] = sprintf($this->lang['error_size'], '0-9');
     $d['size']['object']['type'] = 'htmlobject_input';
     $d['size']['object']['attrib']['name'] = 'size';
     $d['size']['object']['attrib']['type'] = 'text';
     $d['size']['object']['attrib']['value'] = '';
     $d['size']['object']['attrib']['maxlength'] = 50;
     $d['type']['label'] = $this->lang['form_type'];
     $d['type']['object']['type'] = 'htmlobject_select';
     $d['type']['object']['attrib']['name'] = 'type';
     $d['type']['object']['attrib']['index'] = array(0, 1);
     $d['type']['object']['attrib']['options'] = $image_types;
     $form->add($d);
     $response->form = $form;
     return $response;
 }
コード例 #27
0
ファイル: kvm.image.class.php プロジェクト: kelubo/OpenQRM
 function image()
 {
     $response = '';
     $errors = array();
     $message = array();
     $image_command = $this->response->html->request()->get('image_command');
     if ($image_command !== '') {
         switch ($image_command) {
             case 'add':
                 $root_device = $this->response->html->request()->get('root_device');
                 if ($this->deployment->type == 'kvm-gluster-deployment') {
                     $image_name = $this->response->html->request()->get('image_name');
                 } else {
                     $image_name = basename($root_device);
                 }
                 // check if image name is not in use yet
                 $image = new image();
                 $image->get_instance_by_name($image_name);
                 if (strlen($image->id)) {
                     $errors[] = sprintf($this->lang['error_exists'], $image_name);
                 } else {
                     $tables = $this->openqrm->get('table');
                     $image_fields = array();
                     $image_fields["image_id"] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                     $image_fields['image_name'] = $image_name;
                     $image_fields['image_type'] = $this->deployment->type;
                     $image_fields['image_rootfstype'] = 'local';
                     $image_fields['image_storageid'] = $this->storage->id;
                     $image_fields['image_comment'] = "Image Object for volume {$image_name}";
                     $image_fields['image_rootdevice'] = $root_device;
                     $image = new image();
                     $image->add($image_fields);
                     $message[] = sprintf($this->lang['msg_added_image'], $image_name);
                 }
                 break;
             case 'remove':
                 $image_id = $this->response->html->request()->get('image_id');
                 // check if image is not in use any more before removing
                 $remove_error = 0;
                 $appliance = new appliance();
                 $appliance_id_list = $appliance->get_all_ids();
                 foreach ($appliance_id_list as $appliance_list) {
                     $appliance_id = $appliance_list['appliance_id'];
                     $app_image_remove_check = new appliance();
                     $app_image_remove_check->get_instance_by_id($appliance_id);
                     if ($app_image_remove_check->imageid == $image_id) {
                         $image_is_used_by_appliance .= $appliance_id . " ";
                         $remove_error = 1;
                     }
                 }
                 if ($remove_error == 1) {
                     $errors[] = sprintf($this->lang['error_image_still_in_use'], $image_id, $image_is_used_by_appliance);
                 } else {
                     $image_remove = new image();
                     $image_remove->remove($image_id);
                     $message[] = sprintf($this->lang['msg_removed_image'], $image_id);
                 }
                 break;
         }
         if (count($errors) === 0) {
             $response = join('<br>', $message);
         } else {
             $msg = array_merge($errors, $message);
             $response = join('<br>', $msg);
         }
     } else {
         $response = '';
     }
     return $response;
 }
コード例 #28
0
ファイル: kvm-vm.edit.class.php プロジェクト: kelubo/OpenQRM
 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'];
                     $a->label = $this->lang['action_clone'];
                     $a->handler = 'onclick="wait();"';
                     $a->css = 'clone';
                     $a->href = $this->response->get_url($this->actions_name, "clone") . '&vm=' . $name . '&mac=' . $mac;
                     $clone_link = $a->get_string();
                     if ($res_virtualization->type == 'kvm-vm-local') {
                         if ($state === '0' && $resource->image === 'idle') {
                             $update = $update_link;
                             $clone = $clone_link;
                         }
                     }
                     if ($res_virtualization->type == 'kvm-vm-net') {
                         if ($state !== '2' && $resource->image === 'idle') {
                             $update = $update_link;
                             $clone = $clone_link;
                         }
                     }
                     $migrate = '';
                     $a = $this->response->html->a();
                     $a->title = $this->lang['action_migrate'];
                     $a->label = $this->lang['action_migrate'];
                     $a->handler = 'onclick="wait();"';
                     $a->css = 'migrate';
                     $a->href = $this->response->get_url($this->actions_name, "migrate") . '&vm=' . $name . '&mac=' . $mac;
                     if (count($kvm_hosts) >= 1 && $state === '1') {
                         $migrate = $a->get_string();
                     }
                     $data = '<b>' . $this->lang['table_id'] . '</b>: ' . $resource->id . '<br>';
                     $data .= '<b>' . $this->lang['table_name'] . '</b>: ' . $name . '<br>';
                     $data .= '<b>' . $this->lang['table_type'] . '</b>: ' . $res_virtualization->name . '<br>';
                     $data .= '<b>' . $this->lang['table_ip'] . '</b>: ' . $resource->ip . '<br>';
                     $data .= '<b>' . $this->lang['table_mac'] . '</b>: ' . $mac . '<br>';
                     $data .= '<b>' . $this->lang['table_vnc'] . '</b>: ' . $line[5] . '<br>';
                     $data .= '<b>' . $this->lang['table_cpu'] . '</b>: ' . $line[3] . '<br>';
                     $data .= '<b>' . $this->lang['table_ram'] . '</b>: ' . $line[4] . '<br>';
                     $data .= '<b>' . $this->lang['table_nics'] . '</b>: ' . $resource->nics;
                     $appliance = new appliance();
                     $appliance->get_instance_by_virtualization_and_resource($resource->vtype, $resource->id);
                     $server = array();
                     $server[0] = '';
                     $server[1] = '1000000000000000000000000';
                     if ($appliance->id !== '') {
                         $kernel = new kernel();
                         $kernel->get_instance_by_id($appliance->kernelid);
                         $image = new image();
                         $image->get_instance_by_id($appliance->imageid);
                         $storage = new storage();
                         $storage->get_instance_by_id($image->storageid);
                         $s = '<b>' . $this->lang['table_appliance'] . '</b>: ' . $appliance->id . '<br>';
                         $s .= '<b>' . $this->lang['table_name'] . '</b>: ' . $appliance->name . '<br>';
                         $s .= '<b>' . $this->lang['table_kernel'] . '</b>: ' . $kernel->name . '<br>';
                         $s .= '<b>' . $this->lang['table_image'] . '</b>: ' . $image->name . '<br>';
                         $s .= '<b>' . $this->lang['table_storage'] . '</b>: ' . $storage->name . '<br>';
                         $server[0] = $s;
                         $server[1] = $appliance->id;
                     }
                     $console = '';
                     if ($state === '2') {
                         $t = $this->response->html->template($this->openqrm->get('webdir') . '/js/openqrm-progressbar.js');
                         $identifier_disabled[] = $name;
                         // progressbar
                         $t->add(uniqid('b'), 'id');
                         $t->add($this->openqrm->get('baseurl') . '/api.php?action=plugin&plugin=kvm&controller=kvm-vm&kvm_vm_action=progress&name=' . $name . '.vm_migration_progress', 'url');
                         $t->add($this->lang['action_migrate_in_progress'], 'lang_in_progress');
                         $t->add($this->lang['action_migrate_finished'], 'lang_finished');
                         $console = $t->get_string();
                     } else {
                         if ($remote_console === true && $resource->imageid !== 1 && $state === '1') {
                             foreach ($remote_functions as $function) {
                                 $a = $function($resource->id);
                                 if (is_object($a)) {
                                     $console .= $a->get_string();
                                 }
                             }
                         }
                     }
                     $state = array();
                     $state[0] = '<span class="pill idle">idle</span>';
                     $state[1] = 'i';
                     if ($line[0] === '1' && $resource->image !== 'idle') {
                         $state[0] = '<span class="pill active">active</span>';
                         $state[1] = 'a';
                     }
                     if ($res_virtualization->type == 'kvm-vm-net' && $line[0] === '0') {
                         $state[0] = '<span class="pill off">off</span>';
                         $state[1] = 'o';
                     }
                     $action = '';
                     if (!in_array($name, $identifier_disabled)) {
                         $action = $update . $clone . $migrate;
                     }
                     $body[$i] = array('state' => $state[0], 'state_s' => $state[1], 'name' => $name, 'id' => $resource->id, 'mac' => $mac, 'cpu' => $line[3], 'ram' => $line[4], 'ip' => $resource->ip, 'vnc' => $line[5], 'data' => $data, 'appliance' => $server[0], 'appliance_s' => $server[1], 'plugins' => $console, 'action' => $action);
                 }
                 $i++;
             }
         }
     }
     $h['state']['title'] = $this->lang['table_state'];
     $h['state']['sortable'] = false;
     $h['state_s']['title'] = $this->lang['table_state'];
     $h['state_s']['sortable'] = true;
     $h['state_s']['hidden'] = true;
     $h['id']['title'] = $this->lang['table_id'];
     $h['id']['hidden'] = true;
     $h['name']['title'] = $this->lang['table_name'];
     $h['name']['hidden'] = true;
     $h['ip']['title'] = $this->lang['table_ip'];
     $h['ip']['hidden'] = true;
     $h['mac']['title'] = $this->lang['table_mac'];
     $h['mac']['hidden'] = true;
     $h['vnc']['title'] = $this->lang['table_vnc'];
     $h['vnc']['hidden'] = true;
     $h['cpu']['title'] = $this->lang['table_cpu'];
     $h['cpu']['hidden'] = true;
     $h['ram']['title'] = $this->lang['table_ram'];
     $h['ram']['hidden'] = true;
     $h['nics']['title'] = $this->lang['table_nics'];
     $h['nics']['hidden'] = true;
     $h['data']['title'] = '&#160;';
     $h['data']['sortable'] = false;
     $h['appliance']['title'] = '&#160;';
     $h['appliance']['sortable'] = false;
     $h['appliance_s']['title'] = $this->lang['table_appliance'];
     $h['appliance_s']['sortable'] = true;
     $h['appliance_s']['hidden'] = true;
     $h['plugins']['title'] = '&#160;';
     $h['plugins']['sortable'] = false;
     $h['action']['title'] = '&#160;';
     $h['action']['sortable'] = false;
     $table = $this->response->html->tablebuilder('kvm_vm_edit', $this->response->get_array($this->actions_name, 'edit'));
     $table->sort = 'name';
     $table->limit = 10;
     $table->offset = 0;
     $table->order = 'ASC';
     $table->max = count($body);
     $table->autosort = true;
     $table->sort_link = false;
     $table->id = 'Tabelle';
     $table->css = 'htmlobject_table';
     $table->border = 1;
     $table->cellspacing = 0;
     $table->cellpadding = 3;
     $table->form_action = $this->response->html->thisfile;
     $table->head = $h;
     $table->body = $body;
     $table->identifier = 'name';
     $table->identifier_name = $this->identifier_name;
     $table->identifier_disabled = $identifier_disabled;
     $table->actions_name = $this->actions_name;
     $table->actions = array(array('start' => $this->lang['action_start']), array('stop' => $this->lang['action_stop']), array('reboot' => $this->lang['action_reboot']), array('remove' => $this->lang['action_remove']));
     $d['table'] = $table->get_string();
     return $d;
 }
コード例 #29
0
ファイル: kvm.remove.class.php プロジェクト: kelubo/OpenQRM
 function remove()
 {
     $response = $this->get_response();
     $lvols = $response->html->request()->get($this->identifier_name);
     $form = $response->form;
     if ($lvols !== '') {
         $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 ($lvols 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()) {
             $name = $this->openqrm->admin()->name;
             $pass = $this->openqrm->admin()->password;
             $storage = new storage();
             $resource = new resource();
             $deployment = new deployment();
             $storage->get_instance_by_id($this->response->html->request()->get('storage_id'));
             $resource->get_instance_by_id($storage->resource_id);
             $deployment->get_instance_by_id($storage->type);
             $errors = array();
             $message = array();
             foreach ($lvols as $key => $lvol) {
                 // check if an appliance is still using the volume as an image
                 $image = new image();
                 $image->get_instance_by_name($lvol);
                 // check if it is still in use
                 $appliance = new appliance();
                 $appliances_using_resource = $appliance->get_ids_per_image($image->id);
                 if (count($appliances_using_resource) > 0) {
                     $appliances_using_resource_str = implode(",", $appliances_using_resource[0]);
                     $errors[] = sprintf($this->lang['msg_vm_image_still_in_use'], $lvol, $image->id, $appliances_using_resource_str);
                 } else {
                     $command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm remove';
                     $command .= ' -n ' . $lvol;
                     $command .= ' -v ' . $this->volgroup;
                     $command .= ' -t ' . $deployment->type;
                     $command .= ' -u ' . $name . ' -p ' . $pass;
                     $command .= ' --openqrm-ui-user ' . $this->user->name;
                     $command .= ' --openqrm-cmd-mode background';
                     $file = $this->openqrm->get('basedir') . '/plugins/kvm/web/storage/' . $resource->id . '.' . $this->volgroup . '.lv.stat';
                     if ($this->file->exists($file)) {
                         $this->file->remove($file);
                     }
                     $resource->send_command($resource->ip, $command);
                     while (!$this->file->exists($file)) {
                         usleep(10000);
                         // sleep 10ms to unload the CPU
                         clearstatcache();
                     }
                     $form->remove($this->identifier_name . '[' . $key . ']');
                     $message[] = sprintf($this->lang['msg_removed'], $lvol);
                     // remove the image of the volume
                     $image->remove_by_name($lvol);
                 }
             }
             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;
 }
コード例 #30
0
 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;
 }