def removeFirewallClass(self, firewall_class_id): """Removes a firewall class""" session = getSessionE(self._session_id) try: # Retrieve the current record res = session.query("SELECT * FROM firewall_class WHERE " \ "firewall_class_id=%s", (firewall_class_id)) fclass = res[0] session.begin("Remove firewall class: %s'" % \ fclass["firewall_class_name"]) outputDir = session.revision.getConfigBase() path = "services/firewall/%s" % fclass["firewall_class_name"] # Remove the file client.svn_client_delete(["%s/%s" % (outputDir, path)], True, session.revision.ctx, session.revision.pool) # Update the database record session.execute("DELETE FROM firewall_class WHERE " \ "firewall_class_id=%s", (firewall_class_id)) # Commit session.commit() except: # Rollback session.rollback() # Error (etype, value, tb) = sys.exc_info() log_error("Could not remove firewall class: %s" % value, (etype, value, tb)) raise firewall_error(value) return True
def updateFirewallClass(self, details): """Updates a firewall class""" session = getSessionE(self._session_id) # Validate the classname if not re.match("^[\w]*$", details["firewall_class_name"]): raise firewall_error("Invalid firewall class name") if "firewall_class_id" not in details.keys(): raise firewall_error("firewall class ID must be specified") try: session.begin("Updating firewall class: %s'" % \ details["firewall_class_name"]) outputDir = session.revision.getConfigBase() # Retrieve the current record res = session.query("SELECT * FROM firewall_class WHERE " \ "firewall_class_id=%s", (details["firewall_class_id"])) fclass = res[0] classname = fclass["firewall_class_name"] if "firewall_class_name" in details.keys(): if details["firewall_class_name"] != classname: # Class name has changed oldfilename = "%s/services/firewall/%s" % \ (outputDir, classname) client.svn_client_delete([oldfilename], True, session.revision.ctx, session.revision.pool) classname = details["firewall_class_name"] # Save the file, replacing any CFLF sequences with LF outputDir = session.revision.getConfigBase() path = "services/firewall/%s" % classname fp = open("%s/%s" % (outputDir, path), "w") fp.write(details["contents"].replace("\r\n", "\n")) fp.close() details["file_path"] = path # Update the database record props = ["firewall_class_name", "description", "file_path"] sql, values = buildUpdateFromDict("firewall_class", props, details, "firewall_class_id", details["firewall_class_id"]) session.execute(sql, values) # Commit session.commit() except: # Rollback session.rollback() # Error (etype, value, tb) = sys.exc_info() log_error("Could not update firewall class: %s" % value, (etype, value, tb)) raise firewall_error(value) return True