From 71963a0eca24d8ba7e994a2eb984a6ed35766605 Mon Sep 17 00:00:00 2001 From: Joseph Hall Date: Mon, 8 Oct 2012 13:45:13 -0600 Subject: [PATCH 1/2] Add --full-query option to salt-cloud --- saltcloud/cli.py | 20 ++++++++++++++++---- saltcloud/cloud.py | 4 ++-- saltcloud/clouds/aws.py | 1 + saltcloud/clouds/gogrid.py | 1 + saltcloud/clouds/joyent.py | 1 + saltcloud/clouds/linode.py | 1 + saltcloud/clouds/rackspace.py | 1 + saltcloud/libcloudfuncs.py | 16 ++++++++++++++++ 8 files changed, 39 insertions(+), 6 deletions(-) diff --git a/saltcloud/cli.py b/saltcloud/cli.py index e99d66430b..63ba1d85b4 100644 --- a/saltcloud/cli.py +++ b/saltcloud/cli.py @@ -99,8 +99,16 @@ class SaltCloud(object): dest='query', default=False, action='store_true', - help=('Execute a query and return information about the nodes ' - 'running on configured cloud providers')) + help=('Execute a query and return some information about the ' + 'nodes running on configured cloud providers')) + + parser.add_option('-F', + '--full-query', + dest='full_query', + default=False, + action='store_true', + help=('Execute a query and return all information about the ' + 'nodes running on configured cloud providers')) parser.add_option('--list-images', dest='list_images', @@ -199,7 +207,7 @@ class SaltCloud(object): import saltcloud.cloud mapper = saltcloud.cloud.Map(self.opts) - if self.opts['query']: + if self.opts['query'] or self.opts['full_query']: get_outputter = salt.output.get_outputter if self.opts['raw_out']: printout = get_outputter('raw') @@ -212,8 +220,12 @@ class SaltCloud(object): else: printout = get_outputter(None) + query = 'list_nodes' + if self.opts['full_query']: + query = 'list_nodes_full' + color = not bool(self.opts['no_color']) - printout(mapper.map_providers(), color=color) + printout(mapper.map_providers(query=query), color=color) if self.opts['version']: print VERSION diff --git a/saltcloud/cloud.py b/saltcloud/cloud.py index 4374eab5f5..83b3af1a69 100644 --- a/saltcloud/cloud.py +++ b/saltcloud/cloud.py @@ -48,7 +48,7 @@ class Cloud(object): provs.add(fun[:fun.index('.')]) return provs - def map_providers(self): + def map_providers(self, query='list_nodes'): ''' Return a mapping of what named vms are running on what vm providers based on what providers are defined in the configs and vms @@ -56,7 +56,7 @@ class Cloud(object): provs = self.get_providers() pmap = {} for prov in provs: - fun = '{0}.list_nodes'.format(prov) + fun = '{0}.{1}'.format(prov, query) if not fun in self.clouds: print('Public cloud provider {0} is not available'.format( self.provider(vm_)) diff --git a/saltcloud/clouds/aws.py b/saltcloud/clouds/aws.py index ef0ba45515..f4a9b972ee 100644 --- a/saltcloud/clouds/aws.py +++ b/saltcloud/clouds/aws.py @@ -48,6 +48,7 @@ avail_sizes = types.FunctionType(avail_sizes.__code__, globals()) script = types.FunctionType(script.__code__, globals()) destroy = types.FunctionType(destroy.__code__, globals()) list_nodes = types.FunctionType(list_nodes.__code__, globals()) +list_nodes_full = types.FunctionType(list_nodes_full.__code__, globals()) # Only load in this module if the AWS configurations are in place diff --git a/saltcloud/clouds/gogrid.py b/saltcloud/clouds/gogrid.py index 7e18eaedb5..fc2ccb2a29 100644 --- a/saltcloud/clouds/gogrid.py +++ b/saltcloud/clouds/gogrid.py @@ -43,6 +43,7 @@ avail_sizes = types.FunctionType(avail_sizes.__code__, globals()) script = types.FunctionType(script.__code__, globals()) destroy = types.FunctionType(destroy.__code__, globals()) list_nodes = types.FunctionType(list_nodes.__code__, globals()) +list_nodes_full = types.FunctionType(list_nodes_full.__code__, globals()) # Only load in this module is the GOGRID configurations are in place diff --git a/saltcloud/clouds/joyent.py b/saltcloud/clouds/joyent.py index 8bf3ff20e2..9545c79a77 100644 --- a/saltcloud/clouds/joyent.py +++ b/saltcloud/clouds/joyent.py @@ -42,6 +42,7 @@ avail_sizes = types.FunctionType(avail_sizes.__code__, globals()) script = types.FunctionType(script.__code__, globals()) destroy = types.FunctionType(destroy.__code__, globals()) list_nodes = types.FunctionType(list_nodes.__code__, globals()) +list_nodes_full = types.FunctionType(list_nodes_full.__code__, globals()) # Only load in this module is the JOYENT configurations are in place diff --git a/saltcloud/clouds/linode.py b/saltcloud/clouds/linode.py index d692e513d6..322c05b789 100644 --- a/saltcloud/clouds/linode.py +++ b/saltcloud/clouds/linode.py @@ -35,6 +35,7 @@ avail_sizes = types.FunctionType(avail_sizes.__code__, globals()) script = types.FunctionType(script.__code__, globals()) destroy = types.FunctionType(destroy.__code__, globals()) list_nodes = types.FunctionType(list_nodes.__code__, globals()) +list_nodes_full = types.FunctionType(list_nodes_full.__code__, globals()) # Only load in this module if the LINODE configurations are in place diff --git a/saltcloud/clouds/rackspace.py b/saltcloud/clouds/rackspace.py index 24fd620524..2fe1f1fdcf 100644 --- a/saltcloud/clouds/rackspace.py +++ b/saltcloud/clouds/rackspace.py @@ -42,6 +42,7 @@ avail_sizes = types.FunctionType(avail_sizes.__code__, globals()) script = types.FunctionType(script.__code__, globals()) destroy = types.FunctionType(destroy.__code__, globals()) list_nodes = types.FunctionType(list_nodes.__code__, globals()) +list_nodes_full = types.FunctionType(list_nodes_full.__code__, globals()) # Only load in this module is the RACKSPACE configurations are in place diff --git a/saltcloud/libcloudfuncs.py b/saltcloud/libcloudfuncs.py index 8ae7aa5e80..eb6a1a35f7 100644 --- a/saltcloud/libcloudfuncs.py +++ b/saltcloud/libcloudfuncs.py @@ -156,3 +156,19 @@ def list_nodes(): 'size': node.size, 'state': node.state} return ret + +def list_nodes_full(): + ''' + Return a list of the vms that are on the provider + ''' + conn = get_conn() + nodes = conn.list_nodes() + ret = {} + import pprint + for node in nodes: + pairs = {} + for key, value in zip(node.__dict__.keys(), node.__dict__.values()): + pairs[key] = value + ret[node.name] = pairs + return ret + From 5c49accf3c7397be2548518165d08694b4800ee0 Mon Sep 17 00:00:00 2001 From: Joseph Hall Date: Mon, 8 Oct 2012 13:49:16 -0600 Subject: [PATCH 2/2] Oops, left in a pprint debug line --- saltcloud/libcloudfuncs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/saltcloud/libcloudfuncs.py b/saltcloud/libcloudfuncs.py index eb6a1a35f7..16cfa3667a 100644 --- a/saltcloud/libcloudfuncs.py +++ b/saltcloud/libcloudfuncs.py @@ -164,7 +164,6 @@ def list_nodes_full(): conn = get_conn() nodes = conn.list_nodes() ret = {} - import pprint for node in nodes: pairs = {} for key, value in zip(node.__dict__.keys(), node.__dict__.values()):