Skip to content

Add property to get module number in vertices#86

Merged
PaulWinterstein merged 3 commits intoSWR-MoIP:mainfrom
groupmsl:addModuleNumberPropertyToVertex
Feb 13, 2026
Merged

Add property to get module number in vertices#86
PaulWinterstein merged 3 commits intoSWR-MoIP:mainfrom
groupmsl:addModuleNumberPropertyToVertex

Conversation

@groupmsl
Copy link
Contributor

I've added a property to get the module number of a vertex, simply by splitting the id - a very simple addition.

I need to be able to get the module number of a vertex as I have a need to duplicate a virtual device. While I could have the required code at my end, I wonder if it would be useful to be part of the Vertex class.

@PaulWinterstein
Copy link
Collaborator

Hi @groupmsl,
thanks for the contribution 😊

The current implementation parses the vertex ID string, which does not hold up for all vertex ID structures. For example:

  • device4.1.Ethernet1.in — module is at index 1, index 2 would raise a ValueError
  • device4.SwitchingCore — only two segments → IndexError (GUI labels this as "Common")
  • device4.svi.Vlan1234.in — no numeric module at all
  • device39.cf328930-… — UUID-based module identifier
  • virtual.69.1.0 — valid for virtual devices, but follows a different ID structure than physical devices

A more robust approach would be to use gpid.pointId instead of splitting the ID string. The pointId list follows a consistent structure across all vertices:

  • [ "device4", "dev", "1", "Ethernet1" ] — physical device, module id "1"
  • [ "device4", "dev", "SwitchingCore" ] — physical device, no module
  • [ "device4", "dev", "svi", "Vlan1234" ] — physical device, module id "svi"
  • [ "virtual-69", "virt", "1", "0" ] — virtual device, module "1"

So the property could look something like this:

@property
def module_id(self) -> Optional[str]:
    """Module identifier this vertex belongs to, or None for common vertices (e.g. SwitchingCore)."""
    pid = self.gpid.pointId
    if len(pid) >= 4 and pid[1] in ("dev", "virt"):
        return pid[2]
    return None

A few notes on this approach:

  • Returns str instead of int, since the data model stores module identifiers as strings (and some are non-numeric, like "svi" or UUIDs)
  • Returns None for common vertices (e.g. SwitchingCore) instead of raising an error
  • Name module_id rather than module_number, since not all identifiers are numeric

Feel free to push an updated version — either based on this approach or an alternative that covers the edge cases above. Happy to merge once it's in!

Cheers

@groupmsl
Copy link
Contributor Author

Hi @PaulWinterstein,

Thank you for your time and detailed reply! I think your example does exactly what I need, but without the issues my original commit had. I've pushed this now, so hopefully this can be merged. I've also tested against the script I've written that requires this functionality (I'm duplicating virtual devices, while programmatically changing things like multicast addresses and labels).

Cheers, Andrew

@PaulWinterstein PaulWinterstein merged commit 417476a into SWR-MoIP:main Feb 13, 2026
4 checks passed
@PaulWinterstein
Copy link
Collaborator

Released in 0.8.0

pip install --upgrade --force-reinstall videoipath-automation-tool==0.8.0

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

Successfully merging this pull request may close these issues.

2 participants