def _putNetworkConfiguration(self, id, vm, configData): validators.validate(configData, validators.VMSettingsNetworkConfiguration) d = {} d['networkConfiguration'] = configData model.updateVM(web.ctx.veerezoDB, id, d)
def POST(self): try: config = json.loads(web.data()) validators.validate(config, validators.AddVM) tags = config.get('tags', []) image = config['image'] m = re.match('^/images/(\d+)$', image) if not m: raise ValueError('Invalid image definition') image = int(m.groups()[0]) _ = model.getImage(web.ctx.veerezoDB, image) # check for image existance image = 'image-{0}'.format(image) ramMiB = config['ramMiB'] networkConfiguration = config['networkConfiguration'] networkCards = [] validNetworkIDs = model.getNetworkIDs(web.ctx.veerezoDB, web.ctx.username) # TODO somehow support 'global' / 'shared' networks everyone may use validNetworkIDs.append(1) # TODO XXX FIXME temporary workaround to allow VMs access to the outside world without 'global' / 'share'd networks for x in config['networkCards']: if x is None: networkCards.append(None) else: m = re.match(r'^/networks/(\d+)$', x) if not m: raise ValueError('At least one networkCard has an invalid network definition.') id = int(m.groups()[0]) if id not in validNetworkIDs: raise ValueError('At least one networkCard is attached to an unknown network.') networkCards.append(id) except (ValueError, KeyError) as e: web.badrequest() return {'error': 'ValueError: {0}'.format(e.message)} # we have to add the DB entry here so that we don't get confused by the async nature of the job queue id = model.addVM(web.ctx.veerezoDB, image, ramMiB, networkCards, networkConfiguration, web.ctx.username, tags) jobIDs = [] jobIDs.append(web.ctx.postBackendJob('createDiskImages', id)) jobIDs.append(web.ctx.postBackendJob('prepareDiskImages', id, ['root', 'swap', 'data'])) addJobIDsHeader(jobIDs) url = '/vms/{0}'.format(id) web.header('Content-Location', url) web.created() d = {} d['vm'] = url return d
def validate(metaschema, instance): # Use a metaschema to validate the JSON schema rules validator = Draft4Validator(metaschema) try: validator.validate(instance) except ValidationError as error: err_msg = validation_error_to_str(error) sys.exit(err_msg) # Validate what metaschema can't validate try: validators.validate(instance, schemaValidators) except SchemaValidatorError as error: sys.exit(error)
def _handle_user_choice_validate_before_parsing(self): """Handle user choice for validating before gesture file is parsed.""" # Parse the device events. Make sure there are events. self.packets = self.parser.parse_file(self.gesture_file_name) if self.packets or self._empty_packets_is_legal_result(): # Validate this gesture and get the results. (self.new_scores, msg_list, vlogs) = validators.validate(self.packets, self.gesture, self.variation) # If the number of tracking IDs is less than the expected value, # the user probably made a wrong gesture. error = self.check_for_wrong_number_of_fingers(msg_list) if error: prompt = self._get_prompt_abnormal_gestures(error) color = 'red' else: prompt = self._prompt_next color = 'black' self.output.print_window(msg_list) self.output.buffer_report(msg_list) self.output.report_html.insert_validator_logs(vlogs) self.win.set_prompt(prompt, color=color) print prompt self._stop_record_and_post_image() else: self.win.set_prompt(self._get_prompt_no_data(), color='red')
def POST(self): try: data = json.loads(web.data()) validators.validate(data, validators.AddSSHKey) except ValueError as e: web.badrequest() return {'error': 'ValueError: {0}'.format(e)} key = data['key'] id = model.addSSHKey(web.ctx.veerezoDB, key, web.ctx.username) url = '/sshkeys/{0}'.format(id) web.header('Content-Location', url) web.created() d = {} d['sshkey'] = url return d
def count_valid_fields(line): counter = 0 data = line.split(' ') for d in data: parts = d.rstrip('\r\n\t').strip().split(':') if parts[0] in required_fields: res = validate(parts[0], parts[1]) if res: counter += 1 return counter
def POST(self): try: data = json.loads(web.data()) validators.validate(data, validators.AddNetwork) except ValueError as e: web.badrequest() return {'error': 'ValueError: {0}'.format(e.message)} devices = data.get('devices', []) tags = data.get('tags', []) id = model.addNetwork(web.ctx.veerezoDB, devices, web.ctx.username, tags) jobID = web.ctx.postBackendJob('reconfigureNetworks') addJobIDsHeader([jobID]) url = '/networks/{0}'.format(id) web.header('Content-Location', url) web.created() d = {} d['network'] = url return d
def main(): args = arguments() fngr = utilities.Fngr(prog=args.fngr, organism=args.organism, fragment=args.fragment, threshold=args.threshold, kraken_db=args.kraken_database, nt_db=args.nt_database, cores=args.cores) results = validators.validate(sources=args.outgroup, recipients=args.ingroup, gene_mean=args.insertion_mean, gene_stdev=args.insertion_stdev, contig_mean=args.contig_mean, contig_stdev=args.contig_stdev, iterations=args.iterations, fngr=fngr) utilities.user_msg('') expected = {result: compare.create_expected(results[result], args.foreign) for result in results} fngr_output = {res: [r.result for r in results[res]] for res in results} comparisons = compare.compare_each_genome(expected, fngr_output) import pprint pp = pprint.PrettyPrinter(indent =2) for i in comparisons: pp.pprint(i) pp.pprint(comparisons[i]) print('') metacomparison = compare.metacompare(comparisons) pp.pprint(metacomparison)
def _putEmulation(self, id, vm, configData): validators.validate(configData, validators.VMSettingsEmulation) d = {} d['emulation'] = configData model.updateVM(web.ctx.veerezoDB, id, d)
def POST(self): try: config = json.loads(web.data()) validators.validate(config, validators.AddVM) tags = config.get('tags', []) image = config['image'] m = re.match('^/images/(\d+)$', image) if not m: raise ValueError('Invalid image definition') image = int(m.groups()[0]) _ = model.getImage(web.ctx.veerezoDB, image) # check for image existance image = 'image-{0}'.format(image) ramMiB = config['ramMiB'] networkConfiguration = config['networkConfiguration'] networkCards = [] validNetworkIDs = model.getNetworkIDs( web.ctx.veerezoDB, web.ctx.username ) # TODO somehow support 'global' / 'shared' networks everyone may use validNetworkIDs.append( 1 ) # TODO XXX FIXME temporary workaround to allow VMs access to the outside world without 'global' / 'share'd networks for x in config['networkCards']: if x is None: networkCards.append(None) else: m = re.match(r'^/networks/(\d+)$', x) if not m: raise ValueError( 'At least one networkCard has an invalid network definition.' ) id = int(m.groups()[0]) if id not in validNetworkIDs: raise ValueError( 'At least one networkCard is attached to an unknown network.' ) networkCards.append(id) except (ValueError, KeyError) as e: web.badrequest() return {'error': 'ValueError: {0}'.format(e.message)} # we have to add the DB entry here so that we don't get confused by the async nature of the job queue id = model.addVM(web.ctx.veerezoDB, image, ramMiB, networkCards, networkConfiguration, web.ctx.username, tags) jobIDs = [] jobIDs.append(web.ctx.postBackendJob('createDiskImages', id)) jobIDs.append( web.ctx.postBackendJob('prepareDiskImages', id, ['root', 'swap', 'data'])) addJobIDsHeader(jobIDs) url = '/vms/{0}'.format(id) web.header('Content-Location', url) web.created() d = {} d['vm'] = url return d
def validate(self, value): return validators.validate(self.validators, value)
def _putNetworkCards(self, id, vm, configData): validators.validate(configData, validators.VMSettingsNetworkCards) d = {} d['networkCards'] = configData model.updateVM(web.ctx.veerezoDB, id, d)