Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

vlan and vlanranges tables basic initialization

  • Loading branch information...
commit d230a58eb1a71425644e2ca0e5c3c741cbbb2bb9 1 parent 5975c0b
Gabriele Mambrini authored

Showing 1 changed file with 40 additions and 4 deletions. Show diff stats Hide diff stats

  1. +40 4 script/manoc_initdb.pl
44 script/manoc_initdb.pl
@@ -13,17 +13,36 @@ package Manoc::InitDB;
13 13 use Manoc::Logger;
14 14
15 15 extends 'Manoc::App';
16   -#with 'Manoc::Logger::Role';
  16 +with 'MooseX::Getopt::Dashes';
17 17
18   -use SQL::Translator;
  18 +has 'reset_admin' => (
  19 + is => 'rw',
  20 + isa => 'Bool',
  21 + required => 0,
  22 + default => 0
  23 +);
19 24
20 25 sub run {
21 26 my ($self) = @_;
22 27
  28 + if ($self->reset_admin) {
  29 + $self->do_reset_admin;
  30 + return;
  31 + }
  32 +
  33 + # full init
  34 + $self->do_reset_admin;
  35 + $self->init_vlan;
  36 +
  37 +}
  38 +
  39 +sub do_reset_admin {
  40 + my ($self) = @_;
  41 +
23 42 my $schema = $self->schema;
24   - $self->log->debug('Creating admin role... done.');
  43 + $self->log->info('Creating admin role.');
25 44 my $admin_role = $schema->resultset('Role')->update_or_create( { role => 'admin', } );
26   - $self->log->debug('Creating admin user... done.');
  45 + $self->log->info('Creating admin user.');
27 46 my $admin_user = $schema->resultset('User')->update_or_create(
28 47 {
29 48 login => 'admin',
@@ -36,7 +55,24 @@ sub run {
36 55 if ( $admin_user->roles->search( { role => 'admin' } )->count == 0 ) {
37 56 $admin_user->add_to_roles($admin_role);
38 57 }
  58 +}
  59 +
  60 +sub init_vlan {
  61 + my ($self) = @_;
39 62
  63 + my $schema = $self->schema;
  64 + my $rs = $schema->resultset('VlanRange');
  65 + if ($rs->count() > 0) {
  66 + $self->log->info('We have a VLAN range: skipping init.');
  67 + return;
  68 + }
  69 + my $vlan_range = $schema->resultset('VlanRange')->update_or_create({
  70 + name => 'sample',
  71 + description => 'sample range',
  72 + start => 1,
  73 + end => 10,
  74 + });
  75 + $vlan_range->add_to_vlans({ name => 'native', id => 1 });
40 76 }
41 77
42 78 no Moose;

0 comments on commit d230a58

Please sign in to comment.
Something went wrong with that request. Please try again.