The slurmdb is not autopopulated. I'll attach a script that does a
simple unix group to slurm account sync. You'd need to change the
$sacctmgr and $grpregex variables at the top of the script to use it.

I also have a more complicated script that creates user/partition/qos
associations to limit a qos to specific partitions and users. It would
take a little more documentation to be useful and has things more
specific to our site.

On Mon, Feb 18, 2013 at 11:55:09AM -0700, Paul Edmon wrote:
> Actually I'm curious about this too.  We are working on getting a a
> slurmdbd set up as well but I wanted to confirm whether or not the DB
> automatically populates itself from LDAP or if we have to enter it
> manually?  If the manually option does any one have a script that
> would make populating the DB easier?  We also have several thousand
> users and hundreds of groups.
> 
> -Paul Edmon-
> 
> On 2/18/2013 3:48 AM, Marcin Stolarek wrote:
> >Automatic generation of accounts in slurmdbd Hi all,
> >
> >I'm facing a problem with automatic generation and updates of
> >accounts in slurmdbd. The idea is that I'm periodically downloading
> >XML describing users and groups allowed to use computational
> >resources in our site, (for instance I know how many cpus can use
> >in parallel and amount of overall walltime for this group.)
> >Do you think is a good idea to write a simple script parsing XML
> >and using sacct to add accounts? (My first try finished with non
> >responsive slurmctld when script was running, I have thousands of
> >users and accounts)
> >Is there any API to slurmdbd, do you think is worth to write this in C?
> >
> >cheers,
> >marcin
> 

-- 
andy wettstein
hpc system administrator
research computing center
university of chicago
773.702.1104

#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my $sacctmgr = '/software/slurm-2.4-el6-x86_64/bin/sacctmgr';

my $grpregex = '^(pi-gavoth|rcc-staff)$';
my %unixgroup;
my %slurmassoc;

open( ASSOC, "$sacctmgr list assoc format=account,user --parsable2 --noheader 
|" );

while ( defined( my $line = <ASSOC> ) ) {
    chomp $line;
    my ( $acct, $user ) = split /\|/, $line;
    next unless $user;
    push @{ $slurmassoc{$acct} }, $user;
}

while ( my @gr = getgrent() ) {
    next unless $gr[0] =~ /$grpregex/;
    @{ $unixgroup{ $gr[0] } } = split / /, $gr[3];
}

#print Dumper(\%unixgroup);
#print Dumper(\%slurmassoc);

# add users and accounts if they are missing
for my $g ( keys %unixgroup ) {
    if ( !exists $slurmassoc{$g} ) {
        system("$sacctmgr --immediate create account name=$g");
    }
    for my $u ( @{ $unixgroup{$g} } ) {
        if ( !grep /^$u$/, @{ $slurmassoc{$g} } ) {
            system("$sacctmgr --immediate create user name=$u account=$g");
        }
    }
}

# remove users that aren't in the unix group
for my $g ( keys %slurmassoc ) {

    # only check for groups to remove that match the regexp
    next unless $g =~ /$grpregex/;
    for my $u ( @{ $slurmassoc{$g} } ) {
        if ( !grep /^$u$/, @{ $unixgroup{$g} } ) {
            system("$sacctmgr --immediate delete user name=$u account=$g");
        }
    }
}

Reply via email to