def retrieveCert(self): if self.certificate_file is None: usage("please specify certificate file name for the operation") rest = restclient.RestClient(self.server, self.port, {"debug": self.debug}) output_result = "" if self.cmd == "retrieve": opts = { "error_msg": "unable to %s certificate" % self.cmd, "success_msg": "Successfully %s certificate" % self.cmd, } output_result = rest.restCmd("GET", "/pools/default/certificate", self.user, self.password, opts) elif self.cmd == "regenerate": opts = {"error_msg": "unable to %s certificate" % self.cmd, "success_msg": None} output_result = rest.restCmd("POST", "/controller/regenerateCertificate", self.user, self.password, opts) else: print "ERROR: unknown request:", self.cmd return try: fp = open(self.certificate_file, "w") fp.write(output_result) fp.close() print "SUCCESS: %s certificate to '%s'" % (self.cmd, self.certificate_file) except IOError, error: print "ERROR:", error
def groupAddServers(self, name): uri = self.getGroupUri(self.group_name) if uri is None: usage("invalid group name:%s" % self.group_name) uri = "%s/addNode" % uri groups = self.getServerGroups() server_list = self.server_list.split(";") rest = restclient.RestClient(self.server, self.port, {'debug':self.debug}) for server in server_list: rest.setParam('hostname', server) opts = { 'error_msg': "unable to add server '%s' to group '%s'" % (server, self.group_name), 'success_msg': "add server '%s' to group '%s'" % (server, self.group_name) } output_result = rest.restCmd('POST', uri, self.user, self.password, opts) print output_result
def arg_check(): """ Checks to see if enough arguments are passed to the program. """ if len(sys.argv) < 2: print("Error: Not enough arguments.") from usage import usage usage() sys.exit(1)
def run(): """ Main function for testing. """ if len(sys.argv) < 2: print("Error: Not enough arguments.") from usage import usage usage() sys.exit(1) authenticate(sys.argv[1])
def groupDelete(self): uri = self.getGroupUri(self.group_name) if uri is None: usage("invalid group name:%s" % self.group_name) rest = restclient.RestClient(self.server, self.port, {"debug": self.debug}) rest.setParam("name", self.group_name) opts = { "error_msg": "unable to delete group %s" % self.group_name, "success_msg": "group deleted %s" % self.group_name, } output_result = rest.restCmd("DELETE", uri, self.user, self.password, opts) print output_result
def failover(self, servers): known_otps, eject_otps, failover_otps, readd_otps = \ self.getNodeOtps(to_failover=servers['failover']) if len(failover_otps) <= 0: usage("specified servers are not part of the cluster: %s" % servers['failover'].keys()) for failover_otp in failover_otps: rest = restclient.RestClient(self.server, self.port, {'debug':self.debug}) opts = { 'error_msg': "unable to failover %s" % failover_otp, 'success_msg': "failover %s" % failover_otp } rest.setParam('otpNode', failover_otp) if self.hard_failover: output_result = rest.restCmd('POST', rest_cmds['failover'], self.user, self.password, opts) print output_result else: output_result = rest.restCmd('POST', '/controller/startGracefulFailover', self.user, self.password, opts) if self.debug: print "INFO: rebalance started: %s" % output_result sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) print "INFO: graceful failover", status, error = self.rebalanceStatus(prefix='\n') while status == 'running': print ".", time.sleep(0.5) try: status, error = self.rebalanceStatus(prefix='\n') except socket.error: time.sleep(2) status, error = self.rebalanceStatus(prefix='\n') if error: print '\n' + error else: print '\n' + output_result
def collectLogsStart(self, servers): """Starts a cluster-wide log collection task""" if (servers["log"] is None) and (self.all_nodes is not True): usage("please specify a list of nodes to collect logs from, " + " or 'all-nodes'") rest = restclient.RestClient(self.server, self.port, {"debug": self.debug}) if self.all_nodes: rest.setParam("nodes", "*") else: known_otps, eject_otps, failover_otps, readd_otps, hostnames = self.getNodeOtps(to_readd=servers["log"]) if not len(readd_otps): msg = ",".join(hostnames) usage("invalid node name specified for collecting logs, available nodes are:\n" + msg) nodelist = ",".join(readd_otps) rest.setParam("nodes", nodelist) print "NODES:", nodelist if self.upload: if self.upload_host is None: usage("please specify an upload-host when using --upload") rest.setParam("uploadHost", self.upload_host) if not self.customer: usage("please specify a value for --customer when using" + " --upload") rest.setParam("customer", self.customer) rest.setParam("ticket", self.ticket) opts = {"error_msg": "unable to start log collection:", "success_msg": "Log collection started"} output_result = rest.restCmd(self.method, self.rest_cmd, self.user, self.password, opts) print output_result
def groupDelete(self): uri = self.getGroupUri(self.group_name) if uri is None: usage("invalid group name:%s" % self.group_name) rest = restclient.RestClient(self.server, self.port, {'debug': self.debug}) rest.setParam('name', self.group_name) opts = { 'error_msg': "unable to delete group %s" % self.group_name, 'success_msg': "group deleted %s" % self.group_name } output_result = rest.restCmd('DELETE', uri, self.user, self.password, opts) print output_result
def groupManage(self): if self.cmd == 'move-servers': self.groupMoveServer() elif self.cmd == 'list': self.groupList() else: if self.group_name is None: usage("please specify --group-name for the operation") elif self.cmd == 'delete': self.groupDelete() elif self.cmd == 'create': self.groupCreate() elif self.cmd == 'add-servers': self.groupAddServers(self.group_name) elif self.cmd == 'rename': self.groupRename() else: print "Unknown group command:%s" % self.cmd
def groupManage(self): if self.cmd == "move-servers": self.groupMoveServer() elif self.cmd == "list": self.groupList() else: if self.group_name is None: usage("please specify --group-name for the operation") elif self.cmd == "delete": self.groupDelete() elif self.cmd == "create": self.groupCreate() elif self.cmd == "add-servers": self.groupAddServers() elif self.cmd == "rename": self.groupRename() else: print "Unknown group command:%s" % self.cmd
def groupDelete(self): uri = self.getGroupUri(self.group_name) if uri is None: usage("invalid group name:%s" % self.group_name) rest = restclient.RestClient(self.server, self.port, {'debug':self.debug}) rest.setParam('name', self.group_name) opts = { 'error_msg': "unable to delete group %s" % self.group_name, 'success_msg': "group deleted %s" % self.group_name } output_result = rest.restCmd('DELETE', uri, self.user, self.password, opts) print output_result
def failover(self, servers): known_otps, eject_otps, failover_otps, readd_otps = \ self.getNodeOtps(to_failover=servers['failover']) if len(failover_otps) <= 0: usage("specified servers are not part of the cluster: %s" % servers['failover'].keys()) for failover_otp in failover_otps: rest = restclient.RestClient(self.server, self.port, {'debug': self.debug}) rest.setParam('otpNode', failover_otp) opts = { 'error_msg': "unable to failover %s" % failover_otp, 'success_msg': "failover %s" % failover_otp } output_result = rest.restCmd('POST', rest_cmds['failover'], self.user, self.password, opts) print output_result
def groupAddServers(self): uri = self.getGroupUri(self.group_name) if uri is None: usage("invalid group name:%s" % self.group_name) uri = "%s/addNode" % uri groups = self.getServerGroups() for server in self.server_list: rest = restclient.RestClient(self.server, self.port, {"debug": self.debug}) rest.setParam("hostname", server) if self.sa_username: rest.setParam("user", self.sa_username) if self.sa_password: rest.setParam("password", self.sa_password) opts = { "error_msg": "unable to add server '%s' to group '%s'" % (server, self.group_name), "success_msg": "add server '%s' to group '%s'" % (server, self.group_name), } output_result = rest.restCmd("POST", uri, self.user, self.password, opts) print output_result
def main(): if not len(sys.argv[1: ]): usage.usage() try: opts, args = getopt.getopt(sys.argv[1: ], "hle:t:p:cu", ['help', 'listen', 'execute=', 'target=', 'port=', 'command', 'upload']) except getopt.GetoptError as err: print str(err) usage.usage() for o, a in opts: if o in ('-h', '--help'): usage.usage() elif o in ('-l', '--listen'): config.listen = True elif o in ('-e', '--execute'): config.execute = True elif o in ('-c', '--commandshell'): config.command = True elif o in ('-u', '--upload'): config.upload_destination = a elif o in ('-t', '--target'): config.target = a elif o in ('-p', '--port'): config.port = int(a) else: assert False, "Unhandled Option" if not config.listen and len(config.target) and config.port > 0: buffer = sys.stdin.read() sender.client_sender(buffer) if config.listen: loop.server_loop()
def failover(self, servers): known_otps, eject_otps, failover_otps, readd_otps, _ = self.getNodeOtps(to_failover=servers["failover"]) if len(failover_otps) <= 0: usage("specified servers are not part of the cluster: %s" % servers["failover"].keys()) for failover_otp, node_status in failover_otps: rest = restclient.RestClient(self.server, self.port, {"debug": self.debug}) opts = {"error_msg": "unable to failover %s" % failover_otp, "success_msg": "failover %s" % failover_otp} rest.setParam("otpNode", failover_otp) if self.hard_failover or node_status != "healthy": output_result = rest.restCmd("POST", rest_cmds["failover"], self.user, self.password, opts) print output_result else: output_result = rest.restCmd( "POST", "/controller/startGracefulFailover", self.user, self.password, opts ) if self.debug: print "INFO: rebalance started: %s" % output_result sys.stdout = os.fdopen(sys.stdout.fileno(), "w", 0) print "INFO: graceful failover", status, error = self.rebalanceStatus(prefix="\n") while status == "running": print ".", time.sleep(0.5) try: status, error = self.rebalanceStatus(prefix="\n") except socket.error: time.sleep(2) status, error = self.rebalanceStatus(prefix="\n") if error: print "\n" + error else: print "\n" + output_result
def main(): try: file_name = sys.argv.pop(1) data = create_data(file_name) settings = create_settings(sys.argv, data['farm']) ant_squad = make_squad(data, settings, settings['steps_between_nodes']) set_paths_colors(data['farm'], ant_squad) fig = plt.figure("Lem-in", figsize=(settings['window_size'])) ani = FuncAnimation(fig, action, frames=data['farm'].moves_nb * settings["steps_between_nodes"], fargs=(data, fig, ant_squad, settings), interval=settings['interval'], repeat=settings['repeat'], blit=0) plt.title('Lem-in') plt.show() except: usage() sys.exit(1)
def failover(self, servers): known_otps, eject_otps, failover_otps, readd_otps = \ self.getNodeOtps(to_failover=servers['failover']) if len(failover_otps) <= 0: usage("specified servers are not part of the cluster: %s" % servers['failover'].keys()) for failover_otp in failover_otps: rest = restclient.RestClient(self.server, self.port, {'debug':self.debug}) rest.setParam('otpNode', failover_otp) opts = {} opts['error_msg'] = "unable to failover %s" % failover_otp opts['success_msg'] = "failover %s" % failover_otp output_result = rest.restCmd('POST', rest_cmds['failover'], self.user, self.password, opts) print output_result
def groupAddServers(self, name): uri = self.getGroupUri(self.group_name) if uri is None: usage("invalid group name:%s" % self.group_name) uri = "%s/addNode" % uri groups = self.getServerGroups() server_list = self.server_list.split(";") rest = restclient.RestClient(self.server, self.port, {'debug': self.debug}) for server in server_list: rest.setParam('hostname', server) opts = { 'error_msg': "unable to add server '%s' to group '%s'" % (server, self.group_name), 'success_msg': "add server '%s' to group '%s'" % (server, self.group_name) } output_result = rest.restCmd('POST', uri, self.user, self.password, opts) print output_result
def runCmd(self, cmd, server, port, user, password, opts): self.rest_cmd = rest_cmds[cmd] self.method = methods[cmd] self.server = server self.port = int(port) self.user = user self.password = password servers = self.processOpts(cmd, opts) if self.debug: print "INFO: servers %s" % servers if cmd == 'server-add' and not servers['add']: usage("please list one or more --server-add=HOST[:PORT];" " or use -h for more help.") if cmd == 'server-readd' and not servers['add']: usage("please list one or more --server-add=HOST[:PORT];" " or use -h for more help.") if cmd in ('server-add', 'rebalance'): self.addServers(servers['add']) if cmd == 'rebalance': self.rebalance(servers) if cmd == 'server-readd': self.reAddServers(servers) if cmd == 'rebalance-status': output_result = self.rebalanceStatus() print output_result if cmd == 'rebalance-stop': output_result = self.rebalanceStop() print output_result if cmd == 'failover': if len(servers['failover']) <= 0: usage("please list one or more --server-failover=HOST[:PORT];" " or use -h for more help.") self.failover(servers) if cmd == 'cluster-init': self.clusterInit() if cmd == 'node-init': self.nodeInit()
def main(): if not len(sys.argv[1:]): usage.usage() try: opts, args = getopt.getopt(sys.argv[1:], "hle:t:p:cu", [ 'help', 'listen', 'execute=', 'target=', 'port=', 'command', 'upload' ]) except getopt.GetoptError as err: print str(err) usage.usage() for o, a in opts: if o in ('-h', '--help'): usage.usage() elif o in ('-l', '--listen'): config.listen = True elif o in ('-e', '--execute'): config.execute = True elif o in ('-c', '--commandshell'): config.command = True elif o in ('-u', '--upload'): config.upload_destination = a elif o in ('-t', '--target'): config.target = a elif o in ('-p', '--port'): config.port = int(a) else: assert False, "Unhandled Option" if not config.listen and len(config.target) and config.port > 0: buffer = sys.stdin.read() sender.client_sender(buffer) if config.listen: loop.server_loop()
def runCmd(self, cmd, server, port, user, password, opts): self.user = user self.password = password bucketname = '' buckettype = '' authtype = 'sasl' bucketport = '11211' bucketpassword = '' bucketramsize = '' bucketreplication = '1' output = 'default' wait_for_bucket_ready = False for (o, a) in opts: if o == '-b' or o == '--bucket': bucketname = a if o == '--bucket-type': buckettype = a if o == '--bucket-port': bucketport = a if o == '--bucket-password': bucketpassword = a if o == '--bucket-ramsize': bucketramsize = a if o == '--bucket-replica': bucketreplication = a if o == '-d' or o == '--debug': self.debug = True if o in ('-o', '--output'): output = a if o == '--wait': wait_for_bucket_ready = True self.rest_cmd = rest_cmds[cmd] rest = restclient.RestClient(server, port, {'debug':self.debug}) # get the parameters straight if cmd in ('bucket-create', 'bucket-edit'): if bucketname: rest.setParam('name', bucketname) if bucketname == "default": if bucketport and bucketport != "11211": usage("default bucket must be on port 11211.") if bucketpassword: usage("default bucket should only have empty password.") authtype = 'sasl' else: if bucketport == "11211": authtype = 'sasl' else: authtype = 'none' if bucketpassword: usage("a sasl bucket is supported only on port 11211.") if buckettype: rest.setParam('bucketType', buckettype) if authtype: rest.setParam('authType', authtype) if bucketport: rest.setParam('proxyPort', bucketport) if bucketpassword: rest.setParam('saslPassword', bucketpassword) if bucketramsize: rest.setParam('ramQuotaMB', bucketramsize) if bucketreplication: rest.setParam('replicaNumber', bucketreplication) if cmd in ('bucket-delete', 'bucket-flush', 'bucket-edit'): self.rest_cmd = self.rest_cmd + bucketname if cmd == 'bucket-flush': self.rest_cmd = self.rest_cmd + '/controller/doFlush' opts = {} opts['error_msg'] = "unable to %s; please check your username (-u) and password (-p);" % cmd opts['success_msg'] = "%s" % cmd data = rest.restCmd(methods[cmd], self.rest_cmd, self.user, self.password, opts) if cmd in ("bucket-get", "bucket-stats", "bucket-node-stats"): return rest.getJson(data) elif cmd == "bucket-list": if output == 'json': print data else: json = rest.getJson(data) for bucket in json: print '%s' % bucket['name'] print ' bucketType: %s' % bucket['bucketType'] print ' authType: %s' % bucket['authType'] if bucket['authType'] == "sasl": print ' saslPassword: %s' % bucket['saslPassword'] else: print ' proxyPort: %s' % bucket['proxyPort'] print ' numReplicas: %s' % bucket['replicaNumber'] print ' ramQuota: %s' % bucket['quota']['ram'] print ' ramUsed: %s' % bucket['basicStats']['memUsed'] elif cmd == "bucket-create" and wait_for_bucket_ready: rest_query = restclient.RestClient(server, port, {'debug':self.debug}) timeout_in_seconds = 120 start = time.time() # Make sure the bucket exists before querying its status bucket_exist = False while (time.time() - start) <= timeout_in_seconds and not bucket_exist: buckets = rest_query.restCmd('GET', rest_cmds['bucket-list'], self.user, self.password, opts) for bucket in rest_query.getJson(buckets): if bucket["name"] == bucketname: bucket_exist = True break if not bucket_exist: sys.stderr.write(".") time.sleep(2) if not bucket_exist: print "\nFail to create bucket '%s' within %s seconds" %\ (bucketname, timeout_in_seconds) return False #Query status for all bucket nodes while (time.time() - start) <= timeout_in_seconds: bucket_info = rest_query.restCmd('GET', rest_cmds['bucket-info'] % bucketname, self.user, self.password, opts) json = rest_query.getJson(bucket_info) all_node_ready = True for node in json["nodes"]: if node["status"] != "healthy": all_node_ready = False break if all_node_ready: if output == 'json': print rest.jsonMessage(data) else: print data return True else: sys.stderr.write(".") time.sleep(2) print "\nBucket '%s' is created but not ready to use within %s seconds" %\ (bucketname, timeout_in_seconds) return False else: if output == 'json': print rest.jsonMessage(data) else: print data
def runCmd(self, cmd, server, port, user, password, opts): self.user = user self.password = password bucketname = "" buckettype = "" authtype = "sasl" bucketport = "11211" bucketpassword = "" bucketramsize = "" bucketreplication = "1" output = "default" for (o, a) in opts: if o == "-b" or o == "--bucket": bucketname = a if o == "--bucket-type": buckettype = a if o == "--bucket-port": bucketport = a if o == "--bucket-password": bucketpassword = a if o == "--bucket-ramsize": bucketramsize = a if o == "--bucket-replica": bucketreplication = a if o == "-d" or o == "--debug": self.debug = True if o in ("-o", "--output"): output = a self.rest_cmd = rest_cmds[cmd] rest = restclient.RestClient(server, port, {"debug": self.debug}) # get the parameters straight if cmd in ("bucket-create", "bucket-edit"): if bucketname: rest.setParam("name", bucketname) if bucketname == "default": if bucketport and bucketport != "11211": usage("default bucket must be on port 11211.") if bucketpassword: usage("default bucket should only have empty password.") authtype = "sasl" else: if bucketport == "11211": authtype = "sasl" else: authtype = "none" if bucketpassword: usage("a sasl bucket is supported only on port 11211.") if buckettype: rest.setParam("bucketType", buckettype) if authtype: rest.setParam("authType", authtype) if bucketport: rest.setParam("proxyPort", bucketport) if bucketpassword: rest.setParam("saslPassword", bucketpassword) if bucketramsize: rest.setParam("ramQuotaMB", bucketramsize) if bucketreplication: rest.setParam("replicaNumber", bucketreplication) if cmd in ("bucket-delete", "bucket-flush", "bucket-edit"): self.rest_cmd = self.rest_cmd + bucketname if cmd == "bucket-flush": self.rest_cmd = self.rest_cmd + "/controller/doFlush" opts = {} opts["error_msg"] = "unable to %s" % cmd opts["success_msg"] = "%s" % cmd data = rest.restCmd(methods[cmd], self.rest_cmd, self.user, self.password, opts) if cmd == "bucket-list": if output == "json": print data else: json = rest.getJson(data) for bucket in json: print "%s" % bucket["name"] print " bucketType: %s" % bucket["bucketType"] print " authType: %s" % bucket["authType"] if bucket["authType"] == "sasl": print " saslPassword: %s" % bucket["saslPassword"] else: print " proxyPort: %s" % bucket["proxyPort"] print " numReplicas: %s" % bucket["replicaNumber"] print " ramQuota: %s" % bucket["quota"]["ram"] print " ramUsed: %s" % bucket["basicStats"]["memUsed"] else: if output == "json": print rest.jsonMessage(data) else: print data
def runCmd(self, cmd, server, port, user, password, opts): self.user = user self.password = password bucketname = '' buckettype = '' authtype = '' bucketport = '' bucketpassword = '' bucketramsize = '' bucketreplication = '' output = 'default' for (o, a) in opts: if o == '-b' or o == '--bucket': bucketname = a if o == '--bucket-type': buckettype = a if o == '--bucket-port': bucketport = a authtype = 'none' if o == '--bucket-password': bucketpassword = a authtype = 'sasl' if o == '--bucket-ramsize': bucketramsize = a if o == '--bucket-replica': bucketreplication = a if o == '-d' or o == '--debug': self.debug = True if o in ('-o', '--output'): output = a self.rest_cmd = rest_cmds[cmd] rest = restclient.RestClient(server, port, {'debug':self.debug}) # get the parameters straight if cmd in ('bucket-create', 'bucket-edit'): if bucketname: rest.setParam('name', bucketname) if bucketname == "default": if bucketport and bucketport != "11211": usage("default bucket must be on port 11211.") if bucketpassword: usage("default bucket should only have empty password.") else: if bucketpassword and bucketport and bucketport != "11211": usage("a sasl bucket is supported only on port 11211.") if buckettype: rest.setParam('bucketType', buckettype) if authtype: rest.setParam('authType', authtype) if bucketport: rest.setParam('proxyPort', bucketport) if bucketpassword: rest.setParam('saslPassword', bucketpassword) if bucketramsize: rest.setParam('ramQuotaMB', bucketramsize) if bucketreplication: rest.setParam('replicaNumber', bucketreplication) if cmd in ('bucket-delete', 'bucket-flush', 'bucket-edit'): self.rest_cmd = self.rest_cmd + bucketname if cmd == 'bucket-flush': self.rest_cmd = self.rest_cmd + '/controller/doFlush' opts = {} opts['error_msg'] = "unable to %s" % cmd opts['success_msg'] = "%s" % cmd data = rest.restCmd(methods[cmd], self.rest_cmd, self.user, self.password, opts) if cmd == "bucket-list": if output == 'json': print data else: json = rest.getJson(data) for bucket in json: print '%s' % bucket['name'] print ' bucketType: %s' % bucket['bucketType'] print ' authType: %s' % bucket['authType'] if bucket['authType'] == "sasl": print ' saslPassword: %s' % bucket['saslPassword'] else: print ' proxyPort: %s' % bucket['proxyPort'] print ' numReplicas: %s' % bucket['replicaNumber'] print ' ramQuota: %s' % bucket['quota']['ram'] print ' ramUsed: %s' % bucket['basicStats']['memUsed'] else: if output == 'json': print rest.jsonMessage(data) else: print data
start_time = time_start, end_time = time_end, period = 60, unit = 'None') if len(app_service_result) == 0: service_cost = 0 else: service_cost = app_service_result[0]['Maximum'] print aws_service, int(service_cost) service_cost_list.append( service_cost ) # google spreadsheetへ書き込み sheet_name = app_name + "_cost" spreadsheets.update_sheet( sheet_name, app_name, service_cost_list, time_end ) ''' [main function] ''' if __name__ == '__main__': # usage + option解析 result = usage() # cost_count app_name = "test" aws_access_key = config.get(app_name, 'AWS_ACCESS_KEY') aws_secret_access_key = config.get(app_name, 'AWS_SECRET_ACCESS_KEY') aws_cost_count(app_name, aws_access_key, aws_secret_access_key, result)
def read(bot): global Bot Bot = bot if bot.remote['nick'] and bot.remote['nick'] != bot.nick: if bot.remote['message'].startswith("!"): args = bot.remote['message'][1:].rstrip().split(" ") command = args[0].lower() alibrary = { 'reload': lambda: bot._reload(args), 'voice': lambda: voice(args), 'nick': lambda: cnick(args), 'release': lambda: release(args), 'identify': lambda: ident(), 'join': lambda: join(args), 'part': lambda: part(args), 'kick': lambda: kick(args), 'mode': lambda: mode(args), 'perms': lambda: perms(args), 'eval': lambda: reply(bot.remote['sendee'], eval.parse(bot, args)), 'raw': lambda: raw(args) } clibrary = { 'topic': lambda: topic(bot, args), 'help': lambda: "Available commands: %s" % ', '.join(sorted(clibrary.keys())), 'time': lambda: time(bot, args), 'say': lambda: say(bot, args), 'calc': lambda: wolframalpha.wa(bot, args), 'go': lambda: googleapi.search(bot, args), 'lookup': lambda: dnstools.lookup(bot, args), 'wiki': lambda: dnstools.wiki(bot, args), 'tell': lambda: tell.answer(bot, args), 'twss': lambda: fun.twss(bot, args), 'cookie': lambda: fun.cookie(bot, args), 'spin': lambda: fun.spin(bot, args), 'man': lambda: man.man(bot, args), 'choose': lambda: fun.choose(bot, args), '8ball': lambda: fun.m8b(bot, args), 'ghetto': lambda: fun.ghetto(bot, args), 'sortinghat': lambda: fun.sorting_hat(bot, args), 'lotto': lambda: lotto.get_results(bot, args), 'quotes': lambda: quotes.get_quote(bot, args), 'imdb': lambda: imdb.info(bot, args), 'usage': lambda: usage.usage(bot, args), 'maxx': lambda: maxx.times(bot, args), 'js': lambda: js.execute(bot, args) } if bot.remote['nick'].lower() not in bot.inv['banned']: if command in alibrary: if bot.remote['host'] in [host.strip() for host in bot.config.get(bot.network, 'admin_hostnames').split(',')]: alibrary[command]() bot.previous['user'] = bot.remote['sendee'] else: if bot.voice: reply(bot.remote['sendee'], "%s: Can't do that, noob." % bot.remote['nick']) elif bot.voice and command in clibrary: try: result = clibrary[command]() except __import__('urllib2').HTTPError: result = "!%s: derping the herp" % args[0] except (__import__('urllib2').URLError, __import__('socket').timeout): result = "!%s: response timeout exceeded." % args[0] bot.previous['user'] = bot.remote['sendee'] if result: reply(bot.remote['sendee'], result) elif bot.remote['message'].startswith("\x01") and bot.remote['message'].endswith("\x01"): type = bot.remote['message'][1:-1].split()[0] args = bot.remote['message'][1:-1].split()[1:] if type != "ACTION": ctcp(type, args) else: if bot.init['registered'] and not bot.init['identified']: if bot.remote['nick'] == "NickServ": if "registered" in bot.remote['message']: bot._login() elif "identified" in bot.remote['message']: bot.init['identified'] = True __import__('time').sleep(3) autojoin() if bot.voice: # start scanning messages for certain data try: response = scanner.scan(bot) except (__import__('urllib2').URLError, __import__('socket').timeout): response = "fetch: response timeout exceeded." if response: reply(bot.remote['sendee'], response) else: if (bot.remote['mid'].startswith("4") or bot.remote['mid'].startswith("5")) and bot.remote['mid'] != "462": reply(bot.previous['user'], "Message from %s: Error #%s: %s" % (bot.remote['server'], bot.remote['mid'], bot.remote['message'])) if not bot.init['joined'] and not bot.init['registered']: autojoin()
def processOpts(self, cmd, opts): """ Set standard opts. note: use of a server key keeps optional args aligned with server. """ servers = {"add": {}, "remove": {}, "failover": {}, "recovery": {}, "log": {}} # don't allow options that don't correspond to given commands for o, a in opts: usage_msg = "option '%s' is not used with command '%s'" % (o, cmd) if o in ("-r", "--server-remove"): if cmd in server_no_remove: usage(usage_msg) elif o in ("-a", "--server-add", "--server-add-username", "--server-add-password"): if cmd in server_no_add: usage(usage_msg) server = None for o, a in opts: if o in ("-a", "--server-add"): if a == "self": a = socket.gethostbyname(socket.getfqdn()) server = "%s:%d" % util.hostport(a) servers["add"][server] = {"user": "", "password": ""} self.server_list.append(server) elif o == "--server-add-username": if server: servers["add"][server]["user"] = a self.sa_username = a elif o == "--server-add-password": if server: servers["add"][server]["password"] = a self.sa_password = a elif o in ("-r", "--server-remove"): server = "%s:%d" % util.hostport(a) servers["remove"][server] = True server = None elif o in ("--server-failover"): server = "%s:%d" % util.hostport(a) servers["failover"][server] = True server = None elif o in ("--server-recovery"): server = "%s:%d" % util.hostport(a) servers["recovery"][server] = True server = None elif o == "--nodes": for server in self.normalize_servers(a): servers["log"][server] = True elif o in ("-o", "--output"): if a == "json": self.output = a server = None elif o in ("-d", "--debug"): self.debug = True server = None elif o in ("--cluster-init-password", "--cluster-password"): self.password_new = a elif o in ("--cluster-init-username", "--cluster-username"): self.username_new = a elif o in ("--cluster-init-port", "--cluster-port"): self.port_new = a elif o in ("--cluster-init-ramsize", "--cluster-ramsize"): self.per_node_quota = a elif o == "--enable-auto-failover": self.enable_auto_failover = bool_to_str(a) elif o == "--enable-notification": self.enable_notification = bool_to_str(a) elif o == "--auto-failover-timeout": self.autofailover_timeout = a elif o == "--compaction-db-percentage": self.compaction_db_percentage = a elif o == "--compaction-db-size": self.compaction_db_size = a elif o == "--compaction-view-percentage": self.compaction_view_percentage = a elif o == "--compaction-view-size": self.compaction_view_size = a elif o == "--compaction-period-from": self.compaction_period_from = a elif o == "--compaction-period-to": self.compaction_period_to = a elif o == "--enable-compaction-abort": self.enable_compaction_abort = bool_to_str(a) elif o == "--enable-compaction-parallel": self.enable_compaction_parallel = bool_to_str(a) elif o == "--enable-email-alert": self.enable_email_alert = bool_to_str(a) elif o == "--node-init-data-path": self.data_path = a elif o == "--node-init-index-path": self.index_path = a elif o == "--node-init-hostname": self.hostname = a elif o == "--email-recipients": self.email_recipient = a elif o == "--email-sender": self.email_sender = a elif o == "--email-user": self.email_user = a elif o == "--email-password": self.email_password = a elif o == "--email-host": self.email_host = a elif o == "--email-port": self.email_port = a elif o == "--enable-email-encrypt": self.email_enable_encrypt = bool_to_str(a) elif o == "--alert-auto-failover-node": self.autofailover_node = True elif o == "--alert-auto-failover-max-reached": self.autofailover_max_reached = True elif o == "--alert-auto-failover-node-down": self.autofailover_node_down = True elif o == "--alert-auto-failover-cluster-small": self.autofailover_cluster_small = True elif o == "--alert-ip-changed": self.alert_ip_changed = True elif o == "--alert-disk-space": self.alert_disk_space = True elif o == "--alert-meta-overhead": self.alert_meta_overhead = True elif o == "--alert-meta-oom": self.alert_meta_oom = True elif o == "--alert-write-failed": self.alert_write_failed = True elif o == "--create": self.cmd = "create" elif o == "--list": self.cmd = "list" elif o == "--delete": self.cmd = "delete" elif o == "--set": self.cmd = "set" elif o == "--ro-username": self.ro_username = a elif o == "--ro-password": self.ro_password = a elif o == "--metadata-purge-interval": self.purge_interval = a elif o == "--group-name": self.group_name = a elif o == "--add-servers": self.server_list = self.normalize_servers(a) self.cmd = "add-servers" elif o == "--remove-servers": self.server_list = self.normalize_servers(a) self.cmd = "remove-servers" elif o == "--move-servers": self.server_list = self.normalize_servers(a) self.cmd = "move-servers" elif o == "--from-group": self.from_group = a elif o == "--to-group": self.to_group = a elif o == "--rename": self.group_rename = a self.cmd = "rename" elif o == "--retrieve-cert": self.cmd = "retrieve" self.certificate_file = a elif o == "--regenerate-cert": self.cmd = "regenerate" self.certificate_file = a elif o == "--force": self.hard_failover = True elif o == "--recovery-type": self.recovery_type = a elif o == "--recovery-buckets": self.recovery_buckets = a elif o == "--nodes": self.nodes = a elif o == "--all-nodes": self.all_nodes = True elif o == "--upload": self.upload = True elif o == "--upload-host": self.upload_host = a elif o == "--customer": self.customer = a elif o == "--ticket": self.ticket = a return servers
def processOpts(self, cmd, opts): """ Set standard opts. note: use of a server key keeps optional args aligned with server. """ servers = {'add': {}, 'remove': {}, 'failover': {}} # don't allow options that don't correspond to given commands for o, a in opts: usage_msg = "option '%s' is not used with command '%s'" % (o, cmd) if o in ("-r", "--server-remove"): if cmd in server_no_remove: usage(usage_msg) elif o in ("-a", "--server-add", "--server-add-username", "--server-add-password"): if cmd in server_no_add: usage(usage_msg) server = None for o, a in opts: if o in ("-a", "--server-add"): if a == "self": a = socket.gethostbyname(socket.getfqdn()) server = "%s:%d" % util.hostport(a) servers['add'][server] = {'user': '', 'password': ''} elif o == "--server-add-username": if server is None: usage("please specify --server-add" " before --server-add-username") servers['add'][server]['user'] = a elif o == "--server-add-password": if server is None: usage("please specify --server-add" " before --server-add-password") servers['add'][server]['password'] = a elif o in ("-r", "--server-remove"): server = "%s:%d" % util.hostport(a) servers['remove'][server] = True server = None elif o in ("--server-failover"): server = "%s:%d" % util.hostport(a) servers['failover'][server] = True server = None elif o in ('-o', '--output'): if a == 'json': self.output = a server = None elif o in ('-d', '--debug'): self.debug = True server = None elif o in ('--cluster-init-password', '--cluster-password'): self.password_new = a elif o in ('--cluster-init-username', '--cluster-username'): self.username_new = a elif o in ('--cluster-init-port', '--cluster-port'): self.port_new = a elif o in ('--cluster-init-ramsize', '--cluster-ramsize'): self.per_node_quota = a elif o == '--enable-auto-failover': self.enable_auto_failover = bool_to_str(a) elif o == '--enable-notification': self.enable_notification = bool_to_str(a) elif o == '--auto-failover-timeout': self.autofailover_timeout = a elif o == '--compaction-db-percentage': self.compaction_db_percentage = a elif o == '--compaction-db-size': self.compaction_db_size = a elif o == '--compaction-view-percentage': self.compaction_view_percentage = a elif o == '--compaction-view-size': self.compaction_view_size = a elif o == '--compaction-period-from': self.compaction_period_from = a elif o == '--compaction-period-to': self.compaction_period_to = a elif o == '--enable-compaction-abort': self.enable_compaction_abort = bool_to_str(a) elif o == '--enable-compaction-parallel': self.enable_compaction_parallel = bool_to_str(a) elif o == '--enable-email-alert': self.enable_email_alert = bool_to_str(a) elif o == '--node-init-data-path': self.data_path = a elif o == '--node-init-index-path': self.index_path = a elif o == '--email-recipients': self.email_recipient = a elif o == '--email-sender': self.email_sender = a elif o == '--email-user': self.email_user = a elif o == '--email-password': self.email_password = a elif o == '--email-host': self.email_host = a elif o == 'email-port': self.email_port = a elif o == '--enable-email-encrypt': self.email_enable_encrypt = bool_to_str(a) elif o == '--alert-auto-failover-node': self.autofailover_node = True elif o == '--alert-auto-failover-max-reached': self.autofailover_max_reached = True elif o == '--alert-auto-failover-node-down': self.autofailover_node_down = True elif o == '--alert-auto-failover-cluster-small': self.autofailover_cluster_small = True elif o == '--alert-ip-changed': self.alert_ip_changed = True elif o == '--alert-disk-space': self.alert_disk_space = True elif o == '--alert-meta-overhead': self.alert_meta_overhead = True elif o == '--alert-meta-oom': self.alert_meta_oom = True elif o == '--alert-write-failed': self.alert_write_failed = True elif o == '--create': self.cmd = 'create' elif o == '--list': self.cmd = 'list' elif o == '--delete': self.cmd = 'delete' elif o == '--set': self.cmd = 'set' elif o == '--ro-username': self.ro_username = a elif o == '--ro-password': self.ro_password = a elif o == '--metadata-purge-interval': self.purge_interval = a elif o == '--group-name': self.group_name = a elif o == '--add-servers': self.server_list = a self.cmd = 'add-servers' elif o == '--remove-servers': self.server_list = a self.cmd = 'remove-servers' elif o == '--move-servers': self.server_list = a self.cmd = 'move-servers' elif o == '--from-group': self.from_group = a elif o == '--to-group': self.to_group = a elif o == '--rename': self.group_rename = a self.cmd = 'rename' return servers
def print_usage(args): if check_args(args, "-help"): usage()
def runCmd(self, cmd, server, port, user, password, opts): self.rest_cmd = rest_cmds[cmd] self.method = methods[cmd] self.server = server self.port = int(port) self.user = user self.password = password servers = self.processOpts(cmd, opts) if self.debug: print "INFO: servers %s" % servers if cmd == 'server-add' and not servers['add']: usage("please list one or more --server-add=HOST[:PORT];" " or use -h for more help.") if cmd == 'server-readd' and not servers['add']: usage("please list one or more --server-add=HOST[:PORT];" " or use -h for more help.") if cmd in ('server-add', 'rebalance'): if not self.group_name: self.addServers(servers['add']) else: self.groupAddServers() if cmd == 'rebalance': self.rebalance(servers) elif cmd == 'server-readd': self.reAddServers(servers) elif cmd == 'rebalance-status': output_result = self.rebalanceStatus() print output_result elif cmd == 'rebalance-stop': output_result = self.rebalanceStop() print output_result elif cmd == 'failover': if len(servers['failover']) <= 0: usage("please list one or more --server-failover=HOST[:PORT];" " or use -h for more help.") self.failover(servers) elif cmd in ('cluster-init', 'cluster-edit'): self.clusterInit(cmd) elif cmd == 'node-init': self.nodeInit() elif cmd == 'setting-compaction': self.compaction() elif cmd == 'setting-notification': self.notification() elif cmd == 'setting-alert': self.alert() elif cmd == 'setting-autofailover': self.autofailover() elif cmd == 'user-manage': self.userManage() elif cmd == 'group-manage': self.groupManage() elif cmd == 'ssl-manage': self.retrieveCert()
import json import sys import os import dateutil.parser import base64 from usage import usage from json_template import get_geojson_template, get_feature_template if __name__ == '__main__': # # Process arguments and remove them from the list as they're processed # if '-h' in sys.argv: usage() exit(0) should_include_pcap = False if '-b' in sys.argv: sys.argv.remove('-b') should_include_pcap = True savefile = None if '-o' in sys.argv: arg_index = sys.argv.index('-o') sys.argv.remove('-o') savefile = sys.argv.pop(arg_index)
def write(self, message): self.terminal.write(message) self.log.write(message) class myThread (threading.Thread): def __init__(self, name): threading.Thread.__init__(self) self.name = name #self.test = test def run(self): os.system(self.name) usage(server_ip) usage(confile) usage(fs) usage(export) check_setup(fs) if lfile == "": lfile="/tmp/ganesha.log" if os.path.isfile(lfile) == True : os.remove(lfile) sys.stdout = Logger() header.header_1(lfile) test_list = check_tests.check_list(test_list, version);
def write(self, message): self.terminal.write(message) self.log.write(message) class myThread(threading.Thread): def __init__(self, name): threading.Thread.__init__(self) self.name = name #self.test = test def run(self): os.system(self.name) usage(server_ip) usage(confile) usage(fs) usage(export) check_setup(fs) if lfile == "": lfile = "/tmp/ganesha.log" if os.path.isfile(lfile) == True: os.remove(lfile) sys.stdout = Logger() header.header_1(lfile) test_list = check_tests.check_list(test_list, version)
def runCmd(self, cmd, server, port, user, password, opts): self.user = user self.password = password bucketname = '' buckettype = '' authtype = 'sasl' bucketport = '11211' bucketpassword = '' bucketramsize = '' bucketreplication = '1' bucketpriority = None eviction_policy = None output = 'default' wait_for_bucket_ready = False enable_flush = None enable_replica_index = None force = False compact_data_only = False compact_view_only = False for (o, a) in opts: if o in ('-b', '--bucket'): bucketname = a elif o == '--bucket-type': buckettype = a elif o == '--bucket-port': bucketport = a elif o == '--bucket-password': bucketpassword = a elif o == '--bucket-ramsize': bucketramsize = a elif o == '--bucket-replica': bucketreplication = a elif o == '--bucket-eviction-policy': eviction_policy = a elif o == '--bucket-priority': bucketpriority = a elif o == '-d' or o == '--debug': self.debug = True elif o in ('-o', '--output'): output = a elif o == '--enable-flush': enable_flush = a elif o == '--enable-index-replica': enable_replica_index = a elif o == '--wait': wait_for_bucket_ready = True elif o == '--force': force = True elif o == '--data-only': compact_data_only = True elif o == '--view-only': compact_view_only = True self.rest_cmd = rest_cmds[cmd] rest = restclient.RestClient(server, port, {'debug':self.debug}) # get the parameters straight opts = {} opts['error_msg'] = "unable to %s;" % cmd opts['success_msg'] = "%s" % cmd if cmd in ('bucket-create', 'bucket-edit'): if bucketname: rest.setParam('name', bucketname) if bucketname == "default": if bucketport and bucketport != "11211": usage("default bucket must be on port 11211.") if bucketpassword: usage("default bucket should only have empty password.") authtype = 'sasl' else: if bucketport == "11211": authtype = 'sasl' else: authtype = 'none' if bucketpassword: usage("a sasl bucket is supported only on port 11211.") if buckettype: rest.setParam('bucketType', buckettype) if authtype: rest.setParam('authType', authtype) if bucketport: rest.setParam('proxyPort', bucketport) if bucketpassword: rest.setParam('saslPassword', bucketpassword) if bucketramsize: rest.setParam('ramQuotaMB', bucketramsize) if bucketreplication: rest.setParam('replicaNumber', bucketreplication) if enable_flush: rest.setParam('flushEnabled', enable_flush) if eviction_policy: if eviction_policy in ['valueOnly', 'fullEviction']: rest.setParam('evictionPolicy', eviction_policy) else: usage("eviction policy value should be either 'valueOnly' or 'fullEviction'.") if enable_replica_index and cmd == 'bucket-create': rest.setParam('replicaIndex', enable_replica_index) if bucketpriority: if bucketpriority in priority: rest.setParam('threadsNumber', priority[bucketpriority]) else: usage("bucket priority must be either low or high.") if cmd in ('bucket-delete', 'bucket-flush', 'bucket-edit'): self.rest_cmd = self.rest_cmd + bucketname if cmd == 'bucket-flush': self.rest_cmd = self.rest_cmd + '/controller/doFlush' if not force: question = "Running this command will totally PURGE database data from disk." + \ "Do you really want to do it? (Yes/No)" confirm = raw_input(question) if confirm in ('Y', 'Yes'): print "Database data will be purged from disk ..." else: print "Database data will not be purged. Done." return False else: print "Database data will be purged from disk ..." opts['error_msg'] = "unable to %s; please check if the bucket exists or not;" % cmd elif cmd == 'bucket-compact': if compact_data_only and compact_view_only: print "You cannot compact data only and view only at the same time." return False elif compact_data_only: self.rest_cmd = self.rest_cmd + bucketname + '/controller/compactDatabases' elif compact_view_only: self.compact_view(rest, server, port, bucketname) return True else: self.rest_cmd = self.rest_cmd + bucketname + '/controller/compactBucket' elif cmd == 'bucket-ddocs': self.rest_cmd = self.rest_cmd % bucketname data = rest.restCmd(methods[cmd], urllib.quote(self.rest_cmd), self.user, self.password, opts) if cmd in ("bucket-get", "bucket-stats", "bucket-node-stats", "bucket-ddocs"): return rest.getJson(data) elif cmd == "bucket-list": if output == 'json': print data else: json = rest.getJson(data) for bucket in json: print '%s' % bucket['name'] print ' bucketType: %s' % bucket['bucketType'] print ' authType: %s' % bucket['authType'] if bucket['authType'] == "sasl": print ' saslPassword: %s' % bucket['saslPassword'] else: print ' proxyPort: %s' % bucket['proxyPort'] print ' numReplicas: %s' % bucket['replicaNumber'] print ' ramQuota: %s' % bucket['quota']['ram'] print ' ramUsed: %s' % bucket['basicStats']['memUsed'] elif cmd == "bucket-create" and wait_for_bucket_ready: rest_query = restclient.RestClient(server, port, {'debug':self.debug}) timeout_in_seconds = 120 start = time.time() # Make sure the bucket exists before querying its status bucket_exist = False while (time.time() - start) <= timeout_in_seconds and not bucket_exist: buckets = rest_query.restCmd('GET', rest_cmds['bucket-list'], self.user, self.password, opts) for bucket in rest_query.getJson(buckets): if bucket["name"] == bucketname: bucket_exist = True break if not bucket_exist: sys.stderr.write(".") time.sleep(2) if not bucket_exist: print "\nFail to create bucket '%s' within %s seconds" %\ (bucketname, timeout_in_seconds) return False #Query status for all bucket nodes while (time.time() - start) <= timeout_in_seconds: bucket_info = rest_query.restCmd('GET', urllib.quote(rest_cmds['bucket-info'] % bucketname), self.user, self.password, opts) json = rest_query.getJson(bucket_info) all_node_ready = True for node in json["nodes"]: if node["status"] != "healthy": all_node_ready = False break if all_node_ready: if output == 'json': print rest.jsonMessage(data) else: print data return True else: sys.stderr.write(".") time.sleep(2) print "\nBucket '%s' is created but not ready to use within %s seconds" %\ (bucketname, timeout_in_seconds) return False else: if output == 'json': print rest.jsonMessage(data) else: print data
return (data) def make_graph(farm): g = nx.Graph() g.add_nodes_from(farm.nodes) g.add_edges_from(farm.links) return (g) try: args = sys.argv data = create_data() settings = create_settings(args, data['farm']) check_is_big_map(args) ant_squad = make_squad(data, settings, settings['steps_between_nodes']) set_paths_colors(data['farm'], ant_squad) fig = plt.figure(figsize=(settings['window_size'])) anim_running = True ani = matAni.FuncAnimation(fig, action, frames=data['farm'].moves_nb * settings['steps_between_nodes'], fargs=(data, fig, ant_squad, settings), interval=settings['interval'], repeat=settings['repeat'], blit=0) plt.show() except: usage() quit()
def runCmd(self, cmd, server, port, user, password, opts): self.user = user self.password = password bucketname = '' buckettype = '' authtype = 'sasl' bucketport = '11211' bucketpassword = '' bucketramsize = '' bucketreplication = '1' output = 'default' wait_for_bucket_ready = False for (o, a) in opts: if o == '-b' or o == '--bucket': bucketname = a if o == '--bucket-type': buckettype = a if o == '--bucket-port': bucketport = a if o == '--bucket-password': bucketpassword = a if o == '--bucket-ramsize': bucketramsize = a if o == '--bucket-replica': bucketreplication = a if o == '-d' or o == '--debug': self.debug = True if o in ('-o', '--output'): output = a if o == '--wait': wait_for_bucket_ready = True self.rest_cmd = rest_cmds[cmd] rest = restclient.RestClient(server, port, {'debug': self.debug}) # get the parameters straight if cmd in ('bucket-create', 'bucket-edit'): if bucketname: rest.setParam('name', bucketname) if bucketname == "default": if bucketport and bucketport != "11211": usage("default bucket must be on port 11211.") if bucketpassword: usage( "default bucket should only have empty password.") authtype = 'sasl' else: if bucketport == "11211": authtype = 'sasl' else: authtype = 'none' if bucketpassword: usage( "a sasl bucket is supported only on port 11211." ) if buckettype: rest.setParam('bucketType', buckettype) if authtype: rest.setParam('authType', authtype) if bucketport: rest.setParam('proxyPort', bucketport) if bucketpassword: rest.setParam('saslPassword', bucketpassword) if bucketramsize: rest.setParam('ramQuotaMB', bucketramsize) if bucketreplication: rest.setParam('replicaNumber', bucketreplication) if cmd in ('bucket-delete', 'bucket-flush', 'bucket-edit'): self.rest_cmd = self.rest_cmd + bucketname if cmd == 'bucket-flush': self.rest_cmd = self.rest_cmd + '/controller/doFlush' opts = {} opts[ 'error_msg'] = "unable to %s; please check your username (-u) and password (-p);" % cmd opts['success_msg'] = "%s" % cmd data = rest.restCmd(methods[cmd], self.rest_cmd, self.user, self.password, opts) if cmd in ("bucket-get", "bucket-stats", "bucket-node-stats"): return rest.getJson(data) elif cmd == "bucket-list": if output == 'json': print data else: json = rest.getJson(data) for bucket in json: print '%s' % bucket['name'] print ' bucketType: %s' % bucket['bucketType'] print ' authType: %s' % bucket['authType'] if bucket['authType'] == "sasl": print ' saslPassword: %s' % bucket['saslPassword'] else: print ' proxyPort: %s' % bucket['proxyPort'] print ' numReplicas: %s' % bucket['replicaNumber'] print ' ramQuota: %s' % bucket['quota']['ram'] print ' ramUsed: %s' % bucket['basicStats']['memUsed'] elif cmd == "bucket-create" and wait_for_bucket_ready: rest_query = restclient.RestClient(server, port, {'debug': self.debug}) timeout_in_seconds = 120 start = time.time() # Make sure the bucket exists before querying its status bucket_exist = False while (time.time() - start) <= timeout_in_seconds and not bucket_exist: buckets = rest_query.restCmd('GET', rest_cmds['bucket-list'], self.user, self.password, opts) for bucket in rest_query.getJson(buckets): if bucket["name"] == bucketname: bucket_exist = True break if not bucket_exist: sys.stderr.write(".") time.sleep(2) if not bucket_exist: print "\nFail to create bucket '%s' within %s seconds" %\ (bucketname, timeout_in_seconds) return False #Query status for all bucket nodes while (time.time() - start) <= timeout_in_seconds: bucket_info = rest_query.restCmd( 'GET', rest_cmds['bucket-info'] % bucketname, self.user, self.password, opts) json = rest_query.getJson(bucket_info) all_node_ready = True for node in json["nodes"]: if node["status"] != "healthy": all_node_ready = False break if all_node_ready: if output == 'json': print rest.jsonMessage(data) else: print data return True else: sys.stderr.write(".") time.sleep(2) print "\nBucket '%s' is created but not ready to use within %s seconds" %\ (bucketname, timeout_in_seconds) return False else: if output == 'json': print rest.jsonMessage(data) else: print data
def runCmd(self, cmd, server, port, user, password, opts): self.user = user self.password = password bucketname = '' buckettype = '' authtype = 'sasl' bucketport = '11211' bucketpassword = '' bucketramsize = '' bucketreplication = '1' output = 'default' for (o, a) in opts: if o == '-b' or o == '--bucket': bucketname = a if o == '--bucket-type': buckettype = a if o == '--bucket-port': bucketport = a if o == '--bucket-password': bucketpassword = a if o == '--bucket-ramsize': bucketramsize = a if o == '--bucket-replica': bucketreplication = a if o == '-d' or o == '--debug': self.debug = True if o in ('-o', '--output'): output = a self.rest_cmd = rest_cmds[cmd] rest = restclient.RestClient(server, port, {'debug':self.debug}) # get the parameters straight if cmd in ('bucket-create', 'bucket-edit'): if bucketname: rest.setParam('name', bucketname) if bucketname == "default": if bucketport and bucketport != "11211": usage("default bucket must be on port 11211.") if bucketpassword: usage("default bucket should only have empty password.") authtype = 'sasl' else: if bucketport == "11211": authtype = 'sasl' else: authtype = 'none' if bucketpassword: usage("a sasl bucket is supported only on port 11211.") if buckettype: rest.setParam('bucketType', buckettype) if authtype: rest.setParam('authType', authtype) if bucketport: rest.setParam('proxyPort', bucketport) if bucketpassword: rest.setParam('saslPassword', bucketpassword) if bucketramsize: rest.setParam('ramQuotaMB', bucketramsize) if bucketreplication: rest.setParam('replicaNumber', bucketreplication) if cmd in ('bucket-delete', 'bucket-flush', 'bucket-edit'): self.rest_cmd = self.rest_cmd + bucketname if cmd == 'bucket-flush': self.rest_cmd = self.rest_cmd + '/controller/doFlush' opts = {} opts['error_msg'] = "unable to %s; please check your username (-u) and password (-p);" % cmd opts['success_msg'] = "%s" % cmd data = rest.restCmd(methods[cmd], self.rest_cmd, self.user, self.password, opts) if cmd in ("bucket-get", "bucket-stats", "bucket-node-stats"): return rest.getJson(data) elif cmd == "bucket-list": if output == 'json': print data else: json = rest.getJson(data) for bucket in json: print '%s' % bucket['name'] print ' bucketType: %s' % bucket['bucketType'] print ' authType: %s' % bucket['authType'] if bucket['authType'] == "sasl": print ' saslPassword: %s' % bucket['saslPassword'] else: print ' proxyPort: %s' % bucket['proxyPort'] print ' numReplicas: %s' % bucket['replicaNumber'] print ' ramQuota: %s' % bucket['quota']['ram'] print ' ramUsed: %s' % bucket['basicStats']['memUsed'] else: if output == 'json': print rest.jsonMessage(data) else: print data
def processOpts(self, cmd, opts): """ Set standard opts. note: use of a server key keeps optional args aligned with server. """ servers = { 'add': {}, 'remove': {}, 'failover': {} } # don't allow options that don't correspond to given commands for o, a in opts: usage_msg = "option '%s' is not used with command '%s'" % (o, cmd) if o in ( "-r", "--server-remove"): if cmd in server_no_remove: usage(usage_msg) elif o in ( "-a", "--server-add", "--server-add-username", "--server-add-password"): if cmd in server_no_add: usage(usage_msg) server = None for o, a in opts: if o in ("-a", "--server-add"): if a == "self": a = socket.gethostbyname(socket.getfqdn()) server = "%s:%d" % util.hostport(a) servers['add'][server] = { 'user':'', 'password':''} elif o == "--server-add-username": if server is None: usage("please specify --server-add" " before --server-add-username") servers['add'][server]['user'] = a elif o == "--server-add-password": if server is None: usage("please specify --server-add" " before --server-add-password") servers['add'][server]['password'] = a elif o in ( "-r", "--server-remove"): server = "%s:%d" % util.hostport(a) servers['remove'][server] = True server = None elif o in ( "--server-failover"): server = "%s:%d" % util.hostport(a) servers['failover'][server] = True server = None elif o in ('-o', '--output'): if a == 'json': self.output = a server = None elif o in ('-d', '--debug'): self.debug = True server = None elif o in ('--cluster-init-password', '--cluster-password'): self.password_new = a elif o in ('--cluster-init-username', '--cluster-username'): self.username_new = a elif o in ('--cluster-init-port', '--cluster-port'): self.port_new = a elif o in ('--cluster-init-ramsize', '--cluster-ramsize'): self.per_node_quota = a elif o == '--enable-auto-failover': self.enable_auto_failover = bool_to_str(a) elif o == '--enable-notification': self.enable_notification = bool_to_str(a) elif o == '--auto-failover-timeout': self.autofailover_timeout = a elif o == '--compaction-db-percentage': self.compaction_db_percentage = a elif o == '--compaction-db-size': self.compaction_db_size = a elif o == '--compaction-view-percentage': self.compaction_view_percentage = a elif o == '--compaction-view-size': self.compaction_view_size = a elif o == '--compaction-period-from': self.compaction_period_from = a elif o == '--compaction-period-to': self.compaction_period_to = a elif o == '--enable-compaction-abort': self.enable_compaction_abort = bool_to_str(a) elif o == '--enable-compaction-parallel': self.enable_compaction_parallel = bool_to_str(a) elif o == '--enable-email-alert': self.enable_email_alert = bool_to_str(a) elif o == '--node-init-data-path': self.data_path = a elif o == '--node-init-index-path': self.index_path = a elif o == '--email-recipients': self.email_recipient = a elif o == '--email-sender': self.email_sender = a elif o == '--email-user': self.email_user = a elif o == '--email-password': self.email_password = a elif o == '--email-host': self.email_host = a elif o == 'email-port': self.email_port = a elif o == '--enable-email-encrypt': self.email_enable_encrypt = bool_to_str(a) elif o == '--alert-auto-failover-node': self.autofailover_node = True elif o == '--alert-auto-failover-max-reached': self.autofailover_max_reached = True elif o == '--alert-auto-failover-node-down': self.autofailover_node_down = True elif o == '--alert-auto-failover-cluster-small': self.autofailover_cluster_small = True elif o == '--alert-ip-changed': self.alert_ip_changed = True elif o == '--alert-disk-space': self.alert_disk_space = True elif o == '--alert-meta-overhead': self.alert_meta_overhead = True elif o == '--alert-meta-oom': self.alert_meta_oom = True elif o == '--alert-write-failed': self.alert_write_failed = True elif o == '--create': self.cmd = 'create' elif o == '--list': self.cmd = 'list' elif o == '--delete': self.cmd = 'delete' elif o == '--set': self.cmd = 'set' elif o == '--ro-username': self.ro_username = a elif o == '--ro-password': self.ro_password = a elif o == '--metadata-purge-interval': self.purge_interval = a elif o == '--group-name': self.group_name = a elif o == '--add-servers': self.server_list = a self.cmd = 'add-servers' elif o == '--remove-servers': self.server_list = a self.cmd = 'remove-servers' elif o == '--move-servers': self.server_list = a self.cmd = 'move-servers' elif o == '--from-group': self.from_group = a elif o == '--to-group': self.to_group = a elif o == '--rename': self.group_rename = a self.cmd = 'rename' return servers
def runCmd(self, cmd, server, port, user, password, opts): self.rest_cmd = rest_cmds[cmd] self.method = methods[cmd] self.server = server self.port = int(port) self.user = user self.password = password servers = self.processOpts(cmd, opts) if self.debug: print "INFO: servers %s" % servers if cmd == "server-add" and not servers["add"]: usage("please list one or more --server-add=HOST[:PORT];" " or use -h for more help.") if cmd == "server-readd" and not servers["add"]: usage("please list one or more --server-add=HOST[:PORT];" " or use -h for more help.") if cmd in ("server-add", "rebalance"): if len(servers["add"]) > 0: if not self.group_name: self.addServers(servers["add"]) else: self.groupAddServers() if cmd == "rebalance": self.rebalance(servers) elif cmd == "server-readd": self.reAddServers(servers) elif cmd == "rebalance-status": output_result = self.rebalanceStatus() print output_result elif cmd == "rebalance-stop": output_result = self.rebalanceStop() print output_result elif cmd == "failover": if len(servers["failover"]) <= 0: usage("please list one or more --server-failover=HOST[:PORT];" " or use -h for more help.") self.failover(servers) elif cmd == "recovery": if len(servers["recovery"]) <= 0: usage("please list one or more --server-recovery=HOST[:PORT];" " or use -h for more help.") self.recovery(servers) elif cmd in ("cluster-init", "cluster-edit"): self.clusterInit(cmd) elif cmd == "node-init": self.nodeInit() elif cmd == "setting-compaction": self.compaction() elif cmd == "setting-notification": self.notification() elif cmd == "setting-alert": self.alert() elif cmd == "setting-autofailover": self.autofailover() elif cmd == "user-manage": self.userManage() elif cmd == "group-manage": self.groupManage() elif cmd == "ssl-manage": self.retrieveCert() elif cmd == "collect-logs-start": self.collectLogsStart(servers) elif cmd == "collect-logs-stop": self.collectLogsStop() elif cmd == "collect-logs-status": self.collectLogsStatus()
def runCmd(self, cmd, server, port, user, password, opts): self.user = user self.password = password bucketname = '' buckettype = '' authtype = 'sasl' bucketport = '11211' bucketpassword = '' bucketramsize = '' bucketreplication = '1' output = 'default' wait_for_bucket_ready = False enable_flush = None enable_replica_index = None force = False compact_data_only = False compact_view_only = False for (o, a) in opts: if o in ('-b', '--bucket'): bucketname = a elif o == '--bucket-type': buckettype = a elif o == '--bucket-port': bucketport = a elif o == '--bucket-password': bucketpassword = a elif o == '--bucket-ramsize': bucketramsize = a elif o == '--bucket-replica': bucketreplication = a elif o == '-d' or o == '--debug': self.debug = True elif o in ('-o', '--output'): output = a elif o == '--enable-flush': enable_flush = a elif o == '--enable-index-replica': enable_replica_index = a elif o == '--wait': wait_for_bucket_ready = True elif o == '--force': force = True elif o == '--data-only': compact_data_only = True elif o == '--view-only': compact_view_only = True self.rest_cmd = rest_cmds[cmd] rest = restclient.RestClient(server, port, {'debug': self.debug}) # get the parameters straight opts = {} opts[ 'error_msg'] = "unable to %s; please check your username (-u) and password (-p);" % cmd opts['success_msg'] = "%s" % cmd if cmd in ('bucket-create', 'bucket-edit'): if bucketname: rest.setParam('name', bucketname) if bucketname == "default": if bucketport and bucketport != "11211": usage("default bucket must be on port 11211.") if bucketpassword: usage( "default bucket should only have empty password.") authtype = 'sasl' else: if bucketport == "11211": authtype = 'sasl' else: authtype = 'none' if bucketpassword: usage( "a sasl bucket is supported only on port 11211." ) if buckettype: rest.setParam('bucketType', buckettype) if authtype: rest.setParam('authType', authtype) if bucketport: rest.setParam('proxyPort', bucketport) if bucketpassword: rest.setParam('saslPassword', bucketpassword) if bucketramsize: rest.setParam('ramQuotaMB', bucketramsize) if bucketreplication: rest.setParam('replicaNumber', bucketreplication) if enable_flush: rest.setParam('flushEnabled', enable_flush) if enable_replica_index and cmd == 'bucket-create': rest.setParam('replicaIndex', enable_replica_index) if cmd in ('bucket-delete', 'bucket-flush', 'bucket-edit'): self.rest_cmd = self.rest_cmd + bucketname if cmd == 'bucket-flush': self.rest_cmd = self.rest_cmd + '/controller/doFlush' if not force: question = "Running this command will totally PURGE database data from disk." + \ "Do you really want to do it? (Yes/No)" confirm = raw_input(question) if confirm in ('Y', 'Yes'): print "Database data will be purged from disk ..." else: print "Database data will not be purged. Done." return False else: print "Database data will be purged from disk ..." opts[ 'error_msg'] = "unable to %s; please check username/password or if the bucket exists or not;" % cmd elif cmd == 'bucket-compact': if compact_data_only and compact_view_only: print "You cannot compact data only and view only at the same time." return False elif compact_data_only: self.rest_cmd = self.rest_cmd + bucketname + '/controller/compactDatabases' elif compact_view_only: self.compact_view(rest, server, port, bucketname) return True else: self.rest_cmd = self.rest_cmd + bucketname + '/controller/compactBucket' elif cmd == 'bucket-ddocs': self.rest_cmd = self.rest_cmd % bucketname data = rest.restCmd(methods[cmd], self.rest_cmd, self.user, self.password, opts) if cmd in ("bucket-get", "bucket-stats", "bucket-node-stats", "bucket-ddocs"): return rest.getJson(data) elif cmd == "bucket-list": if output == 'json': print data else: json = rest.getJson(data) for bucket in json: print '%s' % bucket['name'] print ' bucketType: %s' % bucket['bucketType'] print ' authType: %s' % bucket['authType'] if bucket['authType'] == "sasl": print ' saslPassword: %s' % bucket['saslPassword'] else: print ' proxyPort: %s' % bucket['proxyPort'] print ' numReplicas: %s' % bucket['replicaNumber'] print ' ramQuota: %s' % bucket['quota']['ram'] print ' ramUsed: %s' % bucket['basicStats']['memUsed'] elif cmd == "bucket-create" and wait_for_bucket_ready: rest_query = restclient.RestClient(server, port, {'debug': self.debug}) timeout_in_seconds = 120 start = time.time() # Make sure the bucket exists before querying its status bucket_exist = False while (time.time() - start) <= timeout_in_seconds and not bucket_exist: buckets = rest_query.restCmd('GET', rest_cmds['bucket-list'], self.user, self.password, opts) for bucket in rest_query.getJson(buckets): if bucket["name"] == bucketname: bucket_exist = True break if not bucket_exist: sys.stderr.write(".") time.sleep(2) if not bucket_exist: print "\nFail to create bucket '%s' within %s seconds" %\ (bucketname, timeout_in_seconds) return False #Query status for all bucket nodes while (time.time() - start) <= timeout_in_seconds: bucket_info = rest_query.restCmd( 'GET', rest_cmds['bucket-info'] % bucketname, self.user, self.password, opts) json = rest_query.getJson(bucket_info) all_node_ready = True for node in json["nodes"]: if node["status"] != "healthy": all_node_ready = False break if all_node_ready: if output == 'json': print rest.jsonMessage(data) else: print data return True else: sys.stderr.write(".") time.sleep(2) print "\nBucket '%s' is created but not ready to use within %s seconds" %\ (bucketname, timeout_in_seconds) return False else: if output == 'json': print rest.jsonMessage(data) else: print data
def processOpts(self, cmd, opts): """ Set standard opts. note: use of a server key keeps optional args aligned with server. """ servers = { 'add': {}, 'remove': {}, 'failover': {} } # don't allow options that don't correspond to given commands for o, a in opts: usage_msg = "option '%s' is not used with command '%s'" % (o, cmd) if o in ( "-r", "--server-remove"): if cmd in server_no_remove: usage(usage_msg) elif o in ( "-a", "--server-add", "--server-add-username", "--server-add-password"): if cmd in server_no_add: usage(usage_msg) server = None for o, a in opts: if o in ("-a", "--server-add"): if a == "self": a = socket.gethostbyname(socket.getfqdn()) server = "%s:%d" % util.hostport(a) servers['add'][server] = { 'user':'', 'password':''} elif o == "--server-add-username": if server is None: usage("please specify --server-add" " before --server-add-username") servers['add'][server]['user'] = a elif o == "--server-add-password": if server is None: usage("please specify --server-add" " before --server-add-password") servers['add'][server]['password'] = a elif o in ( "-r", "--server-remove"): server = "%s:%d" % util.hostport(a) servers['remove'][server] = True server = None elif o in ( "--server-failover"): server = "%s:%d" % util.hostport(a) servers['failover'][server] = True server = None elif o in ('-o', '--output'): if a == 'json': self.output = a server = None elif o in ('-d', '--debug'): self.debug = True server = None elif o in ('--cluster-init-password'): self.password_new = a elif o in ('--cluster-init-username'): self.username_new = a elif o in ('--cluster-init-port'): self.port_new = a elif o in ('--cluster-init-ramsize'): self.per_node_quota = a elif o in ('--node-init-data-path'): self.data_path = a return servers
options = {} current = "" for val in sys.argv[1:]: if val.startswith("-"): current = val[1:] options[current] = [] else: if current in options: options[current].append(val) else: options[current] = [val] if not "" in options: print("No Input File Given") usage.usage() sys.exit() input_file_name = options[""][0] output_file_name = "result.asm" input_file_data = open(input_file_name, "r").read() if "o" in options: output_file_name = options["o"][0] settings.DISPLAY_ASM = "A" in options.keys() settings.DISPLAY_OPTIMIZATION = "O" in options.keys() settings.DISPLAY_TREE = "t" in options.keys() settings.DISPLAY_INTERMEDIATE = "I" in options.keys() settings.USE_COLORS = "C" not in options.keys()
def processOpts(self, cmd, opts): """ Set standard opts. note: use of a server key keeps optional args aligned with server. """ servers = {'add': {}, 'remove': {}, 'failover': {}} # don't allow options that don't correspond to given commands for o, a in opts: usage_msg = "option '%s' is not used with command '%s'" % (o, cmd) if o in ("-r", "--server-remove"): if cmd in server_no_remove: usage(usage_msg) elif o in ("-a", "--server-add", "--server-add-username", "--server-add-password"): if cmd in server_no_add: usage(usage_msg) server = None for o, a in opts: if o in ("-a", "--server-add"): if a == "self": a = socket.gethostbyname(socket.getfqdn()) server = "%s:%d" % util.hostport(a) servers['add'][server] = {'user': '', 'password': ''} elif o == "--server-add-username": if server is None: usage("please specify --server-add" " before --server-add-username") servers['add'][server]['user'] = a elif o == "--server-add-password": if server is None: usage("please specify --server-add" " before --server-add-password") servers['add'][server]['password'] = a elif o in ("-r", "--server-remove"): server = "%s:%d" % util.hostport(a) servers['remove'][server] = True server = None elif o in ("--server-failover"): server = "%s:%d" % util.hostport(a) servers['failover'][server] = True server = None elif o in ('-o', '--output'): if a == 'json': self.output = a server = None elif o in ('-d', '--debug'): self.debug = True server = None elif o == '--cluster-init-password': self.password_new = a elif o == '--cluster-init-username': self.username_new = a elif o == '--cluster-init-port': self.port_new = a elif o == '--cluster-init-ramsize': self.per_node_quota = a elif o == '--node-init-data-path': self.data_path = a return servers
end_time=time_end, period=60, unit='None') if len(app_service_result) == 0: service_cost = 0 else: service_cost = app_service_result[0]['Maximum'] print aws_service, int(service_cost) service_cost_list.append(service_cost) # google spreadsheetへ書き込み sheet_name = app_name + "_cost" spreadsheets.update_sheet(sheet_name, app_name, service_cost_list, time_end) ''' [main function] ''' if __name__ == '__main__': # usage + option解析 result = usage() # cost_count app_name = "test" aws_access_key = config.get(app_name, 'AWS_ACCESS_KEY') aws_secret_access_key = config.get(app_name, 'AWS_SECRET_ACCESS_KEY') aws_cost_count(app_name, aws_access_key, aws_secret_access_key, result)