Skip to content

Commit

Permalink
Add skeleton code for infra migration APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
yunkon-kim committed Nov 16, 2023
1 parent f4c8cc2 commit ae3b177
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 0 deletions.
218 changes: 218 additions & 0 deletions pkg/api/rest/server/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}

////////////////////////
4 changes: 4 additions & 0 deletions pkg/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae3b177

Please sign in to comment.