Skip to content

Commit

Permalink
Add a Physical Network View
Browse files Browse the repository at this point in the history
  • Loading branch information
spjmurray committed Aug 23, 2024
1 parent 56d832a commit b8fe120
Show file tree
Hide file tree
Showing 7 changed files with 375 additions and 100 deletions.
4 changes: 2 additions & 2 deletions charts/region/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: A Helm chart for deploying Unikorn's Region Controller

type: application

version: v0.1.34
appVersion: v0.1.34
version: v0.1.35
appVersion: v0.1.35

icon: https://raw.githubusercontent.com/unikorn-cloud/assets/main/images/logos/dark-on-light/icon.png

Expand Down
38 changes: 37 additions & 1 deletion pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func (h *Handler) convertPhysicalNetwork(ctx context.Context, in *unikornv1.Phys

out := &openapi.PhysicalNetworkRead{
Metadata: conversion.ProjectScopedResourceReadMetadata(in, provisioningStatus),
Spec: &openapi.PhysicalNetworkReadSpec{
Spec: openapi.PhysicalNetworkReadSpec{
RegionId: in.Labels[constants.RegionLabel],
Prefix: in.Spec.Prefix.String(),
DnsNameservers: convertIPv4List(in.Spec.DNSNameservers),
Expand Down Expand Up @@ -550,6 +550,42 @@ func (h *Handler) convertPhysicalNetwork(ctx context.Context, in *unikornv1.Phys
return out
}

func (h *Handler) convertPhysicalNetworkList(ctx context.Context, in unikornv1.PhysicalNetworkList) openapi.PhysicalNetworksRead {
out := make(openapi.PhysicalNetworksRead, len(in.Items))

for i := range in.Items {
out[i] = *h.convertPhysicalNetwork(ctx, &in.Items[i])
}

return out
}

func (h *Handler) GetApiV1OrganizationsOrganizationIDPhysicalnetworks(w http.ResponseWriter, r *http.Request, organizationID openapi.OrganizationIDParameter) {
if err := rbac.AllowOrganizationScope(r.Context(), "physicalnetworks", identityapi.Read, organizationID); err != nil {
errors.HandleError(w, r, err)
return
}

var result unikornv1.PhysicalNetworkList

options := &client.ListOptions{
LabelSelector: labels.SelectorFromSet(map[string]string{
coreconstants.OrganizationLabel: organizationID,
}),
}

if err := h.client.List(r.Context(), &result, options); err != nil {
errors.HandleError(w, r, errors.OAuth2ServerError("unable to list physical networks").WithError(err))
return
}

slices.SortStableFunc(result.Items, func(a, b unikornv1.PhysicalNetwork) int {
return cmp.Compare(a.Name, b.Name)
})

util.WriteJSONResponse(w, r, http.StatusOK, h.convertPhysicalNetworkList(r.Context(), result))
}

func (h *Handler) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks(w http.ResponseWriter, r *http.Request, organizationID openapi.OrganizationIDParameter, projectID openapi.ProjectIDParameter, identityID openapi.IdentityIDParameter) {
if err := rbac.AllowProjectScope(r.Context(), "physicalnetworks", identityapi.Create, organizationID, projectID); err != nil {
errors.HandleError(w, r, err)
Expand Down
141 changes: 141 additions & 0 deletions pkg/openapi/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions pkg/openapi/router.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b8fe120

Please sign in to comment.