def sendJob( i_port): # Prepare action object. act = dict() act['user_name'] = cgruconfig.VARS['USERNAME'] act['host_name'] = cgruconfig.VARS['HOSTNAME'] act['type'] = 'jobs' act['ids'] = [Options.jobid] # Set environment for env-blocks. act['block_mask'] = Options.envblocks par = dict() par['environment'] = dict() par['environment']['TRACKER_ADDRESS'] = cgruconfig.VARS['HOSTNAME'] par['environment']['TRACKER_PORT'] = str(i_port) act['params'] = par data = json.dumps({'action':act}, sort_keys=True, indent=4) print( data) res = afnetwork.sendServer( data) print( res) # Reset depend mask for dep-blocks. act['block_mask'] = Options.depblocks par = dict() par['depend_mask'] = '' act['params'] = par data = json.dumps({'action':act}, sort_keys=True, indent=4) print( data) res = afnetwork.sendServer( data) print( res) # Flush printed text to stdout out. sys.stdout.flush()
def send(self, verbose=False): """Missing DocString :param verbose: :return: """ if len(self.blocks) == 0: print('Error: Job has no blocks') self.fillBlocks() # Set folder if empty: if "folders" not in self.data: self.data["folders"] = dict() # Try to set output folder from files: for block in self.blocks: if "files" in block.data and len(block.data["files"]): self.data["folders"][block.data['name']] = os.path.dirname(block.data["files"][0]) # Set branch if empty: if 'branch' not in self.data: if 'output' in self.data['folders']: self.data['branch'] = self.data['folders']['output'] elif 'input' in self.data['folders']: self.data['branch'] = self.data['folders']['input'] else: self.data['branch'] = self.blocks[0].data['working_directory'] obj = {"job": self.data} # print(json.dumps( obj)) return afnetwork.sendServer(json.dumps(obj), verbose)
def sendAction(i_type, i_mask, i_operation, i_params=None): action = dict() action['type'] = i_type action['user_name'] = ActionUser action['host_name'] = ActionHost action['mask'] = i_mask if i_operation is not None: operation = dict() operation['type'] = i_operation action['operation'] = operation if i_params is not None: action['params'] = i_params afnetwork.sendServer(json.dumps({'action': action}))
def sendAction(i_type, i_mask, i_operation, i_params=None): action = dict() action['type'] = i_type action['user_name'] = ActionUser action['host_name'] = ActionHost action['mask'] = i_mask if i_operation is not None: operation = dict() operation['type'] = i_operation action['operation'] = operation if i_params is not None: action['params'] = i_params afnetwork.sendServer(json.dumps({'action': action}), False, False)
def send(self, verbose=False): if len(self.blocks) == 0: print('Error: Job has no blocks') return False self.fillBlocks() obj = {"job": self.data} #print(json.dumps( obj)) return afnetwork.sendServer(json.dumps(obj), False, verbose)[0]
def send( self, verbose = False): if len( self.blocks) == 0: print('Error: Job has no blocks') return False self.fillBlocks() obj = {"job": self.data } #print(json.dumps( obj)) return afnetwork.sendServer( json.dumps( obj), False, verbose)[0]
def _sendRequest(self, verbose=False): if self.action is None: print('ERROR: Action is not set.') return None receive = (self.action == 'get') obj = {self.action: self.data} #print(json.dumps( obj)) output = afnetwork.sendServer(json.dumps(obj), receive, verbose) if output[0] == True: return output[1] else: return None
def _sendRequest(self, verbose = False): if self.action is None: print('ERROR: Action is not set.') return None receive = ( self.action == 'get') obj = { self.action: self.data } #print(json.dumps( obj)) output = afnetwork.sendServer( json.dumps( obj), receive, verbose) if output[0] == True: return output[1] else: return None
def send(self, verbose=False): """Missing DocString :param verbose: :return: """ if len(self.blocks) == 0: print('Error: Job has no blocks') # return False self.fillBlocks() obj = {"job": self.data} # print(json.dumps( obj)) return afnetwork.sendServer(json.dumps(obj), True, verbose)
def _sendRequest(action, requestData, verbose=False, without_answer=False): """Missing DocString :param bool verbose: :return: """ data = {'user_name': cgruconfig.VARS['USERNAME'], "host_name": cgruconfig.VARS['HOSTNAME']} data.update(requestData) obj = {action: data} # print(json.dumps(obj)) output = afnetwork.sendServer(json.dumps(obj), verbose, i_without_answer=without_answer) if output[0] is True: return output[1] else: return None
def sendAction(i_type, i_mask, i_operation, i_params=None): action = dict() action['type'] = i_type action['user_name'] = Options.user action['host_name'] = Options.name action['mask'] = i_mask if i_operation is not None: operation = dict() operation['type'] = i_operation action['operation'] = operation if i_params is not None: action['params'] = i_params # print( json.dumps( {'action': action})) status, answer = afnetwork.sendServer(json.dumps({'action': action}), False) return status
def _sendRequest(self, verbose=False, without_answer=False): """Missing DocString :param bool verbose: :return: """ if self.action is None: print('ERROR: Action is not set.') return None obj = {self.action: self.data} # print(json.dumps( obj)) output = afnetwork.sendServer(json.dumps(obj), verbose, without_answer) self.__init__() if output[0] is True: return output[1] else: return None
def sendAction(i_type, i_mask, i_operation, i_params=None): action = dict() action['type'] = i_type action['user_name'] = Options.user action['host_name'] = Options.name action['mask'] = i_mask if i_operation is not None: operation = dict() operation['type'] = i_operation action['operation'] = operation if i_params is not None: action['params'] = i_params # print( json.dumps( {'action': action})) status, answer = afnetwork.sendServer(json.dumps({'action': action}), False, False) return status
def _sendRequest(self, verbose=False): """Missing DocString :param bool verbose: :return: """ if self.action is None: print('ERROR: Action is not set.') return None obj = {self.action: self.data} #print(json.dumps( obj)) output = afnetwork.sendServer(json.dumps(obj), verbose) self.__init__() if output[0] is True: return output[1] else: return None
def send(self, verbose=False): """Missing DocString :param verbose: :return: """ if len(self.blocks) == 0: print('Error: Job has no blocks') self.fillBlocks() # Set folder if empty: if not "folders" in self.data: self.data["folders"] = dict() # Try to set output folder from files: for block in self.blocks: if "files" in block.data and len(block.data["files"]): self.data["folders"]["output"] = os.path.dirname( block.data["files"][0]) obj = {"job": self.data} # print(json.dumps( obj)) return afnetwork.sendServer(json.dumps(obj), True, verbose)
def send(self, verbose=False): """Missing DocString :param verbose: :return: """ if len(self.blocks) == 0: print('Error: Job has no blocks') self.fillBlocks() # Set folder if empty: if not "folders" in self.data: self.data["folders"] = dict() # Try to set output folder from files: for block in self.blocks: if "files" in block.data and len(block.data["files"]): self.data["folders"]["output"] = os.path.dirname( block.data["files"][0]) obj = {"job": self.data} # print(json.dumps( obj)) return afnetwork.sendServer(json.dumps(obj), verbose)
Parser.add_option('-c', '--cycles', dest='cycles', type ='int', default=1, help='Cycles for operation repeat') Parser.add_option('-t', '--time', dest='time', type ='float', default=-1, help='Sleep time between cycles') Parser.add_option('-V', '--verbose', dest='verbose', action='store_true', default=False, help='Verbose mode') (Options, Args) = Parser.parse_args() if len( Args ) < 1: print('Send file to Afanasy server.') print('Usage: %s file' % sys.argv[0]) sys.exit(1) File = Args[0] if not os.path.isfile( File): print('File not founded:') print( File) sys.exit(1) file = open( File, 'rb') data = file.read( os.path.getsize( File)) file.close for i in range( 0, Options.cycles): status, answer = afnetwork.sendServer( data, Options.recv, Options.verbose) if not status: sys.exit(1) if Options.recv and answer: print( answer) if Options.time > 0: time.sleep( Options.time)
Options, Args = Parser.parse_args() if len(Args) < 1: print('Send file to Afanasy server.') print('Usage: %s file' % sys.argv[0]) sys.exit(1) File = Args[0] if not os.path.isfile(File): print('File not found:') print(File) sys.exit(1) with open(File, 'rb') as f: data = f.read(os.path.getsize(File)) for i in range(0, Options.cycles): status, answer = afnetwork.sendServer(data, Options.verbose) if not status: sys.exit(1) if answer: print(answer) if Options.time > 0: time.sleep(Options.time)