From db226dbbae2529d4fc0d5f38d5f762830cadcdcd Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 25 Feb 2026 14:20:00 +0100 Subject: [PATCH] MT#64514 Remove instances support Change-Id: Ie6b57d9c87e3e3ae0138cb298f1ffa851713ddab --- Makefile | 2 - debian/ngcp-ngcpcfg.install | 4 - debian/rules | 1 - docs/ngcpcfg.txt | 22 - etc/ngcp-ngcpcfg/ngcpcfg.cfg | 3 - helper/instance-info | 67 -- helper/instances-info | 195 ---- helper/tt2-process | 4 - lib/NGCP/Template/Object.pm | 28 - lib/get_all_adv_ips_for_instance | 40 - lib/get_all_cluster_set_shared_ip_maps | 12 - lib/get_all_ips_for_instance | 38 - lib/get_all_ips_of_connection_for_instance | 66 -- lib/get_all_rtp_for_instance | 118 --- lib/get_all_v6ips_for_instance | 44 - lib/get_hosts_records_for_db_connections | 71 -- lib/get_instances_for_service | 31 - sbin/ngcp-instances-validator | 206 ----- schemas/instances.yml | 17 - scripts/build | 40 - scripts/check | 9 +- scripts/services | 88 +- .../etc/kamailio/lb/kamailio.cfg.tt2 | 65 -- .../etc/kamailio/lb/ngcpcfg.services | 3 - t/fixtures/apply_instances/var/.placeholder | 1 - t/fixtures/build_instances/etc/fake.txt.tt2 | 1 - .../etc/kamailio/lb/kamailio.cfg.tt2 | 62 -- .../etc/kamailio/lb/ngcpcfg.services | 3 - .../lb/simple.cfg.customtt.tt2.inst-b | 2 - .../etc/kamailio/lb/simple.cfg.tt2 | 1 - .../etc/kamailio/lb/whatever.cfg.tt2 | 34 - .../etc/rtpengine/rtpengine.conf.tt2 | 57 -- t/fixtures/build_instances/var/.placeholder | 1 - .../host_to_run_on_is_absent.yml | 243 ----- .../repeated_instance_name.yml | 243 ----- .../repeated_instance_name_in_connections.yml | 243 ----- t/fixtures/instances-validator/wrong_link.yml | 216 ----- .../wrong_link_interfaces.yml | 216 ----- t/fixtures/ngcpcfg_carrier_instances.cfg | 60 -- t/fixtures/ngcpcfg_pro_instances.cfg | 56 -- t/fixtures/output/instance_info_A | 25 - t/fixtures/output/instances_info_args | 6 - t/fixtures/output/instances_info_args_longer | 2 - t/fixtures/output/instances_info_args_same | 2 - t/fixtures/output/instances_info_noargs | 6 - t/fixtures/output/lb_custom_cfg_instances_B | 2 - t/fixtures/output/lb_kamailio_cfg_carrier | 10 - t/fixtures/output/lb_kamailio_cfg_instances_A | 15 - t/fixtures/output/lb_kamailio_cfg_instances_B | 15 - t/fixtures/output/rtpengine.conf_instances_A | 6 - .../output/status.cfg_carrier_instances | 9 - t/fixtures/output/status.cfg_pro | 9 + t/fixtures/output/status.cfg_pro_instances | 9 - .../output/whatever.cfg_carrier_instances_A | 3 - .../output/whatever.cfg_carrier_instances_B | 3 - .../output/whatever.cfg_pro_instances_A | 3 - .../output/whatever.cfg_pro_instances_B | 3 - t/fixtures/programs.py | 1 - t/fixtures/read_cfg.sh | 3 - t/fixtures/repos/instances.yml | 14 - .../repos/network_carrier_instances.yml | 834 ------------------ .../repos/network_carrier_instances_rtp.yml | 768 ---------------- t/fixtures/repos/network_pro_instances.yml | 216 ----- t/fixtures/repos/templates/etc/status.cfg.tt2 | 8 - t/test_fixture_ngcpcfg.py | 4 +- t/test_ngcp_instances_validator.py | 114 --- t/test_ngcpcfg_apply_instances.py | 117 --- t/test_ngcpcfg_build_instances.py | 149 ---- t/test_ngcpcfg_instance_info.py | 42 - ..._get_all_ips_of_connection_for_instance.py | 74 -- ...st_ngcpcfg_lib_get_all_rtp_for_instance.py | 34 - t/test_ngcpcfg_lib_status.py | 21 +- testsuite/NGCP_Template_Object.t | 71 +- 73 files changed, 22 insertions(+), 5189 deletions(-) delete mode 100755 helper/instance-info delete mode 100755 helper/instances-info delete mode 100644 lib/get_all_adv_ips_for_instance delete mode 100644 lib/get_all_ips_for_instance delete mode 100644 lib/get_all_ips_of_connection_for_instance delete mode 100644 lib/get_all_rtp_for_instance delete mode 100644 lib/get_all_v6ips_for_instance delete mode 100644 lib/get_hosts_records_for_db_connections delete mode 100644 lib/get_instances_for_service delete mode 100755 sbin/ngcp-instances-validator delete mode 100644 schemas/instances.yml delete mode 100644 t/fixtures/apply_instances/etc/kamailio/lb/kamailio.cfg.tt2 delete mode 100755 t/fixtures/apply_instances/etc/kamailio/lb/ngcpcfg.services delete mode 100644 t/fixtures/apply_instances/var/.placeholder delete mode 100644 t/fixtures/build_instances/etc/fake.txt.tt2 delete mode 100644 t/fixtures/build_instances/etc/kamailio/lb/kamailio.cfg.tt2 delete mode 100755 t/fixtures/build_instances/etc/kamailio/lb/ngcpcfg.services delete mode 100644 t/fixtures/build_instances/etc/kamailio/lb/simple.cfg.customtt.tt2.inst-b delete mode 100644 t/fixtures/build_instances/etc/kamailio/lb/simple.cfg.tt2 delete mode 100644 t/fixtures/build_instances/etc/kamailio/lb/whatever.cfg.tt2 delete mode 100644 t/fixtures/build_instances/etc/rtpengine/rtpengine.conf.tt2 delete mode 100644 t/fixtures/build_instances/var/.placeholder delete mode 100644 t/fixtures/instances-validator/host_to_run_on_is_absent.yml delete mode 100644 t/fixtures/instances-validator/repeated_instance_name.yml delete mode 100644 t/fixtures/instances-validator/repeated_instance_name_in_connections.yml delete mode 100644 t/fixtures/instances-validator/wrong_link.yml delete mode 100644 t/fixtures/instances-validator/wrong_link_interfaces.yml delete mode 100644 t/fixtures/ngcpcfg_carrier_instances.cfg delete mode 100644 t/fixtures/ngcpcfg_pro_instances.cfg delete mode 100644 t/fixtures/output/instance_info_A delete mode 100644 t/fixtures/output/instances_info_args delete mode 100644 t/fixtures/output/instances_info_args_longer delete mode 100644 t/fixtures/output/instances_info_args_same delete mode 100644 t/fixtures/output/instances_info_noargs delete mode 100644 t/fixtures/output/lb_custom_cfg_instances_B delete mode 100644 t/fixtures/output/lb_kamailio_cfg_carrier delete mode 100644 t/fixtures/output/lb_kamailio_cfg_instances_A delete mode 100644 t/fixtures/output/lb_kamailio_cfg_instances_B delete mode 100644 t/fixtures/output/rtpengine.conf_instances_A delete mode 100644 t/fixtures/output/status.cfg_carrier_instances create mode 100644 t/fixtures/output/status.cfg_pro delete mode 100644 t/fixtures/output/status.cfg_pro_instances delete mode 100644 t/fixtures/output/whatever.cfg_carrier_instances_A delete mode 100644 t/fixtures/output/whatever.cfg_carrier_instances_B delete mode 100644 t/fixtures/output/whatever.cfg_pro_instances_A delete mode 100644 t/fixtures/output/whatever.cfg_pro_instances_B delete mode 100644 t/fixtures/repos/instances.yml delete mode 100644 t/fixtures/repos/network_carrier_instances.yml delete mode 100644 t/fixtures/repos/network_carrier_instances_rtp.yml delete mode 100644 t/fixtures/repos/network_pro_instances.yml delete mode 100644 t/test_ngcp_instances_validator.py delete mode 100644 t/test_ngcpcfg_apply_instances.py delete mode 100644 t/test_ngcpcfg_build_instances.py delete mode 100644 t/test_ngcpcfg_instance_info.py delete mode 100644 t/test_ngcpcfg_lib_get_all_ips_of_connection_for_instance.py delete mode 100644 t/test_ngcpcfg_lib_get_all_rtp_for_instance.py diff --git a/Makefile b/Makefile index 9c36355c..10552ebe 100644 --- a/Makefile +++ b/Makefile @@ -12,14 +12,12 @@ PERL_SCRIPTS = \ helper/sync-db \ helper/tt2-process \ helper/validate-yml helper/fileformat_version \ - sbin/ngcp-instances-validator \ sbin/ngcp-network \ sbin/ngcp-network-validator \ sbin/ngcp-sync-db-creds \ sbin/ngcp-sync-db-grants \ # EOL YAML_SCHEMAS = \ - schemas/instances.yml \ schemas/sites.yml \ # EOL RESULTS ?= results diff --git a/debian/ngcp-ngcpcfg.install b/debian/ngcp-ngcpcfg.install index 816dc215..04411140 100644 --- a/debian/ngcp-ngcpcfg.install +++ b/debian/ngcp-ngcpcfg.install @@ -7,8 +7,6 @@ helper/cat-yml usr/share/ngcp-ngcpcfg/helper/ helper/check-for-mysql usr/share/ngcp-ngcpcfg/helper/ helper/del-value usr/share/ngcp-ngcpcfg/helper/ helper/fileformat_version usr/share/ngcp-ngcpcfg/helper/ -helper/instance-info usr/share/ngcp-ngcpcfg/helper/ -helper/instances-info usr/share/ngcp-ngcpcfg/helper/ helper/restore-permissions usr/share/ngcp-ngcpcfg/helper/ helper/set-value usr/share/ngcp-ngcpcfg/helper/ helper/sort-yml usr/share/ngcp-ngcpcfg/helper/ @@ -18,13 +16,11 @@ helper/validate-yml usr/share/ngcp-ngcpcfg/helper/ hooks/ usr/share/ngcp-ngcpcfg/ lib/get_* usr/lib/ngcp-ngcpcfg/ lib/set_* usr/lib/ngcp-ngcpcfg/ -sbin/ngcp-instances-validator usr/sbin/ sbin/ngcp-network usr/sbin/ sbin/ngcp-network-validator usr/sbin/ sbin/ngcp-sync-db-creds usr/sbin/ sbin/ngcp-sync-db-grants usr/sbin/ sbin/ngcpcfg usr/sbin/ -schemas/instances.yml usr/share/ngcp-ngcpcfg/schemas/ schemas/sites.yml usr/share/ngcp-ngcpcfg/schemas/ scripts/apply usr/share/ngcp-ngcpcfg/scripts/ scripts/build usr/share/ngcp-ngcpcfg/scripts/ diff --git a/debian/rules b/debian/rules index 749c1a6a..9b9506a3 100755 --- a/debian/rules +++ b/debian/rules @@ -5,7 +5,6 @@ #export DH_VERBOSE = 1 SCRIPTS = \ - $(CURDIR)/usr/sbin/ngcp-instances-validator \ $(CURDIR)/usr/sbin/ngcp-network \ $(CURDIR)/usr/sbin/ngcp-network-validator \ # EOL diff --git a/docs/ngcpcfg.txt b/docs/ngcpcfg.txt index 06b1b315..60109b24 100644 --- a/docs/ngcpcfg.txt +++ b/docs/ngcpcfg.txt @@ -114,9 +114,6 @@ precedence to higher precedence): file, used by template-handler for generating /etc/foobar/baz. Configuration file is usually provided by a Debian package. -* _/etc/ngcp-config/templates/etc/foobar/baz.tt2.inst-$INSTANCE_NAME_: ngcp_instance specific -template file. $INSTANCE_NAME in lowercase specified at instances part on network.yml. - * _/etc/ngcp-config/templates/etc/foobar/baz.tt2.$NGCP_NODENAME_: node specific template file. $NGCP_NODENAME is determined using the __ngcp-nodename__ program (being _spce_ for CE systems, and _spN_ where N is the index of the node in the @@ -145,12 +142,6 @@ Note: This feature is available in High Availability setups only. template file, but configuration usually isn't provided by a Debian package and can be modified independently from any Debian package mechanism. -* _/etc/ngcp-config/templates/etc/foobar/baz.customtt.tt2.inst-$INSTANCE_NAME_: -configuration file similar to -_/etc/ngcp-config/templates/etc/foobar/baz.tt2.inst-$INSTANCE_NAME_ but it's guaranteed -that the file won't be part of any Debian package mechanism. $INSTANCE_NAME in -lowercase specified at instances part on network.yml. - * _/etc/ngcp-config/templates/etc/foobar/baz.customtt.tt2.$NGCP_NODENAME_: node specific template file. Regarding $NGCP_NODENAME the same as for _baz.tt2.$NGCP_NODE_NAME_ @@ -173,12 +164,10 @@ available in High Availability setups only. [IMPORTANT] Configuration file precedence (highest to lowest): -*.customtt.tt2.inst-$INSTANCE_NAME *.customtt.tt2.$NGCP_HOSTNAME *.customtt.tt2.$NGCP_PAIRNAME *.customtt.tt2.$NGCP_NODENAME *.customtt.tt2 -*.tt2.inst-$INSTANCE_NAME *.tt2.$NGCP_HOSTNAME *.tt2.$NGCP_PAIRNAME *.tt2.$NGCP_NODENAME @@ -255,17 +244,6 @@ be executed under "bash $FILE", so you can use commands e.g. like "ngcp-service foobar restart" and any further shell scripting syntax inside the services files -NGCP instances -~~~~~~~~~~~~~~ - -ngcp-templates package provides the *TEMPLATE_INSTANCES* file defining what are -the supported templates for instances. Meaning that ngcpcfg will generate -one additional output per instance following the specifications provide by the -file. - -ngcpcfg will generate that output with the template variable **instance_name** defined -and the environment variable **INSTANCE_NAME** set for ngcpcfg.service scripts - Global Options -------------- diff --git a/etc/ngcp-ngcpcfg/ngcpcfg.cfg b/etc/ngcp-ngcpcfg/ngcpcfg.cfg index 3a6a004d..08aad3ae 100644 --- a/etc/ngcp-ngcpcfg/ngcpcfg.cfg +++ b/etc/ngcp-ngcpcfg/ngcpcfg.cfg @@ -34,9 +34,6 @@ SERVICES_POOL_BASE="${NGCPCTL_MAIN}/templates" SITES_DIR="${NGCPCTL_MAIN}/sites" SITES_CONFIG="${NGCPCTL_MAIN}/sites.yml" -# location of instances info for templates -TEMPLATE_INSTANCES="${NGCPCTL_MAIN}/instances.yml" - # timestamp format for console output TIME_FORMAT="+%F %T" diff --git a/helper/instance-info b/helper/instance-info deleted file mode 100755 index 475f86de..00000000 --- a/helper/instance-info +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/perl -CSD -# Purpose: generate yaml output with instance_info for bash script -################################################################################ - -use strict; -use warnings; - -use YAML::XS; -use Time::Piece; -use Getopt::Long qw(:config posix_default bundling_values no_ignorecase); - -my $DEBUG = $ENV{DEBUG} || 0; -my $HNAME = $ENV{HNAME} // ''; -my $TIME_FORMAT = $ENV{TIME_FORMAT} // '%F %T'; -$TIME_FORMAT =~ s/^\+//; - -my $NETWORK_CONFIG = $ENV{NETWORK_CONFIG}; - -sub usage { - print <...] instance_name - -Options: - -h, --help This help message. -HELP -} - -if (@ARGV != 1) { - error("wrong number of arguments"); - usage(); - exit 1; -} -my %options = ( help => sub { usage(); exit 0; }, ); - -error("NETWORK_CONFIG is not defined") unless $NETWORK_CONFIG; - -GetOptions( \%options, 'help|?', ); - -my $yaml = YAML::XS::LoadFile($NETWORK_CONFIG); - -sub output_prefix { - my $t = Time::Piece->new; - my $timestamp = $t->strftime($TIME_FORMAT); - - return "$timestamp $HNAME"; -} - -sub error { - my $prefix = output_prefix(); - die "$prefix: Error: @_\n"; -} - -exit 1 unless defined $yaml->{instances}; -my $instance_name = $ARGV[0]; - -# YAML::XS::Dump returns raw UTF-8 strings. -binmode \*STDOUT, ':raw'; -foreach my $instance ( sort @{ $yaml->{instances} } ) { - if ($instance->{name} eq $instance_name) { - my $out = { - instance_info => $instance, - }; - print Dump($out); - exit 0; - } -} -exit 1; diff --git a/helper/instances-info b/helper/instances-info deleted file mode 100755 index a5bf88e5..00000000 --- a/helper/instances-info +++ /dev/null @@ -1,195 +0,0 @@ -#!/usr/bin/perl -CSD -# Purpose: format yaml instances file for bash script -################################################################################ - -use strict; -use warnings; - -use YAML::XS; -use Getopt::Long qw(:config posix_default bundling_values no_ignorecase); -use Time::Piece; -use Data::Dumper; -use File::Spec; -use Storable qw(dclone); - -my $DEBUG = $ENV{DEBUG} || 0; -my $HNAME = $ENV{HNAME} // ''; -my $TIME_FORMAT = $ENV{TIME_FORMAT} // '%F %T'; -$TIME_FORMAT =~ s/^\+//; - -my $NETWORK_CONFIG = $ENV{NETWORK_CONFIG}; -my $TEMPLATE_INSTANCES = $ENV{TEMPLATE_INSTANCES}; - -sub usage { - print <...] ... - -Options: - -h, --help This help message. -HELP -} - -my %options = ( help => sub { usage(); exit 0; }, ); - -error("NETWORK_CONFIG is not defined") unless $NETWORK_CONFIG; - -GetOptions( \%options, 'help|?', ); - -my $yaml = YAML::XS::LoadFile($NETWORK_CONFIG); -my $templ = YAML::XS::LoadFile($TEMPLATE_INSTANCES); - - -sub output_prefix { - my $t = Time::Piece->new; - my $timestamp = $t->strftime($TIME_FORMAT); - - return "$timestamp $HNAME"; -} - - -sub error { - my $prefix = output_prefix(); - die "$prefix: Error: @_\n"; -} - - -sub debug { - return unless $DEBUG; - my $prefix = output_prefix(); - warn "$prefix: DEBUG @_\n"; -} - -my $instances = {}; -my $dirs = {}; - - -sub prefix_root { - my $path = shift; - return $path =~ s/^([^\/].*)/\/$1/r; -} - - -sub split_path { - my $input = shift; - my $val = (); - foreach(split /\//, $input){ - error("relative paths are not supported, ${input}") if ($_ =~ '^\.\.?$'); - if( defined $_ && !($_ =~ /^$/ )) { - push @{$val}, $_; - } - } - return $val; -} - - -sub show_match { - my $path; - my ($bpath, $spath, $suffix) = @_; - - if(defined $spath) { - $path = $spath; - } else { - $path = $bpath; - } - - foreach my $info (sort { $a->{name} cmp $b->{name} } @{$dirs->{$path}}) { - my $dest; - if(defined $spath && defined $suffix) { - $dest = $info->{dest}."/${suffix}"; - } else { - $dest = $info->{dest}; - } - print "$bpath:$dest:".$info->{name}."\n"; - } -} - - -sub prepare_info { - return 0 unless defined $yaml->{instances}; - foreach my $instance (sort { $a->{name} cmp $b->{name} } @{$yaml->{instances}}) { - $instances->{ $instance->{label} } //= (); - push @{ $instances->{ $instance->{label} } }, $instance->{name}; - } - foreach my $def (sort { $a->{orig} cmp $b->{orig} } @{$templ->{sources}}) { - my $inst = $instances->{ $def->{label} }; - next unless $inst; - my $orig = prefix_root $def->{orig}; - $dirs->{$orig} = (); - foreach ( sort @{$inst} ) { - my $dest = $def->{dest} =~ s/^(.*)\$\{INSTANCE_NAME\}(.*)$/$1$_$2/rg; - push @{ $dirs->{$orig} }, { name => $_, dest => prefix_root $dest}; - } - } - #debug("info:".Dumper({instances => $instances, dirs => $dirs})); - return 1; -} - - -sub match_source { - my ($build_path, $matched) = @_; - my $abs_path = File::Spec->rel2abs($build_path); - my $sbuild = split_path $abs_path; - my $size_build = $#{$sbuild}; - my $search = keys %{$dirs}; - - debug("search ${build_path}"); - foreach my $index (0 .. $size_build) { - my $b_part = @{$sbuild}[$index]; - debug("index:${index} b_part:${b_part} b:".join '/', @{$sbuild}[0..$index]); - foreach my $source_path (sort keys %{$dirs}) { - next if defined $matched->{$source_path}; - my $sorig = split_path $source_path; - my $size_orig = $#{$sorig}; - my $i_part = defined(@{$sorig}[$index]) ? @{$sorig}[$index] : ''; - my $equal = defined($i_part) ? $b_part eq $i_part : 0; - - if (not $equal) { - $search--; - $matched->{$source_path} = 0; - debug("!! fail to match ${search} ${source_path}"); - } elsif ($index eq $size_build) { - $search--; - $matched->{$source_path} = {build => $source_path, suffix=> undef}; - debug(" match ${search} ${source_path}"); - } elsif ($index eq $size_orig) { - $search--; - my $temp = join '/', @{$sbuild}[$index+1..$size_build]; - $matched->{$source_path} = { - build => "${source_path}/$temp", - suffix => $temp, - }; - debug(" match ${search} ${source_path}"); - } else { - debug(" index:$index size_build:${size_build} size_orig:${size_orig} ${source_path}"); - } - } - debug("***"); - - # nothing else to match - last unless $search; - } - - # clean the non-matches for next round - foreach (sort keys %{$matched}) { - if ($matched->{$_}) { - show_match $matched->{$_}->{build}, $_, $matched->{$_}->{suffix}; - } else { - delete($matched->{$_}); - } - } -} - -exit unless prepare_info; - -if (@ARGV == 0) { - foreach (sort keys %{$dirs}) { - show_match $_; - } -} else { - my $matched; - foreach my $build (sort @ARGV) { - match_source $build, $matched; - } -} -exit; - diff --git a/helper/tt2-process b/helper/tt2-process index c47f61b1..aa395df5 100755 --- a/helper/tt2-process +++ b/helper/tt2-process @@ -256,10 +256,6 @@ sub generate_iofiles { # Support for PRO/CARRIER systems. my @tt2_hosts; - # Support for instances, name in lowercase!! - if (length $ENV{INSTANCE_NAME}) { - push @tt2_hosts, ".inst-".lc $ENV{INSTANCE_NAME}; - } foreach my $name (qw(HOST_FILE PAIR_FILE NODE_FILE)) { push @tt2_hosts, $ENV{$name} if defined $ENV{$name}; } diff --git a/lib/NGCP/Template/Object.pm b/lib/NGCP/Template/Object.pm index 37bff80d..a95e43ef 100644 --- a/lib/NGCP/Template/Object.pm +++ b/lib/NGCP/Template/Object.pm @@ -264,34 +264,6 @@ sub get_hosts return @res; } -sub get_instances -{ - my ($self, $hostname) = @_; - my $res = []; - - if (not exists $self->{config}{hosts}{$hostname}) { - return $res; - } - if (not exists $self->{config}{instances}) { - return $res; - } - my $peername = $self->{config}{hosts}{$hostname}{peer}; - foreach my $instance (@{$self->{config}{instances}}) { - if ($instance->{host} eq $hostname or $instance->{host} eq $peername) { - # data coming from $hostname - foreach my $iface (@{$instance->{interfaces}}) { - my $ifname = $iface->{name}; - $iface->{netmask} = $self->{config}{hosts}{$hostname}{$ifname}{netmask}; - if( exists $self->{config}{hosts}{$hostname}{$ifname}{cluster_set}) { - $iface->{cluster_set} = $self->{config}{hosts}{$hostname}{$ifname}{cluster_set}; - } - } - push @{$res}, $instance; - } - } - return $res; -} - sub get_ssh_pub_key { my ($self, $key_type) = @_; diff --git a/lib/get_all_adv_ips_for_instance b/lib/get_all_adv_ips_for_instance deleted file mode 100644 index 62cefd3b..00000000 --- a/lib/get_all_adv_ips_for_instance +++ /dev/null @@ -1,40 +0,0 @@ -[% -# vi: ft=tt2 - -# Return an advertised IP from the interface of a given LB instance -# @param argv.instance instance object -# -# @param argv.type The interface type of LB to extract the advertised IP -# from, one of: -# sip_int, sip_ext -# @param argv.status node status [ online, offline, inactive ] -# default value: ['online', 'inactive'] -# @return out The array of IPs. - -IF !argv.status.size; - argv.status = ['online', 'inactive']; -END; - -status = { - online = 0 - offline = 0 - inactive = 0 -}; -FOREACH val IN argv.status; - status.$val = 1; -END; - -out = []; -RETURN UNLESS status.item(argv.instance.status); - -FOREACH iface IN argv.instance.interfaces; - NEXT UNLESS iface.type.grep('^' _ argv.type _ '$').size(); - FOREACH adv IN iface.advertised_ip; - NEXT UNLESS adv; - out.push(adv); - END; -END; - -out = out.sort.unique; - --%] diff --git a/lib/get_all_cluster_set_shared_ip_maps b/lib/get_all_cluster_set_shared_ip_maps index 7a91d575..25fa219a 100644 --- a/lib/get_all_cluster_set_shared_ip_maps +++ b/lib/get_all_cluster_set_shared_ip_maps @@ -46,18 +46,6 @@ FOREACH set IN cluster_sets.sets; END; END; - FOREACH instance IN instances; - NEXT UNLESS status.item(instance.status); - NEXT UNLESS argv.role == instance.label; - host = instance.host; - FOREACH iface IN instance.interfaces; - ifname = iface.name; - NEXT UNLESS hosts.$host.$ifname.cluster_sets.grep('^' _ set.name _ '$').size(); - NEXT UNLESS iface.type.grep('^' _ argv.type _ '$').size(); - theset.ips.push(iface.ip) UNLESS theset.ips.defined(iface.ip); - END; - END; - IF theset.ips.size(); out.push(theset); END; diff --git a/lib/get_all_ips_for_instance b/lib/get_all_ips_for_instance deleted file mode 100644 index 1db0a167..00000000 --- a/lib/get_all_ips_for_instance +++ /dev/null @@ -1,38 +0,0 @@ -[% -# vi: ft=tt2 - -# Return an array of IPs from the interface of a given type -# for an instance. -# @param argv.instance instance -# @param argv.type The interface type of a node to extract the IP -# from, one of: -# web_int, web_ext, sip_int, sip_ext, ... -# @param argv.status node status [ online, offline, inactive ] -# default value: ['online', 'inactive'] -# @return out The array of IPs. - -IF !argv.status.size; - argv.status = ['online', 'inactive']; -END; - -status = { - online = 0 - offline = 0 - inactive = 0 -}; -FOREACH val IN argv.status; - status.$val = 1; -END; - -out = []; -RETURN UNLESS status.item(argv.instance.status); - -FOREACH iface IN argv.instance.interfaces; - NEXT UNLESS iface.type.grep('^' _ argv.type _ '$').size(); - NEXT UNLESS iface.ip; - out.push(iface.ip); -END; - -out = out.sort.unique; - --%] diff --git a/lib/get_all_ips_of_connection_for_instance b/lib/get_all_ips_of_connection_for_instance deleted file mode 100644 index 6e5c7452..00000000 --- a/lib/get_all_ips_of_connection_for_instance +++ /dev/null @@ -1,66 +0,0 @@ -[% -# vi: ft=tt2 - -# Returns an array of IPs getting from the connection list passed as argument -# after getting the one with name argv.name -# The ips are retrieved from the definition of other instances or hosts -# -# @param argv.connection the connection list of the instance -# -# @param argv.name the name of the connection list to use -# -# @param argv.type get IPs for only specific iface type, -# not all of the types present in conn config -# -# @param argv.ngcpcfgdir -# -# @return out the array of IPs. -# @return out_algorithm the algorithm to use. - -out = []; -out_algorithm = ''; - -IF !argv.ngcpcfgdir.length; - argv.ngcpcfgdir = '/usr/lib/ngcp-ngcpcfg'; -END; - -FOR conn IN argv.connection; - NEXT UNLESS conn.name == argv.name; - out_algorithm = conn.algorithm; - FOR link IN conn.links; - # Filtering to get the interface with the correct type - FOR link_interface IN link.interfaces; - NEXT UNLESS link_interface.type.grep('^' _ argv.type _ '$').size(); - - # If type equal instance, then look into the instances definition - IF link.type == "instance"; - FOR conn_instance IN instances; - NEXT UNLESS conn_instance.name == link.name; - FOR iface IN conn_instance.interfaces; - NEXT UNLESS iface.name == link_interface.name; - NEXT UNLESS iface.type.grep('^' _ link_interface.type _ '$').size(); - NEXT UNLESS iface.ip; - out.push(iface.ip); - END; - END; - # If type equal host, then look into the node interfaces definition - ELSE; - IF hosts.exists(link.name); - argv.host = link.name; - argv.type = link_interface.type; - PROCESS "${argv.ngcpcfgdir}/get_all_shared_ips_for_host"; - IF !out.size; - PROCESS "${argv.ngcpcfgdir}/get_all_ips_for_host"; - END; - END; - END; - END; - - # It is assumed to have in the connections only one interface defined with a particular type - LAST; - END; -END; - -out = out.unique; - --%] \ No newline at end of file diff --git a/lib/get_all_rtp_for_instance b/lib/get_all_rtp_for_instance deleted file mode 100644 index 70426673..00000000 --- a/lib/get_all_rtp_for_instance +++ /dev/null @@ -1,118 +0,0 @@ -[% -# vi: ft=tt2 - -# Returns a list of RTP-enabled interfaces for rtpengine. -# -# @param argv.instance instance -# @param argv.format The format of the returned list, one of: -# "list" for plain list of interfaces, -# "address" for plain list of addresses, -# blank or "rtpengine" for full CLI options. -# @param argv.status node status [ online, offline, inactive ] -# default value: ['online', 'inactive'] -# @return out The array of interfaces. - -X_format = argv.format; - -IF ! X_format.defined || X_format == ''; - X_format = 'rtpengine'; -END; - -IF !argv.status.size; - argv.status = ['online', 'inactive']; -END; - -status = { - online = 0 - offline = 0 - inactive = 0 -}; -FOREACH val IN argv.status; - status.$val = 1; -END; - -out = []; -RETURN UNLESS status.item(argv.instance.status); - -FOREACH X_ifc IN argv.instance.interfaces; - X_types = X_ifc.type.grep('^rtp_.'); - FOREACH X_type IN X_types; - X_type = X_type.remove('^rtp_'); - - IF X_format == 'list'; - out.push(X_type); - NEXT; - END; - - X_ips = X_ifc.shared_ip.list; - IF !X_ips.size() || !X_ips.0.defined; - X_ips = X_ifc.ip.list; - END; - X_adv_ips = X_ifc.advertised_ip.list; - - X_suffix = 0; - IF X_ips.size() > 1; - X_suffix = 1; - END; - - FOREACH X_ip IN X_ips; - X_adv_ip = X_adv_ips.shift(); - IF X_format == 'address'; - out.push(X_ip); - ELSE; - X_name = X_type; - IF X_suffix; - X_name = X_name _ ':' _ X_suffix; - X_suffix = X_suffix + 1; - END; - IF X_format == 'objects'; - X_obj = { - name = X_name - address = X_ip - adv_addr = X_adv_ip - port_min = X_ifc.rtp_port_min || 0 - port_max = X_ifc.rtp_port_max || 0 - }; - out.push(X_obj); - ELSE; - out.push(X_name _ '/' _ X_ip _ (X_adv_ip ? ('!' _ X_adv_ip) : '')); - END; - END; - END; - - X_ips = X_ifc.shared_v6ip.list; - IF !X_ips.size() || !X_ips.0.defined; - X_ips = X_ifc.v6ip.list; - END; - - X_suffix = 0; - IF X_ips.size() > 1; - X_suffix = 1; - END; - - FOREACH X_ip IN X_ips; - IF X_format == 'address'; - out.push(X_ip); - ELSE; - X_name = X_type; - IF X_suffix; - X_name = X_name _ ':' _ X_suffix; - X_suffix = X_suffix + 1; - END; - IF X_format == 'objects'; - X_obj = { - name = X_name - address = X_ip - port_min = X_ifc.rtp_port_min || 0 - port_max = X_ifc.rtp_port_max || 0 - }; - out.push(X_obj); - ELSE; - out.push(X_name _ '/' _ X_ip); - END; - END; - END; - END; -END; - --%] diff --git a/lib/get_all_v6ips_for_instance b/lib/get_all_v6ips_for_instance deleted file mode 100644 index f46d729c..00000000 --- a/lib/get_all_v6ips_for_instance +++ /dev/null @@ -1,44 +0,0 @@ -[% -# vi: ft=tt2 - -# Return an array of IPv6s from the interface of a given type -# for an instance. -# @param argv.instance instance -# @param argv.type The interface type of a node to extract the IP -# from, one of: -# web_int, web_ext, sip_int, sip_ext, ... -# @param argv.format Optional reformatting of IPv6 addresses. -# @param argv.status node status [ online, offline, inactive ] -# default value: ['online', 'inactive'] -# @return out The array of IPs. - -IF !argv.status.size; - argv.status = ['online', 'inactive']; -END; - -status = { - online = 0 - offline = 0 - inactive = 0 -}; -FOREACH val IN argv.status; - status.$val = 1; -END; - -out = []; -RETURN UNLESS status.item(argv.instance.status); - -FOREACH iface IN argv.instance.interfaces; - NEXT UNLESS iface.type.grep('^' _ argv.type _ '$').size(); - NEXT UNLESS iface.v6ip; - IF argv.format == 'expand'; - ip = ngcp.net_ip_expand(iface.v6ip); - ELSE; - ip = iface.v6ip; - END; - out.push(ip); -END; - -out = out.sort.unique; - --%] diff --git a/lib/get_hosts_records_for_db_connections b/lib/get_hosts_records_for_db_connections deleted file mode 100644 index 453ba099..00000000 --- a/lib/get_hosts_records_for_db_connections +++ /dev/null @@ -1,71 +0,0 @@ -[% -# vi: ft=tt2 - -# Only for usage with instances setup, and only to be used on Proxy / LB hosts. -# -# Returns a list of prepared records for /etc/hosts file. -# It differentiates PRO and Carrier setups automatically and fills -# the records accordingly to the setup type. -# If the NGCP setup has no instances, script will return an empty list. - -out = []; - -proxy_role = 'proxy'; -lb_role = 'lb'; - -sql_role = 'db'; -nosql_role = 'db'; - -iface_marker = 'ha_int'; - -hostname = ngcp.get_hostname(); -is_lb = ngcp.has_role(hostname, lb_role); -is_proxy = ngcp.has_role(hostname, proxy_role); - -# if this host where the script is running, is not a Proxy/LB node, skip further execution -IF instances.defined && instances.size > 0 && (is_proxy || is_lb); - - hostnames_records_sql = []; - hostnames_records_nosql = []; - - # get my ha ip (not a shared ip) - argv.host = hostname; - argv.type = iface_marker; - PROCESS '/usr/lib/ngcp-ngcpcfg/get_all_ips_for_host'; - my_ha_ip = out.0; - - FOREACH host IN hosts.keys.sort; - this_host_has_sql_role = ngcp.has_role(host, sql_role); - this_host_has_nosql_role = ngcp.has_role(host, nosql_role); - this_host_has_proxy_role = ngcp.has_role(host, proxy_role); - this_host_has_lb_role = ngcp.has_role(host, lb_role); - - IF is_proxy && (this_host_has_sql_role || this_host_has_nosql_role); - argv.host = host; - argv.type = iface_marker; - PROCESS '/usr/lib/ngcp-ngcpcfg/get_all_shared_ips_for_host'; - - IF this_host_has_sql_role && out.0; - hostnames_records_sql.push(out.0 _ ' db.central.' _ host); - END; - IF this_host_has_nosql_role && out.0; - hostnames_records_nosql.push(out.0 _ ' nosql.central.' _ host); - END; - END; - - IF is_proxy && this_host_has_proxy_role; - hostnames_records_sql.push(my_ha_ip _ ' db.replicatedpair.' _ host); - hostnames_records_sql.push(my_ha_ip _ ' db.replicatedcentral.' _ host); - END; - - IF (is_proxy && this_host_has_proxy_role) || (is_lb && this_host_has_lb_role); - hostnames_records_nosql.push(my_ha_ip _ ' nosql.replicatedpair.' _ host); - END; - END; - - out = hostnames_records_nosql.merge(hostnames_records_sql); -END; - -out = out.unique.sort; - --%] diff --git a/lib/get_instances_for_service b/lib/get_instances_for_service deleted file mode 100644 index af5092c0..00000000 --- a/lib/get_instances_for_service +++ /dev/null @@ -1,31 +0,0 @@ -[% -# vi: ft=tt2 - -# Returns a list of instances for a service. -# -# @param argv.service instance service name. -# @param argv.status instance status [ online, offline ], -# default value: [ 'online' ]. -# @return out Hash of instance lists per service. - -IF !argv.status.size; - argv.status = [ 'online' ]; -END; - -status = { - online = 0 - offline = 0 -}; -FOREACH val IN argv.status; - status.$val = 1; -END; - -out = []; -FOREACH instance IN instances; - NEXT UNLESS status.item(instance.status); - NEXT UNLESS instance.service.replace('-', '_') == argv.service; - - out.push(instance); -END; - --%] diff --git a/sbin/ngcp-instances-validator b/sbin/ngcp-instances-validator deleted file mode 100755 index 465677f5..00000000 --- a/sbin/ngcp-instances-validator +++ /dev/null @@ -1,206 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use open qw(:std :encoding(UTF-8)); - -use Storable qw(dclone); -use List::Util qw(any none first); -use Getopt::Long qw(:config posix_default no_ignorecase auto_help auto_version); -use Pod::Usage; -use YAML::XS qw(); -use Kwalify; - -our $VERSION = 'UNRELEASED'; - -my $network_file = '/etc/ngcp-config/network.yml'; - -GetOptions( - 'n|network-file=s' => \$network_file, -) or pod2usage(1); - -my $yaml = YAML::XS::LoadFile($network_file) - or die "cannot parse file $network_file"; - -sub dup_check -{ - my ($dupe, $text) = @_; - my $errors = 0; - - foreach my $id (sort keys %{$dupe}) { - next if scalar @{$dupe->{$id}} <= 1; - - warn " - $text $id (@{$dupe->{$id}})\n"; - $errors++; - } - - return $errors; -} - -# Only run these checks, if we have any of instances defined. -if (exists $yaml->{instances}) { - my $errors = 0; - - my %dupe_instance_name; - my %dupe_conn; - - my @instance_names = map { $_->{name} } @{$yaml->{instances}}; - my @host_names = sort keys %{$yaml->{hosts}}; - - my $i = 0; - - # Cycle through all existing instances definitions to find mistakes in - # connections. - foreach my $instance (@{$yaml->{instances}}) { - my $instance_host = $instance->{host}; - my $j = 0; - - # Just in case, catch name duplicates used for general instances names. - push @{$dupe_instance_name{$instance->{name}}}, "instance number: $i"; - - # Iterate through the list of connections. - foreach my $conn (@{$instance->{connections}}) { - # Catch connections names duplicates of each given instance. - my $conn_id = '#' . $i . ' : ' . $instance->{name} . ': ' . $conn->{name}; - push @{$dupe_conn{$conn_id}}, "con #$j: $conn->{name} ;"; - - # Iterate through the list of connection links. - foreach my $conn_link (@{$conn->{links}}) { - my $conn_link_name = $conn_link->{name}; - my $remote; - - # Check that each connection of type instance/host indeed - # exists. - if ($conn_link->{type} eq 'instance') { - if (none { $_ eq $conn_link_name } @instance_names) { - warn " - [instances/$instance->{name}/$conn->{name}/$conn_link_name] Missing required instance for connection link\n"; - $errors ++; - } - $remote = first { $_->{name} eq $conn_link_name } @{$yaml->{instances}}; - } elsif ($conn_link->{type} eq 'host') { - if (none { $_ eq $conn_link_name } @host_names) { - warn " - [instances/$instance->{name}/$conn->{name}/$conn_link_name] Missing required host for connection link\n"; - $errors ++; - } - $remote = $yaml->{hosts}->{$conn_link_name}; - } - - # Iterate through the list of link interfaces. - foreach my $link_iface (@{$conn_link->{interfaces}}) { - my $link_iface_name = $link_iface->{name}; - my $link_iface_type = $link_iface->{type}; - - # Requested link must indeed have requested interface, - # otherwise not possible to interconnect. - if ($conn_link->{type} eq 'instance' ? - none { $_->{name} eq $link_iface_name } @{$remote->{interfaces}} : - none { $_ eq $link_iface_name } @{$remote->{interfaces}}) - { - warn " - [instances/$instance->{name}/$conn->{name}/$conn_link_name/$link_iface_name] Missing required link interface\n"; - $errors ++; - } - - # Check type interface - my $iface; - if ($conn_link->{type} eq 'instance') { - $iface = first { $_->{name} eq $link_iface_name } @{$remote->{interfaces}}; - } else { - $iface = $remote->{$link_iface_name}; - } - if (none { $_ eq $link_iface_type } @{$iface->{type}}) { - warn " - [instances/$instance->{name}/$conn->{name}/$conn_link_name/$link_iface_name] Missing type $link_iface_type on link interface\n"; - $errors ++; - } - } - } - - $j++; - } - - # Just in case, check also that a host, on which we must run this - # instance, exists. - if (none { $_ eq $instance_host } @host_names) { - warn " - [instances/$instance->{name}] Missing required host $instance_host\n"; - $errors ++; - } - - $i++; - } - - # Check duplicates and raise an error if found. - $errors += dup_check(\%dupe_instance_name, '[/instances/] Duplicate instance name with an existing instance'); - $errors += dup_check(\%dupe_conn, '[/instances/] Duplicate connetion name'); - - exit 1 if $errors; -} - -1; - -# vim: ts=4 sw=4 et - -__END__ - -=encoding utf-8 - -=head1 NAME - -ngcp-instances-validator - dynamically validates the instances connections, if instances are defined. - -=head1 SYNOPSIS - -B [I