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

GO SDK for DHCP based NSX-T segment #61

Merged
merged 27 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/client/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ func (n *NetworksAPIService) CreateNetwork(
) (models.CreateNetworkResponse, error) {
var networksResp models.CreateNetworkResponse
if v, _ := parseVersion("5.4.4"); v <= n.Client.getVersion() {
networkReq.Network.NetworkPool.Pool = networkReq.Network.PoolID
networkReq.Network.PoolID = 0
// network Pool is not required for DHCP
if networkReq.Network.NetworkPool != nil {
networkReq.Network.NetworkPool.Pool = networkReq.Network.PoolID
networkReq.Network.PoolID = 0
}
}
manjunath-batakurki marked this conversation as resolved.
Show resolved Hide resolved
networkAPI := &api{
compatibleVersion: "5.2.13",
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/networks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func TestNetworksAPIService_UpdateNetwork(t *testing.T) {
networkID: 1,
request: models.CreateNetworkRequest{
Network: models.CreateNetwork{
Name: "test_net",
Name: "tf_net",
},
},
},
Expand All @@ -264,7 +264,7 @@ func TestNetworksAPIService_UpdateNetwork(t *testing.T) {
m.EXPECT().prepareRequest(gomock.Any(), path, method,
models.CreateNetworkRequest{
Network: models.CreateNetwork{
Name: "test_net",
Name: "tf_net",
},
},
headers, url.Values{}, url.Values{}, "", nil).Return(req, nil)
Expand Down
4 changes: 2 additions & 2 deletions pkg/models/dhcp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type GetNetworkDhcpServers struct {
type GetNetworkDhcpServerResp struct {
ID int `json:"id" tf:"id,computed"`
DateCreated time.Time `json:"dateCreated"`
ProviderID string `json:"providerId"`
ProviderID string `json:"providerId" tf:"provider_id,computed"`
LastUpdated time.Time `json:"lastUpdated"`
LeaseTime int `json:"leaseTime"`
Name string `json:"name"`
Expand Down Expand Up @@ -62,7 +62,7 @@ type GetSpecificNetworkDhcpServer struct {
type GetSpecificNetworkDhcpServerResp struct {
ID int `json:"id" tf:"id,computed"`
DateCreated time.Time `json:"dateCreated"`
ProviderID string `json:"providerId"`
ProviderID string `json:"providerId" tf:"provider_id,computed"`
LastUpdated time.Time `json:"lastUpdated"`
LeaseTime int `json:"leaseTime"`
Name string `json:"name"`
Expand Down
35 changes: 28 additions & 7 deletions pkg/models/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,58 @@ type CreateNetwork struct {
Description string `json:"description,omitempty" tf:"description"`
DisplayName string `json:"displayName,omitempty" tf:"display_name"`
CloudID int `json:"-" tf:"cloud_id"`
GroupID string `json:"-" tf:"group_id"`
TypeID int `json:"-" tf:"type_id"`
PoolID int `json:"pool,omitempty" tf:"pool_id"`
PoolID int `json:"pool,omitempty"`
NetworkDomainID int `json:"-" tf:"domain_id"`
Site IDStringModel `json:"site,omitempty"`
Type IDModel `json:"type,omitempty"`
NetworkDomain *IDModel `json:"networkDomain,omitempty"`
NetworkProxy *IDModel `json:"networkProxy,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you remove these ? We still have support for Static Pool Networks. Did the story say that we need to remove static pool networks anywhere ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

NetworkServer IDModel `json:"networkServer,omitempty"`
NetworkPool PoolModel `json:"networkPool,omitempty"`
NetworkPool *PoolModel `json:"networkPool,omitempty"`
NetworkProxyID int `json:"-" tf:"proxy_id"`
ProxyID int `json:"-" tf:"proxy_id"`
SearchDomains string `json:"searchDomains,omitempty" tf:"search_domains"`
Cidr string `json:"cidr,omitempty" tf:"cidr"`
Gateway string `json:"gateway,omitempty" tf:"gateway"`
DNSPrimary string `json:"dnsPrimary,omitempty" tf:"primary_dns"`
DNSSecondary string `json:"dnsSecondary,omitempty" tf:"secondary_dns"`
Config *CreateNetworkConfig `json:"config,omitempty" tf:"config,sub"`
Active bool `json:"active" tf:"active"`
Copy link
Contributor

Choose a reason for hiding this comment

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

my only worry about changing the tf fields is that it could break the existing automation if any of the teams have used ? what is the need to change the tf fields which were already existing ? Please have a good explanation about this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Use can create both DHCP and Static Networks. Ideally he should be able to create one at a time. Please add necessary validations for the same.
https://turbo-fortnight-4dcdc26d.pages.github.io/#tag/Networks/operation/CreatesANetwork

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated the proper model for both DHCP and Static Networks.

DhcpServer bool `json:"dhcpServer"`
ScanNetwork bool `json:"scanNetwork" tf:"scan_network"`
AllowStaticOverride bool `json:"allowStaticOverride" tf:"allow_static_override"`
AppURLProxyBypass bool `json:"applianceUrlProxyBypass,omitempty" tf:"appliance_url_proxy_bypass"`
NoProxy string `json:"noProxy,omitempty" tf:"no_proxy"`
ScopeID string `json:"scopeId,omitempty" tf:"scode_id"`
GroupID string `json:"-" tf:"group_id"`
ConnectedGateway string `json:"connectedGateway,omitempty" tf:"connected_gateway"`
VlanIDs string `json:"vlanIDs,omitempty" tf:"vlan_ids"`
DhcpServer bool `json:"dhcpServer" tf:"dhcp_enabled"`
TfDhcpNetwork *CreateDhcpNetwork `json:"-" tf:"dhcp_network,sub"`
TfStaticNetwork *CreateStaticNetwork `json:"-" tf:"static_network,sub"`
Config CreateNetworkConfig `json:"config"`
ResourcePermissions NetworkResPermission `json:"-" tf:"resource_permissions,sub"`
}

type CreateDhcpNetwork struct {
SubnetIPManagementType string `json:"-" tf:"dhcp_type"`
SubnetIPServerID string `json:"-" tf:"dhcp_server"`
SubnetDhcpServerAddress string `json:"-" tf:"dhcp_server_address"`
DhcpRange string `json:"-" tf:"dhcp_range"`
SubnetDhcpLeaseTime string `json:"-" tf:"dhcp_lease_time"`
}

type CreateStaticNetwork struct {
PoolID int `json:"-" tf:"pool_id"`
}

type CreateNetworkConfig struct {
ConnectedGateway string `json:"connectedGateway,omitempty" tf:"connected_gateway"`
VlanIDs string `json:"vlanIDs,omitempty" tf:"vlan_ids"`
ConnectedGateway string `json:"connectedGateway,omitempty"`
VlanIDs string `json:"vlanIDs,omitempty"`
SubnetIPManagementType string `json:"subnetIpManagementType"`
SubnetIPServerID string `json:"subnetIpServerId"`
SubnetDhcpServerAddress string `json:"subnetDhcpServerAddress"`
DhcpRange string `json:"dhcpRange"`
SubnetDhcpLeaseTime string `json:"subnetDhcpLeaseTime"`
Copy link
Contributor

Choose a reason for hiding this comment

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

why is lease time a string ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes

}

type GetNetworkTypesResponse struct {
Expand Down