def unregister(instance_id, cs_id, cs_ip, config=None): config = config or get_ngeo_config() assert_instance_id(instance_id, config) try: with FileLock(get_controller_config_lockfile_path(config)): controller_config_path = get_controller_config_path(config) if not exists(controller_config_path): raise ControllerAssertionError( "This Browse Server instance was not yet registered.", reason="UNBOUND" ) # TODO: controller server ID was removed? controller_config = get_controller_config(controller_config_path) assert_controller_id(cs_id, controller_config, "CONTROLLER_OTHER") assert_controller_ip(cs_ip, controller_config) # remove the controller configuration to complete unregistration os.remove(controller_config_path) except LockException: raise ControllerAssertionError( "There is currently another registration in progress.", reason="CONTROLLER_OTHER" )
def register(instance_id, instance_type, cs_id, cs_ip, config=None): config = config or get_ngeo_config() assert_instance_id(instance_id, config) assert_instance_type(instance_type) try: with FileLock(get_controller_config_lockfile_path(config)): controller_config_path = get_controller_config_path(config) if not exists(controller_config_path): create_controller_config(controller_config_path, cs_id, cs_ip) else: controller_config = get_controller_config( controller_config_path) assert_controller_id(cs_id, controller_config, "ALREADY_OTHER") assert_controller_ip(cs_ip, controller_config) # IP address and ID are the same, so raise the "ALREADY_SAME" # error. raise ControllerAssertionError( "This browse server is already registered on this " "controller server.", reason="ALREADY_SAME") except LockException: raise ControllerAssertionError( "There is currently another registration in progress.", reason="ALREADY_OTHER")
def send_report(ip_address=None, begin=None, end=None, access_logfile=None, report_logfile=None, config=None): config = config or get_ngeo_config() try: if not ip_address: ctrl_config = get_controller_config(get_controller_config_path(config)) ip_address = safe_get(ctrl_config, CONTROLLER_SERVER_SECTION, "address") except IOError: # probably no config file present, so IP cannot be determined. pass if not ip_address: raise Exception("IP address could not be determined") tree = get_report_xml(begin, end, types, access_logfile, report_logfile) req = urllib2.Request( url="http://%s/notify" % ip_address, data=etree.tostring(tree, pretty_print=True), headers={'Content-Type': 'text/xml'} ) print req.data try: urllib2.urlopen(req, timeout=10) except (urllib2.HTTPError, urllib2.URLError), e: logger.error( "Could not send report (%s): '%s'" % (type(e).__name__, str(e)) ) raise
def send_report(ip_address=None, begin=None, end=None, access_logfile=None, report_logfile=None, config=None): config = config or get_ngeo_config() try: if not ip_address: ctrl_config = get_controller_config( get_controller_config_path(config)) ip_address = safe_get(ctrl_config, CONTROLLER_SERVER_SECTION, "address") except IOError: # probably no config file present, so IP cannot be determined. pass if not ip_address: raise Exception("IP address could not be determined") tree = get_report_xml(begin, end, types, access_logfile, report_logfile) req = urllib2.Request(url="http://%s/notify" % ip_address, data=etree.tostring(tree, pretty_print=True), headers={'Content-Type': 'text/xml'}) print req.data try: urllib2.urlopen(req, timeout=10) except (urllib2.HTTPError, urllib2.URLError), e: logger.error("Could not send report (%s): '%s'" % (type(e).__name__, str(e))) raise
def register(instance_id, instance_type, cs_id, cs_ip, config=None): config = config or get_ngeo_config() assert_instance_id(instance_id, config) assert_instance_type(instance_type) try: with FileLock(get_controller_config_lockfile_path(config)): controller_config_path = get_controller_config_path(config) if not exists(controller_config_path): create_controller_config(controller_config_path, cs_id, cs_ip) else: controller_config = get_controller_config( controller_config_path ) assert_controller_id(cs_id, controller_config, "ALREADY_OTHER") assert_controller_ip(cs_ip, controller_config) # IP address and ID are the same, so raise the "ALREADY_SAME" # error. raise ControllerAssertionError( "This browse server is already registered on this " "controller server.", reason="ALREADY_SAME" ) except LockException: raise ControllerAssertionError( "There is currently another registration in progress.", reason="ALREADY_OTHER" )
def notify(summary, message, urgency=None, ip_address=None, config=None): config = config or get_ngeo_config() urgency = urgency or "INFO" if urgency not in ("INFO", "CRITICAL", "BLOCK"): raise ValueError("Invalid urgency value '%s'." % urgency) try: if not ip_address: # get the value for "notification_url" and fall back to # "address" ip_address = safe_get(config, "control", "notification_url") if not ip_address: ctrl_config = get_controller_config( get_controller_config_path(config)) logger.debug( "No 'notification_url' present. Trying to fall back to " "registered IP address.") ip_address = safe_get(ctrl_config, CONTROLLER_SERVER_SECTION, "address") except (IOError, NoSectionError): # probably no config file present, so IP cannot be determined. pass if not ip_address: # cannot log this error as we would run into an endless loop logger.info("Cannot send notification to CTRL.") return tree = E( "notifyControllerServer", E("header", E("timestamp", isotime(now())), E("instance", get_instance_id(config)), E("subsystem", "BROW"), E("urgency", urgency)), E("body", E("summary", summary), E("message", message))) if ip_address.startswith("http://") or ip_address.startswith("https://"): pass else: ip_address = "http://%s" % ip_address if not ip_address.endswith("/notify"): ip_address += "/notify" logger.info("Sending notification to CTRL at IP '%s'." % ip_address) req = urllib2.Request(url=ip_address, data=etree.tostring(tree, pretty_print=True), headers={'Content-Type': 'application/xml'}) try: urllib2.urlopen(req, timeout=1) except (urllib2.HTTPError, urllib2.URLError), e: logger.info("Error sending notification: %s" % e) logger.debug(traceback.format_exc() + "\n")
def notify(summary, message, urgency=None, ip_address=None, config=None): config = config or get_ngeo_config() urgency = urgency or "INFO" if urgency not in ("INFO", "CRITICAL", "BLOCK"): raise ValueError("Invalid urgency value '%s'." % urgency) try: if not ip_address: ctrl_config = get_controller_config(get_controller_config_path(config)) ip_address = safe_get(ctrl_config, CONTROLLER_SERVER_SECTION, "address") except IOError: # probably no config file present, so IP cannot be determined. pass if not ip_address: return tree = E("notifyControllerServer", E("header", E("timestamp", isotime(now())), E("instance", get_instance_id(config)), E("subsystem", "BROW"), E("urgency", urgency) ), E("body", E("summary", summary), E("message", message) ) ) req = urllib2.Request( url="http://%s/notify" % ip_address, data=etree.tostring(tree, pretty_print=True), headers={'Content-Type': 'text/xml'} ) try: urllib2.urlopen(req, timeout=1) except (urllib2.HTTPError, urllib2.URLError): # could not send notification. Out of options pass
def register(instance_id, instance_type, cs_id, cs_ip, config=None): config = config or get_ngeo_config() assert_instance_id(instance_id, config) assert_instance_type(instance_type) try: with FileLock(get_controller_config_lockfile_path(config)): controller_config_path = get_controller_config_path(config) if not exists(controller_config_path): create_controller_config(controller_config_path, cs_id, cs_ip) else: # TODO: controller server ID was removed? controller_config = get_controller_config(controller_config_path) assert_controller_id(cs_id, controller_config, "ALREADY_OTHER") assert_controller_ip(cs_ip, controller_config) except LockException: raise ControllerAssertionError( "There is currently another registration in progress.", reason="ALREADY_OTHER" )
def unregister(instance_id, cs_id, cs_ip, config=None): config = config or get_ngeo_config() assert_instance_id(instance_id, config) try: with FileLock(get_controller_config_lockfile_path(config)): controller_config_path = get_controller_config_path(config) if not exists(controller_config_path): raise ControllerAssertionError( "This Browse Server instance was not yet registered.", reason="UNBOUND") controller_config = get_controller_config(controller_config_path) assert_controller_id(cs_id, controller_config, "CONTROLLER_OTHER") assert_controller_ip(cs_ip, controller_config) # remove the controller configuration to complete unregistration os.remove(controller_config_path) except LockException: raise ControllerAssertionError( "There is currently another registration in progress.", reason="CONTROLLER_OTHER")
def notify(summary, message, urgency=None, ip_address=None, config=None): config = config or get_ngeo_config() urgency = urgency or "INFO" if urgency not in ("INFO", "CRITICAL", "BLOCK"): raise ValueError("Invalid urgency value '%s'." % urgency) try: if not ip_address: # get the value for "notification_url" and fall back to # "address" ip_address = safe_get( config, "control", "notification_url" ) if not ip_address: ctrl_config = get_controller_config( get_controller_config_path(config) ) logger.debug( "No 'notification_url' present. Trying to fall back to " "registered IP address." ) ip_address = safe_get( ctrl_config, CONTROLLER_SERVER_SECTION, "address" ) except (IOError, NoSectionError): # probably no config file present, so IP cannot be determined. pass if not ip_address: # cannot log this error as we would run into an endless loop logger.info("Cannot send notification to CTRL.") return tree = E("notifyControllerServer", E("header", E("timestamp", isotime(now())), E("instance", get_instance_id(config)), E("subsystem", "BROW"), E("urgency", urgency) ), E("body", E("summary", summary), E("message", message) ) ) if ip_address.startswith("http://") or ip_address.startswith("https://"): pass else: ip_address = "http://%s" % ip_address if not ip_address.endswith("/notify"): ip_address += "/notify" logger.info("Sending notification to CTRL at IP '%s'." % ip_address) req = urllib2.Request( url=ip_address, data=etree.tostring(tree, pretty_print=True), headers={'Content-Type': 'application/xml'} ) try: urllib2.urlopen(req, timeout=1) except (urllib2.HTTPError, urllib2.URLError), e: logger.info("Error sending notification: %s" % e) logger.debug(traceback.format_exc() + "\n")