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

Handle routing destinations and static addresses in API like the CLI [specific ci=Group23-VIC-Machine-Service] #6743

Merged
Merged
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
29 changes: 13 additions & 16 deletions lib/apiservers/service/restapi/handlers/vch_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func buildCreate(op trace.Operation, d *data.Data, finder *find.Finder, vch *mod
}
c.ClientNetworkName = path
c.ClientNetworkGateway = fromGateway(vch.Network.Client.Gateway)
c.ClientNetworkIP = fromNetworkAddress(vch.Network.Client.Static)
c.ClientNetworkIP = fromCIDR(&vch.Network.Client.Static)

if err := c.ProcessNetwork(&c.Data.ClientNetwork, "client", c.ClientNetworkName, c.ClientNetworkIP, c.ClientNetworkGateway); err != nil {
return nil, util.WrapError(http.StatusBadRequest, err)
Expand All @@ -250,7 +250,7 @@ func buildCreate(op trace.Operation, d *data.Data, finder *find.Finder, vch *mod
}
c.ManagementNetworkName = path
c.ManagementNetworkGateway = fromGateway(vch.Network.Management.Gateway)
c.ManagementNetworkIP = fromNetworkAddress(vch.Network.Management.Static)
c.ManagementNetworkIP = fromCIDR(&vch.Network.Management.Static)

if err := c.ProcessNetwork(&c.Data.ManagementNetwork, "management", c.ManagementNetworkName, c.ManagementNetworkIP, c.ManagementNetworkGateway); err != nil {
return nil, util.WrapError(http.StatusBadRequest, err)
Expand All @@ -267,7 +267,7 @@ func buildCreate(op trace.Operation, d *data.Data, finder *find.Finder, vch *mod
}
c.PublicNetworkName = path
c.PublicNetworkGateway = fromGateway(vch.Network.Public.Gateway)
c.PublicNetworkIP = fromNetworkAddress(vch.Network.Public.Static)
c.PublicNetworkIP = fromCIDR(&vch.Network.Public.Static)

if err := c.ProcessNetwork(&c.Data.PublicNetwork, "public", c.PublicNetworkName, c.PublicNetworkIP, c.PublicNetworkGateway); err != nil {
return nil, util.WrapError(http.StatusBadRequest, err)
Expand Down Expand Up @@ -295,6 +295,9 @@ func buildCreate(op trace.Operation, d *data.Data, finder *find.Finder, vch *mod
containerNetworks.MappedNetworks[alias] = path

address := net.ParseIP(string(cnetwork.Gateway.Address))
if cnetwork.Gateway.RoutingDestinations == nil || len(cnetwork.Gateway.RoutingDestinations) != 1 {
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error parsing network mask for container network %s: exactly one subnet must be specified", alias))
}
_, mask, err := net.ParseCIDR(string(cnetwork.Gateway.RoutingDestinations[0].CIDR))
if err != nil {
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error parsing network mask for container network %s: %s", alias, err))
Expand Down Expand Up @@ -477,18 +480,6 @@ func fromIPRanges(m *[]models.IPRange) *[]string {
return &s
}

func fromNetworkAddress(m *models.NetworkAddress) string {
if m == nil {
return ""
}

if m.IP != "" {
return string(m.IP)
}

return string(m.Hostname)
}

func fromManagedObject(op trace.Operation, finder *find.Finder, t string, m *models.ManagedObject) (string, error) {
if m == nil {
return "", nil
Expand Down Expand Up @@ -521,7 +512,13 @@ func fromGateway(m *models.Gateway) string {
return ""
}

return fmt.Sprintf("%s:%s", // TODO (#6715): what if RoutingDestinations is empty?
if m.RoutingDestinations == nil {
return fmt.Sprintf("%s",
m.Address,
)
}

return fmt.Sprintf("%s:%s",
strings.Join(*fromIPRanges(&m.RoutingDestinations), ","),
m.Address,
)
Expand Down
15 changes: 1 addition & 14 deletions lib/apiservers/service/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -552,19 +552,6 @@
"description": "TODO: see if this can just be a string with a format that captures IPv4 and IPv6?",
"format": "ipv4"
},
"Network_Address": {
"type": "object",
"description": "TODO: see if this can just be a string with a format that captures IPv4, IPv6, and FQDNs?",
"minProperties": 1,
"maxProperties": 1,
"properties": {
"ip": { "$ref": "#/definitions/IP_Address" },
"hostname": {
"type": "string",
"format": "hostname"
}
}
},
"Gateway": {
"type": "object",
"properties": {
Expand All @@ -584,7 +571,7 @@
"type": "array",
"items": { "$ref": "#/definitions/IP_Address" }
},
"static": { "$ref": "#/definitions/Network_Address" }
"static": { "$ref": "#/definitions/CIDR" }
}
},
"Container_Network" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,12 @@ Fail to create VCH without network
Verify Status Bad Request

Output Should Contain network


Fail to create VCH with gateway without static address
Create VCH '{"name":"%{VCH-NAME}-api-bad-gateway","compute":{"resource":{"name":"%{TEST_RESOURCE}"}},"storage":{"image_stores":["ds://%{TEST_DATASTORE}"]},"network":{"bridge":{"ip_range":"172.16.0.0/12","port_group":{"name":"%{BRIDGE_NETWORK}"}},"public":{"port_group":{"name":"${PUBLIC_NETWORK}"},"gateway":{"address":"127.0.0.1","routing_destinations":[]}}},"auth":{"server":{"generate":{"cname":"vch.example.com","organization":["VMware, Inc."],"size":{"value":2048,"units":"bits"}}},"client":{"no_tls_verify": true}}}'

Verify Return Code
Verify Status Bad Request

Output Should Contain static