Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

extract ipaddresses from multiple subnet participation #767

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thuvh
Copy link

@thuvh thuvh commented Jun 23, 2021

To help us process your pull request efficiently, please include:

  • (Required) Short description of changes in the PR topic line

  • (Required) Detailed description of changes include tests and
    documentation. If the pull request contains multiple commits with
    detailed messages, refer to those instead

  • (Optional) Names of reviewers using @ sign + name


This change is Reviewable

Copy link
Contributor

@rocknes rocknes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r1.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @thuvh)


pyvcloud/vcd/gateway.py, line 204 at r1 (raw file):

            if inf.InterfaceType.text == 'uplink':
                ips = out.setdefault(inf.Name.text, [])
                for subnet_participation in inf.SubnetParticipation:

If this is not a stretched network, then this for loop will throw an exception, right?
The existing code doesn't indicate that the element inf.SubnetParticipation is an array.

Can you please test the code for the case where there is only one inf.SubnetParticipation element?

@thuvh
Copy link
Author

thuvh commented Jun 23, 2021

okie let me check

@thuvh
Copy link
Author

thuvh commented Jun 23, 2021

I think if we use /api endpoints, the results is in xml format. Then, we can use for loop in this case because SubnetParticipation may be have one or more sibling nodes.

For loop can work well with a response look like the below

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<EdgeGateway xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:ovfenv="http://schemas.dmtf.org/ovf/environment/1" xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5" xmlns:ns9="http://www.vmware.com/vcloud/versions" name="test-gw-default-2021" id="urn:vcloud:gateway:gateway-id-test" href="https://vcd.example.com/api/admin/edgeGateway/gateway-id-test" type="application/vnd.vmware.admin.edgeGateway+xml">
    <Link rel="edit" href="https://vcd.example.com/api/admin/edgeGateway/gateway-id-test" type="application/vnd.vmware.admin.edgeGateway+xml"/>
    <Link rel="edit" href="https://vcd.example.com/api/admin/edgeGateway/gateway-id-test" type="application/vnd.vmware.admin.edgeGateway+json"/>
    <Link rel="remove" href="https://vcd.example.com/api/admin/edgeGateway/gateway-id-test"/>
    <Link rel="up" href="https://vcd.example.com/api/admin/vdc/vdc-test-id" type="application/vnd.vmware.admin.vdc+xml"/>
    <Link rel="up" href="https://vcd.example.com/api/admin/vdc/vdc-test-id" type="application/vnd.vmware.admin.vdc+json"/>
    <Link rel="alternate" href="https://vcd.example.com/cloudapi/1.0.0/edgeGateways/urn:vcloud:gateway:gateway-id-test" type="application/json"/>
    <Link rel="edgeGateway:updateProperties" href="https://vcd.example.com/api/admin/edgeGateway/gateway-id-test/action/updateProperties" type="application/vnd.vmware.admin.edgeGateway+xml"/>
    <Link rel="edgeGateway:updateProperties" href="https://vcd.example.com/api/admin/edgeGateway/gateway-id-test/action/updateProperties" type="application/vnd.vmware.admin.edgeGateway+json"/>
    <Link rel="down" href="https://vcd.example.com/api/admin/edgeGateway/gateway-id-test/metadata" type="application/vnd.vmware.vcloud.metadata+xml"/>
    <Link rel="down" href="https://vcd.example.com/api/admin/edgeGateway/gateway-id-test/metadata" type="application/vnd.vmware.vcloud.metadata+json"/>
    <GatewayBackingRef>
        <gatewayId>gateway-id-test</gatewayId>
        <VCRef id="ref-id-test" type="com.vmware.vcloud.entity.nsxtmanager"/>
    </GatewayBackingRef>
    <EdgeGatewayType>NSXT_BACKED</EdgeGatewayType>
    <Configuration>
        <GatewayBackingConfig>compact</GatewayBackingConfig>
        <GatewayInterfaces>
            <GatewayInterface>
                <Name>external-network-name</Name>
                <DisplayName>external-network-name</DisplayName>
                <Network href="https://vcd.example.com/api/admin/network/external-network-id" id="urn:vcloud:network:external-network-id" name="external-network-name" type="application/vnd.vmware.admin.network+xml"/>
                <InterfaceType>uplink</InterfaceType>
                <SubnetParticipation>
                    <Gateway>gateway-ip</Gateway>
                    <Netmask>gateway-netmask</Netmask>
                    <SubnetPrefixLength>gateway-prefix</SubnetPrefixLength>
                    <IpAddress>gateway-ip</IpAddress>
                    <UseForDefaultRoute>false</UseForDefaultRoute>
                </SubnetParticipation>
                <ApplyRateLimit>false</ApplyRateLimit>
                <UseForDefaultRoute>false</UseForDefaultRoute>
                <Connected>true</Connected>
            </GatewayInterface>
            <GatewayInterface>
                <Name>default</Name>
                <DisplayName>default</DisplayName>
                <Network href="https://vcd.example.com/api/admin/network/network-id" id="urn:vcloud:network:network-id" name="default" type="application/vnd.vmware.admin.network+xml"/>
                <InterfaceType>internal</InterfaceType>
                <SubnetParticipation>
                    <Gateway>gateway-internal-ip</Gateway>
                    <Netmask>gateway-internal-netmask</Netmask>
                    <SubnetPrefixLength>gateway-internal-prefix</SubnetPrefixLength>
                    <IpAddress>gateway-internal-ip</IpAddress>
                    <UseForDefaultRoute>false</UseForDefaultRoute>
                </SubnetParticipation>
                <ApplyRateLimit>false</ApplyRateLimit>
                <UseForDefaultRoute>false</UseForDefaultRoute>
                <Connected>true</Connected>
            </GatewayInterface>
        </GatewayInterfaces>
        <HaEnabled>false</HaEnabled>
        <UseDefaultRouteForDnsRelay>false</UseDefaultRouteForDnsRelay>
        <AdvancedNetworkingEnabled>true</AdvancedNetworkingEnabled>
        <DistributedRoutingEnabled>true</DistributedRoutingEnabled>
        <FipsModeEnabled>false</FipsModeEnabled>
        <EdgeClusterConfiguration>
            <PrimaryEdgeCluster href="https://vcd.example.com/cloudapi/1.0.0/edgeClusters/urn:vcloud:edgeCluster:edge-cluster-id" id="urn:vcloud:edgeCluster:edge-cluster-id" name="edge-cluster-name" type="application/json"/>
        </EdgeClusterConfiguration>
    </Configuration>
</EdgeGateway>


@thuvh thuvh requested a review from rocknes June 24, 2021 01:58
Copy link
Author

@thuvh thuvh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @rocknes)


pyvcloud/vcd/gateway.py, line 204 at r1 (raw file):

Previously, rocknes wrote…

If this is not a stretched network, then this for loop will throw an exception, right?
The existing code doesn't indicate that the element inf.SubnetParticipation is an array.

Can you please test the code for the case where there is only one inf.SubnetParticipation element?

I tested with only one inf.SubnetParticipation element and comment in github

Copy link
Author

@thuvh thuvh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @rocknes)


pyvcloud/vcd/gateway.py, line 204 at r1 (raw file):

Previously, thuvh (Hoai-Thu Vuong) wrote…

I tested with only one inf.SubnetParticipation element and comment in github

Done.

Copy link
Author

@thuvh thuvh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @rocknes)

Copy link
Author

@thuvh thuvh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r1.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @rocknes)

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

Successfully merging this pull request may close these issues.

2 participants