def scan_all_servers(): from java.time import Duration from com.couchbase.client.java import Cluster, ClusterOptions from com.couchbase.client.java.env import ClusterEnvironment from com.couchbase.client.core.env import TimeoutConfig, IoConfig cluster_env = ClusterEnvironment.builder().ioConfig(IoConfig.numKvConnections(25)).timeoutConfig(TimeoutConfig.builder().connectTimeout(Duration.ofSeconds(20)).kvTimeout(Duration.ofSeconds(10))) cluster_options = ClusterOptions.clusterOptions("Administrator", "esabhcuoc").environment(cluster_env.build()) cluster = Cluster.connect("172.23.104.162", cluster_options) STATEMENT = "select meta().id from `QE-server-pool` where os='centos' and '12hrreg' in poolId or 'regression' in poolId or 'magmareg' in poolId;" result = cluster.query(STATEMENT); count = 1 for server in result.rowsAsObject(): print "--+--+--+--+-- {}. CHECKING ON SERVER: {} --+--+--+--+--".format(count, server.get("id")) count += 1 check_coredump_exist(server.get("id"))
def execute(cmd="free -m"): cluster_env = ClusterEnvironment.builder().ioConfig(IoConfig.numKvConnections(25)).timeoutConfig(TimeoutConfig.builder().connectTimeout(Duration.ofSeconds(20)).kvTimeout(Duration.ofSeconds(10))) cluster_options = ClusterOptions.clusterOptions("Administrator", "esabhcuoc").environment(cluster_env.build()) cluster = Cluster.connect("172.23.104.162", cluster_options) STATEMENT = "select meta().id from `QE-server-pool` where os='centos' and '12hrreg' in poolId or 'regression' in poolId or 'magmareg' in poolId;" result = cluster.query(STATEMENT); count = 1 for server in result.rowsAsObject(): server = server.get("id") print("--+--+--+--+-- %s. SERVER: %s --+--+--+--+--" % (count, server)) count += 1 output, error = run(cmd, server) if output: print(output) if error: print(error)
def _createConn(self): try: log.info("Creating cluster connection") System.setProperty("com.couchbase.forceIPv4", "false") logger = Logger.getLogger("com.couchbase.client") logger.setLevel(Level.SEVERE) for h in logger.getParent().getHandlers(): if isinstance(h, ConsoleHandler): h.setLevel(Level.SEVERE) self.cluster = Cluster.connect( ClusterEnvironment.builder( ", ".join(self.hosts).replace(" ", ""), self.username, self.password).timeoutConfig( TimeoutConfig.builder().kvTimeout( Duration.ofSeconds(10))).build()) self.bucketObj = self.cluster.bucket(self.bucket) self.collection = self.bucketObj.defaultCollection() except Exception as e: print("Exception: " + str(e)) # self.cluster.disconnect() raise
def connectCluster(self, username=None, password=None): if username: self.username = username if password: self.password = password try: System.setProperty("com.couchbase.forceIPv4", "false") logger = Logger.getLogger("com.couchbase.client") logger.setLevel(Level.SEVERE) for h in logger.getParent().getHandlers(): if isinstance(h, ConsoleHandler): h.setLevel(Level.SEVERE) self.cluster = Cluster.connect( ClusterEnvironment.builder( ",".join(self.server.ip), self.username, self.password).timeoutConfig( TimeoutConfig.builder().kvTimeout( Duration.ofSeconds(10))).build()) except CouchbaseException: print "cannot login from user: %s/%s" % (self.username, self.password) raise