implemented info action for galaxy
This commit is contained in:
parent
7812c70d3b
commit
40caa11082
1 changed files with 63 additions and 9 deletions
|
@ -135,6 +135,7 @@ An optional section for the role authors to include contact information, or a we
|
|||
#-------------------------------------------------------------------------------------
|
||||
|
||||
VALID_ACTIONS = ("init", "info", "install", "list", "remove")
|
||||
SKIP_INFO_KEYS = ("platforms","readme_html", "related", "summary_fields", "average_aw_composite", "average_aw_score", "url" )
|
||||
|
||||
def get_action(args):
|
||||
"""
|
||||
|
@ -237,6 +238,7 @@ def exit_without_ignore(options, rc=1):
|
|||
print '- you can use --ignore-errors to skip failed roles.'
|
||||
sys.exit(rc)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------------
|
||||
# Galaxy API functions
|
||||
#-------------------------------------------------------------------------------------
|
||||
|
@ -257,7 +259,7 @@ def api_get_config(api_server):
|
|||
except:
|
||||
return None
|
||||
|
||||
def api_lookup_role_by_name(api_server, role_name):
|
||||
def api_lookup_role_by_name(api_server, role_name, notify=True):
|
||||
"""
|
||||
Uses the Galaxy API to do a lookup on the role owner/name.
|
||||
"""
|
||||
|
@ -268,6 +270,7 @@ def api_lookup_role_by_name(api_server, role_name):
|
|||
parts = role_name.split(".")
|
||||
user_name = ".".join(parts[0:-1])
|
||||
role_name = parts[-1]
|
||||
if notify:
|
||||
print "- downloading role '%s', owned by %s" % (role_name, user_name)
|
||||
except:
|
||||
parser.print_help()
|
||||
|
@ -676,7 +679,57 @@ def execute_info(args, options, parser):
|
|||
from the galaxy API.
|
||||
"""
|
||||
|
||||
pass
|
||||
if len(args) == 0:
|
||||
# the user needs to specify a role
|
||||
parser.print_help()
|
||||
print "- you must specify a user/role name"
|
||||
sys.exit(1)
|
||||
|
||||
api_server = get_opt(options, "api_server", "galaxy.ansible.com")
|
||||
api_config = api_get_config(api_server)
|
||||
roles_path = get_opt(options, "roles_path")
|
||||
|
||||
for role in args:
|
||||
|
||||
role_info = {}
|
||||
|
||||
install_info = get_galaxy_install_info(role, options)
|
||||
if install_info:
|
||||
if 'version' in install_info:
|
||||
install_info['intalled_version'] = install_info['version']
|
||||
install_info.pop('version', None)
|
||||
role_info.update(install_info)
|
||||
|
||||
remote_data = api_lookup_role_by_name(api_server, role, False)
|
||||
if remote_data:
|
||||
role_info.update(remote_data)
|
||||
|
||||
metadata = get_role_metadata(role, options)
|
||||
if metadata:
|
||||
role_info.update(metadata)
|
||||
|
||||
role_spec = ansible.utils.role_spec_parse(role)
|
||||
if role_spec:
|
||||
role_info.update(role_spec)
|
||||
|
||||
if role_info:
|
||||
print "- %s:" % (role)
|
||||
import pprint
|
||||
for k in sorted(role_info.keys()):
|
||||
|
||||
if k in SKIP_INFO_KEYS:
|
||||
continue
|
||||
|
||||
if isinstance(role_info[k], dict):
|
||||
print "\t%s: " % (k)
|
||||
for key in sorted(role_info[k].keys()):
|
||||
if key in SKIP_INFO_KEYS:
|
||||
continue
|
||||
print "\t\t%s: %s" % (key, role_info[k][key])
|
||||
else:
|
||||
print "\t%s: %s" % (k, role_info[k])
|
||||
else:
|
||||
print "- the role %s was not found" % role
|
||||
|
||||
def execute_install(args, options, parser):
|
||||
"""
|
||||
|
@ -687,23 +740,24 @@ def execute_install(args, options, parser):
|
|||
"""
|
||||
|
||||
role_file = get_opt(options, "role_file", None)
|
||||
api_server = get_opt(options, "api_server", "galaxy.ansible.com")
|
||||
no_deps = get_opt(options, "no_deps", False)
|
||||
roles_path = get_opt(options, "roles_path")
|
||||
|
||||
if len(args) == 0 and not role_file:
|
||||
if len(args) == 0 and role_file is None:
|
||||
# the user needs to specify one of either --role-file
|
||||
# or specify a single user/role name
|
||||
parser.print_help()
|
||||
print "- you must specify a user/role name or a roles file"
|
||||
sys.exit()
|
||||
elif len(args) == 1 and role_file:
|
||||
elif len(args) == 1 and not role_file is None:
|
||||
# using a role file is mutually exclusive of specifying
|
||||
# the role name on the command line
|
||||
parser.print_help()
|
||||
print "- please specify a user/role name, or a roles file, but not both"
|
||||
sys.exit(1)
|
||||
|
||||
api_server = get_opt(options, "api_server", "galaxy.ansible.com")
|
||||
no_deps = get_opt(options, "no_deps", False)
|
||||
roles_path = get_opt(options, "roles_path")
|
||||
|
||||
roles_done = []
|
||||
if role_file:
|
||||
f = open(role_file, 'r')
|
||||
|
|
Loading…
Reference in a new issue