Skip to content

Base modify placement port

Base functionality for modifying Placement Port services.

initial_input_form_generator(subscription_id)

Generate the initial input form for modifying a Placement Port service.

Source code in gso/workflows/placement_port/base_modify_placement_port.py
def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
    """Generate the initial input form for modifying a Placement Port service."""
    subscription = SubscriptionModel.from_subscription(subscription_id)
    product_name = subscription.product.name
    l3_interface = subscription.l3_interface  # type: ignore[attr-defined]

    class ModifyPlacementPortForm(SubmitFormPage):
        model_config = ConfigDict(title=f"Modify {product_name}")

        tt_number: TTNumber
        gs_id: str = l3_interface.gs_id
        edge_port: read_only_field(  # type: ignore[valid-type]
            EdgePort.from_subscription(l3_interface.edge_port.owner_subscription_id).description
        )
        is_tagged: bool = l3_interface.is_tagged
        vlan_id: VLAN_ID | None = l3_interface.vlan_id
        divider1: Divider = Field(None, exclude=True)
        ipv4_address: IPv4AddressType | None = l3_interface.ipv4_address
        ipv4_mask: IPv4Netmask | None = l3_interface.ipv4_mask
        ipv6_address: IPv6AddressType | None = l3_interface.ipv6_address
        ipv6_mask: IPv6Netmask | None = l3_interface.ipv6_mask
        custom_firewall_filters: bool = l3_interface.custom_firewall_filters
        divider2: Divider = Field(None, exclude=True)

        @model_validator(mode="after")
        def validate_gs_id(self) -> Self:
            """Validate the GS ID only if user has changed it and if it was not generated automatically."""
            if self.gs_id != l3_interface.gs_id:
                validate_id(self.gs_id, prefix="GS", field_name="gs_id")
            return self

    modified_input = yield ModifyPlacementPortForm

    return modified_input.model_dump()

update_subscription_model(subscription, gs_id, vlan_id, ipv4_address, ipv4_mask, ipv6_address, ipv6_mask, custom_firewall_filters=None, is_tagged=None)

Initialize the placement port subscription with the provided parameters.

Source code in gso/workflows/placement_port/base_modify_placement_port.py
@step("Modify subscription")
def update_subscription_model(
    subscription: SubscriptionModel,
    gs_id: str,
    vlan_id: VLAN_ID | None,
    ipv4_address: IPv4AddressType | None,
    ipv4_mask: IPv4Netmask | None,
    ipv6_address: IPv6AddressType | None,
    ipv6_mask: IPv6Netmask | None,
    custom_firewall_filters: bool | None = None,  # noqa: FBT001
    is_tagged: bool | None = None,  # noqa: FBT001
) -> State:
    """Initialize the placement port subscription with the provided parameters."""
    l3_interface = subscription.l3_interface  # type: ignore[attr-defined]
    l3_interface.gs_id = gs_id
    l3_interface.is_tagged = is_tagged
    l3_interface.vlan_id = vlan_id
    l3_interface.ipv4_address = ipv4_address
    l3_interface.ipv4_mask = ipv4_mask
    l3_interface.ipv6_address = ipv6_address
    l3_interface.ipv6_mask = ipv6_mask
    l3_interface.custom_firewall_filters = custom_firewall_filters
    subscription.description = f"{subscription.product.name} - {gs_id}"

    return {"subscription": subscription}