From 603c79412df1b141230ec55f032ad086ada37097 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Wed, 11 Feb 2015 14:41:52 -0500 Subject: Checking in oscp. --- bin/ossh | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'bin/ossh') diff --git a/bin/ossh b/bin/ossh index 0b48ca46c..d74244501 100755 --- a/bin/ossh +++ b/bin/ossh @@ -99,31 +99,28 @@ class Ossh(object): dict['servername'] = dns_name ''' if cache_only: - self.host_inventory = self.ansible.build_host_dict(['--cache-only']) + self.host_inventory = self.ansible.build_host_dict_by_env(['--cache-only']) else: - self.host_inventory = self.ansible.build_host_dict() + self.host_inventory = self.ansible.build_host_dict_by_env() - def select_host(self, regex=False): + def select_host(self): '''select host attempts to match the host specified on the command line with a list of hosts. - - if regex is specified then we will attempt to match - all *{host_string}* equivalents. ''' - re_host = re.compile(self.host) - results = [] - for hostname, server_info in self.host_inventory[self.env].items(): - if hostname.split(':')[0] == self.host: - # an exact match, return it! - return [(hostname, server_info)] - elif re_host.search(hostname): - results.append((hostname, server_info)) + for env in self.host_inventory.keys(): + for hostname, server_info in self.host_inventory[env].items(): + if hostname.split(':')[0] == self.host: + results.append((hostname, server_info)) + + # attempt to select the correct environment if specified + if self.env: + results = filter(lambda result: result[1]['ec2_tag_environment'] == self.env, results) if results: return results else: - print "Could not find specified host: %s in %s" % (self.host, self.env) + print "Could not find specified host: %s." % self.host # default - no results found. return None @@ -135,7 +132,7 @@ class Ossh(object): ''' if self.env: - results = self.select_host(True) + results = self.select_host() if len(results) == 1: hostname, server_info = results[0] sorted_keys = server_info.keys() -- cgit v1.2.3 From cf65db9573ec99b0f4e2b599b6f158785602c230 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Wed, 11 Feb 2015 16:11:18 -0500 Subject: Updated oscp and ossh. --- bin/ossh | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'bin/ossh') diff --git a/bin/ossh b/bin/ossh index d74244501..6b04cb46e 100755 --- a/bin/ossh +++ b/bin/ossh @@ -24,15 +24,10 @@ class Ossh(object): # parse host and user self.process_host() - if not self.args.list and not self.env: - print "Please specify an environment." - return - if self.args.host == '' and not self.args.list: self.parser.print_help() return - if self.args.debug: print self.args @@ -176,16 +171,18 @@ class Ossh(object): for arg in self.args.ssh_opts.split(","): ssh_args.append("-o%s" % arg) - result = self.select_host() - if not result: + results = self.select_host() + if not results: return # early exit, no results - if len(result) > 1: - self.list_hosts(10) + if len(results) > 1: + print "Multiple results found for %s." % self.host + for result in results: + print "{ec2_tag_Name:<35} {ec2_tag_environment:<5} {ec2_id:<10}".format(**result[1]) return # early exit, too many results # Assume we have one and only one. - hostname, server_info = result[0] + hostname, server_info = results[0] dns = server_info['ec2_public_dns_name'] ssh_args.append(dns) -- cgit v1.2.3