def Add(self, **unused_args): """Add a task to the schedule.""" if not acl.UserIsScheduleAdmin(): self.error(404) return # new request or type changed, so show a blank form if (not self.request.POST.has_key('selectedType') or self.request.POST['type'] != self.request.POST['selectedType']): # assume new request, update type if otherwise try: if self.request.POST.has_key('type'): thetype = self.request.POST['type'] measurement = MeasurementType.GetMeasurement(thetype) else: measurement = MeasurementType.GetDefaultMeasurement() except RuntimeError, error: # occurs if someone specifies an invalid measurement type logging.warning('Type in POST is invalid: %s', error) self.error(501) return # dynamically creates a form based on the specified fields add_to_schedule_form = type( 'AddToScheduleForm', (forms.BaseForm, ), {'base_fields': self._BuildFields(measurement)})()
def Dashboard(self, **unused_args): """Main handler for the service dashboard.""" errormsg = None devices, cursor = self._GetDeviceList( cursor=self.request.get('device_cursor')) if cursor: parsed_url = list(urlparse.urlparse(self.request.url)) url_query_dict = {'device_cursor': cursor} parsed_url[4] = urllib.urlencode(url_query_dict) more_devices_link = urlparse.urlunparse(parsed_url) else: more_devices_link = None schedule = model.Task.all() schedule.order('-created') template_args = { 'user_schedule_admin': acl.UserIsScheduleAdmin(), 'devices': devices, 'schedule': schedule, 'user': users.get_current_user().email(), 'logout_link': users.create_logout_url('/'), 'more_devices_link': more_devices_link, 'error': errormsg } self.response.out.write( template.render('templates/home.html', template_args))
def Delete(self, **unused_args): """Delete a task from the schedule.""" if not acl.UserIsScheduleAdmin(): self.error(404) return errormsg = None message = None add_to_schedule_form = type('AddToScheduleForm', (forms.BaseForm, ), {'base_fields': self._BuildFields()})() task_id = self.request.get('id') task = model.Task.get_by_id(int(task_id)) if not task: errormsg = 'Task %s does not exist' % task_id else: # TODO(mdw): Do we need to wrap the following in a transaction? # First DeviceTasks that refer to this one device_tasks = model.DeviceTask.all() device_tasks.filter('task =', task) for dt in device_tasks: dt.delete() # Now delete the task itself task.delete() message = 'Task %s deleted' % task_id schedule = model.Task.all() schedule.order('-created') template_args = { 'user_schedule_admin': acl.UserIsScheduleAdmin(), 'add_form': add_to_schedule_form, 'message': message, 'error': errormsg, 'schedule': schedule, 'user': users.get_current_user().email(), 'logout_link': users.create_logout_url('/') } self.response.out.write( template.render('templates/schedule.html', template_args))
def Add(self, **unused_args): """Add a task to the schedule.""" if not acl.UserIsScheduleAdmin(): self.error(404) return if not self.request.POST: add_to_schedule_form = AddToScheduleForm() else: add_to_schedule_form = AddToScheduleForm(self.request.POST) add_to_schedule_form.full_clean() if add_to_schedule_form.is_valid(): thetype = add_to_schedule_form.cleaned_data['type'] param1 = add_to_schedule_form.cleaned_data['param1'] param2 = add_to_schedule_form.cleaned_data['param2'] param3 = add_to_schedule_form.cleaned_data['param3'] tag = add_to_schedule_form.cleaned_data['tag'] thefilter = add_to_schedule_form.cleaned_data['filter'] count = add_to_schedule_form.cleaned_data['count'] or -1 interval = add_to_schedule_form.cleaned_data['interval'] logging.info('Got TYPE: ' + thetype) task = model.Task() task.created = datetime.datetime.utcnow() task.user = users.get_current_user() task.type = thetype if tag: task.tag = tag if thefilter: task.filter = thefilter task.count = count task.interval_sec = float(interval) # Set up correct type-specific measurement parameters if task.type == 'ping': task.mparam_target = param1 task.mparam_ping_timeout_sec = param2 task.mparam_packet_size_byte = param3 elif task.type == 'traceroute': task.mparam_target = param1 task.mparam_pings_per_hop = param2 task.mparam_max_hop_count = param3 elif task.type == 'http': task.mparam_url = param1 task.mparam_method = param2 task.mparam_headers = param3 elif task.type == 'dns_lookup': task.mparam_target = param1 task.mparam_server = param2 task.put() schedule = model.Task.all() schedule.order('-created') template_args = { 'user_schedule_admin': acl.UserIsScheduleAdmin(), 'add_form': add_to_schedule_form, 'schedule': schedule, 'user': users.get_current_user().email(), 'logout_link': users.create_logout_url('/') } self.response.out.write( template.render('templates/schedule.html', template_args))
if thefilter: task.filter = thefilter task.count = count task.interval_sec = float(interval) task.priority = priority # Set up correct type-specific measurement parameters for name, value in params.items(): setattr(task, 'mparam_' + name, value) task.put() schedule = model.Task.all() schedule.order('-created') template_args = { 'user_schedule_admin': acl.UserIsScheduleAdmin(), 'add_form': add_to_schedule_form, 'schedule': schedule, 'user': users.get_current_user().email(), 'logout_link': users.create_logout_url('/') } self.response.out.write( template.render('templates/schedule.html', template_args)) def Delete(self, **unused_args): """Delete a task from the schedule.""" if not acl.UserIsScheduleAdmin(): self.error(404) return errormsg = None