def info(self, **kwargs): shared_config = { 'rabbitmq': getConfiguration(kwargs['--config'])['rabbitmq'], 'maxbunny': getConfiguration(kwargs['--config'])['maxbunny'] } print print json_pretty_print(shared_config, mask_passwords=True) print
def add_instance(self, **kwargs): instance_name = getOptionFrom(kwargs, 'instance-name') environment = getOptionFrom(kwargs, 'env', default='') mountpoint = getOptionFrom(kwargs, 'mpoint', default='') ldap_branch = getOptionFrom(kwargs, 'ldap-branch', instance_name) allow_shared_mountpoint = getOptionFrom(kwargs, 'f', False) create = False self.extra_config = {'ldap_config': getConfiguration(kwargs['--config'])['ldap']} genweb_server = self.Server if environment and mountpoint: if not genweb_server.is_mountpoint_available(environment, mountpoint, allow_shared=allow_shared_mountpoint): print "This mountpoint is unavailable" return create = True else: available_mountpoint = genweb_server.get_available_mountpoint() if available_mountpoint: environment = available_mountpoint['environment'] mountpoint = available_mountpoint['id'] create = True else: print "There's no available mountpoint in any environment" return ldap_config = getConfiguration(kwargs['--config'])['ldap'] ldap_password = ldap_config['branch_admin_password'] if create: siteid = instance_name title = siteid.capitalize() language = 'ca' env_params = genweb_server.get_environment(environment) logecho = LogEcho( env_params.ssh_user, env_params.server, '{}/zc1.log'.format(env_params.log_folder), target_lines=326, filters=['INFO'] ) run_recipe_with_confirmation( "Adding a new Genweb", { "name": siteid, "server": environment, "mountpoint": mountpoint, "ldap_branch": ldap_branch, }, genweb_server.new_instance, *[instance_name, environment, mountpoint, title, language, ldap_branch, ldap_password, logecho] )
def add_instance(self, **kwargs): """ Adds a existing max instance to the list used by utalk to know to which max route incoming messages and tweets """ step_log('Checking parameters consistency') instance_name = getOptionFrom(kwargs, 'domain') hashtag = getOptionFrom(kwargs, 'hashtag', '') language = getOptionFrom(kwargs, 'language', 'ca') username = getOptionFrom(kwargs, 'username', 'restricted') password = getOptionFrom(kwargs, 'password') padded_log('Checking max server ...') max_config = getConfiguration(kwargs['--config'])['max'] maxserver = MaxServer(max_config) max_instance = maxserver.get_instance(instance_name) if not max_instance: padded_error("There's no defined max server named {}".format(instance_name)) return None padded_log('Checking oauth server ...') oauth_server_url = max_instance['oauth'] oauth_instance_name = oauth_server_url.split('/')[-1] oauth_config = getConfiguration(kwargs['--config'])['oauth'] oauthserver = OauthServer(oauth_config) oauth_instance = oauthserver.get_instance(oauth_instance_name) if not oauth_instance: padded_error("Max server {} is bound to an oauth {} that doesn't exist".format(instance_name, oauth_instance_name)) return None run_recipe_with_confirmation( 'Adding a new utalk domain', { 'server': max_instance['server']['dns'], 'name': instance_name, 'hashtag': hashtag, 'language': language, }, self.Server.add_instance, name=instance_name, oauthserver=oauth_instance, maxserver=max_instance, hashtag=hashtag, restricted_user=username, restricted_user_password=password, language=language)
def main(): try: getConfiguration() except: generate = raw_input('> Do you want to generate a sample .gum.conf on this folder to fill up? (Y,n): ') if generate.strip().upper() in ['Y', '']: # Write a copy of sample.gum.conf with comments stripped sample = open(pkg_resources.resource_filename(__name__, 'sample.gum.conf')).read() open('.gum.conf', 'w').write(re.sub(r'#.*?(\n|$)', r'\1', sample)) print 'Done.' print sys.exit() # Workaround to allow empty <branchname> on ldap commands sysargs = sys.argv[1:] if sysargs[1:3] in [['add', 'user'], ['add', 'users'], ['list', 'users'], ['delete', 'user'], ['check', 'user']]: sysargs.insert(1, '.') doc_with_config_options = re.sub(r'gum (\w+) (?!help)(.*)', r'gum \1 \2 [-c]', __doc__) doc_with_config_options = doc_with_config_options.replace('\n\n gum', '\n gum') arguments = docopt.docopt(doc_with_config_options, argv=sysargs, version='GUM Cli ' + pkg_resources.require("gummanager.cli")[0].version) help_mode = False if sys.argv[2] == 'help': help_mode = True arguments['help'] = False for cmd in getOptionFrom(arguments, 'command'): if cmd in arguments: arguments[cmd] = True targets = [arg_name for arg_name, arg_value in arguments.items() if arg_name in TARGETS and arg_value is True] if targets == []: print 'No such target "{}"'.format(sys.argv[1]) sys.exit(1) target_name = targets[0] config = getConfiguration(arguments['--config']) target = TARGETS[target_name](config) action_method_name = target.forge_command_from_arguments(arguments) target_method = getattr(target, action_method_name, None) if target_method is None: sys.exit('Not Implemented: {}'.format(action_method_name)) if help_mode: command_line = ' .*?'.join([a for a in ['gum'] + sys.argv[1:] if a != 'help']) command_definition = re.search(r'\n\s*({}.*?)\n'.format(command_line), __doc__).groups()[0] target.help(action_method_name, definition=command_definition) else: target_method(**arguments)
def test(self, **kwargs): instance_name = getOptionFrom(kwargs, 'domain') max_config = getConfiguration(kwargs['--config'])['max'] maxserver = MaxServer(max_config) oauth_config = getConfiguration(kwargs['--config'])['oauth'] oauthserver = OauthServer(oauth_config) self.extra_config = { 'max': maxserver, 'oauth': oauthserver } self.Server.test(instance_name)
def cfgfile_role(name, rawtext, text, lineno, inliner, options={}, content=[]): configuration = getConfiguration() common_config = { 'server_dns': configuration.max.server_dns, 'bigmax_port': ports.BIGMAX_BASE_PORT, 'instance_folder': configuration.max.instances_root + '/{instance_name}', 'oauth_dns': configuration.max.default_oauth_server_dns, 'instance_name': '{instance_name}', 'oauth_name': '{oauth_name}', 'max_port': '{max_port}', 'circus_nginx_port': '{circus_nginx_port}', 'circus_httpd_endpoint': '{circus_httpd_endpoint}', 'port_index': '{port_index}', 'name': '{name}', 'hashtag': '', 'server': configuration.max.server_dns + '/{name}', 'oauth_server': configuration.max.default_oauth_server_dns + '/{name}', 'restricted_user': '******', 'restricted_user_token': 'aTGrQepAAeVQr1udDGmc8f2Uxdch0RXS', 'language': 'ca' } filename, format = text.split(',') configfile = config_files.__dict__.get(filename, 'Config file {} not found'.format(filename)) configfile = configfile.replace('\n ', '\n') configfile = configfile.format(**common_config) node = nodes.literal_block(configfile, configfile) node['language'] = format return [node], []
def test(self, **kwargs): """ Tests that a max instance is working as expected. An username and a password of an existing user has to be provided. """ instance_name = getOptionFrom(kwargs, 'instance-name') maxserver = self.Server instance_info = maxserver.get_instance(instance_name) oauth_config = getConfiguration(kwargs['--config'])['oauth'] oauthserver = OauthServer(**oauth_config) oauth_info = oauthserver.instance_by_dns(instance_info['oauth']) ldap_branch = oauth_info['ldap']['branch'] ldap_branch = oauth_info['ldap']['branch'] maxserver.test(instance_name, ldap_branch) print 'Test end'
def add_instance(self, **kwargs): step_log('Checking parameters consistency') instance_name = getOptionFrom(kwargs, 'instance-name') environment = getOptionFrom(kwargs, 'env', default='') mountpoint = getOptionFrom(kwargs, 'mpoint', default='') max_instance_name = getOptionFrom(kwargs, 'max', default=instance_name) padded_log('Checking max server ...') max_config = getConfiguration(kwargs['--config'])['max'] maxserver = MaxServer(max_config) max_instance = maxserver.get_instance(max_instance_name) self.extra_config = {'ldap_config': getConfiguration(kwargs['--config'])['ldap']} ulearn_server = self.Server if not max_instance: padded_error("There's no defined max server named {}".format(max_instance_name)) return None padded_log('Checking oauth server ...') oauth_server_url = max_instance['oauth'] oauth_instance_name = oauth_server_url.split('/')[-1] oauth_config = getConfiguration(kwargs['--config'])['oauth'] oauthserver = OauthServer(oauth_config) oauth_instance = oauthserver.get_instance(oauth_instance_name) if not oauth_instance: padded_error("Max server {} is bound to an oauth {} that doesn't exist".format(max_instance_name, oauth_instance_name)) return None ldap_branch = re.search(r'ou=(\w+),', oauth_instance['ldap']['basedn']).groups()[0] allow_shared_mountpoint = getOptionFrom(kwargs, 'f', False) create = False padded_log('Checking mountpoint ...') if environment and mountpoint: if not ulearn_server.is_mountpoint_available(environment, mountpoint, allow_shared=allow_shared_mountpoint): padded_error("This mountpoint is unavailable") return create = True else: available_mountpoint = ulearn_server.get_available_mountpoint() if available_mountpoint: environment = available_mountpoint['environment'] mountpoint = available_mountpoint['id'] create = True else: padded_error("There's no available mountpoint in any environment") return ldap_config = getConfiguration(kwargs['--config'])['ldap'] ldap_password = getOptionFrom(kwargs, 'ldappassword') if create: siteid = instance_name title = siteid.capitalize() language = 'ca' env_params = ulearn_server.get_environment(environment) logecho = LogEcho( env_params.ssh_user, env_params.server, '{}/{}.log'.format(env_params.log_folder, env_params.instance_name), target_lines=359, filters=['INFO GenericSetup'] ) run_recipe_with_confirmation( "Adding a new Ulearn", { "name": siteid, "server": environment, "mountpoint": mountpoint, "oauth_instance": max_instance['oauth'], "ldap_branch": ldap_branch, "max": max_instance['server']['dns'] }, ulearn_server.new_instance, *[instance_name, environment, mountpoint, title, language, max_instance_name, max_instance['server']['direct'], oauth_instance_name, ldap_branch, ldap_password, logecho] )