-
Notifications
You must be signed in to change notification settings - Fork 173
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
[specific ci=Group23-Vic-Machine-Service] syslog support added to VCH create and inspect API #6582
Changes from all commits
a3b3132
e518893
dd03e5b
17e3514
77eee58
16c412c
56fb57a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"io" | ||
"math" | ||
"net" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"path" | ||
|
@@ -79,7 +80,7 @@ func (h *VCHCreate) Handle(params operations.PostTargetTargetVchParams, principa | |
|
||
validator, err := validateTarget(params.HTTPRequest.Context(), d) | ||
if err != nil { | ||
return operations.NewPostTargetTargetVchDefault(400).WithPayload(&models.Error{Message: err.Error()}) | ||
return operations.NewPostTargetTargetVchDefault(http.StatusBadRequest).WithPayload(&models.Error{Message: err.Error()}) | ||
} | ||
|
||
c, err := buildCreate(params.HTTPRequest.Context(), d, validator.Session.Finder, params.Vch) | ||
|
@@ -115,7 +116,7 @@ func (h *VCHDatacenterCreate) Handle(params operations.PostTargetTargetDatacente | |
|
||
validator, err := validateTarget(params.HTTPRequest.Context(), d) | ||
if err != nil { | ||
return operations.NewPostTargetTargetDatacenterDatacenterVchDefault(400).WithPayload(&models.Error{Message: err.Error()}) | ||
return operations.NewPostTargetTargetDatacenterDatacenterVchDefault(http.StatusBadRequest).WithPayload(&models.Error{Message: err.Error()}) | ||
} | ||
|
||
c, err := buildCreate(params.HTTPRequest.Context(), d, validator.Session.Finder, params.Vch) | ||
|
@@ -164,17 +165,17 @@ func buildCreate(ctx context.Context, d *data.Data, finder *find.Finder, vch *mo | |
|
||
if vch != nil { | ||
if vch.Version != "" && version.String() != string(vch.Version) { | ||
return nil, util.NewError(400, fmt.Sprintf("Invalid version: %s", vch.Version)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Invalid version: %s", vch.Version)) | ||
} | ||
|
||
c.DisplayName = vch.Name | ||
|
||
// TODO: move validation to swagger | ||
if err := common.CheckUnsupportedChars(c.DisplayName); err != nil { | ||
return nil, util.NewError(400, fmt.Sprintf("Invalid display name: %s", err)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Invalid display name: %s", err)) | ||
} | ||
if len(c.DisplayName) > create.MaxDisplayNameLen { | ||
return nil, util.NewError(400, fmt.Sprintf("Invalid display name: length exceeds %d characters", create.MaxDisplayNameLen)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Invalid display name: length exceeds %d characters", create.MaxDisplayNameLen)) | ||
} | ||
|
||
debug := int(vch.Debug) | ||
|
@@ -195,10 +196,10 @@ func buildCreate(ctx context.Context, d *data.Data, finder *find.Finder, vch *mo | |
|
||
resourcePath, err := fromManagedObject(ctx, finder, "ResourcePool", vch.Compute.Resource) // TODO: Do we need to handle clusters differently? | ||
if err != nil { | ||
return nil, util.NewError(400, fmt.Sprintf("Error finding resource pool: %s", err)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error finding resource pool: %s", err)) | ||
} | ||
if resourcePath == "" { | ||
return nil, util.NewError(400, "Resource pool must be specified (by name or id)") | ||
return nil, util.NewError(http.StatusBadRequest, "Resource pool must be specified (by name or id)") | ||
} | ||
c.ComputeResourcePath = resourcePath | ||
} | ||
|
@@ -207,67 +208,67 @@ func buildCreate(ctx context.Context, d *data.Data, finder *find.Finder, vch *mo | |
if vch.Network.Bridge != nil { | ||
path, err := fromManagedObject(ctx, finder, "Network", vch.Network.Bridge.PortGroup) | ||
if err != nil { | ||
return nil, util.NewError(400, fmt.Sprintf("Error finding bridge network: %s", err)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error finding bridge network: %s", err)) | ||
} | ||
if path == "" { | ||
return nil, util.NewError(400, "Bridge network portgroup must be specified (by name or id)") | ||
return nil, util.NewError(http.StatusBadRequest, "Bridge network portgroup must be specified (by name or id)") | ||
} | ||
c.BridgeNetworkName = path | ||
c.BridgeIPRange = fromCIDR(&vch.Network.Bridge.IPRange.CIDR) | ||
|
||
if err := c.ProcessBridgeNetwork(); err != nil { | ||
return nil, util.WrapError(400, err) | ||
return nil, util.WrapError(http.StatusBadRequest, err) | ||
} | ||
} | ||
|
||
if vch.Network.Client != nil { | ||
path, err := fromManagedObject(ctx, finder, "Network", vch.Network.Client.PortGroup) | ||
if err != nil { | ||
return nil, util.NewError(400, fmt.Sprintf("Error finding client network portgroup: %s", err)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error finding client network portgroup: %s", err)) | ||
} | ||
if path == "" { | ||
return nil, util.NewError(400, "Client network portgroup must be specified (by name or id)") | ||
return nil, util.NewError(http.StatusBadRequest, "Client network portgroup must be specified (by name or id)") | ||
} | ||
c.ClientNetworkName = path | ||
c.ClientNetworkGateway = fromGateway(vch.Network.Client.Gateway) | ||
c.ClientNetworkIP = fromNetworkAddress(vch.Network.Client.Static) | ||
|
||
if err := c.ProcessNetwork(&c.Data.ClientNetwork, "client", c.ClientNetworkName, c.ClientNetworkIP, c.ClientNetworkGateway); err != nil { | ||
return nil, util.WrapError(400, err) | ||
return nil, util.WrapError(http.StatusBadRequest, err) | ||
} | ||
} | ||
|
||
if vch.Network.Management != nil { | ||
path, err := fromManagedObject(ctx, finder, "Network", vch.Network.Management.PortGroup) | ||
if err != nil { | ||
return nil, util.NewError(400, fmt.Sprintf("Error finding management network portgroup: %s", err)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error finding management network portgroup: %s", err)) | ||
} | ||
if path == "" { | ||
return nil, util.NewError(400, "Management network portgroup must be specified (by name or id)") | ||
return nil, util.NewError(http.StatusBadRequest, "Management network portgroup must be specified (by name or id)") | ||
} | ||
c.ManagementNetworkName = path | ||
c.ManagementNetworkGateway = fromGateway(vch.Network.Management.Gateway) | ||
c.ManagementNetworkIP = fromNetworkAddress(vch.Network.Management.Static) | ||
|
||
if err := c.ProcessNetwork(&c.Data.ManagementNetwork, "management", c.ManagementNetworkName, c.ManagementNetworkIP, c.ManagementNetworkGateway); err != nil { | ||
return nil, util.WrapError(400, err) | ||
return nil, util.WrapError(http.StatusBadRequest, err) | ||
} | ||
} | ||
|
||
if vch.Network.Public != nil { | ||
path, err := fromManagedObject(ctx, finder, "Network", vch.Network.Public.PortGroup) | ||
if err != nil { | ||
return nil, util.NewError(400, fmt.Sprintf("Error finding public network portgroup: %s", err)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error finding public network portgroup: %s", err)) | ||
} | ||
if path == "" { | ||
return nil, util.NewError(400, "Public network portgroup must be specified (by name or id)") | ||
return nil, util.NewError(http.StatusBadRequest, "Public network portgroup must be specified (by name or id)") | ||
} | ||
c.PublicNetworkName = path | ||
c.PublicNetworkGateway = fromGateway(vch.Network.Public.Gateway) | ||
c.PublicNetworkIP = fromNetworkAddress(vch.Network.Public.Static) | ||
|
||
if err := c.ProcessNetwork(&c.Data.PublicNetwork, "public", c.PublicNetworkName, c.PublicNetworkIP, c.PublicNetworkGateway); err != nil { | ||
return nil, util.WrapError(400, err) | ||
return nil, util.WrapError(http.StatusBadRequest, err) | ||
} | ||
} | ||
|
||
|
@@ -284,17 +285,17 @@ func buildCreate(ctx context.Context, d *data.Data, finder *find.Finder, vch *mo | |
|
||
path, err := fromManagedObject(ctx, finder, "Network", cnetwork.PortGroup) | ||
if err != nil { | ||
return nil, util.NewError(400, fmt.Sprintf("Error finding portgroup for container network %s: %s", alias, err)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error finding portgroup for container network %s: %s", alias, err)) | ||
} | ||
if path == "" { | ||
return nil, util.NewError(400, fmt.Sprintf("Container network %s portgroup must be specified (by name or id)", alias)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Container network %s portgroup must be specified (by name or id)", alias)) | ||
} | ||
containerNetworks.MappedNetworks[alias] = path | ||
|
||
address := net.ParseIP(string(cnetwork.Gateway.Address)) | ||
_, mask, err := net.ParseCIDR(string(cnetwork.Gateway.RoutingDestinations[0].CIDR)) | ||
if err != nil { | ||
return nil, util.NewError(400, fmt.Sprintf("Error parsing network mask for container network %s: %s", alias, err)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error parsing network mask for container network %s: %s", alias, err)) | ||
} | ||
containerNetworks.MappedNetworksGateways[alias] = net.IPNet{ | ||
IP: address, | ||
|
@@ -327,7 +328,7 @@ func buildCreate(ctx context.Context, d *data.Data, finder *find.Finder, vch *mo | |
} | ||
|
||
if err := common.CheckUnsupportedCharsDatastore(c.ImageDatastorePath); err != nil { | ||
return nil, util.WrapError(400, err) | ||
return nil, util.WrapError(http.StatusBadRequest, err) | ||
} | ||
|
||
if vch.Storage.VolumeStores != nil { | ||
|
@@ -339,7 +340,7 @@ func buildCreate(ctx context.Context, d *data.Data, finder *find.Finder, vch *mo | |
vs := common.VolumeStores{VolumeStores: cli.StringSlice(volumes)} | ||
volumeLocations, err := vs.ProcessVolumeStores() | ||
if err != nil { | ||
return nil, util.NewError(400, fmt.Sprintf("Error processing volume stores: %s", err)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error processing volume stores: %s", err)) | ||
} | ||
c.VolumeLocations = volumeLocations | ||
} | ||
|
@@ -367,7 +368,7 @@ func buildCreate(ctx context.Context, d *data.Data, finder *find.Finder, vch *mo | |
c.Certs.KeySize = fromValueBits(vch.Auth.Server.Generate.Size) | ||
|
||
if err := c.Certs.ProcessCertificates(c.DisplayName, c.Force, 0); err != nil { | ||
return nil, util.NewError(400, fmt.Sprintf("Error generating certificates: %s", err)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error generating certificates: %s", err)) | ||
} | ||
} else { | ||
c.Certs.CertPEM = []byte(vch.Auth.Server.Certificate.Pem) | ||
|
@@ -397,7 +398,7 @@ func buildCreate(ctx context.Context, d *data.Data, finder *find.Finder, vch *mo | |
} | ||
} | ||
if err := c.OpsCredentials.ProcessOpsCredentials(true, c.Target.User, c.Target.Password); err != nil { | ||
return nil, util.WrapError(400, err) | ||
return nil, util.WrapError(http.StatusBadRequest, err) | ||
} | ||
} | ||
|
||
|
@@ -413,10 +414,17 @@ func buildCreate(ctx context.Context, d *data.Data, finder *find.Finder, vch *mo | |
c.Proxies = fromImageFetchProxy(vch.Registry.ImageFetchProxy) | ||
_, _, err := c.Proxies.ProcessProxies() | ||
if err != nil { | ||
return nil, util.NewError(400, fmt.Sprintf("Error processing proxies: %s", err)) | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error processing proxies: %s", err)) | ||
} | ||
} | ||
} | ||
|
||
if vch.SyslogAddr != "" { | ||
c.SyslogAddr = vch.SyslogAddr.String() | ||
if err := c.ProcessSyslog(); err != nil { | ||
return nil, util.NewError(http.StatusBadRequest, fmt.Sprintf("Error processing syslog server address: %s", err)) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't you write a simple unit test to verify these new code paths? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is part of the create API handler and we haven't figured out a pattern to do unit tests on swagger handlers yet. |
||
} | ||
|
||
return c, nil | ||
|
@@ -435,7 +443,7 @@ func handleCreate(ctx context.Context, c *create.Create, validator *validate.Val | |
executor := management.NewDispatcher(validator.Context, validator.Session, nil, false) | ||
err = executor.CreateVCH(vchConfig, vConfig) | ||
if err != nil { | ||
return nil, util.NewError(500, fmt.Sprintf("Failed to create VCH: %s", err)) | ||
return nil, util.NewError(http.StatusInternalServerError, fmt.Sprintf("Failed to create VCH: %s", err)) | ||
} | ||
|
||
return nil, nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a really good change. Can you file an issue so that we remember to clean this up in the rest of the handlers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can do it in this pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixes done