Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference between Start and Record Start? #41

Closed
OzNetNerd opened this issue Oct 26, 2016 · 8 comments
Closed

Difference between Start and Record Start? #41

OzNetNerd opened this issue Oct 26, 2016 · 8 comments

Comments

@OzNetNerd
Copy link

OzNetNerd commented Oct 26, 2016

Hi there,

I've recently started looking into Ansible and in the process came across your project. I'd love to contribute once I get up and running. In the meantime I've been going through some of the code and was wondering what is the difference between "Start" and "Record Start", e.g as seen in the cisco_ios_show_cdp_neighbors_detail.template file.

I found an explanation for "Record" in this blog post but am yet to find one for "Record Start".

Thanks in advance.

@GGabriele
Copy link
Contributor

Hi,
Record Start is not one full "action", but you can see it like the action Record + the state Start. This means that if something matches ^${SOFTWARE_VERSION} it will be recorded before to get back to the Start state.

@OzNetNerd
Copy link
Author

Thank you for the response. It appears that I'm misunderstanding the code. According to the documentation, "The FSM starts in state Start, so this label is mandatory and the template will not parse without it".

Q1) Can you explain why it is necessary for the CDP code to have three 'Start' states?

Q2) Why does the GetVersion state transition have a record action but the ParseIP state transition doesn't?

@GGabriele
Copy link
Contributor

Actually, the CDP code doesn't have three 'Start' states, but only one.

The Start state is this:

Start
  ^${LOCAL_HOST}[>#].
  ^Device ID: ${DESTINATION_HOST}
  ^Entry address\(es\): -> ParseIP
  ^Platform: ${PLATFORM},
  ^Interface: ${LOCAL_PORT},  Port ID \(outgoing port\): ${REMOTE_PORT}
  ^Version : -> GetVersion

Other lines like the following represent a State transition, so that if a match is found the computation goes to the specified state.

ParseIP
  ^.*IP address: ${MANAGEMENT_IP} -> Start

That said, in this particular case I think it's not necessary to have multiple states, but it often helps to make the code cleaner. Other times it may be necessary because there might be some ambiguity in the text (for example, two lines starting with IP address: x.x.x.x may be present in the same section but they may refer to something different).

Regarding your other question, the Record action is the ultimate one and you should use it when you've complete all the parsing. If you'd have added Record in the ParseIP state you'd have miss the SOFTWARE_VERSION value.

I hope this helps :)

@OzNetNerd
Copy link
Author

Thanks for the input Gabriele.

I'd love to contribute to this project but unfortunately I've got no FSM experience so your post above doesn't make a whole lot of sense to me. For example, why is a state change required? Is it necessary in order to perform a record?

I'll continue studying and am sure I'll get there. If you've got any suggested readings/documents which you think would assist me in grasping this concept I'd love to have a look.

@GGabriele
Copy link
Contributor

The nice thing about projects like this is that you only need to clone the repo to start testing and learning on your own :)

A state transition is not generally necessary in order to perform a record, but sometime it's needed. It all depends on what you want/have to parse.
Since you're just starting, I'd go with something easy. You can try to re-write some existing templates and compare outcomes :)

Take a look here:
https://code.google.com/archive/p/textfsm/wikis
https://github.com/google/textfsm

@GGabriele
Copy link
Contributor

Also, feel free to access the networking centric Slack team here: http://slack.networktocode.com/
You can ask whatever question you have there and get a pretty fast response from a pool of more than 1300 netengs :)

@GGabriele
Copy link
Contributor

@OzNetNerd do you think we can close this? Feel free to re-open or ask on Slack if you need more guidance :)

@OzNetNerd
Copy link
Author

@GGabriele, that sounds like a great idea. Let's proceed with the closure of this issue and talk further on Slack instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants