Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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'
Ejemplo n.º 3
0
    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]
            )