From 4c85a1fa05f6cefd735657b033e15e3f28945beb Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Tue, 1 Nov 2016 15:07:50 +0100 Subject: [PATCH] Refactor code for VirtualFacts (#18122) The populate method is cut and paste on every subclass, so we should push it up, and add a default method that is overloaded --- lib/ansible/module_utils/facts.py | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index d76668d3b8..296467b8c7 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -3080,8 +3080,13 @@ class Virtual(Facts): return super(cls, subclass).__new__(subclass, *arguments, **keyword) def populate(self): + self.get_virtual_facts() return self.facts + def get_virtual_facts(self): + self.facts['virtualization_type'] = '' + self.facts['virtualization_role'] = '' + class LinuxVirtual(Virtual): """ This is a Linux-specific subclass of Virtual. It defines @@ -3090,10 +3095,6 @@ class LinuxVirtual(Virtual): """ platform = 'Linux' - def populate(self): - self.get_virtual_facts() - return self.facts - # For more information, check: http://people.redhat.com/~rjones/virt-what/ def get_virtual_facts(self): # lxc/docker @@ -3265,14 +3266,6 @@ class FreeBSDVirtual(Virtual): """ platform = 'FreeBSD' - def populate(self): - self.get_virtual_facts() - return self.facts - - def get_virtual_facts(self): - self.facts['virtualization_type'] = '' - self.facts['virtualization_role'] = '' - class DragonFlyVirtual(FreeBSDVirtual): platform = 'DragonFly' @@ -3284,10 +3277,6 @@ class OpenBSDVirtual(Virtual): """ platform = 'OpenBSD' - def populate(self): - self.get_virtual_facts() - return self.facts - def get_virtual_facts(self): sysctl_path = self.module.get_bin_path('sysctl') @@ -3332,10 +3321,6 @@ class HPUXVirtual(Virtual): """ platform = 'HP-UX' - def populate(self): - self.get_virtual_facts() - return self.facts - def get_virtual_facts(self): if os.path.exists('/usr/sbin/vecheck'): rc, out, err = self.module.run_command("/usr/sbin/vecheck") @@ -3369,10 +3354,6 @@ class SunOSVirtual(Virtual): """ platform = 'SunOS' - def populate(self): - self.get_virtual_facts() - return self.facts - def get_virtual_facts(self): # Check if it's a zone