Exemplo n.º 1
0
    def test_cb_servers(self, couchbase_hostname):
        cb_hosts = base.re_split_host.findall(couchbase_hostname)

        retval = {'result': True, 'reason': ''}

        for i, cb_host in enumerate(cb_hosts):

            cbm_ = CBM(cb_host, Config.couchebaseClusterAdmin,
                       Config.cb_password)
            if not Config.thread_queue:
                print("    Checking Couchbase connection for " + cb_host)

            cbm_result = cbm_.test_connection()
            if not cbm_result.ok:
                if not Config.thread_queue:
                    print(
                        "    Can't establish connection to Couchbase server with given parameters."
                    )
                    print("**", cbm_result.reason)
                retval['result'] = False
                retval['reason'] = cb_host + ': ' + cbm_result.reason
                return retval
            try:
                result = cbm_.get_services()
                if result.ok:
                    data = result.json()
                    for node in data.get('nodesExt', []):
                        if node.get('thisNode'):
                            if 'n1qlSSL' in node.get('services', []):
                                Config.cb_query_node = cb_host
                                retval['result'] = True
                                if not Config.thread_queue:
                                    print(
                                        "{}    Successfully connected to Couchbase server{}"
                                        .format(colors.OKGREEN, colors.ENDC))
                                return retval
            except:
                pass

        if not Config.thread_queue:
            print("Can't find any query node")

        retval['result'] = False
        retval['reason'] = "Can't find any query node"

        return retval
Exemplo n.º 2
0
    def load_properties(self, prop_file, no_update=[]):
        self.logIt('Loading Properties %s' % prop_file)

        no_update += [
            'noPrompt', 'jre_version', 'node_version', 'jetty_version',
            'jython_version', 'jreDestinationPath'
        ]

        cb_install = False
        map_db = []

        if prop_file.endswith('.enc'):
            if not Config.properties_password:
                print(
                    "setup.properties password was not supplied. Please run with argument -properties-password"
                )
                sys.exit(False)

            prop_file = self.decrypt_properties(prop_file,
                                                Config.properties_password)

        try:
            p = base.read_properties_file(prop_file)
        except:
            self.logIt("Error loading properties", True)

        if p.get('ldap_type') == 'openldap':
            self.logIt(
                "ldap_type in setup.properties was changed from openldap to opendj"
            )
            p['ldap_type'] = 'opendj'

        if p.get('cb_install') == '0':
            p['cb_install'] = InstallTypes.NONE

        if p.get('wrends_install') == '0':
            p['wrends_install'] = InstallTypes.NONE

        properties_list = list(p.keys())

        for prop in properties_list:
            if prop in no_update:
                continue
            try:
                setattr(Config, prop, p[prop])
                if prop == 'mappingLocations':
                    mappingLocations = json.loads(p[prop])
                    setattr(Config, prop, mappingLocations)
                    for l in mappingLocations:
                        if not mappingLocations[l] in map_db:
                            map_db.append(mappingLocations[l])

                if p[prop] == 'True':
                    setattr(Config, prop, True)
                elif p[prop] == 'False':
                    setattr(Config, prop, False)
            except:
                self.logIt("Error loading property %s" % prop)

        if prop_file.endswith('-DEC~'):
            self.run(['rm', '-f', prop_file])

        if not 'admin_password' in properties_list:
            Config.admin_password = p['ldapPass']

        if p.get('ldap_hostname') != 'localhost':
            if p.get('remoteLdap', '').lower() == 'true':
                Config.wrends_install = InstallTypes.REMOTE
            elif p.get('installLdap', '').lower() == 'true':
                Config.wrends_install = InstallTypes.LOCAL
            elif p.get('wrends_install'):
                Config.wrends_install = p['wrends_install']
            else:
                Config.wrends_install = InstallTypes.NONE

        if map_db and not 'ldap' in map_db:
            Config.wrends_install = InstallTypes.NONE

        if 'couchbase' in map_db:
            if 'remoteCouchbase' in properties_list and p.get(
                    'remoteCouchbase', '').lower() == 'true':
                Config.cb_install = InstallTypes.REMOTE
            elif p.get('cb_install'):
                Config.cb_install = p['cb_install']
            elif 'persistence_type' in properties_list and p.get(
                    'persistence_type') in ('couchbase', 'hybrid'):
                Config.cb_install = InstallTypes.LOCAL
            else:
                Config.cb_install = InstallTypes.NONE

        if Config.cb_install == InstallTypes.LOCAL:
            available_backends = self.getBackendTypes()
            if not 'couchbase' in available_backends:
                print("Couchbase package is not available exiting.")
                sys.exit(1)

        if (not 'cb_password' in properties_list) and Config.cb_install:
            Config.cb_password = p.get('ldapPass')

        if Config.cb_install == InstallTypes.REMOTE:
            cbm_ = CBM(Config.couchbase_hostname,
                       Config.couchebaseClusterAdmin, Config.cb_password)
            if not cbm_.test_connection().ok:
                print(
                    "Can't connect to remote Couchbase Server with credentials found in setup.properties."
                )
                sys.exit(1)

        if Config.wrends_install == InstallTypes.REMOTE:
            conn_check = self.check_remote_ldap(Config.ldap_hostname,
                                                Config.ldap_binddn,
                                                Config.ldapPass)
            if not conn_check['result']:
                print(
                    "Can't connect to remote LDAP Server with credentials found in setup.properties."
                )
                sys.exit(1)

        if not 'admin_password' in p:
            p['admin_password'] = p['ldapPass']

        return p