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

Changes to support SDN virtualnetwork #273

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/text v0.20.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand All @@ -53,14 +53,15 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/sys v0.27.0 // indirect
google.golang.org/protobuf v1.35.1
google.golang.org/protobuf v1.35.2
)

replace (
github.com/Azure/go-autorest v11.1.2+incompatible => github.com/Azure/go-autorest/autorest v0.10.0
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.1.0
github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
github.com/hashicorp/go-retryablehttp => github.com/hashicorp/go-retryablehttp v0.7.7
github.com/microsoft/moc => github.com/microsoft/moc v0.24.3-0.20241122180939-7e7083078716
github.com/miekg/dns => github.com/miekg/dns v1.1.25
github.com/nats-io/nkeys => github.com/nats-io/nkeys v0.4.6
golang.org/x/crypto => golang.org/x/crypto v0.26.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/microsoft/moc v0.24.1 h1:NQu1hfB6W2vPGwQXupVIjBbzAimYjPt4V0/vMwTvJNI=
github.com/microsoft/moc v0.24.1/go.mod h1:pQsX7kxEXbFCx0LX2fiR3okJ5dnBtCtZJRW+R8pOA2Q=
github.com/microsoft/moc v0.24.3-0.20241122180939-7e7083078716 h1:E7HPsGQ7VYNOyb+8JvtNUJBka2IC5yutG/P1AIwVTM8=
github.com/microsoft/moc v0.24.3-0.20241122180939-7e7083078716/go.mod h1:nvYz7yZT6x+rRx/aEkswVTI2sa8AyAG9mZmWvXHk8cw=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down Expand Up @@ -167,8 +167,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 h1:XVhgTWWV3kGQlwJHR3upFWZeTsei6Oks1apkZSeonIE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f h1:C1QccEa9kUwvMgEUORqQD9S17QesQijxjZ84sO82mfo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
Expand All @@ -179,8 +179,8 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
11 changes: 8 additions & 3 deletions services/network/logicalnetwork/logicalnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func getWssdLogicalNetwork(c *network.LogicalNetwork) (*wssdcloudnetwork.Logical
if c.LogicalNetworkPropertiesFormat.MacPoolName != nil {
wssdnetwork.MacPoolName = *c.LogicalNetworkPropertiesFormat.MacPoolName
}

if c.LogicalNetworkPropertiesFormat.NetworkVirtualizationEnabled != nil {
wssdnetwork.NetworkVirtualizationEnabled = *c.LogicalNetworkPropertiesFormat.NetworkVirtualizationEnabled
}
}

return wssdnetwork, nil
Expand Down Expand Up @@ -189,9 +193,10 @@ func getLogicalNetwork(c *wssdcloudnetwork.LogicalNetwork) *network.LogicalNetwo
ID: &c.Id,
Version: &c.Status.Version.Number,
LogicalNetworkPropertiesFormat: &network.LogicalNetworkPropertiesFormat{
Subnets: getNetworkSubnets(c.Subnets),
Statuses: status.GetStatuses(c.GetStatus()),
MacPoolName: &c.MacPoolName,
Subnets: getNetworkSubnets(c.Subnets),
Statuses: status.GetStatuses(c.GetStatus()),
MacPoolName: &c.MacPoolName,
NetworkVirtualizationEnabled: &c.NetworkVirtualizationEnabled,
},
Tags: tags.ProtoToMap(c.Tags),
}
Expand Down
2 changes: 2 additions & 0 deletions services/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@ type LogicalNetworkPropertiesFormat struct {
ProvisioningState *string `json:"provisioningState,omitempty"`
// State - State
Statuses map[string]*string `json:"statuses"`
// NetworkVirtualizationEnabled - Denotes if this lnet can be used as overlay for a vnet
NetworkVirtualizationEnabled *bool `json:"networkVirtualizationEnabled,omitempty"`
}

// LogicalNetwork defines the structure of an LNET
Expand Down
81 changes: 78 additions & 3 deletions services/network/networkinterface/networkinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package networkinterface

