def exhibit_contained(dinosaur,percent): if dinosaur not in ['velociraptor', 'tyrannosaurus', 'guaibasaurus', 'triceratops', 'all']: return 'error' all_exhibits = set() fence_sections = {} data_model.load_from_disk() for id,node in data_model.fence_segments.items(): all_exhibits.add(node.dinosaur) fence_sections[id] = node number_up = 0 total_number = 0 for section in fence_sections.values(): if dinosaur == 'all' or section.dinosaur == dinosaur: total_number += 1 if section.state >= 0.3: number_up += 1 percent_up = int(100 * (float(number_up)/float(total_number))) if percent_up >= percent: return 'up' else: return 'down'
def _do_set(self, args): if args.scope == 'exhibit': data_model.load_from_disk() self.println('node\texhibit\t\tstatus') self.println('====\t=======\t\t======') # DATABASE_SECTION for id, node in data_model.fence_segments.items(): if node.dinosaur != args.name: continue # The node matches the requested exhibit, so make it so: if args.state == 'up' and node.enabled: self.println('Error: requested node to up is already up') break node.enabled = (args.state == 'up' ) # True for up, False for down self.println('%x\t%s\t%s' % (id, node.dinosaur, node.fence_status())) data_model.save_to_disk() elif args.scope == 'node': data_model.load_from_disk() if args.id not in data_model.fence_segments: self.println('error') # TODO: "dump core" raise EOFError() # DATABASE_SECTION node = data_model.fence_segments[args.id] node.enabled = (args.state == 'up') # True for up, False for down data_model.save_to_disk() self.println('node\tstatus') self.println('====\t======') self.println('%x\t%s' % (node.id, node.fence_status()))
def degrade_step(): data_model.load_from_disk() for id, node in data_model.fence_segments.items(): if node.state < 1.0: print('Degrading %x' % id) node.state -= 0.067 data_model.save_to_disk()
def degrade_segment(index): if index >= 97 or index < 0: return 'bad' else: data_model.load_from_disk() node = list(data_model.fence_segments.values())[index] node.state -= 0.067 data_model.save_to_disk() return 'done'
def _do_resync(self, args): # The only option, currently, is `alloc node <id> <val>` # so we know that's been validated. # DATABASE_SECTION data_model.load_from_disk() if args.id not in data_model.fence_segments: self.println('error') conn.close() # TODO: "dump core" raise EOFError() # Now we know val, and id, are both ok. node = data_model.fence_segments[args.id] node.resync() data_model.save_to_disk() self.println('node\tstatus\tcondition') self.println('====\t======\t=========') self.println('%x\t%s\t%0.3f' % (node.id, node.fence_status(), node.state))
def _do_show(self, args): all_exhibits = set() fence_sections = {} data_model.load_from_disk() for id, node in data_model.fence_segments.items(): all_exhibits.add(node.dinosaur) fence_sections[id] = node if args.command == 'all': self.println('node\texhibit\t\tstatus') self.println('====\t=======\t\t======') for section in fence_sections.values(): self.println( '%x\t%s\t%s' % (section.id, section.dinosaur, section.fence_status())) time.sleep(data_model.DELAY_SLEEP) elif args.command == 'exhibit': if args.name: self.println('node\tstatus') self.println('====\t======') for section in fence_sections.values(): if section.dinosaur == args.name: time.sleep(data_model.DELAY_SLEEP) self.println('%x\t%s' % (section.id, section.fence_status())) else: self.println('exhibit') self.println('=======') for exh in all_exhibits: time.sleep(data_model.DELAY_SLEEP) self.println(exh) elif args.command == 'node': if args.id: self.println('node\texhibit\t\tstatus\tcondition') self.println('====\t=======\t\t======\t=========') if args.id in fence_sections: section = fence_sections[args.id] time.sleep(data_model.DELAY_SLEEP) self.println('%x\t%s\t%s\t%0.3f' % (section.id, section.dinosaur, section.fence_status(), section.state))