Skip to content

Commit

Permalink
Merge pull request #998 from jihoon-seo/211126_Update_gRPC_codes_2
Browse files Browse the repository at this point in the history
Update gRPC codes (2)
  • Loading branch information
seokho-son authored Dec 6, 2021
2 parents 9743a84 + 5e87635 commit f0839d7
Show file tree
Hide file tree
Showing 14 changed files with 1,671 additions and 834 deletions.
45 changes: 45 additions & 0 deletions src/api/grpc/cbadm/cmd/commonresource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cmd

import (
"github.com/spf13/cobra"
)

// ===== [ Constants and Variables ] =====

// ===== [ Types ] =====

// ===== [ Implementations ] =====

// ===== [ Private Functions ] =====

// ===== [ Public Functions ] =====

// NewCommonResourceCmd : "cbadm commonresource *" (for CB-Spider)
func NewCommonResourceCmd() *cobra.Command {

commonResourceCmd := &cobra.Command{
Use: "commonresource",
Short: "This is a manageable command for common resources",
Long: "This is a manageable command for common resources",
}

// Adds the commands for application.
commonResourceCmd.AddCommand(NewCommonResourceLoadCmd())

return commonResourceCmd
}

// NewCommonResourceLoadCmd : "cbadm commonresource load"
func NewCommonResourceLoadCmd() *cobra.Command {

loadCmd := &cobra.Command{
Use: "load",
Short: "Load common resources into the namespace 'common'.",
Long: "Load common resources into the namespace 'common'.",
Run: func(cmd *cobra.Command, args []string) {
SetupAndRun(cmd, args)
},
}

return loadCmd
}
65 changes: 65 additions & 0 deletions src/api/grpc/cbadm/cmd/defaultresource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cmd

import (
"github.com/cloud-barista/cb-tumblebug/src/api/grpc/logger"
"github.com/spf13/cobra"
)

// ===== [ Constants and Variables ] =====

// ===== [ Types ] =====

// ===== [ Implementations ] =====

// ===== [ Private Functions ] =====

// ===== [ Public Functions ] =====

// NewDefaultResourceCmd : "cbadm defaultresource *" (for CB-Spider)
func NewDefaultResourceCmd() *cobra.Command {

defaultResourceCmd := &cobra.Command{
Use: "defaultresource",
Short: "This is a manageable command for default resources",
Long: "This is a manageable command for default resources",
}

// Adds the commands for application.
defaultResourceCmd.AddCommand(NewDefaultResourceLoadCmd())

return defaultResourceCmd
}

// NewDefaultResourceLoadCmd : "cbadm defaultresource load"
func NewDefaultResourceLoadCmd() *cobra.Command {

loadCmd := &cobra.Command{
Use: "load",
Short: "Load default resources into the namespace 'default'.",
Long: "Load default resources into the namespace 'default'.",
Run: func(cmd *cobra.Command, args []string) {
logger := logger.NewLogger()
if nameSpaceID == "" {
logger.Error("failed to validate --ns parameter")
return
} else if resourceType == "" {
logger.Error("failed to validate --resourceType parameter")
return
} //else if connConfigName == "" {
// logger.Error("failed to validate --connConfigName parameter")
// return
// }
logger.Debug("--ns parameter value : ", nameSpaceID)
logger.Debug("--resourceType parameter value : ", resourceType)
logger.Debug("--connConfigName parameter value : ", connConfigName)

SetupAndRun(cmd, args)
},
}

loadCmd.PersistentFlags().StringVarP(&nameSpaceID, "ns", "", "", "namespace id")
loadCmd.PersistentFlags().StringVarP(&resourceType, "resourceType", "", "", "resource type [all, vnet, sg, sshkey]")
loadCmd.PersistentFlags().StringVarP(&connConfigName, "connConfigName", "", "", "connection config name (optional)")

return loadCmd
}
16 changes: 14 additions & 2 deletions src/api/grpc/cbadm/cmd/gclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func SetupAndRun(cmd *cobra.Command, args []string) {
defer ns.Close()
}

if cmd.Parent().Name() == "image" || cmd.Parent().Name() == "network" || cmd.Parent().Name() == "securitygroup" || cmd.Parent().Name() == "keypair" || cmd.Parent().Name() == "spec" {
if cmd.Parent().Name() == "image" || cmd.Parent().Name() == "network" || cmd.Parent().Name() == "securitygroup" || cmd.Parent().Name() == "keypair" || cmd.Parent().Name() == "spec" || cmd.Parent().Name() == "commonresource" || cmd.Parent().Name() == "defaultresource" {
// MCIR API
mcir = tb_api.NewMCIRManager()
err = mcir.SetConfigPath(configFile)
Expand Down Expand Up @@ -157,7 +157,7 @@ func SetupAndRun(cmd *cobra.Command, args []string) {
ns.SetInType(inType)
ns.SetOutType(outType)
}
if cmd.Parent().Name() == "image" || cmd.Parent().Name() == "network" || cmd.Parent().Name() == "securitygroup" || cmd.Parent().Name() == "keypair" || cmd.Parent().Name() == "spec" {
if cmd.Parent().Name() == "image" || cmd.Parent().Name() == "network" || cmd.Parent().Name() == "securitygroup" || cmd.Parent().Name() == "keypair" || cmd.Parent().Name() == "spec" || cmd.Parent().Name() == "commonresource" || cmd.Parent().Name() == "defaultresource" {
mcir.SetInType(inType)
mcir.SetOutType(outType)
}
Expand Down Expand Up @@ -354,6 +354,18 @@ func SetupAndRun(cmd *cobra.Command, args []string) {
case "update":
result, err = mcir.UpdateSpec(inData)
}
case "commonresource":
switch cmd.Name() {
case "load":
result, err = mcir.LoadCommonResource()
}
case "defaultresource":
switch cmd.Name() {
case "load":
result, err = mcir.LoadDefaultResourceByParam(nameSpaceID, resourceType, connConfigName)
// case "delete":
// result, err = mcir.DeleteDefaultResource()
}
case "mcis":
switch cmd.Name() {
case "create":
Expand Down
2 changes: 2 additions & 0 deletions src/api/grpc/cbadm/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func NewRootCmd() *cobra.Command {
rootCmd.AddCommand(NewKeypairCmd())
rootCmd.AddCommand(NewSpecCmd())
rootCmd.AddCommand(NewMcisCmd())
rootCmd.AddCommand(NewCommonResourceCmd())
rootCmd.AddCommand(NewDefaultResourceCmd())

rootCmd.AddCommand(NewYamlApplyCmd())
rootCmd.AddCommand(NewYamlGetCmd())
Expand Down
Loading

0 comments on commit f0839d7

Please sign in to comment.