|
|
@ -135,8 +135,10 @@ def build_option_parser(action):
|
|
|
|
the user wants to execute.
|
|
|
|
the user wants to execute.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
parser = OptionParser()
|
|
|
|
usage = "usage: %%prog [%s] [--help] [options] ..." % "|".join(VALID_ACTIONS)
|
|
|
|
parser.set_usage("usage: %%prog [%s] [options] ..." % "|".join(VALID_ACTIONS))
|
|
|
|
epilog = "\nSee '%s <command> --help' for more information on a specific command.\n\n" % os.path.basename(sys.argv[0])
|
|
|
|
|
|
|
|
OptionParser.format_epilog = lambda self, formatter: self.epilog
|
|
|
|
|
|
|
|
parser = OptionParser(usage=usage, epilog=epilog)
|
|
|
|
|
|
|
|
|
|
|
|
if not action:
|
|
|
|
if not action:
|
|
|
|
parser.print_help()
|
|
|
|
parser.print_help()
|
|
|
@ -246,6 +248,7 @@ def api_lookup_role_by_name(api_server, role_name):
|
|
|
|
role_name = parts[-1]
|
|
|
|
role_name = parts[-1]
|
|
|
|
print " downloading role '%s', owned by %s" % (role_name, user_name)
|
|
|
|
print " downloading role '%s', owned by %s" % (role_name, user_name)
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
|
|
|
|
parser.print_help()
|
|
|
|
print "Invalid role name (%s). You must specify username.rolename" % role_name
|
|
|
|
print "Invalid role name (%s). You must specify username.rolename" % role_name
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
@ -484,7 +487,7 @@ def install_role(role_name, role_version, role_filename, options):
|
|
|
|
# Action functions
|
|
|
|
# Action functions
|
|
|
|
#-------------------------------------------------------------------------------------
|
|
|
|
#-------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
def execute_init(args, options):
|
|
|
|
def execute_init(args, options, parser):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Executes the init action, which creates the skeleton framework
|
|
|
|
Executes the init action, which creates the skeleton framework
|
|
|
|
of a role that complies with the galaxy metadata format.
|
|
|
|
of a role that complies with the galaxy metadata format.
|
|
|
@ -516,6 +519,7 @@ def execute_init(args, options):
|
|
|
|
"been modified there already."
|
|
|
|
"been modified there already."
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
except Exception, e:
|
|
|
|
except Exception, e:
|
|
|
|
|
|
|
|
parser.print_help()
|
|
|
|
print "No role name specified for init"
|
|
|
|
print "No role name specified for init"
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
@ -577,7 +581,7 @@ def execute_init(args, options):
|
|
|
|
f.close()
|
|
|
|
f.close()
|
|
|
|
print "%s was created successfully" % role_name
|
|
|
|
print "%s was created successfully" % role_name
|
|
|
|
|
|
|
|
|
|
|
|
def execute_info(args, options):
|
|
|
|
def execute_info(args, options, parser):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Executes the info action. This action prints out detailed
|
|
|
|
Executes the info action. This action prints out detailed
|
|
|
|
information about an installed role as well as info available
|
|
|
|
information about an installed role as well as info available
|
|
|
@ -586,7 +590,7 @@ def execute_info(args, options):
|
|
|
|
|
|
|
|
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def execute_install(args, options):
|
|
|
|
def execute_install(args, options, parser):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Executes the installation action. The args list contains the
|
|
|
|
Executes the installation action. The args list contains the
|
|
|
|
roles to be installed, unless -f was specified. The list of roles
|
|
|
|
roles to be installed, unless -f was specified. The list of roles
|
|
|
@ -601,11 +605,13 @@ def execute_install(args, options):
|
|
|
|
if len(args) == 0 and not role_file:
|
|
|
|
if len(args) == 0 and not role_file:
|
|
|
|
# the user needs to specify one of either --role-file
|
|
|
|
# the user needs to specify one of either --role-file
|
|
|
|
# or specify a single user/role name
|
|
|
|
# or specify a single user/role name
|
|
|
|
|
|
|
|
parser.print_help()
|
|
|
|
print "You must specify a user/role name or a roles file"
|
|
|
|
print "You must specify a user/role name or a roles file"
|
|
|
|
sys.exit()
|
|
|
|
sys.exit()
|
|
|
|
elif len(args) == 1 and role_file:
|
|
|
|
elif len(args) == 1 and role_file:
|
|
|
|
# using a role file is mutually exclusive of specifying
|
|
|
|
# using a role file is mutually exclusive of specifying
|
|
|
|
# the role name on the command line
|
|
|
|
# the role name on the command line
|
|
|
|
|
|
|
|
parser.print_help()
|
|
|
|
print "Please specify a user/role name, or a roles file, but not both"
|
|
|
|
print "Please specify a user/role name, or a roles file, but not both"
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
@ -698,13 +704,14 @@ def execute_install(args, options):
|
|
|
|
exit_without_ignore(options)
|
|
|
|
exit_without_ignore(options)
|
|
|
|
sys.exit(0)
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
def execute_remove(args, options):
|
|
|
|
def execute_remove(args, options, parser):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Executes the remove action. The args list contains the list
|
|
|
|
Executes the remove action. The args list contains the list
|
|
|
|
of roles to be removed. This list can contain more than one role.
|
|
|
|
of roles to be removed. This list can contain more than one role.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
if len(args) == 0:
|
|
|
|
if len(args) == 0:
|
|
|
|
|
|
|
|
parser.print_help()
|
|
|
|
print 'You must specify at least one role to remove.'
|
|
|
|
print 'You must specify at least one role to remove.'
|
|
|
|
sys.exit()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
|
@ -718,7 +725,7 @@ def execute_remove(args, options):
|
|
|
|
print '%s is not installed, skipping.' % role
|
|
|
|
print '%s is not installed, skipping.' % role
|
|
|
|
sys.exit(0)
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
def execute_list(args, options):
|
|
|
|
def execute_list(args, options, parser):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Executes the list action. The args list can contain zero
|
|
|
|
Executes the list action. The args list can contain zero
|
|
|
|
or one role. If one is specified, only that role will be
|
|
|
|
or one role. If one is specified, only that role will be
|
|
|
@ -750,10 +757,12 @@ def execute_list(args, options):
|
|
|
|
roles_path = get_opt(options, 'roles_path')
|
|
|
|
roles_path = get_opt(options, 'roles_path')
|
|
|
|
roles_path = os.path.expanduser(roles_path)
|
|
|
|
roles_path = os.path.expanduser(roles_path)
|
|
|
|
if not os.path.exists(roles_path):
|
|
|
|
if not os.path.exists(roles_path):
|
|
|
|
|
|
|
|
parser.print_help()
|
|
|
|
print "The path %s does not exist. Please specify a valid path with --roles-path" % roles_path
|
|
|
|
print "The path %s does not exist. Please specify a valid path with --roles-path" % roles_path
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
elif not os.path.isdir(roles_path):
|
|
|
|
elif not os.path.isdir(roles_path):
|
|
|
|
print "%s exists, but it is not a directory. Please specify a valid path with --roles-path" % roles_path
|
|
|
|
print "%s exists, but it is not a directory. Please specify a valid path with --roles-path" % roles_path
|
|
|
|
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
path_files = os.listdir(roles_path)
|
|
|
|
path_files = os.listdir(roles_path)
|
|
|
|
for path_file in path_files:
|
|
|
|
for path_file in path_files:
|
|
|
@ -780,7 +789,7 @@ def main():
|
|
|
|
# execute the desired action
|
|
|
|
# execute the desired action
|
|
|
|
if 1: #try:
|
|
|
|
if 1: #try:
|
|
|
|
fn = globals()["execute_%s" % action]
|
|
|
|
fn = globals()["execute_%s" % action]
|
|
|
|
fn(args, options)
|
|
|
|
fn(args, options, parser)
|
|
|
|
#except KeyError, e:
|
|
|
|
#except KeyError, e:
|
|
|
|
# print "Error: %s is not a valid action. Valid actions are: %s" % (action, ", ".join(VALID_ACTIONS))
|
|
|
|
# print "Error: %s is not a valid action. Valid actions are: %s" % (action, ", ".join(VALID_ACTIONS))
|
|
|
|
# sys.exit(1)
|
|
|
|
# sys.exit(1)
|
|
|
|