Hi,
This patch fix oscar database bootstrapping.
This is a fix to the command /usr/bin/create_and_populate_basic_node_info.
Now:
- The Nics table is populated with informations regarding
OSCAR_NETWORK_INTERFACE.
- The Networks table is populated with network related to this interface.
The table clusters still lack a default value for install_mode. Maybe the stage
6 will initialize it. I'll check later.
Sorry, patch is against normal package as I'm lost in the svn. :)
Best regards,
Olivier.
--
Olivier LAHAYE
CEA Saclay
DRT-LIST-DETECS-SSTM
--- /usr/bin/create_and_populate_basic_node_info.orig 2009-12-01 09:53:02.000000000 +0100
+++ /usr/bin/create_and_populate_basic_node_info 2009-12-01 16:56:47.000000000 +0100
@@ -38,6 +38,7 @@
use OSCAR::Package;
use OSCAR::oda;
use OSCAR::Logger;
+#use OSCAR::MAC;
my %options = ();
my %field_value_hash = ();
@@ -47,6 +48,25 @@
$options{debug} = 1 if $ENV{OSCAR_DB_DEBUG};
$options{verbose} = 1 if $ENV{OSCAR_DB_VERBOSE};
+# Compute network base ip adress from an ip adress and its netmask.
+sub get_network_base_ip ($$) {
+ my ($ip , $netmask) = @_;
+
+ # Compute network from broadcast and netmask, then check the Network table.
+ my @addrarr=split(/\./,$ip);
+ my ( $ipaddress ) = unpack( "N", pack( "C4",@addrarr ) );
+
+ my @maskarr=split(/\./,$netmask);
+ my ( $netmask ) = unpack( "N", pack( "C4",@maskarr ) );
+
+ # Calculate network address by logical AND operation of addr & netmask
+ # and convert network address to IP address format
+ my $netadd = ( $ipaddress & $netmask );
+ my @netarr=unpack( "C4", pack( "N",$netadd ) );
+ my $netaddress=join(".",@netarr);
+ return $netaddress;
+}
+
# see if there is already a node named oscar_server,
# and make it if it doesn't already exist, this will also
# make a special associated node group named oscar_server
@@ -67,7 +87,7 @@
my @errors = ();
#locking("write", \%options, \...@tables, \...@errors);
-# Populate "Nodes" table
+# Populate "Nodes" table (the head is a node)
my $msg = "in create_and_populate_basic_node_info Populating Nodes records for oscar_server ...\n";
print "DB_DEBUG>$0:====>\n$msg" if $options{debug};
@errors = ("cannot read nodes database table");
@@ -78,6 +98,94 @@
die "ERROR: Impossible to set headnode information in the database";
}
+# Get headnode_iface config so we can populate Nics table.
+my %head_nic ;
+my %head_network ;
+my $private_netif_name = OSCAR::Database::get_headnode_iface(undef, undef);
+my @private_netif_config = `LC_ALL=C ifconfig $private_netif_name` ;
+for ( @private_netif_config ) {
+ %head_nic->{ip} = $1 if ( /\s*inet addr:([\d.]+)/ ) ;
+ %head_nic->{mac} = $1 if ( /HWaddr\s+([[:xdigit:]:]+)\s+/ ) ;
+ %head_network->{broadcast} = $1 if ( /\s*Bcast:([\d.]+)/ ) ;
+ %head_network->{netmask} = $1 if ( /\s*Mask:([\d.]+)/ ) ;
+}
+
+# Get the network base ip on the private iface so we can populate the network table.
+my $netaddress = get_network_base_ip(%head_network->{broadcast}, %head_network->{netmask}) ;
+
+# Get the gateway adress associated with this network.
+my $cmd = "route -n |grep -E '".$netaddress."[[:space:]]+.*".$private_netif_name."'";
+my $output = `$cmd`;
+my ($net, $gw, $nm, $flgs, $metric, $ref, $use, $iface) = split (/\s+/, $output);
+
+die "create_and_populate_basic_node_info: No route defined for network $netaddress"
+ if! defined($gw);
+# Check if network already registered.
+my @networks ;
+...@errors = ("cannot read Networks database table");
+die "DB_DEBUG>$0:\n====>Failed to query Networks table"
+ if! get_networks(\...@networks, \%options, \...@errors);
+
+# Scan Networks from ODA. If found update, else create.
+my $found=0;
+for my $network (@networks ) {
+ $found=1 if ($network->{base_ip} eq $netaddress);
+}
+
+my $sql ;
+if($found) {
+ $sql = "UPDATE Networks SET broadcast='".%head_network->{broadcast}.
+ "',gateway='".$gw."',".
+ "netmask='".%head_network->{netmask}."'".
+ " WHERE base_ip='".$netaddress."'";
+ print "DB_DEBUG>$0:\n===> in create_and_populate_basic_node_info SQL: $sql\n";
+ @errors = ("cannot update Networks database table");
+ die "DB_DEBUG>$0:\n====>Failed to update values via << $sql >>"
+ if !&do_update($sql,
+ "Networks",
+ \%options,
+ \...@errors);
+} else {
+ $sql = "INSERT INTO Networks (base_ip,broadcast,cluster_id,gateway,name,netmask) VALUES ('".
+ $netaddress."','".
+ %head_network->{broadcast}."','".
+ "1"."','".
+ "0.0.0.0"."','".
+ "oscarnetwork"."','".
+ %head_network->{netmask}."')";
+ print "DB_DEBUG>$0:\n====> in create_and_populate_basic_node_info SQL : $sql\n";
+ @errors = ("cannot insert into Networks database table");
+ die "DB_DEBUG>$0:\n====>Failed to insert values via << $sql >>"
+ if !&do_insert($sql,
+ "Image_Package_Status",
+ \%options,
+ \...@errors);
+}
+
+# Populate the "Nics" table (the head iface dedicated to nodes)
+# 1st, Get the id of the network for our nic in the Networks table
+...@errors = ("cannot read Networks database table");
+die "DB_DEBUG>$0:\n====>Failed to query again Networks table"
+ if! get_networks(\...@networks, \%options, \...@errors);
+for my $network (@networks ) {
+ if ($network->{base_ip} eq $netaddress) {
+ %head_nic->{network_id} = $network->{n_id};
+ last;
+ }
+}
+
+# 2nd, using previous informations, populate the nic table.
+my $msg = "in create_and_populate_basic_node_info Populating Nics records for oscar_server ...\n";
+print "DB_DEBUG>$0:====>\n$msg" if $options{debug};
+...@errors = ("cannot read Nics database table");
+if (set_nics_with_node($private_netif_name,
+ $OSCAR_SERVER_NODE,
+ \%head_nic,
+ \%options,
+ \...@errors) !=1) {
+ die "ERROR: Impossible to set headnode nic information in the database";
+}
+
# update some of the fields in the node record for oscar_server
my $hostname = `hostname`;
------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Oscar-devel mailing list
Oscar-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oscar-devel