From ae3b177371655b62159654607c1d50b32af668cd Mon Sep 17 00:00:00 2001 From: Yunkon Kim Date: Thu, 16 Nov 2023 14:40:44 +0900 Subject: [PATCH] Add skeleton code for infra migration APIs --- pkg/api/rest/server/migration/migration.go | 218 +++++++++++++++++++++ pkg/api/rest/server/server.go | 4 + 2 files changed, 222 insertions(+) diff --git a/pkg/api/rest/server/migration/migration.go b/pkg/api/rest/server/migration/migration.go index a3bbc5b..105a34b 100644 --- a/pkg/api/rest/server/migration/migration.go +++ b/pkg/api/rest/server/migration/migration.go @@ -119,3 +119,221 @@ func createVMInfra(nsId string, infraModel *TbMcisDynamicReq) (TbMcisInfo, error return responseBody, nil } + +//////////////////////// + +type Network struct { + Name string `json:"name"` + Id string `json:"id"` + IPv4CIDRBlock string `json:"ipv4CidrBlock"` + IPv6CIDRBlock string `json:"ipv6CidrBlock"` +} + +type Subnet struct { + Network + ParentNetworkId string `json:"parentNetworkId"` +} + +type DummyNetwork struct { + Network + Subnets []Subnet `json:"subnets"` +} + +type MigrateNetworkRequest struct { + DummyNetwork +} + +type MigrateNetworkResponse struct { + DummyNetwork +} + +// MigrateNetwork godoc +// @Summary (Skeleton) Migrate network on a cloud platform +// @Description It migrates network on a cloud platform. Network includes name, ID, IPv4 CIDR block, IPv6 CIDR block, and so on. +// @Tags [Migration] Network +// @Accept json +// @Produce json +// @Param Network information body MigrateNetworkRequest true "Specify name, IPv4 CIDR block, etc." +// @Success 200 {object} MigrateNetworkResponse "Successfully migrated network on a cloud platform" +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /migration/infra/network [post] +func (rh *Handlers) MigrateNetwork(c echo.Context) error { + + // [Note] Input section + req := &MigrateNetworkRequest{} + if err := c.Bind(req); err != nil { + return err + } + + fmt.Printf("RequestBody: %v\n", req) + fmt.Print(req) + fmt.Print(req.DummyNetwork) + + // [Note] Process section + // Something to process here like, + // Perform some functions, + // Calls external APIs and so on + + res := &MigrateNetworkResponse{} + fmt.Print(res) + fmt.Print(res.DummyNetwork) + + // This is an intentionally created variable. + // You will have to delete this later. + var err error = nil + + // [Note] Ouput section + if err != nil { + common.CBLog.Error(err) + mapA := map[string]string{"message": err.Error()} + return c.JSON(http.StatusInternalServerError, &mapA) + } + + return c.JSON(http.StatusOK, res) + +} + +//////////////////////// + +//////////////////////// + +type Storage struct { + Name string `json:"name"` + Id string `json:"id"` + Type string `json:"type"` + Size string `json:"size"` +} + +type DummyStorage struct { + Storage + NetworkID string `json:"NetworkId"` +} + +type MigrateStorageRequest struct { + DummyStorage +} + +type MigrateStorageResponse struct { + DummyStorage +} + +// MigrateStorage godoc +// @Summary (Skeleton) Migrate storage on a cloud platform +// @Description It migrates storage on a cloud platform. Storage includes name, ID, type, size, and so on. +// @Tags [Migration] Storage +// @Accept json +// @Produce json +// @Param Storage information body MigrateStorageRequest true "Specify name, type, size, affiliated Network ID, and so on." +// @Success 200 {object} MigrateStorageResponse "Successfully migrated storage on a cloud platform" +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /migration/infra/storage [post] +func (rh *Handlers) MigrateStorage(c echo.Context) error { + + // [Note] Input section + req := &MigrateStorageRequest{} + if err := c.Bind(req); err != nil { + return err + } + + fmt.Printf("RequestBody: %v\n", req) + fmt.Print(req) + fmt.Print(req.DummyStorage) + + // [Note] Process section + // Something to process here like, + // Perform some functions, + // Calls external APIs and so on + + res := &MigrateStorageResponse{} + fmt.Print(res) + fmt.Print(res.DummyStorage) + + // This is an intentionally created variable. + // You will have to delete this later. + var err error = nil + + // [Note] Ouput section + if err != nil { + common.CBLog.Error(err) + mapA := map[string]string{"message": err.Error()} + return c.JSON(http.StatusInternalServerError, &mapA) + } + + return c.JSON(http.StatusOK, res) + +} + +//////////////////////// + +//////////////////////// + +type Instance struct { + Name string `json:"name"` + Id string `json:"id"` + Spec string `json:"type"` + OS string `json:"os"` +} + +type DummyInstance struct { + Instance + NetworkID string `json:"NetworkId"` +} + +type MigrateInstanceRequest struct { + DummyInstance +} + +type MigrateInstanceResponse struct { + DummyInstance +} + +// MigrateInstance godoc +// @Summary (Skeleton) Migrate instance on a cloud platform +// @Description It migrates instance on a cloud platform. Storage includes name, spec, OS, and so on. +// @Tags [Migration] Instance +// @Accept json +// @Produce json +// @Param Instance information body MigrateInstanceRequest true "Specify name, spec, OS, and so on." +// @Success 200 {object} MigrateInstanceResponse "Successfully migrated storage on a cloud platform" +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /migration/infra/instance [post] +func (rh *Handlers) MigrateInstance(c echo.Context) error { + + // [Note] Input section + req := &MigrateInstanceRequest{} + if err := c.Bind(req); err != nil { + return err + } + + fmt.Printf("RequestBody: %v\n", req) + fmt.Print(req) + fmt.Print(req.DummyInstance) + + // [Note] Process section + // Something to process here like, + // Perform some functions, + // Calls external APIs and so on + + res := &MigrateInstanceResponse{} + fmt.Print(res) + fmt.Print(res.DummyInstance) + + // This is an intentionally created variable. + // You will have to delete this later. + var err error = nil + + // [Note] Ouput section + if err != nil { + common.CBLog.Error(err) + mapA := map[string]string{"message": err.Error()} + return c.JSON(http.StatusInternalServerError, &mapA) + } + + return c.JSON(http.StatusOK, res) + +} + +//////////////////////// diff --git a/pkg/api/rest/server/server.go b/pkg/api/rest/server/server.go index 9d87a9f..4e921db 100644 --- a/pkg/api/rest/server/server.go +++ b/pkg/api/rest/server/server.go @@ -146,6 +146,10 @@ func RunServer(port string) { mig.POST("/infra", migHandlers.MigrateInfra) + mig.POST("/infra/network", migHandlers.MigrateInfra) + mig.POST("/infra/storage", migHandlers.MigrateInfra) + mig.POST("/infra/instance", migHandlers.MigrateInfra) + } // Route