From 83b2b0c194ecbf80e43e8fe70afd86c733f0e2ed Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Sat, 27 Dec 2014 14:23:19 -0500 Subject: [PATCH] Database schema changes to support improved stp discovery and topology --- Netdisco/lib/App/Netdisco/DB.pm | 2 +- Netdisco/lib/App/Netdisco/DB/Result/Device.pm | 33 +++++++++--- .../App/Netdisco/DB/Result/DevicePortStp.pm | 51 ++++++++++++++++++ .../lib/App/Netdisco/DB/Result/DeviceStp.pm | 53 +++++++++++++++++++ .../App-Netdisco-DB-39-40-PostgreSQL.sql | 46 ++++++++++++++++ 5 files changed, 178 insertions(+), 7 deletions(-) create mode 100644 Netdisco/lib/App/Netdisco/DB/Result/DevicePortStp.pm create mode 100644 Netdisco/lib/App/Netdisco/DB/Result/DeviceStp.pm create mode 100644 Netdisco/lib/App/Netdisco/DB/schema_versions/App-Netdisco-DB-39-40-PostgreSQL.sql diff --git a/Netdisco/lib/App/Netdisco/DB.pm b/Netdisco/lib/App/Netdisco/DB.pm index e0d6a45c..f0e99f84 100644 --- a/Netdisco/lib/App/Netdisco/DB.pm +++ b/Netdisco/lib/App/Netdisco/DB.pm @@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces( ); our # try to hide from kwalitee - $VERSION = 39; # schema version used for upgrades, keep as integer + $VERSION = 40; # schema version used for upgrades, keep as integer use Path::Class; use File::Basename; diff --git a/Netdisco/lib/App/Netdisco/DB/Result/Device.pm b/Netdisco/lib/App/Netdisco/DB/Result/Device.pm index 19aefbc2..402ac374 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/Device.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/Device.pm @@ -1,9 +1,6 @@ use utf8; package App::Netdisco::DB::Result::Device; -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - use strict; use warnings; @@ -75,12 +72,13 @@ __PACKAGE__->add_columns( { data_type => "timestamp", is_nullable => 1 }, "last_arpnip", { data_type => "timestamp", is_nullable => 1 }, + "stp_ver", + { data_type => "text", is_nullable => 1 }, + "b_mac", + { data_type => "macaddr", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("ip"); -# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:671/XuuvsO2aMB1+IRWFjg - =head1 RELATIONSHIPS =head2 device_ips @@ -186,6 +184,29 @@ Returns the row from the community string table, if one exists. __PACKAGE__->might_have( community => 'App::Netdisco::DB::Result::Community', 'ip'); +=head2 stp_instances + +Returns the set of STP instances on this Device. + +=cut + +__PACKAGE__->has_many( + stp_instances => 'App::Netdisco::DB::Result::DeviceStp', + 'ip', { join_type => 'RIGHT' } +); + +=head2 stp_ports + +Returns the set of STP instances known to be configured on Ports on this +Device. + +=cut + +__PACKAGE__->has_many( + stp_ports => 'App::Netdisco::DB::Result::DevicePortStp', + 'ip', { join_type => 'RIGHT' } +); + =head1 ADDITIONAL COLUMNS =head2 port_count diff --git a/Netdisco/lib/App/Netdisco/DB/Result/DevicePortStp.pm b/Netdisco/lib/App/Netdisco/DB/Result/DevicePortStp.pm new file mode 100644 index 00000000..bc35c721 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/DB/Result/DevicePortStp.pm @@ -0,0 +1,51 @@ +use utf8; +package App::Netdisco::DB::Result::DevicePortStp; + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; +__PACKAGE__->table("device_port_stp"); +__PACKAGE__->add_columns( + "ip", + { data_type => "inet", is_nullable => 0 }, + "port", + { data_type => "text", is_nullable => 0 }, + "instance", + { data_type => "integer", is_nullable => 0 }, + "port_id", + { data_type => "integer", is_nullable => 0 }, + "des_bridge_mac", + { data_type => "macaddr", is_nullable => 1 }, + "des_port_id", + { data_type => "integer", is_nullable => 1 }, + "status", + { data_type => "text", is_nullable => 1 }, +); +__PACKAGE__->set_primary_key("port", "ip", "instance"); + + +=head1 RELATIONSHIPS + +=head2 port + +Returns the entry from the C table for which this Power entry applies. + +=cut + +__PACKAGE__->belongs_to( port => 'App::Netdisco::DB::Result::DevicePort', { + 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port', +}); + +=head2 stp_instance + +Returns the entry from the C table for which this STP entry +applies. + +=cut + +__PACKAGE__->belongs_to( device_stp => 'App::Netdisco::DB::Result::DeviceStp', { + 'foreign.ip' => 'self.ip', 'foreign.instance' => 'self.instance', +}); + +1; diff --git a/Netdisco/lib/App/Netdisco/DB/Result/DeviceStp.pm b/Netdisco/lib/App/Netdisco/DB/Result/DeviceStp.pm new file mode 100644 index 00000000..6c553df1 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/DB/Result/DeviceStp.pm @@ -0,0 +1,53 @@ +use utf8; +package App::Netdisco::DB::Result::DeviceStp; + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; +__PACKAGE__->table("device_stp"); +__PACKAGE__->add_columns( + "ip", + { data_type => "inet", is_nullable => 0 }, + "instance", + { data_type => "integer", is_nullable => 0 }, + "mac", + { data_type => "macaddr", is_nullable => 1 }, + "top_change", + { data_type => "integer", is_nullable => 1 }, + "top_lastchange", + { data_type => "bigint", is_nullable => 1 }, + "des_root_mac", + { data_type => "macaddr", is_nullable => 1 }, + "root_port", + { data_type => "text", is_nullable => 1 }, +); +__PACKAGE__->set_primary_key("ip", "instance"); + + +=head1 RELATIONSHIPS + +=head2 device + +Returns the entry from the C table to which this STP instance relates. + +=cut + +__PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' ); + +=head2 stp_ports + +Returns the set of STP instances known to be configured on Ports on this +Device. + +=cut + +__PACKAGE__->has_many( + ports => 'App::Netdisco::DB::Result::DevicePortStp', + { + 'foreign.ip' => 'self.ip', + 'foreign.instance' => 'self.instance', + }, +); + +1; diff --git a/Netdisco/lib/App/Netdisco/DB/schema_versions/App-Netdisco-DB-39-40-PostgreSQL.sql b/Netdisco/lib/App/Netdisco/DB/schema_versions/App-Netdisco-DB-39-40-PostgreSQL.sql new file mode 100644 index 00000000..c6cc91c6 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/DB/schema_versions/App-Netdisco-DB-39-40-PostgreSQL.sql @@ -0,0 +1,46 @@ +BEGIN; + +-- Add/Alter tables to support stp topology +-- +-- Table: device_stp. +-- +CREATE TABLE "device_stp" ( + "ip" inet NOT NULL, + "instance" integer NOT NULL, + "mac" macaddr, + "top_change" integer, + "top_lastchange" bigint, + "des_root_mac" macaddr, + "root_port" text, + PRIMARY KEY ("ip", "instance") +); +CREATE INDEX "device_stp_idx_ip" on "device_stp" ("ip"); +CREATE INDEX "device_stp_idx_des_root_mac" on "device_stp" ("des_root_mac"); + +-- +-- Table: device_port_stp. +-- +CREATE TABLE "device_port_stp" ( + "ip" inet NOT NULL, + "port" text NOT NULL, + "instance" integer NOT NULL, + "port_id" integer NOT NULL, + "des_bridge_mac" macaddr, + "des_port_id" integer, + "status" text, + PRIMARY KEY ("ip", "port", "instance") +); +CREATE INDEX "device_port_stp_idx_ip_instance" on "device_port_stp" ("ip", "instance"); +CREATE INDEX "device_port_stp_idx_ip_port" on "device_port_stp" ("ip", "port"); +CREATE INDEX "device_port_stp_idx_port_id" on "device_port_stp" ("port_id"); +CREATE INDEX "device_port_stp_idx_mac" on "device_port_stp" ("des_bridge_mac"); + +-- +-- Alter Table: device +-- +ALTER TABLE device ADD COLUMN "stp_ver" text; +-- existing mac may not be the bridge base mac +ALTER TABLE device ADD COLUMN "b_mac" macaddr; +CREATE INDEX "device_idx_b_mac" on "device" ("b_mac"); + +COMMIT;