import (
"strings"

"github.com/microsoft/moc-sdk-for-go/services/network"
"github.com/microsoft/moc/pkg/errors"
"github.com/microsoft/moc/pkg/status"
Expand All @@ -11,6 +13,13 @@ import (
wssdcommonproto "github.com/microsoft/moc/rpc/common"
)

const (
LNET_PREFIX = "logicalnetworks"
LNET_PREFIX_LEGACY = "logicalnetwork"
VNET_PREFIX = "virtualnetworks"
SUBNET_PREFIX = "subnets"
)

// Conversion functions from network interface to wssdcloud network interface
func getWssdNetworkInterface(c *network.Interface, group string) (*wssdcloudnetwork.NetworkInterface, error) {
if c == nil || c.InterfacePropertiesFormat == nil {
Expand Down Expand Up @@ -114,9 +123,21 @@ func getWssdNetworkInterfaceIPConfig(ipConfig *network.InterfaceIPConfiguration,
return nil, errors.Wrapf(errors.InvalidConfiguration, "Missing Subnet Reference")
}

wssdipconfig := &wssdcloudnetwork.IpConfiguration{
Subnetid: *ipConfig.Subnet.ID,
wssdipconfig := &wssdcloudnetwork.IpConfiguration{}

subnet, err := getWssdSubnetReference(ipConfig.Subnet.ID)

if err != nil {
return nil, err
}

if subnet != nil {
wssdipconfig.Subnet = subnet
} else {
// for backward compat
wssdipconfig.Subnetid = *ipConfig.Subnet.ID
}

if ipConfig.PrivateIPAddress != nil {
wssdipconfig.Ipaddress = *ipConfig.PrivateIPAddress
}
Expand Down Expand Up @@ -189,13 +210,18 @@ func getNetworkIpConfig(wssdcloudipconfig *wssdcloudnetwork.IpConfiguration) *ne
ipconfig := &network.InterfaceIPConfiguration{
InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{
PrivateIPAddress: &wssdcloudipconfig.Ipaddress,
Subnet: &network.APIEntityReference{ID: &wssdcloudipconfig.Subnetid},
Gateway: &wssdcloudipconfig.Gateway,
PrefixLength: &wssdcloudipconfig.Prefixlength,
Primary: &wssdcloudipconfig.Primary,
},
}

if wssdcloudipconfig.Subnet != nil {
ipconfig.Subnet = getQualifiedSubnetReference(wssdcloudipconfig.Subnet)
} else {
ipconfig.Subnet = &network.APIEntityReference{ID: &wssdcloudipconfig.Subnetid}
}

if wssdcloudipconfig.NetworkSecurityGroupRef != nil {
ipconfig.InterfaceIPConfigurationPropertiesFormat.NetworkSecurityGroup = &network.SubResource{
ID: &wssdcloudipconfig.NetworkSecurityGroupRef.ResourceRef.Name,
Expand Down Expand Up @@ -232,3 +258,52 @@ func getIovSetting(vnic *wssdcloudnetwork.NetworkInterface) *bool {
}
return &isAcceleratedNetworkingEnabled
}

func getWssdSubnetReference(subnetId *string) (*wssdcommonproto.SubnetReference, error) {

// /virtualnetworks/<networkname>/subnets/<subnetname>
subnetComponents := strings.Split(*subnetId, "/")

if len(subnetComponents) != 5 {
return nil, nil
}

networkRef := &wssdcommonproto.NetworkReference{
ResourceRef: &wssdcommonproto.ResourceReference{
Name: subnetComponents[2],
},
}

if strings.EqualFold(subnetComponents[1], VNET_PREFIX) {
networkRef.NetworkType = wssdcommonproto.NetworkType_VIRTUAL_NETWORK
} else if strings.EqualFold(subnetComponents[1], LNET_PREFIX) || strings.EqualFold(subnetComponents[1], LNET_PREFIX_LEGACY) {
networkRef.NetworkType = wssdcommonproto.NetworkType_LOGICAL_NETWORK
} else {
return nil, errors.Wrapf(errors.InvalidInput, "Cannot parse network type for the vnic")
}

return &wssdcommonproto.SubnetReference{
Network: networkRef,
ResourceRef: &wssdcommonproto.ResourceReference{
Name: subnetComponents[4],
},
}, nil
}

func getQualifiedSubnetReference(subnet *wssdcommonproto.SubnetReference) *network.APIEntityReference {

var networkPrefix string

if subnet.GetNetwork().NetworkType == wssdcommonproto.NetworkType_VIRTUAL_NETWORK {
networkPrefix = VNET_PREFIX
} else {
networkPrefix = LNET_PREFIX

}

id := "/" + networkPrefix + "/" + subnet.GetNetwork().GetResourceRef().GetName() + "/subnets/" + subnet.GetResourceRef().GetName()

return &network.APIEntityReference{
ID: &id,
}
}
18 changes: 18 additions & 0 deletions services/network/virtualnetwork/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import (
// Service interface
type Service interface {
Get(context.Context, string, string) (*[]network.VirtualNetwork, error)
GetWithVersion(context.Context, string, string, string) (*[]network.VirtualNetwork, error)
CreateOrUpdate(context.Context, string, string, *network.VirtualNetwork) (*network.VirtualNetwork, error)
CreateOrUpdateWithVersion(context.Context, string, string, *network.VirtualNetwork, string) (*network.VirtualNetwork, error)
Delete(context.Context, string, string) error
DeleteWithVersion(context.Context, string, string, string) error
Precheck(ctx context.Context, group string, virtualNetworks []*network.VirtualNetwork) (bool, error)
}

Expand All @@ -39,16 +42,31 @@ func (c *VirtualNetworkClient) Get(ctx context.Context, group, name string) (*[]
return c.internal.Get(ctx, group, name)
}

// Get methods invokes the client Get method
func (c *VirtualNetworkClient) GetWithVersion(ctx context.Context, group, name, apiVersion string) (*[]network.VirtualNetwork, error) {
return c.internal.GetWithVersion(ctx, group, name, apiVersion)
}

// CreateOrUpdate methods invokes create or update on the client
func (c *VirtualNetworkClient) CreateOrUpdate(ctx context.Context, group, name string, network *network.VirtualNetwork) (*network.VirtualNetwork, error) {
return c.internal.CreateOrUpdate(ctx, group, name, network)
}

// CreateOrUpdate methods invokes create or update on the client
func (c *VirtualNetworkClient) CreateOrUpdateWithVersion(ctx context.Context, group, name string, network *network.VirtualNetwork, apiVersion string) (*network.VirtualNetwork, error) {
return c.internal.CreateOrUpdateWithVersion(ctx, group, name, network, apiVersion)
}

// Delete methods invokes delete of the network resource
func (c *VirtualNetworkClient) Delete(ctx context.Context, group, name string) error {
return c.internal.Delete(ctx, group, name)
}

// Delete methods invokes delete of the network resource
func (c *VirtualNetworkClient) DeleteWithVersion(ctx context.Context, group, name, apiVersion string) error {
return c.internal.DeleteWithVersion(ctx, group, name, apiVersion)
}

// Prechecks whether the system is able to create specified resources.
// Returns true if it is possible; or false with reason in error message if not.
func (c *VirtualNetworkClient) Precheck(ctx context.Context, group string, virtualNetworks []*network.VirtualNetwork) (bool, error) {
Expand Down
8 changes: 8 additions & 0 deletions services/network/virtualnetwork/virtualnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func getWssdVirtualNetwork(c *network.VirtualNetwork, groupName string) (*wssdcl
Servers: *c.DhcpOptions.DNSServers,
}
}

if c.AddressSpace != nil && c.AddressSpace.AddressPrefixes != nil {
wssdnetwork.Cidr = append(wssdnetwork.Cidr, *c.AddressSpace.AddressPrefixes...)
}
}

if c.Type == nil {
Expand Down Expand Up @@ -227,6 +231,7 @@ func getVirtualNetwork(c *wssdcloudnetwork.VirtualNetwork, group string) *networ
if c.Dns != nil {
dnsservers = c.Dns.Servers
}

return &network.VirtualNetwork{
Name: &c.Name,
Location: &c.LocationName,
Expand All @@ -240,6 +245,9 @@ func getVirtualNetwork(c *wssdcloudnetwork.VirtualNetwork, group string) *networ
DhcpOptions: &network.DhcpOptions{
DNSServers: &dnsservers,
},
AddressSpace: &network.AddressSpace{
AddressPrefixes: &c.Cidr,
},
},
Tags: tags.ProtoToMap(c.Tags),
}
Expand Down
Loading
Loading