summaryrefslogtreecommitdiffstats
path: root/drakpxelinux.pl
diff options
context:
space:
mode:
authorAntoine Ginies <aginies@mandriva.com>2005-08-29 13:21:32 +0000
committerAntoine Ginies <aginies@mandriva.com>2005-08-29 13:21:32 +0000
commite6b22b9dfff44af6f29600e13f8441f480c03ada (patch)
tree211c5eaa293ca306ff518891ae59c66acab91635 /drakpxelinux.pl
parentea8e93de89256b822a45968f14c85f76950e1785 (diff)
downloaddrakpxelinux-e6b22b9dfff44af6f29600e13f8441f480c03ada.tar
drakpxelinux-e6b22b9dfff44af6f29600e13f8441f480c03ada.tar.gz
drakpxelinux-e6b22b9dfff44af6f29600e13f8441f480c03ada.tar.bz2
drakpxelinux-e6b22b9dfff44af6f29600e13f8441f480c03ada.tar.xz
drakpxelinux-e6b22b9dfff44af6f29600e13f8441f480c03ada.zip
merge kadeploy code (blino)
Diffstat (limited to 'drakpxelinux.pl')
-rw-r--r--drakpxelinux.pl256
1 files changed, 209 insertions, 47 deletions
diff --git a/drakpxelinux.pl b/drakpxelinux.pl
index 6104a61..2498eac 100644
--- a/drakpxelinux.pl
+++ b/drakpxelinux.pl
@@ -38,6 +38,11 @@ use network::tools;
use interactive;
# must come *after* definition of textdomains for proper initialisation
use ugtk2 qw(:ask :helpers :wrappers :create :dialogs);
+use mygtk2 qw(gtknew);
+use Gtk2::SimpleList;
+use Gtk2::Helper;
+use run_program;
+use IO::Socket;
use constant FALSE => 0;
use constant TRUE => 1;
@@ -789,6 +794,97 @@ sub add_columns {
}
+# drakdeploy code from blino
+my $mac_regexp = '(?:[0-9a-f]{2}:){5}[0-9a-f]{2}';
+my $profiles_conf = network::pxe::read_profiles();
+
+my $systems = Gtk2::SimpleList->new(N("MAC address") => 'text',
+ N("Installed") => 'bool',
+ N("System") => 'text',
+ );
+$systems->get_selection->set_mode('multiple');
+$systems->get_model->set_sort_column_id(0, 'ascending');
+#- don't let the user modify the "Installed" state
+$systems->get_column(1)->get_cell_renderers->set_property('mode', 'inert');
+
+my $profiles = Gtk2::SimpleList->new(undef => 'text');
+$profiles->set_headers_visible(0);
+$profiles->get_selection->set_mode('browse');
+$profiles->get_selection->signal_connect(changed => sub {
+ my ($model, $iter) = $_[0]->get_selected or return;
+ profile_selected($model->get($iter, 0));
+ });
+
+my $log_text = gtknew('TextView');
+
+sub system_entry_set_profile { my ($entry, $profile) = @_; $entry->[2] = $profile || N("None") }
+sub system_entry_set_installed { my ($entry, $state) = @_; $entry->[1] = $state }
+
+sub find_system_entry_for_mac_address {
+ my ($mac_address) = @_;
+ find { $_->[0] eq $mac_address } @{$systems->{data}};
+}
+
+sub add_configured_mac_addresses() {
+ while (my ($mac_address, $conf) = each %{$profiles_conf->{per_mac}}) {
+ my $entry = [ $mac_address ];
+ system_entry_set_profile($entry, $conf->{profile});
+ system_entry_set_installed($entry, !$conf->{to_install});
+ push @{$systems->{data}}, $entry;
+ gtktext_append($log_text, "Detected new system: $mac_address\n");
+ }
+}
+
+sub get_mac_addresses_from_dhcp_log() {
+ my %addresses;
+ foreach (cat_("/var/log/daemons/info")) {
+ /dhcpd:\s+DHCP(?:DISCOVER|REQUEST).*\s+from\s+($mac_regexp)\b/ and $addresses{$1} = 1;
+ }
+ foreach (difference2([ keys %addresses ], [ map { $_->[0] } @{$systems->{data}} ])) {
+ my $entry = [ $_ ];
+ system_entry_set_profile($entry, '');
+ push @{$systems->{data}}, $entry;
+ gtktext_append($log_text, "Detected new system: $_\n");
+ }
+ 1; #- run callback on next timeout
+}
+
+my ($profiles_combo, $install_button);
+
+sub refresh_profiles() {
+ my @profiles = network::pxe::list_profiles($profiles_conf);
+ mygtk2::gtkset($profiles_combo, list => [ '', @profiles ]);
+ @{$profiles->{data}} = @profiles;
+}
+
+sub add_profile() {
+ my $w = ugtk2->new(N("Deployment center"));
+ my ($entry, $to_install);
+ $w->{ok_clicked} = sub {
+ my $profile = $entry->get_text;
+ network::pxe::profile_exists($profiles_conf, $profile) and err_dialog(N("Deployment center"), N("The %s profile already exists!", $profile)), return;
+ network::pxe::add_empty_profile($profiles_conf, $profile, $to_install->get_active);
+ refresh_profiles();
+ Gtk2->main_quit;
+ };
+ gtkadd($w->{window},
+ gtknew('VBox', children_loose => [
+ $entry = gtknew('Entry', text => network::pxe::find_next_profile_name($profiles_conf, 'profile')),
+ $to_install = gtknew('CheckButton', text => 'This profile needs an installation'),
+ create_okcancel($w),
+ ]));
+ $w->main;
+}
+
+sub profile_selected {
+ my ($profile) = @_;
+ $install_button->set_sensitive(exists $profiles_conf->{profiles}{install}{$profile});
+}
+
+
+
+
+
###############
# Main Program
###############
@@ -816,6 +912,8 @@ $::isWizard = 0;
my $model = create_model();
my $window = ugtk2->new("Drakpxelinux $version");
+my $w = ugtk2->new(N("Deployment center"));
+
$window->{rwindow}->set_size_request(800, 500) unless $::isEmbedded;
my $W = $window->{window};
$W->signal_connect(delete_event => sub { ugtk2->exit });
@@ -864,52 +962,116 @@ my $okcancel = create_okcancel({
);
# main interface
-$W->add(gtkpack_(Gtk2::VBox->new(0,0),
- 0, $menu,
- if_(!$::isEmbedded, 0, Gtk2::Banner->new('drakgw', N("Drakpxelinux manage your PXE server"))),
- if_($::isEmbedded, 0, Gtk2::Label->new("Here you can manage your PXE server.")),
- 1, gtkpack_(gtkset_border_width(Gtk2::HBox->new, 3),
- 1, create_scrolled_window($treeview),
- 0, gtkpack_(create_vbox('start'),
- 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Add a PXE entry")), 'addpxe'), clicked => sub {
- eval { wizard_add_entry($model, $treeview) };
- my $err = $@;
- $::WizardWindow->destroy if defined $::WizardWindow;
- undef $::WizardWindow;
- if ($err && $err !~ /wizcancel/) {
- err_dialog(N("Error"), N("The PXE entry wizard has unexpectedly failed:")
- . "\n\n" . $err);
- }
- }),
- 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Remove PXE entry")), 'removepxe'), clicked => sub {
- remove_item($model, $treeview) }
- ),
- 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Edit PXE entry")), 'editb'), clicked => sub {
- edit_box_item($model, $treeview) }
- ),
- 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Apply")), 'apply'), clicked => sub {
- write_conf }
- ),
- 0, Gtk2::HSeparator->new,
- 0, Gtk2::Label->new(N("Default boot:")),
- 0, $labelscombo,
- 0, Gtk2::HSeparator->new,
- # create_vbox('end'),
- 0, gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Reconfigure PXE Server")), 'wizardsrv'), clicked => sub {
- eval { wizard_pxe_server() };
- my $err = $@;
- $::WizardWindow->destroy if defined $::WizardWindow;
- undef $::WizardWindow;
- if ($err && $err !~ /wizcancel/) {
- err_dialog(N("Error"), N("The PXE server wizard has unexpectedly failed:")
- . "\n\n" . $err);
- }
- }),
- 0, gtksignal_connect(new Gtk2::Button(N("Help")), clicked => \&show_help),
- ),
- ),
- 0, $okcancel,
- ),
+gtkpack($w->{window},
+ $menu,
+ if_(!$::isEmbedded, Gtk2::Banner->new('drakgw', N("Drakpxelinux manage your PXE server"))),
+ if_($::isEmbedded, Gtk2::Label->new("Here you can manage your PXE server.")),
+ gtknew('Notebook', children => [
+ gtknew('Label', text => N("PXE configuration file")),
+ gtknew('HBox', spacing => 0,
+ children => [
+ 1, gtknew('ScrolledWindow', width => 500, height => 300, child => $treeview),
+ 0, gtknew('VBox',
+ children => [
+ 0, gtknew('VButtonBox', children_loose => [
+ gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Add PXE entry")), 'addpxe'), clicked => sub {
+ eval { wizard_add_entry($model, $treeview) };
+ my $err = $@;
+ $::WizardWindow->destroy if defined $::WizardWindow;
+ undef $::WizardWindow;
+ if ($err && $err !~ /wizcancel/) {
+ err_dialog(N("Error"), N("The PXE entry wizard has unexpectedly failed:") . "\n\n" . $err);
+ }
+ }),
+ gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Remove")), 'removepxe'), clicked => sub { remove_item($model, $treeview) }),
+ gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Edit")), 'editb'), clicked => sub {
+ edit_box_item($model, $treeview) }),
+ gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Apply")), 'apply'), clicked => sub { write_conf }),
+ ],),
+ 0, gtknew('HSeparator'),
+ 0, gtknew('VButtonBox', children_loose => [
+ gtknew('Label', text => N("Default boot:")),
+ $labelscombo,
+ ]),
+ 0, gtknew('HSeparator'),
+ 0, gtknew('VButtonBox', children_loose => [
+ gtksignal_connect(set_help_tip(Gtk2::Button->new(N("Reconfigure PXE Server")), 'wizardsrv'), clicked => sub {
+ eval { wizard_pxe_server() };
+ my $err = $@;
+ $::WizardWindow->destroy if defined $::WizardWindow;
+ undef $::WizardWindow;
+ if ($err && $err !~ /wizcancel/) {
+ err_dialog(N("Error"), N("The PXE server wizard has unexpectedly failed:")
+ . "\n\n" . $err);
+ }
+ }),
+ gtksignal_connect(new Gtk2::Button(N("Help")), clicked => \&show_help),
+ ]),
+ ]),
+ ]),
+ gtknew('Label', text => N("Profiles")),
+ gtknew('HBox', spacing => 1,
+ children_loose => [
+ gtknew('ScrolledWindow', child => $profiles),
+ gtknew('VBox',
+ children_loose => [
+ gtknew('VButtonBox', children_loose => [
+ gtksignal_connect(gtknew('Button', text => N("Add profile")), clicked => \&add_profile),
+ gtksignal_connect(gtknew('Button', text => N("Clone profile")), clicked => sub {
+ network::pxe::clone_profile($profiles_conf, $profiles->{data}[$_][0]) foreach $profiles->get_selected_indices;
+ refresh_profiles();
+ }),
+ gtksignal_connect(gtknew('Button', text => N("Remove profile")), clicked => sub {
+ network::pxe::remove_profile($profiles_conf, $profiles->{data}[$_][0]) foreach $profiles->get_selected_indices;
+ refresh_profiles();
+ }),
+ ]),
+ gtknew('HSeparator'),
+ gtknew('VButtonBox', children_loose => [
+ gtksignal_connect($install_button = gtknew('Button', text => N("Edit installation settings")), clicked => sub {
+ run_program::raw({ detach => 1 }, 'drakpxelinux', '--type=install', '--profile=' . $profiles->{data}[$_][0]) foreach $profiles->get_selected_indices;
+ }),
+ gtksignal_connect(gtknew('Button', text => N("Edit boot settings")), clicked => sub {
+ run_program::raw({ detach => 1 }, 'drakpxelinux', '--type=boot', '--profile=' . $profiles->{data}[$_][0]) foreach $profiles->get_selected_indices;
+ }),
+ ]),
+ ]),
+ ]),
+
+
+ gtknew('Label', text => N("Systems")),
+ gtknew('VBox', spacing => 1,
+ children => [
+ 1, gtknew('ScrolledWindow', child => $systems),
+ 0, gtknew('HBox',
+ children_loose => [
+ # gtknew('Button', text => N("Scan for systems")),
+ gtksignal_connect(gtknew('Button', text => N("Set system")), clicked => sub {
+ my $profile = $profiles_combo->get_active_text;
+ my $to_install = exists $profiles_conf->{profiles}{install}{$profile};
+ foreach ($systems->get_selected_indices) {
+ my $entry = $systems->{data}[$_];
+ network::pxe::set_profile_for_mac_address($profile, $to_install, $entry->[0]);
+ system_entry_set_installed($entry, 0);
+ system_entry_set_profile($entry, $profile);
+ }
+ }),
+ $profiles_combo = gtknew('ComboBox'),
+ ]),
+ ]),
+ gtknew('Label', text => N("Log")),
+ gtknew('VBox', spacing => 1, children_loose => [
+ gtknew('ScrolledWindow', width => 600, height => 400, child => $log_text),
+ ]),
+ ]),
+ $okcancel,
);
-$W->show_all;
+
+add_configured_mac_addresses();
+get_mac_addresses_from_dhcp_log();
+Glib::Timeout->add(60000, \&get_mac_addresses_from_dhcp_log);
+refresh_profiles();
+$w->show;
+
+#$W->show_all;
Gtk2->main;