Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

vlan and vlanranges tables basic initialization

  • Loading branch information...
commit d230a58eb1a71425644e2ca0e5c3c741cbbb2bb9 1 parent 5975c0b
@gmambro authored
Showing with 40 additions and 4 deletions.
  1. +40 −4 script/manoc_initdb.pl
View
44 script/manoc_initdb.pl
@@ -13,17 +13,36 @@ package Manoc::InitDB;
use Manoc::Logger;
extends 'Manoc::App';
-#with 'Manoc::Logger::Role';
+with 'MooseX::Getopt::Dashes';
-use SQL::Translator;
+has 'reset_admin' => (
+ is => 'rw',
+ isa => 'Bool',
+ required => 0,
+ default => 0
+);
sub run {
my ($self) = @_;
+ if ($self->reset_admin) {
+ $self->do_reset_admin;
+ return;
+ }
+
+ # full init
+ $self->do_reset_admin;
+ $self->init_vlan;
+
+}
+
+sub do_reset_admin {
+ my ($self) = @_;
+
my $schema = $self->schema;
- $self->log->debug('Creating admin role... done.');
+ $self->log->info('Creating admin role.');
my $admin_role = $schema->resultset('Role')->update_or_create( { role => 'admin', } );
- $self->log->debug('Creating admin user... done.');
+ $self->log->info('Creating admin user.');
my $admin_user = $schema->resultset('User')->update_or_create(
{
login => 'admin',
@@ -36,7 +55,24 @@ sub run {
if ( $admin_user->roles->search( { role => 'admin' } )->count == 0 ) {
$admin_user->add_to_roles($admin_role);
}
+}
+
+sub init_vlan {
+ my ($self) = @_;
+ my $schema = $self->schema;
+ my $rs = $schema->resultset('VlanRange');
+ if ($rs->count() > 0) {
+ $self->log->info('We have a VLAN range: skipping init.');
+ return;
+ }
+ my $vlan_range = $schema->resultset('VlanRange')->update_or_create({
+ name => 'sample',
+ description => 'sample range',
+ start => 1,
+ end => 10,
+ });
+ $vlan_range->add_to_vlans({ name => 'native', id => 1 });
}
no Moose;
Please sign in to comment.
Something went wrong with that request. Please try again.