Giuseppe Lavagetto has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311223

Change subject: realm: convert main_ipaddress and site into facts
......................................................................

realm: convert main_ipaddress and site into facts

This both makes sense from a code cleanup prospective (that is, cleaning
up anything that is in realm.pp and shouldn't be) and from the fact this
will allow us to select on the 'site' fact when e.g. querying puppetdb.

Bug: T85459
Change-Id: I33d7bf98cdcd3944e4a047d83aacb0cad0377636
---
M manifests/realm.pp
A modules/base/lib/facter/main_ipaddress.rb
A modules/base/lib/facter/site.rb
3 files changed, 45 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/23/311223/1

diff --git a/manifests/realm.pp b/manifests/realm.pp
index 09871f5..928fa99 100644
--- a/manifests/realm.pp
+++ b/manifests/realm.pp
@@ -2,40 +2,6 @@
 # Collection of global definitions used across sites, within one realm.
 #
 
-# Determine the site the server is in
-
-# If our puppetmaster is 3.5+ then use the trusted $facts hash
-if versioncmp($::serverversion, '3.5') >= 0 and $facts {
-    if $facts['ipaddress_eth0'] {
-        $main_ipaddress = $facts['ipaddress_eth0']
-    } elsif $facts['ipaddress_bond0'] {
-        $main_ipaddress = $facts['ipaddress_bond0']
-    } else {
-        $main_ipaddress = $facts['ipaddress']
-    }
-# Otherwise fallback to pre 3.5 behaviour
-} else {
-    if $::ipaddress_eth0 != undef {
-        $main_ipaddress = $::ipaddress_eth0
-    } elsif $::ipaddress_bond0 != undef {
-        $main_ipaddress = $::ipaddress_bond0
-    } else {
-        $main_ipaddress = $::ipaddress
-    }
-}
-
-$site = $main_ipaddress ? {
-    /^208\.80\.15[23]\./                      => 'codfw',
-    /^208\.80\.15[45]\./                      => 'eqiad',
-    /^10\.6[48]\./                            => 'eqiad',
-    /^10\.19[26]\./                           => 'codfw',
-    /^91\.198\.174\./                         => 'esams',
-    /^198\.35\.26\.([0-9]|[1-5][0-9]|6[0-2])/ => 'ulsfo',
-    /^10\.128\./                              => 'ulsfo',
-    /^10\.20\.0\./                            => 'esams',
-    default                                   => '(undefined)'
-}
-
 # Lab testing cluster all prefix labtest
 if $::hostname =~ /^labtest/ {
     $realm = 'labtest'
diff --git a/modules/base/lib/facter/main_ipaddress.rb 
b/modules/base/lib/facter/main_ipaddress.rb
new file mode 100644
index 0000000..6dec9bf
--- /dev/null
+++ b/modules/base/lib/facter/main_ipaddress.rb
@@ -0,0 +1,22 @@
+# Copyright (c) 2016 Wikimedia Foundation, Inc.
+# Author: Giuseppe Lavagetto <j...@wikimedia.org>
+#
+# Fact: main_ipaddress
+#
+# Purpose: extract the ip address we'll use for all practical purposes.
+#
+# Resolution:
+#
+#    We don't really expect this to be useful outside of the boundaries of our 
own
+#    site.
+Facter.add("main_ipaddress") do
+  setcode do
+    if Facter.value(:ipaddress_eth0)
+      Facter.value(:ipaddress_eth0)
+    elsif Facter.value(:ipaddress_bond0)
+      Facter.value(:ipaddress_bond0)
+    else
+      Facter.value(:ipaddress)
+    end
+  end
+end
diff --git a/modules/base/lib/facter/site.rb b/modules/base/lib/facter/site.rb
new file mode 100644
index 0000000..aafc3fe
--- /dev/null
+++ b/modules/base/lib/facter/site.rb
@@ -0,0 +1,23 @@
+# Copyright (c) 2016 Wikimedia Foundation, Inc.
+# Author: Giuseppe Lavagetto <j...@wikimedia.org>
+#
+# Fact: site
+#
+# Purpose: find the site the server is located in, from its ip address
+#
+Facter.add("site") do
+  setcode do
+    case Facter.value(:main_ipaddress)
+    when /^208\.80\.15[23]\./, /^10\.19[26]\./
+      'codfw'
+    when /^208\.80\.15[45]\./, /^10\.6[48]\./
+      'eqiad'
+    when /^91\.198\.174\./, /^10\.20\.0\./
+      'esams'
+    when /^198\.35\.26\.([0-9]|[1-5][0-9]|6[0-2])/, /^10\.128\./
+      'ulsfo'
+    else
+      '(undefined)'
+    end
+  end
+end

-- 
To view, visit https://gerrit.wikimedia.org/r/311223
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I33d7bf98cdcd3944e4a047d83aacb0cad0377636
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Giuseppe Lavagetto <glavage...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to