def __init__(self, session, entity_ids, refresh_all, single): """ Initialise a request for the named IDs. :param session: Haystack HTTP session object. :param entity_ids: A list of IDs to request. :param refresh_all: Refresh all entities, ignore existing content. """ self._log = session._log.getChild("get_entity") super(GetEntityOperation, self).__init__(session, single) self._entity_ids = set( map(lambda r: r.name if isinstance(r, hszinc.Ref) else r, entity_ids)) self._todo = self._entity_ids.copy() self._refresh_all = refresh_all self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("cache_checked", "init", "read"), ("read_done", "read", "done"), ("exception", "*", "done"), ], callbacks={ "onenterread": self._do_read, "onenterdone": self._do_done }, )
def __init__(self, agent): package_version = 'unknown' try: package_version = pkg_resources.get_distribution('instana').version except pkg_resources.DistributionNotFound: pass logger.info( "Stan is on the scene. Starting Instana instrumentation version: %s" % package_version) logger.debug("initializing fsm") self.agent = agent self.fsm = f.Fysom({ "events": [("lookup", "*", "found"), ("announce", "found", "announced"), ("ready", "announced", "good2go")], "callbacks": { "onlookup": self.lookup_agent_host, "onannounce": self.announce_sensor, "onready": self.agent.start, "onchangestate": self.printstatechange } }) self.timer = t.Timer(5, self.fsm.lookup) self.timer.daemon = True self.timer.name = "Startup" self.timer.start()
def __init__(self, actor, logLevel=logging.INFO): self.actor = actor self.logger = logging.getLogger('cryomode') self.delayedEvent = None callbacks = dict([(f'on{mode}', self.modeChangeCB) for mode in self.validModes]) events = [{'name': 'toOffline', 'src': ['unknown', 'pumpdown', 'cooldown', 'operation', 'warmup', 'bakeout', 'standby'], 'dst': 'offline'}, {'name': 'toPumpdown', 'src': ['offline'], 'dst': 'pumpdown'}, {'name': 'toBakeout', 'src': ['offline', 'pumpdown'], 'dst': 'bakeout'}, {'name': 'toCooldown', 'src': ['offline', 'pumpdown'], 'dst': 'cooldown'}, {'name': 'toOperation', 'src': ['offline', 'cooldown'], 'dst': 'operation'}, {'name': 'toWarmup', 'src': ['cooldown', 'operation'], 'dst': 'warmup'}] for name, delay in self.standbyTime.items(): goEvent = f'go{name}' callbacks[f'on{name}'] = partial(self.standby, delay, goEvent) [delayedEvent] = [event for event in events if event['name'] == name] events.append(dict(name=goEvent, src='standby', dst=delayedEvent['dst'])) delayedEvent['dst'] = 'standby' self.mode = fysom.Fysom({'initial': 'unknown', 'events': events, 'callbacks': callbacks }) self.actor.models[self.actor.name].keyVarDict['turboSpeed'].addCallback(self.turboAtSpeed)
def __init__(self, session, retries=0): """ Attempt to log in to the VRT WideSky server. The procedure is as follows: POST to auth_dir URI: Headers: Accept: application/json Authorization: Basic [BASE64:"[ID]:[SECRET]"] Content-Type: application/json Body: { username: "******", password: "******", grant_type: "password" } EXPECT reply: Headers: Content-Type: application/json Body: { access_token: ..., refresh_token: ..., expires_in: ..., token_type: ... } :param session: Haystack HTTP session object. :param retries: Number of retries permitted in case of failure. """ super(WideskyAuthenticateOperation, self).__init__() self._auth_headers = { 'Authorization': (u'Basic %s' % base64.b64encode( ':'.join([session._client_id, session._client_secret]).encode('utf-8') ).decode('us-ascii') ).encode('us-ascii'), 'Accept': 'application/json', 'Content-Type': 'application/json', } self._auth_body = json.dumps({ 'username': session._username, 'password': session._password, 'grant_type': 'password', }).encode('utf-8') self._session = session self._retries = retries self._auth_result = None self._state_machine = fysom.Fysom( initial='init', final='done', events=[ # Event Current State New State ('do_login', ['init', 'failed'], 'login'), ('login_done', 'login', 'done'), ('exception', '*', 'failed'), ('retry', 'failed', 'login'), ('abort', 'failed', 'done'), ], callbacks={ 'onenterlogin': self._do_login, 'onenterfailed': self._do_fail_retry, 'onenterdone': self._do_done, })
def __init__(self, session, entity_ids, refresh_all, single): """ Initialise a request for the named IDs. :param session: Haystack HTTP session object. :param entity_ids: A list of IDs to request. :param refresh_all: Refresh all entities, ignore existing content. """ self._log = session._log.getChild('get_entity') super(GetEntityOperation, self).__init__(session, single) self._entity_ids = set(map(lambda r : r.name \ if isinstance(r, hszinc.Ref) else r, entity_ids)) self._todo = self._entity_ids.copy() self._refresh_all = refresh_all self._state_machine = fysom.Fysom( initial='init', final='done', events=[ # Event Current State New State ('cache_checked', 'init', 'read'), ('read_done', 'read', 'done'), ('exception', '*', 'done'), ], callbacks={ 'onenterread': self._do_read, 'onenterdone': self._do_done, })
def __init__(self): # ROS rospy.init_node("gait_state_manager", anonymous=True) self.gait_state_text_pub = rospy.Publisher("gait_state_text", jsk_rviz_plugins.msg.OverlayText, queue_size=1) rospy.Service('call_gait_state_event', hrpsys_ros_bridge_jvrc.srv.StringRequest, self.__callGaitStateEvent) # Finite State Machine : document `pydoc fysom` self.fsm = fysom.Fysom({ 'initial': 'biped standby', 'events' : [ {'name': 'biped walk', 'src': 'biped standby', 'dst': 'biped walking'}, {'name': 'biped stop', 'src': 'biped walking', 'dst': 'biped standby'}, {'name': 'to quadruped', 'src': 'biped standby', 'dst': 'quadruped transforming'}, {'name': 'finish quadruped', 'src': 'quadruped transforming', 'dst': 'quadruped standby'}, {'name': 'to biped', 'src': 'quadruped standby', 'dst': 'biped transforming'}, {'name': 'finish biped', 'src': 'biped transforming', 'dst': 'biped standby'}, {'name': 'quadruped walk', 'src': 'quadruped standby', 'dst': 'quadruped walking'}, {'name': 'quadruped stop', 'src': 'quadruped walking', 'dst': 'quadruped standby'} ] }) # ??? I don't know why, but this works. self.fsm.onchangestate = self.__change_state_cb for dst in self.fsm.get_all_state(): for src in self.fsm.get_all_state(): self.fsm.add_event({'events':[{'name': dst, 'src': src, 'dst': dst}]}) self.fsm.fatal_event = [] self.fsm.warn_event = ['biped walk', 'to quadruped', 'to biped', 'quadruped walk']
def __init__(self, session, filter_expr, limit, single): """ Initialise a request for the named IDs. :param session: Haystack HTTP session object. :param filter_expr: Filter expression. :param limit: Maximum number of entities to fetch. """ self._log = session._log.getChild('find_entity') super(FindEntityOperation, self).__init__(session, single) self._filter_expr = filter_expr self._limit = limit self._state_machine = fysom.Fysom( initial='init', final='done', events=[ # Event Current State New State ('go', 'init', 'read'), ('read_done', 'read', 'done'), ('exception', '*', 'done'), ], callbacks={ 'onenterdone': self._do_done, })
def __init__(self, session, filter_expr, limit, single): """ Initialise a request for the named IDs. :param session: Haystack HTTP session object. :param filter_expr: Filter expression. :param limit: Maximum number of entities to fetch. """ self._log = session._log.getChild("find_entity") super(FindEntityOperation, self).__init__(session, single) self._filter_expr = filter_expr self._limit = limit self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("go", "init", "read"), ("read_done", "read", "done"), ("exception", "*", "done"), ], callbacks={"onenterdone": self._do_done}, )
def __init__(self, session, retries=2): """ Attempt to log in to the Skyspark server. :param session: Haystack HTTP session object. :param retries: Number of retries permitted in case of failure. """ super(SkysparkAuthenticateOperation, self).__init__() self._retries = retries self._session = session self._cookie = None self._nonce = None self._username = None self._user_salt = None self._digest = None self._login_uri = '%s/auth/%s/api?%s' % \ (session._client.uri, session._project, session._username) self._state_machine = fysom.Fysom( initial='init', final='done', events=[ # Event Current State New State ('get_new_session', 'init', 'newsession'), ('do_login', 'newsession', 'login'), ('login_done', 'login', 'done'), ('exception', '*', 'failed'), ('retry', 'failed', 'newsession'), ('abort', 'failed', 'done'), ], callbacks={ 'onenternewsession': self._do_new_session, 'onenterlogin': self._do_login, 'onenterfailed': self._do_fail_retry, 'onenterdone': self._do_done, })
def __init__(self, session, columns, rng, tz, frame_format): """ Read the series data and return it. :param session: Haystack HTTP session object. :param columns: IDs of historical point objects to read. :param rng: Range to read from 'point' :param tz: Timezone to translate timezones to. May be None. :param frame_format: What format to present the frame in. """ super(HisReadFrameOperation, self).__init__() self._log = session._log.getChild('his_read_frame') if frame_format not in (self.FORMAT_LIST, self.FORMAT_DICT, self.FORMAT_FRAME): raise ValueError('Unrecognised frame_format %s' % frame_format) if (frame_format == self.FORMAT_FRAME) and (not HAVE_PANDAS): raise NotImplementedError('pandas not available.') # Convert the columns to a list of tuples. strip_ref = lambda r: r.name if isinstance(r, hszinc.Ref) else r if isinstance(columns, dict): # Ensure all are strings to references columns = [(str(c), strip_ref(r)) for c, r in columns.items()] else: # Translate to a dict: columns = [(strip_ref(c), c) for c in columns] self._session = session self._columns = columns self._range = hszinc.dump_scalar(rng, mode=hszinc.MODE_ZINC) self._tz = _resolve_tz(tz) self._frame_format = frame_format self._data_by_ts = {} self._todo = set([c[0] for c in columns]) self._state_machine = fysom.Fysom( initial='init', final='done', events=[ # Event Current State New State ('probe_multi', 'init', 'probing'), ('do_multi_read', 'probing', 'multi_read'), ('all_read_done', 'multi_read', 'postprocess'), ('do_single_read', 'probing', 'single_read'), ('all_read_done', 'single_read', 'postprocess'), ('process_done', 'postprocess', 'done'), ('exception', '*', 'done'), ], callbacks={ 'onenterprobing': self._do_probe_multi, 'onentermulti_read': self._do_multi_read, 'onentersingle_read': self._do_single_read, 'onenterpostprocess': self._do_postprocess, 'onenterdone': self._do_done, })
def __init__(self, session, point, series, tz): """ Write the series data to the point. :param session: Haystack HTTP session object. :param point: ID of historical 'point' object to write. :param series: Series data to be written to the point. :param tz: If not None, a datetime.tzinfo instance for this write. """ super(HisWriteSeriesOperation, self).__init__() # We've either been given an Entity instance or a string/reference # giving the name of an entity. if isinstance(point, string_types) or isinstance(point, hszinc.Ref): # We have the name of an entity, we'll need to fetch it. self._entity_id = point self._point = None else: # We have an entity. self._point = point self._entity_id = point.id self._session = session self._series = series self._tz = _resolve_tz(tz) self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("have_tz", "init", "write"), ("have_point", "init", "get_point_tz"), ("need_point", "init", "get_point"), ("have_point", "get_point", "get_point_tz"), ("have_tz", "get_point_tz", "write"), ("need_equip", "get_point_tz", "get_equip"), ("have_equip", "get_equip", "get_equip_tz"), ("have_tz", "get_equip_tz", "write"), ("need_site", "get_equip_tz", "get_site"), ("have_site", "get_site", "get_site_tz"), ("have_tz", "get_site_tz", "write"), ("write_done", "write", "done"), ("exception", "*", "done"), ], callbacks={ "onenterget_point": self._do_get_point, "onenterget_point_tz": self._do_get_point_tz, "onenterget_equip": self._do_get_equip, "onenterget_equip_tz": self._do_get_equip_tz, "onenterget_site": self._do_get_site, "onenterget_site_tz": self._do_get_site_tz, "onenterwrite": self._do_write, "onenterdone": self._do_done, }, )
def initialize_fsm(): return fysom.Fysom({ 'initial': 'startup', 'final': 'end', 'events': [{ 'name': 'saw_divider', 'src': ['quiz_entry', 'video_entry', 'exercise_entry', 'new_playlist'], 'dst': 'divider_entry' }, { 'name': 'saw_video', 'src': [ 'divider_entry', 'video_entry', 'exercise_entry', 'quiz_entry', 'new_playlist' ], 'dst': 'video_entry' }, { 'name': 'saw_exercise', 'src': [ 'new_playlist', 'quiz_entry', 'divider_entry', 'video_entry', 'exercise_entry' ], 'dst': 'exercise_entry' }, { 'name': 'saw_quiz', 'src': ['exercise_entry', 'video_entry'], 'dst': 'quiz_entry', }, { 'name': 'saw_new_playlist', 'src': ['startup', 'video_entry', 'quiz_entry', 'exercise_entry'], 'dst': 'new_playlist', }, { 'name': 'eof', 'src': ['video_entry', 'quiz_entry', 'exercise_entry'], 'dst': 'end', }], 'callbacks': { 'onnew_playlist': new_playlist, 'oneof': eof, 'onsaw_divider': saw_divider, 'onsaw_video': saw_misc_entry, 'onsaw_exercise': saw_misc_entry, 'onsaw_quiz': saw_misc_entry, } })
def get_default_fsm(self, path): """Get node fsm for node, if not exists it will create the default fsm :param path: the path :return: the fsm :raise: ValueError for the root node [] """ if path == []: raise ValueError('There should be no state machine for the root') node = self.root_node.get_node_safe(path=path) return node.props.setdefault(SE_FSM, fysom.Fysom(FSM_NODE_CONFIG))
def __init__(self, session, retries=0): """ Attempt to log in to the Niagara 4 server. :param session: Haystack HTTP session object. :param retries: Number of retries permitted in case of failure. """ super(Niagara4ScramAuthenticateOperation, self).__init__() self._retries = retries self._session = session self._cookie = None self._nonce = None self._username = None self._user_salt = None self._digest = None self._algorithm = None self._handshake_token = None self._server_first_msg = None self._server_nonce = None self._server_salt = None self._server_iterations = None self._auth_token = None self._auth = None self._login_uri = '%s' % \ (session._client.uri) self._state_machine = fysom.Fysom( initial='init', final='done', events=[ # Event Current State New State ('get_new_session', 'init', 'newsession'), ('do_prelogin', 'newsession', 'prelogin'), ('do_first_msg', 'prelogin', 'first_msg'), ('do_second_msg', 'first_msg', 'second_msg'), ('do_validate_login', 'second_msg', 'validate_login'), ('login_done', 'validate_login', 'done'), ('exception', '*', 'failed'), ('retry', 'failed', 'newsession'), ('abort', 'failed', 'done'), ], callbacks={ 'onenternewsession': self._do_new_session, 'onenterprelogin': self._do_prelogin, 'onenterfirst_msg': self._do_first_msg, 'onentersecond_msg': self._do_second_msg, 'onentervalidate_login': self._do_validate_login, 'onenterfailed': self._do_fail_retry, 'onenterdone': self._do_done, })
def __init__(self, session, retries=0): """ Attempt to log in to the Niagara 4 server. :param session: Haystack HTTP session object. :param retries: Number of retries permitted in case of failure. """ super(Niagara4ScramAuthenticateOperation, self).__init__() self._retries = retries self._session = session self._cookie = None self._nonce = None self._username = None self._user_salt = None self._digest = None self._algorithm = None self._handshake_token = None self._server_first_msg = None self._server_nonce = None self._server_salt = None self._server_iterations = None self._auth_token = None self._auth = None self._login_uri = "%s" % (session._client.uri) self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("get_new_session", "init", "newsession"), ("do_prelogin", "newsession", "prelogin"), ("do_first_msg", "prelogin", "first_msg"), ("do_second_msg", "first_msg", "second_msg"), ("do_validate_login", "second_msg", "validate_login"), ("login_done", "validate_login", "done"), ("exception", "*", "failed"), ("retry", "failed", "newsession"), ("abort", "failed", "done"), ], callbacks={ "onenternewsession": self._do_new_session, "onenterprelogin": self._do_prelogin, "onenterfirst_msg": self._do_first_msg, "onentersecond_msg": self._do_second_msg, "onentervalidate_login": self._do_validate_login, "onenterfailed": self._do_fail_retry, "onenterdone": self._do_done, }, )
def __init__(self, cfg=None, initial=None, events=None, callbacks=None, final=None, **kwargs): """ Constructor. It creates the Fysom object. """ if cfg is None: cfg = {} self._fysom = fysom.Fysom(cfg, initial, events, callbacks, final) super().__init__(**kwargs)
def __init__(self, session, uri, retries=2, cache=False): """ Initialise a request for the authenticating with the given URI and arguments. It also contains the state machine for reconnection if needed. :param session: Haystack HTTP session object. :param uri: Possibly partial URI relative to the server base address to perform a query. No arguments shall be given here. :param retries: Number of retries permitted in case of failure. :param cache: Whether or not to cache this result. If True, the result is cached by the session object. """ super(BaseAuthOperation, self).__init__() self._retries = retries self._session = session self._uri = uri self._headers = {} self._cache = cache self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("auth_ok", "init", "check_cache"), ("auth_not_ok", "init", "auth_attempt"), ("auth_ok", "auth_attempt", "check_cache"), ("auth_not_ok", "auth_attempt", "auth_failed"), ("auth_failed", "auth_attempt", "done"), ("cache_hit", "check_cache", "done"), ("cache_miss", "check_cache", "submit"), ("response_ok", "submit", "done"), ("exception", "*", "failed"), ("retry", "failed", "init"), ("abort", "failed", "done"), ], callbacks={ "onretry": self._check_auth, "onenterauth_attempt": self._do_auth_attempt, "onenterauth_failed": self._do_auth_failed, "onentercheck_cache": self._do_check_cache, "onentersubmit": self._do_submit, "onenterfailed": self._do_fail_retry, "onenterdone": self._do_done, }, )
def __init__(self, session, features, cache=True): """ Initialise a request for the grid with the given URI and arguments. :param session: Haystack HTTP session object. :param features: Iterable of features to check for. :param cache: Whether or not to use cache for this check. """ super(HasFeaturesOperation, self).__init__() self._log = session._log.getChild("has_features") self._session = session self._features = set(features) self._cache = cache # Needed feature data. If there are no extensions involved, just # compare the features to the op names to see if they're present. self._need_about = False self._need_formats = False self._need_ops = any([("/" not in feature) for feature in self._features]) # Retrieved feature data self._about = None self._about_data = {} self._formats = None self._formats_data = {} self._ops = None self._ops_data = {} self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("go", "init", "get_about"), ("about_done", "get_about", "get_formats"), ("formats_done", "get_formats", "get_ops"), ("ops_done", "get_ops", "check_features"), ("checked", "check_features", "done"), ("exception", "*", "done"), ], callbacks={ "onenterget_about": self._do_get_about, "onenterget_formats": self._do_get_formats, "onenterget_ops": self._do_get_ops, "onentercheck_features": self._do_check_features, "onenterdone": self._do_done, }, )
def __init__(self, session, features, cache=True): """ Initialise a request for the grid with the given URI and arguments. :param session: Haystack HTTP session object. :param features: Iterable of features to check for. :param cache: Whether or not to use cache for this check. """ super(HasFeaturesOperation, self).__init__() self._log = session._log.getChild('has_features') self._session = session self._features = set(features) self._cache = cache # Needed feature data. If there are no extensions involved, just # compare the features to the op names to see if they're present. self._need_about = False self._need_formats = False self._need_ops = any([('/' not in feature) \ for feature in self._features]) # Retrieved feature data self._about = None self._about_data = {} self._formats = None self._formats_data = {} self._ops = None self._ops_data = {} self._state_machine = fysom.Fysom( initial='init', final='done', events=[ # Event Current State New State ('go', 'init', 'get_about'), ('about_done', 'get_about', 'get_formats'), ('formats_done', 'get_formats', 'get_ops'), ('ops_done', 'get_ops', 'check_features'), ('checked', 'check_features', 'done'), ('exception', '*', 'done'), ], callbacks={ 'onenterget_about': self._do_get_about, 'onenterget_formats': self._do_get_formats, 'onenterget_ops': self._do_get_ops, 'onentercheck_features': self._do_check_features, 'onenterdone': self._do_done, })
def __init__(self, session, uri, retries=2, cache=False,): """ Initialise a request for the authenticating with the given URI and arguments. It also contains the state machine for reconnection if needed. :param session: Haystack HTTP session object. :param uri: Possibly partial URI relative to the server base address to perform a query. No arguments shall be given here. :param retries: Number of retries permitted in case of failure. :param cache: Whether or not to cache this result. If True, the result is cached by the session object. """ super(BaseAuthOperation, self).__init__() self._retries = retries self._session = session self._uri = uri self._headers = {} self._cache = cache self._state_machine = fysom.Fysom( initial='init', final='done', events=[ # Event Current State New State ('auth_ok', 'init', 'check_cache'), ('auth_not_ok', 'init', 'auth_attempt'), ('auth_ok', 'auth_attempt', 'check_cache'), ('auth_not_ok', 'auth_attempt', 'auth_failed'), ('auth_failed', 'auth_attempt', 'done'), ('cache_hit', 'check_cache', 'done'), ('cache_miss', 'check_cache', 'submit'), ('response_ok', 'submit', 'done'), ('exception', '*', 'failed'), ('retry', 'failed', 'init'), ('abort', 'failed', 'done'), ], callbacks={ 'onretry': self._check_auth, 'onenterauth_attempt': self._do_auth_attempt, 'onenterauth_failed': self._do_auth_failed, 'onentercheck_cache': self._do_check_cache, 'onentersubmit': self._do_submit, 'onenterfailed': self._do_fail_retry, 'onenterdone': self._do_done, })
def __init__(self, session, point, rng, tz, series_format): """ Read the series data and return it. :param session: Haystack HTTP session object. :param point: ID of historical 'point' object to read. :param rng: Range to read from 'point' :param tz: Timezone to translate timezones to. May be None. :param series_format: What format to present the series in. """ super(HisReadSeriesOperation, self).__init__() if series_format not in ( self.FORMAT_LIST, self.FORMAT_DICT, self.FORMAT_SERIES, ): raise ValueError("Unrecognised series_format %s" % series_format) if (series_format == self.FORMAT_SERIES) and (not HAVE_PANDAS): raise NotImplementedError("pandas not available.") if isinstance(rng, slice): rng = ",".join([ hszinc.dump_scalar(p, mode=hszinc.MODE_ZINC) for p in (rng.start, rng.stop) ]) self._session = session self._point = point self._range = hszinc.dump_scalar(rng, mode=hszinc.MODE_ZINC) self._tz = _resolve_tz(tz) self._series_format = series_format self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("go", "init", "read"), ("read_done", "read", "done"), ("exception", "*", "done"), ], callbacks={ "onenterread": self._do_read, "onenterdone": self._do_done }, )
def __init__(self, name, spec): """ Create an FSM from a collection of YAML specs """ self.event_stack = [] self.name = name initial = spec["initial"] events = spec["events"] event_list = [] for name, event_spec in events.iteritems(): ev = dict(event_spec) ev["name"] = name event_list.append(ev) fysom_spec = {'initial': initial, 'events': event_list} self.fsm = fysom.Fysom(fysom_spec, trace=True) logger.info(json.dumps({'type': 'fsm_created', 'name': self.name})) # attach event handlers for name, event_spec in events.iteritems(): if "before" in event_spec: self.fsm.__dict__['onbefore%s' % name] = lambda x, y=event_spec[ "before"]: self.fire_event(y) if "after" in event_spec: self.fsm.__dict__[ 'onafter%s' % name] = lambda x, y=event_spec["after"]: self.fire_event(y) # attach state handlers if "state_callbacks" in spec: self.state_callbacks = spec["state_callbacks"] for state, callbacks in self.state_callbacks.iteritems(): if "enter" in callbacks: self.fsm.__dict__['onenter%s' % state] = lambda x, y=callbacks[ "enter"]: self.fire_event(y) if "exit" in callbacks: self.fsm.__dict__['onleave%s' % state] = lambda x, y=callbacks[ "exit"]: self.fire_event(y) if "reenter" in callbacks: self.fsm.__dict__['onreenter%s' % state] = lambda x, y=callbacks[ "reenter"]: self.fire_event(y)
def __init__(self, session, retries=0): """ Attempt to log in to the Niagara AX server. :param session: Haystack HTTP session object. :param uri: Possibly partial URI relative to the server base address to perform a query. No arguments shall be given here. :param expect_format: Request that the grid be sent in the given format. :param args: Dictionary of key-value pairs to be given as arguments. :param multi_grid: Boolean indicating if we are to expect multiple grids or not. If True, then the operation will _always_ return a list, otherwise, it will _always_ return a single grid. :param raw_response: Boolean indicating if we should try to parse the result. If True, then we should just pass back the raw HTTPResponse object. :param retries: Number of retries permitted in case of failure. """ super(NiagaraAXAuthenticateOperation, self).__init__() self._retries = retries self._session = session self._cookies = {} self._auth = BasicAuthenticationCredentials(session._username, session._password) self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("get_new_session", "init", "newsession"), ("do_login", "newsession", "login"), ("login_done", "login", "done"), ("exception", "*", "failed"), ("retry", "failed", "newsession"), ("abort", "failed", "done"), ], callbacks={ "onenternewsession": self._do_new_session, "onenterlogin": self._do_login, "onenterfailed": self._do_fail_retry, "onenterdone": self._do_done, }, )
def __init__(self, session, entities, single): """ :param session: Haystack HTTP session object. :param entities: A list of entities to create. """ self._log = session._log.getChild('create_entity') super(CreateEntityOperation, self).__init__(session, single) self._new_entities = entities self._state_machine = fysom.Fysom( initial='init', final='done', events=[ # Event Current State New State ('send_create', 'init', 'create'), ('read_done', 'create', 'done'), ('exception', '*', 'done'), ], callbacks={ 'onenterdone': self._do_done, })
def __init__(self, session, entities, single): """ :param session: Haystack HTTP session object. :param entities: A list of entities to create. """ self._log = session._log.getChild("create_entity") super(CreateEntityOperation, self).__init__(session, single) self._new_entities = entities self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("send_create", "init", "create"), ("read_done", "create", "done"), ("exception", "*", "done"), ], callbacks={"onenterdone": self._do_done}, )
def __init__(self, session, new_password, **kwargs): super(WideSkyPasswordChangeOperation, self).__init__(session=session, uri="user/updatePassword", **kwargs) self._new_password = new_password self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("send_update", "init", "update"), ("update_done", "update", "done"), ("exception", "*", "done"), ], callbacks={ "onsend_update": self._do_submit, "onenterdone": self._do_done }, )
def __init__(self, agent): log.info("Stan is on the scene. Starting Instana instrumentation version", get_distribution('instana').version) log.debug("initializing fsm") self.agent = agent self.fsm = f.Fysom({ "events": [ ("lookup", "*", "found"), ("announce", "found", "announced"), ("ready", "announced", "good2go")], "callbacks": { "onlookup": self.lookup_agent_host, "onannounce": self.announce_sensor, "onready": self.start_metric_reporting, "onchangestate": self.printstatechange}}) timer = t.Timer(2, self.fsm.lookup) timer.daemon = True timer.name = "Startup" timer.start()
def __init__(self, entity, updates): """ Initialise a request for the named IDs. :param session: Haystack HTTP session object. """ super(EntityTagUpdateOperation, self).__init__(result_copy=False) self._log = entity._session._log.getChild('update_tags') self._entity = entity self._updates = updates self._state_machine = fysom.Fysom( initial='init', final='done', events=[ # Event Current State New State ('do_update', 'init', 'update'), ('update_done', 'update', 'done'), ('exception', '*', 'done'), ], callbacks={ 'onenterdone': self._do_done, })
def __init__(self, session, retries=2): """ Attempt to log in to the Skyspark server. :param session: Haystack HTTP session object. :param retries: Number of retries permitted in case of failure. """ super(SkysparkAuthenticateOperation, self).__init__() self._retries = retries self._session = session self._cookie = None self._nonce = None self._username = None self._user_salt = None self._digest = None self._login_uri = "%s/auth/%s/api?%s" % ( session._client.uri, session._project, session._username, ) self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("get_new_session", "init", "newsession"), ("do_login", "newsession", "login"), ("login_done", "login", "done"), ("exception", "*", "failed"), ("retry", "failed", "newsession"), ("abort", "failed", "done"), ], callbacks={ "onenternewsession": self._do_new_session, "onenterlogin": self._do_login, "onenterfailed": self._do_fail_retry, "onenterdone": self._do_done, }, )
def __init__(self, entity, updates): """ Initialise a request for the named IDs. :param session: Haystack HTTP session object. """ super(EntityTagUpdateOperation, self).__init__(result_copy=False) self._log = entity._session._log.getChild("update_tags") self._entity = entity self._updates = updates self._state_machine = fysom.Fysom( initial="init", final="done", events=[ # Event Current State New State ("do_update", "init", "update"), ("update_done", "update", "done"), ("exception", "*", "done"), ], callbacks={"onenterdone": self._do_done}, )