From e470de2c98eb46d9c49e6829a6bd7998253ebfca Mon Sep 17 00:00:00 2001 From: award Date: Thu, 10 Jul 2014 15:26:40 -0400 Subject: Add support for child hostgroups --- theforeman.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/theforeman.py b/theforeman.py index b9472d2..809bf3f 100755 --- a/theforeman.py +++ b/theforeman.py @@ -207,8 +207,7 @@ They must be specified via ini file.''' if group is None: return group - group_name = (re.sub("[^A-Za-z0-9\-]", "-", group.get('name')).lower()) - return group_name + return group.get('label') def _get_environment_from_id(self, env_id): """Get environment name""" -- cgit v1.2.3 From 2374853e226d43aa14d997e40a73853798634ccd Mon Sep 17 00:00:00 2001 From: award Date: Thu, 10 Jul 2014 16:19:56 -0400 Subject: Add hostgroup to the host description output --- theforeman.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/theforeman.py b/theforeman.py index 809bf3f..8bbd816 100755 --- a/theforeman.py +++ b/theforeman.py @@ -43,6 +43,7 @@ based on the data obtained from Foreman: - created - updated - status + - hostgroup - ansible_ssh_host When run in --list mode, instances are grouped by the following categories: @@ -146,6 +147,7 @@ They must be specified via ini file.''' 'created': meta.get('created_at'), 'updated': meta.get('updated_at'), 'status': meta.get('status'), + 'hostgroup': self._get_hostgroup_from_id(meta.get('hostgroup_id')), # to ssh from ansible 'ansible_ssh_host': meta.get('ip'), } -- cgit v1.2.3 From 95325f1ffbdeb9da06af0fcd83f85a2dcb6c8e92 Mon Sep 17 00:00:00 2001 From: award Date: Thu, 10 Jul 2014 16:32:51 -0400 Subject: Add python 2.6 compatibility --- theforeman.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/theforeman.py b/theforeman.py index 8bbd816..398c3ea 100755 --- a/theforeman.py +++ b/theforeman.py @@ -60,7 +60,7 @@ Version: 0.0.1 import sys import os import re -import argparse +import optparse import ConfigParser import collections @@ -88,7 +88,10 @@ class ForemanInventory(object): def _empty_cache(self): """Empty cache""" keys = ['operatingsystem', 'hostgroup', 'environment', 'model', 'compute_resource', 'domain', 'subnet', 'architecture', 'host'] - return {k:{} for k in keys} + keys_d = {} + for i in keys: + keys_d[i] = {} + return keys_d def __init__(self): """Main execution path""" @@ -189,10 +192,10 @@ They must be specified via ini file.''' def parse_cli_args(self): """Command line argument processing""" - parser = argparse.ArgumentParser(description='Produce an Ansible Inventory file based on Foreman') - parser.add_argument('--list', action='store_true', default=True, help='List instances (default: True)') - parser.add_argument('--host', action='store', help='Get all the variables about a specific instance') - self.args = parser.parse_args() + parser = optparse.OptionParser(description='Produce an Ansible Inventory file based on Foreman') + parser.add_option('--list', action='store_true', default=True, help='List instances (default: True)') + parser.add_option('--host', action='store', help='Get all the variables about a specific instance') + (self.args, self.options) = parser.parse_args() def _get_os_from_id(self, os_id): """Get operating system name""" -- cgit v1.2.3