Skip to content

Commit

Permalink
Merge pull request saltstack#79 from techhat/develop
Browse files Browse the repository at this point in the history
Add --full-query option to salt-cloud
  • Loading branch information
thatch45 committed Oct 8, 2012
2 parents 22586b3 + 5c49acc commit 61decf7
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 6 deletions.
20 changes: 16 additions & 4 deletions saltcloud/cli.py
Expand Up @@ -99,8 +99,16 @@ def _parse_cli(self):
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',
Expand Down Expand Up @@ -199,7 +207,7 @@ def run(self):
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')
Expand All @@ -212,8 +220,12 @@ def run(self):
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
Expand Down
4 changes: 2 additions & 2 deletions saltcloud/cloud.py
Expand Up @@ -48,15 +48,15 @@ def get_providers(self):
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
'''
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_))
Expand Down
1 change: 1 addition & 0 deletions saltcloud/clouds/aws.py
Expand Up @@ -48,6 +48,7 @@
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
Expand Down
1 change: 1 addition & 0 deletions saltcloud/clouds/gogrid.py
Expand Up @@ -43,6 +43,7 @@
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
Expand Down
1 change: 1 addition & 0 deletions saltcloud/clouds/joyent.py
Expand Up @@ -42,6 +42,7 @@
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
Expand Down
1 change: 1 addition & 0 deletions saltcloud/clouds/linode.py
Expand Up @@ -35,6 +35,7 @@
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
Expand Down
1 change: 1 addition & 0 deletions saltcloud/clouds/rackspace.py
Expand Up @@ -42,6 +42,7 @@
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
Expand Down
15 changes: 15 additions & 0 deletions saltcloud/libcloudfuncs.py
Expand Up @@ -156,3 +156,18 @@ 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 = {}
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

0 comments on commit 61decf7

Please sign in to comment.