[docs]classUploadSchedule(AbstractPlugin):""" This plugin accomplishes three primary objectives: 1. Upload all VM schedules to the :py:class:`ScheduleDb <firewheel.vm_resource_manager.schedule_db.ScheduleDb>`. 2. Upload the VM mapping to the :py:class:`VMMapping <firewheel.vm_resource_manager.vm_mapping.VMMapping>` database. 3. Identify all VMRs for an experiment. """
[docs]def_put_all_vm_resource_schedules(self):""" For every :py:class:`VMEndpoint <base_objects.VMEndpoint>` in the experiment, iterate over its schedule and put it in the schedule database. """sched_db=ScheduleDb()vm_mapping=VMMapping()sched_list=[]mapping_list=[]forvertinself.g.get_vertices():ifnotvert.is_decorated_by(VMEndpoint):continuetry:control_ip=Nonetry:control_ip=str(vert.control_ip)exceptAttributeError:passsched=list(vert.vm_resource_schedule.get_schedule())self.log.debug("Schedule length %d for %s",len(sched),vert.name)schedule=pickle.dumps(sched)# add required vm_resources to setforiteminsched:fordata_entryinitem.data:try:self.g.required_vm_resources.add(data_entry["filename"])exceptKeyError:# some vm_resources don't have files to uploadcontinueself.log.debug("Got schedule %s for %s",schedule,vert.name)sched_list.append({"server_name":vert.name,"text":schedule,"ip":control_ip})self.log.debug("Adding %s%s%s to VM Mapping",vert.uuid,control_ip,vert.name)mapping_list.append({"server_uuid":vert.uuid,"server_name":vert.name,"control_ip":control_ip,})exceptAttributeError:self.log.exception('No vm_resource schedule for VM "%s".',vert.name)# Batch insert into the databases for performance reasonsifsched_list:sched_db.batch_put(sched_list)vm_mapping.batch_put(mapping_list)else:self.log.warning("No vm resources scheduled")
[docs]defrun(self):""" Initialize the required VMR set and call :py:meth:`vm_resource.schedule._put_all_vm_resource_schedules` which contains the main Plugin logic. """self.g.required_vm_resources=set()self._put_all_vm_resource_schedules()