From 90e760ba84a795dd47a5b3f860bf9b29e1354280 Mon Sep 17 00:00:00 2001 From: Dagobert Michelsen Date: Fri, 20 Feb 2015 10:11:06 +0100 Subject: [PATCH 1/2] Add LDom support --- lib/ansible/module_utils/facts.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 6d602af7366..c1285027be9 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -2498,6 +2498,27 @@ class SunOSVirtual(Virtual): if 'VirtualBox' in line: self.facts['virtualization_type'] = 'virtualbox' self.facts['virtualization_role'] = 'guest' + # Detect domaining on Sparc hardware + if os.path.exists("/usr/sbin/virtinfo"): + # The output of virtinfo is different whether we are on a machine with logical + # domains ('LDoms') on a T-series or domains ('Domains') on a M-series. Try LDoms first. + rc, out, err = module.run_command("/usr/sbin/virtinfo -p") + # The output contains multiple lines with different keys like this: + # DOMAINROLE|impl=LDoms|control=false|io=false|service=false|root=false + # The output may also be not formated and the returncode is set to 0 regardless of the error condition: + # virtinfo can only be run from the global zone + for line in out.split('\n'): + fields = line.split('|') + if( fields[0] == 'DOMAINROLE' and fields[1] == 'impl=LDoms' ): + self.facts['virtualization_type'] = 'ldom' + self.facts['virtualization_role'] = 'guest' + hostfeatures = [] + for field in fields[2:]: + arg = field.split('=') + if( arg[1] == 'true' ): + hostfeatures.append(arg[0]) + if( len(hostfeatures) > 0 ): + self.facts['virtualization_role'] = 'host (' + ','.join(hostfeatures) + ')' def get_file_content(path, default=None, strip=True): data = default From c1dba60961b32e79ded4674837ad71fe30b59eb2 Mon Sep 17 00:00:00 2001 From: Dagobert Michelsen Date: Fri, 20 Feb 2015 13:57:02 +0100 Subject: [PATCH 2/2] Use try block for field splitting --- lib/ansible/module_utils/facts.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index c1285027be9..63a7d4d0a66 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -2507,18 +2507,21 @@ class SunOSVirtual(Virtual): # DOMAINROLE|impl=LDoms|control=false|io=false|service=false|root=false # The output may also be not formated and the returncode is set to 0 regardless of the error condition: # virtinfo can only be run from the global zone - for line in out.split('\n'): - fields = line.split('|') - if( fields[0] == 'DOMAINROLE' and fields[1] == 'impl=LDoms' ): - self.facts['virtualization_type'] = 'ldom' - self.facts['virtualization_role'] = 'guest' - hostfeatures = [] - for field in fields[2:]: - arg = field.split('=') - if( arg[1] == 'true' ): - hostfeatures.append(arg[0]) - if( len(hostfeatures) > 0 ): - self.facts['virtualization_role'] = 'host (' + ','.join(hostfeatures) + ')' + try: + for line in out.split('\n'): + fields = line.split('|') + if( fields[0] == 'DOMAINROLE' and fields[1] == 'impl=LDoms' ): + self.facts['virtualization_type'] = 'ldom' + self.facts['virtualization_role'] = 'guest' + hostfeatures = [] + for field in fields[2:]: + arg = field.split('=') + if( arg[1] == 'true' ): + hostfeatures.append(arg[0]) + if( len(hostfeatures) > 0 ): + self.facts['virtualization_role'] = 'host (' + ','.join(hostfeatures) + ')' + except ValueError, e: + pass def get_file_content(path, default=None, strip=True): data = default