-
Notifications
You must be signed in to change notification settings - Fork 373
SR-SIM classic CLI support #2916
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
base: main
Are you sure you want to change the base?
Changes from 14 commits
d55ab6b
671a78e
9805982
b58c8e5
a6ed388
8e09861
5260633
5990212
86cd6aa
860d018
27f44f0
364348f
e28985a
afdcb12
98626bb
a33069e
72e9ff8
1fb9a87
5fe9d82
530c422
c812d4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -90,30 +90,14 @@ func (c *CLab) generateAnsibleInventory(w io.Writer) error { | |||||
| } | ||||||
|
|
||||||
| for _, n := range c.Nodes { | ||||||
| kind, props := c.getAnsibleKindAndProps(n.Config()) | ||||||
| inv.Kinds[kind] = props | ||||||
|
|
||||||
| ansibleNode := &AnsibleInventoryNode{ | ||||||
| NodeConfig: n.Config(), | ||||||
| } | ||||||
|
|
||||||
| // add AnsibleKindProps to the inventory struct | ||||||
| // the ansibleKindProps is passed as a ref and is populated | ||||||
| // down below | ||||||
| ansibleKindProps := &AnsibleKindProps{} | ||||||
| inv.Kinds[n.Config().Kind] = ansibleKindProps | ||||||
|
|
||||||
| // add username and password to kind properties | ||||||
| // assumption is that all nodes of the same kind have the same credentials | ||||||
| nodeRegEntry := c.Reg.Kind(n.Config().Kind) | ||||||
| if nodeRegEntry != nil { | ||||||
| ansibleKindProps.Username = nodeRegEntry.GetCredentials().GetUsername() | ||||||
| ansibleKindProps.Password = nodeRegEntry.GetCredentials().GetPassword() | ||||||
| } | ||||||
|
|
||||||
| // add network_os to the node | ||||||
| ansibleKindProps.setNetworkOS(n.Config().Kind) | ||||||
| // add ansible_connection to the node | ||||||
| ansibleKindProps.setAnsibleConnection(n.Config().Kind) | ||||||
|
|
||||||
| inv.Nodes[n.Config().Kind] = append(inv.Nodes[n.Config().Kind], ansibleNode) | ||||||
| inv.Nodes[kind] = append(inv.Nodes[kind], ansibleNode) | ||||||
|
|
||||||
| if n.Config().Labels["ansible-group"] != "" { | ||||||
| inv.Groups[n.Config().Labels["ansible-group"]] = | ||||||
|
|
@@ -148,24 +132,39 @@ func (c *CLab) generateAnsibleInventory(w io.Writer) error { | |||||
| return err | ||||||
| } | ||||||
|
|
||||||
| // setNetworkOS sets the network_os variable for the kind. | ||||||
| func (n *AnsibleKindProps) setNetworkOS(kind string) { | ||||||
| switch kind { | ||||||
| case "nokia_srlinux", "srl": | ||||||
| n.NetworkOS = "nokia.srlinux.srlinux" | ||||||
| case "nokia_sros", "vr-sros", "nokia_srsim": | ||||||
| n.NetworkOS = "nokia.sros.md" | ||||||
| // Determine Ansible kind and properties for containerlab node | ||||||
| func (c *CLab) getAnsibleKindAndProps(cfg *clabtypes.NodeConfig) (string, *AnsibleKindProps) { | ||||||
| ansibleGroup := cfg.Kind | ||||||
| ansibleProps := &AnsibleKindProps{} | ||||||
|
|
||||||
| // Set `ansible_user` and `ansible_password` | ||||||
| // Assumption: All nodes of the same kind share same credentials | ||||||
| nodeRegEntry := c.Reg.Kind(ansibleGroup) | ||||||
| if nodeRegEntry != nil { | ||||||
| ansibleProps.Username = nodeRegEntry.GetCredentials().GetUsername() | ||||||
| ansibleProps.Password = nodeRegEntry.GetCredentials().GetPassword() | ||||||
| } | ||||||
|
|
||||||
| // Generally we use the containerlab kind for grouping in Ansible Inventory. | ||||||
| // Special case: For SROS we differentiate between classic and model-driven. | ||||||
| if cfg.Env["CLAB_SROS_CONFIG_MODE"] == "classic" { | ||||||
|
||||||
| if cfg.Env["CLAB_SROS_CONFIG_MODE"] == "classic" { | |
| if strings.EqualFold(cfg.Env["CLAB_SROS_CONFIG_MODE"], "classic") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function comment should document the special handling of classic mode SROS nodes where the ansible group name is modified from the original kind. For example: "Determine Ansible kind and properties for containerlab node. For SROS nodes with CLAB_SROS_CONFIG_MODE=classic, returns 'nokia_srsim_classic' as the kind to enable proper Ansible network_os grouping."