Beispiel #1
0
 def create_mw(self):
     """Create a new maintenance window."""
     now = datetime.datetime.now(pytz.utc)
     data = request.get_json()
     if not data:
         return jsonify("Bad request: The request do not have a json."), 415
     maintenance = MW.from_dict(data, self.controller)
     if maintenance is None:
         return jsonify('One or more items are invalid'), 400
     if maintenance.start < now:
         return jsonify('Start in the past not allowed'), 400
     if maintenance.end <= maintenance.start:
         return jsonify('End before start not allowed'), 400
     self.scheduler.add(maintenance)
     self.maintenances[maintenance.id] = maintenance
     return jsonify({'mw_id': maintenance.id}), 201
Beispiel #2
0
 def create_mw(self):
     """Create a new maintenance window."""
     now = datetime.datetime.now(pytz.utc)
     data = request.get_json()
     if not data:
         raise UnsupportedMediaType('The request does not have a json.')
     try:
         maintenance = MW.from_dict(data, self.controller)
     except ValueError as err:
         raise BadRequest(f'{err}')
     if maintenance is None:
         raise BadRequest('One or more items are invalid')
     if maintenance.start < now:
         raise BadRequest('Start in the past not allowed')
     if maintenance.end <= maintenance.start:
         raise BadRequest('End before start not allowed')
     self.scheduler.add(maintenance)
     self.maintenances[maintenance.id] = maintenance
     return jsonify({'mw_id': maintenance.id}), 201