def __call__(self, target, creds, enforcer): """Check http: rules by calling to a remote server. This example implementation simply verifies that the response is exactly 'True'. """ url = ('http:' + self.match) % target data = {'target': jsonutils.dumps(target), 'credentials': jsonutils.dumps(creds)} post_data = urllib.urlencode(data) f = urllib2.urlopen(url, post_data) return f.read() == "True"
def __call__(self, target, creds, enforcer): """Check http: rules by calling to a remote server. This example implementation simply verifies that the response is exactly 'True'. """ url = ('http:' + self.match) % target data = { 'target': jsonutils.dumps(target), 'credentials': jsonutils.dumps(creds) } post_data = urllib.urlencode(data) f = urllib2.urlopen(url, post_data) return f.read() == "True"
def format(self, record): message = {'message': record.getMessage(), 'asctime': self.formatTime(record, self.datefmt), 'name': record.name, 'msg': record.msg, 'args': record.args, 'levelname': record.levelname, 'levelno': record.levelno, 'pathname': record.pathname, 'filename': record.filename, 'module': record.module, 'lineno': record.lineno, 'funcname': record.funcName, 'created': record.created, 'msecs': record.msecs, 'relative_created': record.relativeCreated, 'thread': record.thread, 'thread_name': record.threadName, 'process_name': record.processName, 'process': record.process, 'traceback': None} if hasattr(record, 'extra'): message['extra'] = record.extra if record.exc_info: message['traceback'] = self.formatException(record.exc_info) return jsonutils.dumps(message)
def format(self, record): message = { 'message': record.getMessage(), 'asctime': self.formatTime(record, self.datefmt), 'name': record.name, 'msg': record.msg, 'args': record.args, 'levelname': record.levelname, 'levelno': record.levelno, 'pathname': record.pathname, 'filename': record.filename, 'module': record.module, 'lineno': record.lineno, 'funcname': record.funcName, 'created': record.created, 'msecs': record.msecs, 'relative_created': record.relativeCreated, 'thread': record.thread, 'thread_name': record.threadName, 'process_name': record.processName, 'process': record.process, 'traceback': None } if hasattr(record, 'extra'): message['extra'] = record.extra if record.exc_info: message['traceback'] = self.formatException(record.exc_info) return jsonutils.dumps(message)
def notify(_context, message): """Notifies the recipient of the desired event given the model. Log notifications using openstack's default logging system. """ priority = message.get('priority', CONF.default_notification_level) priority = priority.lower() logger = logging.getLogger( 'dragon.openstack.common.notification.%s' % message['event_type']) getattr(logger, priority)(jsonutils.dumps(message))
def __str__(self): """Dumps a string representation of the rules.""" # Start by building the canonical strings for the rules out_rules = {} for key, value in self.items(): # Use empty string for singleton TrueCheck instances if isinstance(value, TrueCheck): out_rules[key] = '' else: out_rules[key] = str(value) # Dump a pretty-printed JSON representation return jsonutils.dumps(out_rules, indent=4)
(policy_status)) if policy_status: status = "Protected" # TODO(Oshrit): change to final else: status = "Error" LOG.debug( "workload_policy_execution_set_status %s with status %s" % (workload_action_excution.id, status)) api.workload_policy_execution_set_status( cnxt, workload_action_excution.id, status) # save workload_policy_execution log swift_conn.put_object(container_name, "workload_policy_execution.log", jsonutils.dumps(protect_statuses)) # save metadata to container swift_conn.put_object(container_name, "metadata", jsonutils.dumps(metadata)) swift_conn.put_object(container_name, "template.yaml", template_generator.get_template()) headers = {'X-Container-Meta-dr_state': 'ready'} swift_conn.post_container(container_name, headers) return policy_status def post_protect(self, cnxt, workload_action_excution): for db_action in self.actions:
try: self.post_protect(cnxt, workload_action_excution) except Exception, ex: LOG.debug(ex) LOG.debug("workload_policy protect, policy_status = %s" % (policy_status)) if policy_status: status = "Protected" # TODO(Oshrit): change to final else: status = "Error" LOG.debug("workload_policy_execution_set_status %s with status %s" % (workload_action_excution.id, status)) api.workload_policy_execution_set_status(cnxt, workload_action_excution.id, status) # save workload_policy_execution log swift_conn.put_object(container_name, "workload_policy_execution.log", jsonutils.dumps(protect_statuses)) # save metadata to container swift_conn.put_object(container_name, "metadata", jsonutils.dumps(metadata)) swift_conn.put_object(container_name, "template.yaml", template_generator.get_template()) headers = {"X-Container-Meta-dr_state": "ready"} swift_conn.post_container(container_name, headers) return policy_status def post_protect(self, cnxt, workload_action_excution): for db_action in self.actions: # instantiate action class action_obj = action.load(db_action, context=cnxt)