diff options
author | Kristian Lyngstol <kristian@bohemians.org> | 2016-11-15 10:00:14 +0100 |
---|---|---|
committer | Kristian Lyngstol <kristian@bohemians.org> | 2016-11-15 10:00:14 +0100 |
commit | d9069802f61b3a36807c02c429ec0b9c9a63c857 (patch) | |
tree | 8074f51382b7b43a8f27e78e409da2060ba90228 | |
parent | 502c46a7299cac16018a8a2e7b376f139627ecae (diff) |
Start clean switches-table
Lots of cruft
-rw-r--r-- | ansible/roles/test/tasks/main.yml | 10 | ||||
-rw-r--r-- | ansible/roles/test/vars/main.yml | 4 | ||||
-rw-r--r-- | build/schema.sql | 6 | ||||
-rwxr-xr-x | web/api/public/switches | 2 | ||||
-rwxr-xr-x | web/api/read/switches-management | 2 | ||||
-rwxr-xr-x | web/api/write/switch-add | 4 | ||||
-rwxr-xr-x | web/api/write/switch-update | 4 |
7 files changed, 18 insertions, 14 deletions
diff --git a/ansible/roles/test/tasks/main.yml b/ansible/roles/test/tasks/main.yml index 342cb9b..798644a 100644 --- a/ansible/roles/test/tasks/main.yml +++ b/ansible/roles/test/tasks/main.yml @@ -29,5 +29,11 @@ user: demo password: demo body: '[{"mgmt_v4_addr":"127.0.0.1","sysname":"core"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.2","sysname":"distro0"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.3","sysname":"e1-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.4","sysname":"e1-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.5","sysname":"e3-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.6","sysname":"e3-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.7","sysname":"e5-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.8","sysname":"e5-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.9","sysname":"e7-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.10","sysname":"e7-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.11","sysname":"e9-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.12","sysname":"e9-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.14","sysname":"e11-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.15","sysname":"e11-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.16","sysname":"e13-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.17","sysname":"e13-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.18","sysname":"e15-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.19","sysname":"e15-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.20","sysname":"e17-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.21","sysname":"e17-2"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.22","sysname":"e19-1"},{"distro_name":"distro0","mgmt_v4_addr":"127.0.0.23","sysname":"e19-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.24","sysname":"distro1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.25","sysname":"e21-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.26","sysname":"e21-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.27","sysname":"e23-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.28","sysname":"e23-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.29","sysname":"e25-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.30","sysname":"e25-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.31","sysname":"e27-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.32","sysname":"e27-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.33","sysname":"e29-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.34","sysname":"e29-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.36","sysname":"e31-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.37","sysname":"e31-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.38","sysname":"e33-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.39","sysname":"e33-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.40","sysname":"e35-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.41","sysname":"e35-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.42","sysname":"e37-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.43","sysname":"e37-2"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.44","sysname":"e39-1"},{"distro_name":"distro1","mgmt_v4_addr":"127.0.0.45","sysname":"e39-2"},{"distro_name":"core","mgmt_v4_addr":"127.0.0.46","sysname":"noc"}]' - - +- name: test read api after data is added + uri: + url: http://{{ ip.stdout }}{{ item }} + user: demo + password: demo + with_items: "{{ populated_urls }}" + tags: + - test diff --git a/ansible/roles/test/vars/main.yml b/ansible/roles/test/vars/main.yml index e760c4c..0bed216 100644 --- a/ansible/roles/test/vars/main.yml +++ b/ansible/roles/test/vars/main.yml @@ -7,10 +7,12 @@ simple_urls: - "/api/public/dhcp-summary" - "/index.html" - "/templates/switches.txt" - - "/api/templates/switches.txt" - "/render/?target=carbon.agents.*.errors" read_urls: - "/api/read/oplog" - "/api/read/snmp" - "/api/read/switches-management" - "/api/read/distro-tree" +populated_urls: + - "/api/templates/switches.txt" + diff --git a/build/schema.sql b/build/schema.sql index e40ba15..3e8ee91 100644 --- a/build/schema.sql +++ b/build/schema.sql @@ -292,12 +292,10 @@ CREATE TABLE switches ( switch integer DEFAULT nextval(('"switches_switch_seq"'::text)::regclass) NOT NULL, mgmt_v4_addr inet, sysname character varying NOT NULL, - switchtype character varying DEFAULT 'ex2200'::character varying NOT NULL, last_updated timestamp with time zone, locked boolean DEFAULT false NOT NULL, poll_frequency interval DEFAULT '00:01:00'::interval NOT NULL, community character varying DEFAULT 'FullPuppTilNMS'::character varying NOT NULL, - lldp_chassis_id character varying, mgmt_v6_addr inet, placement box, subnet4 cidr, @@ -308,9 +306,7 @@ CREATE TABLE switches ( mgmt_v4_gw inet, mgmt_vlan integer DEFAULT 666, traffic_vlan integer, - last_config_fetch timestamp with time zone, - tags jsonb DEFAULT '[]', - current_mac macaddr + tags jsonb DEFAULT '[]'::jsonb ); diff --git a/web/api/public/switches b/web/api/public/switches index 5528789..e7f4cb0 100755 --- a/web/api/public/switches +++ b/web/api/public/switches @@ -13,7 +13,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "5"; $nms::web::cc{'stale-while-revalidate'} = "30"; -my $q2 = $nms::web::dbh->prepare('select switch,sysname,tags,distro_name,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,tags,distro_name,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,poll_frequency,community,last_updated from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/api/read/switches-management b/web/api/read/switches-management index 33fc6ab..34323b1 100755 --- a/web/api/read/switches-management +++ b/web/api/read/switches-management @@ -13,7 +13,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "5"; $nms::web::cc{'stale-while-revalidate'} = "30"; -my $q2 = $nms::web::dbh->prepare('select sysname,mgmt_v4_addr,subnet4,subnet6,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated,distro_phy_port,community from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select sysname,mgmt_v4_addr,subnet4,subnet6,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,poll_frequency,last_updated,distro_phy_port,community from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/api/write/switch-add b/web/api/write/switch-add index f77df0a..dbaa1e5 100755 --- a/web/api/write/switch-add +++ b/web/api/write/switch-add @@ -23,7 +23,7 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); -my @fields = ( 'community', 'current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan'); +my @fields = ( 'community', 'distro_name', 'distro_phy_port', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'sysname', 'traffic_vlan'); sub convertplace { @@ -82,7 +82,7 @@ foreach my $tmp2 (@tmp) { } keys %switch; - $nms::web::dbh->do("INSERT INTO SWITCHES (mgmt_v4_addr, sysname, poll_frequency, community, lldp_chassis_id, mgmt_v6_addr, placement,subnet4,subnet6,distro_name) VALUES ($template{'mgmt_v4_addr'}, $template{'sysname'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'mgmt_v6_addr'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro_name'});"); + $nms::web::dbh->do("INSERT INTO SWITCHES (mgmt_v4_addr, sysname, poll_frequency, community, mgmt_v6_addr, placement,subnet4,subnet6,distro_name) VALUES ($template{'mgmt_v4_addr'}, $template{'sysname'}, $template{'poll_frequency'}, $template{'community'}, $template{'mgmt_v6_addr'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro_name'});"); push @added, $switch{'sysname'}; oplog("\"" . $switch{'sysname'} . "\"", "Switch added: " . $switch{'sysname'}); } diff --git a/web/api/write/switch-update b/web/api/write/switch-update index 797a14b..0ee4681 100755 --- a/web/api/write/switch-update +++ b/web/api/write/switch-update @@ -23,7 +23,7 @@ my @dups; my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?"); -my @fields = ( 'community', 'tags','current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v4_netsize', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_v6_netsize', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan'); +my @fields = ( 'community', 'tags', 'distro_name', 'distro_phy_port', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v4_netsize', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_v6_netsize', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'sysname', 'traffic_vlan'); sub convertplace { @@ -82,7 +82,7 @@ foreach my $tmp2 (@tmp) { } keys %switch; - $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, tags, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'tags'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); + $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, tags, community, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'tags'}, $template{'community'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});"); push @added, $switch{'sysname'}; } else { if (defined($switch{'placement'})) { |