Skip to content

Commit

Permalink
Fixed issue with trace flag, adjust unit test, describe print now obj…
Browse files Browse the repository at this point in the history
…ect name when client pass wrong name or id.
  • Loading branch information
spyroot committed Jul 12, 2021
1 parent ab82400 commit 9b43c5c
Show file tree
Hide file tree
Showing 46 changed files with 751 additions and 442 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

APP_NAME=tcactl
BINARY=tcactl
VERSION=0.6.0
VERSION=0.7.0
PLATFORMS=darwin linux windows
ARCHITECTURES=386 amd64
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test

LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD}"

default: build

clean:
$(GOCLEAN)

.PHONY: all
all: clean build_all install

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ tcactl tool provider.

* Ability to leverage tosca policy to scale, upgrade CNF or VNF.

* tcactl has build in Tosca parser, tool allow you apply transformation
* tcactl has build in Tosca parser, tool allow you to apply transformation
to existing CSAR and upload to a system.

* tcactl resolve most of the name in all artifact. For example instead of using
ID and execute multiply command tool allow indicate just name.
ID and execute multiply command tool allow to indicate just name.

## Build

Expand Down
34 changes: 23 additions & 11 deletions app/main/cmds/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func Chunks(s string, chunkSize int, sep byte) []string {
return []string{s}
}

var chunks []string = make([]string, 0, (len(s)-1)/chunkSize+1)
var chunks = make([]string, 0, (len(s)-1)/chunkSize+1)
currentLen := 0
currentStart := 0
for i := range s {
Expand Down Expand Up @@ -176,7 +176,6 @@ func (ctl *TcaCtl) CmdCreate() *cobra.Command {

// BuildCmd build all commands and attaches to root cmd
// in case you need add sub-command you can, add to plugin dir.
//(TODO) add dynamic loading plugin
func (ctl *TcaCtl) BuildCmd() {

var describe = &cobra.Command{
Expand All @@ -196,6 +195,9 @@ Command describes TCA entity. CNFI is CNFI in the inventory, CNFC Catalog entiti
},
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if ctl.IsTrace {
ctl.GetApi().SetTrace(ctl.IsTrace)
}
},
}

Expand All @@ -204,15 +206,17 @@ Command describes TCA entity. CNFI is CNFI in the inventory, CNFC Catalog entiti
Use: "get [cnfi, cnfc, clusters, pools]",
Short: "Command retrieves tca entity (cnf, catalog, cluster) etc",
Long: templates.LongDesc(`
Command retrieves tca entity from. CNFI is CNFI in the inventory, CNFC Catalog entities.`),

Command retrieves tca entities. Cnfs, Cluster Catalog etc.`),
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// get authentication token
err := ctl.Authorize()
if err != nil {
CheckErrLogError(err)
}

// set trace
if ctl.IsTrace {
ctl.GetApi().SetTrace(ctl.IsTrace)
}
},
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -235,6 +239,9 @@ Command updates, apply changes to tca entity (cnf, cnf catalog , cluster or node
if err != nil {
CheckErrLogError(err)
}
if ctl.IsTrace {
ctl.GetApi().SetTrace(ctl.IsTrace)
}
},
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -254,6 +261,9 @@ Command creates a new object in TCA. For example new CNF instance, cluster , clu
if err != nil {
CheckErrLogError(err)
}
if ctl.IsTrace {
ctl.GetApi().SetTrace(ctl.IsTrace)
}
},
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -265,25 +275,27 @@ Command creates a new object in TCA. For example new CNF instance, cluster , clu
Use: "set",
Short: "Command sets config variables (Username, Password etc) for tcactl.",
Long: templates.LongDesc(`
Command sets config variables (Username, Password etc) for tcactl.`),

Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
},
}

// delete root command
var cmdDelete = &cobra.Command{
Use: "delete",
Short: "Command deletes object (template,cluster,cnf etc).",
Long: `Command deletes object (template,cluster,cnf etc).`,
Use: "delete",
Short: "Command deletes object (template,cluster,cnf etc).",
Long: templates.LongDesc(
`Command deletes object in tca, (template,cluster,cnf etc).`),
Aliases: []string{"del"},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
err := ctl.Authorize()
if err != nil {
return
}
if ctl.IsTrace {
ctl.GetApi().SetTrace(ctl.IsTrace)
}
},
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
68 changes: 40 additions & 28 deletions app/main/cmds/cmd_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ func (ctl *TcaCtl) CmdGetClusters() *cobra.Command {
var _cmdClusters = &cobra.Command{
Use: "clusters",
Short: "Command retrieves cluster related information.",
Long: `
Long: templates.LongDesc(`
Command retrieves cluster-related information. Each sub-command
require either cluster name or cluster id.
`,
Example: "\t- tcactl get clusters info mycluster\n" +
"\t -tcactl get clusters pool mycluster",
`),
Example: "\t - tcactl get clusters info mycluster\n" +
"\t - tcactl get clusters pool mycluster",
Args: cobra.MinimumNArgs(1),
Aliases: []string{"cluster", "cl"},
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -132,34 +132,41 @@ func (ctl *TcaCtl) CmdGetCluster() *cobra.Command {
)

var _cmd = &cobra.Command{
Use: "cluster [name or id]",
Short: "Command describes kubernetes cluster or clusters information",
Long: `Command returns kubernetes cluster or cluster information.`,
Example: "- tcactl describe clusters 794a675c-777a-47f4-8edb-36a686ef4065 -o json",
Use: "cluster [name or id]",
Short: "Command describes kubernetes cluster or clusters information",
Long: templates.LongDesc(
`Command returns kubernetes cluster or cluster information.`),
Example: "\t - tcactl describe clusters 794a675c-777a-47f4-8edb-36a686ef4065 -o json",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {

var (
ctx = context.Background()
_clusterId string
err error
ctx = context.Background()
cid string
err error
)

_clusterId = args[0]
if !IsValidUUID(args[0]) {
_clusterId, err = ctl.ResolveClusterName(args[0])
CheckErrLogError(err)
}

// global output type
_defaultPrinter = ctl.RootCmd.PersistentFlags().Lookup("output").Value.String()
// set wide or not
_isWide, err := cmd.Flags().GetBool("wide")
CheckErrLogError(err)
_defaultStyler.SetWide(_isWide)

cluster, err := ctl.tca.GetCluster(ctx, _clusterId)
CheckErrLogError(err)
cid = args[0]

cluster, err := ctl.tca.GetCluster(ctx, cid)
if err != nil {
clusters, err := ctl.tca.GetClusters(ctx)
if err != nil {
return
}
fmt.Println("Unknown cluster, current cluster list:")
for _, spec := range clusters.Clusters {
fmt.Println(" * ", spec.ClusterName)
}
return
}

if printer, ok := ctl.ClusterPrinter[_defaultPrinter]; ok {
printer(cluster, _defaultStyler)
Expand Down Expand Up @@ -189,8 +196,9 @@ func (ctl *TcaCtl) CmdGetClustersPoolNodes() *cobra.Command {
Long: templates.LongDesc(
`Command returns a list kubernetes node pool for a given cluster name.`),

Example: "- tcactl get clusters nodes 794a675c-777a-47f4-8edb-36a686ef4065\n - tcactl get clusters nodes edge",
Args: cobra.MinimumNArgs(1),
Example: "\t - tcactl get clusters nodes 794a675c-777a-47f4-8edb-36a686ef4065\n " +
"\t - tcactl get clusters nodes edge",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {

ctx := context.Background()
Expand Down Expand Up @@ -240,10 +248,11 @@ func (ctl *TcaCtl) CmdDescClusterNodePool() *cobra.Command {
)

var _cmd = &cobra.Command{
Use: "pool [name or id]",
Short: "Command describes kubernetes node pool",
Long: `Command describes kubernetes node pool for a given or default cluster name.`,
Example: "tcactl describe pool 794a675c-777a-47f4-8edb-36a686ef4065",
Use: "pool [name or id]",
Short: "Command describes kubernetes node pool",
Long: templates.LongDesc(
`Command describes kubernetes node pool for a given or default cluster name.`),
Example: "\t - tcactl describe pool 794a675c-777a-47f4-8edb-36a686ef4065",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {

Expand Down Expand Up @@ -343,12 +352,14 @@ func (ctl *TcaCtl) CmdGetClustersList() *cobra.Command {
var _cmd = &cobra.Command{
Use: "info [optional cluster name]",
Short: "Command returns kubernetes cluster or cluster information.",
Long: `Command returns kubernetes cluster or cluster information.`,
Long: templates.LongDesc(
`Command returns kubernetes clusters or cluster information.`),
Run: func(cmd *cobra.Command, args []string) {

// global output type
ctx := context.Background()
_defaultPrinter = ctl.RootCmd.PersistentFlags().Lookup(FlagOutput).Value.String()

_defaultStyler.SetColor(ctl.IsColorTerm)
_defaultStyler.SetWide(ctl.IsWideTerm)

Expand Down Expand Up @@ -390,8 +401,9 @@ func (ctl *TcaCtl) CmdGetClustersK8SConfig() *cobra.Command {
var _cmd = &cobra.Command{
Use: "kubeconfig [cluster name]",
Short: "Command returns cluster kubeconfig",
Long: `Command returns cluster kubeconfig.`,
Args: cobra.MinimumNArgs(1),
Long: templates.LongDesc(
`Command returns cluster kubeconfig.`),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {

ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion app/main/cmds/cmd_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"strings"
)

//
//CmdGetExtensions command get extensions from TCA
func (ctl *TcaCtl) CmdGetExtensions() *cobra.Command {

var (
Expand Down
5 changes: 3 additions & 2 deletions app/main/cmds/cmd_lcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ and node pool.
return
}

var newInstanceReq = api.NewInstanceRequestSpec(ctl.DefaultCloudName,
newInstanceReq, err := api.NewInstanceRequestSpec(ctl.DefaultCloudName,
ctl.DefaultClusterName, vimType, args[0], ctl.DefaultRepoName, args[1], ctl.DefaultNodePoolName)
CheckErrLogError(err)

newInstanceReq.AdditionalParams.DisableAutoRollback = disableAutoRollback
newInstanceReq.AdditionalParams.IgnoreGrantFailure = ignoreGrantFailure
Expand Down Expand Up @@ -238,7 +239,7 @@ and node pool.
return cmdCreate
}

//
//CmdReconfigure command reconfigures lcm instance
func (ctl *TcaCtl) CmdReconfigure() *cobra.Command {

var (
Expand Down
2 changes: 1 addition & 1 deletion app/main/cmds/cmd_set.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package app
// Package cmds
// Copyright 2020-2021 Author.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
12 changes: 10 additions & 2 deletions app/main/cmds/cmd_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,16 @@ func (ctl *TcaCtl) CmdDescribeTemplate() *cobra.Command {

var templateId = args[0]
t, err := ctl.tca.GetNamedClusterTemplate(templateId)
CheckErrLogError(err)

if err != nil {
fmt.Println("Unknown template name or id. List of templates")
clusterTemplates, err := ctl.tca.GetClusterTemplates()
CheckErrLogError(err)
for _, template := range clusterTemplates.ClusterTemplates {
fmt.Println("* ", template.Name)
}
return
}
//
if printer, ok := ctl.TemplatePrinter[_defaultPrinter]; ok {
printer(t, _defaultStyler)
}
Expand Down
16 changes: 7 additions & 9 deletions app/main/cmds/cmd_vims.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"strings"
)

// CmdGetVim - get VIM root command.
// each sub-command gets particular facts about attached VIM, Cloud provider.
// CmdGetVim - Get's VIM root command.
// - Each sub-command gets particular facts about attached VIM, Cloud provider.
func (ctl *TcaCtl) CmdGetVim() *cobra.Command {

// cloud - tenants
Expand All @@ -38,10 +38,10 @@ func (ctl *TcaCtl) CmdGetVim() *cobra.Command {
Aliases: []string{"vims"},
Short: "Command retrieves a vim-cloud provider information.",
Long: templates.LongDesc(`
Command retrieves a vim-cloud provider information.`),

Example: " - tcactl describe vim compute my_cloud_provider",
Example: "\t - tcactl get vim compute my_cloud_provider\n " +
"\t - tcactl get vim datastore my_cloud_provider\n" +
"\t - tcactl get vim folders my_cloud_provider",
//Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return fmt.Errorf("%s requires a subcommand", cmd.Name())
Expand All @@ -58,8 +58,8 @@ Command retrieves a vim-cloud provider information.`),
return _cmd
}

// CmdDescribeVim - command describe VIM , Cloud Provider
// attached to system.
// CmdDescribeVim - command describe VIM ,
// Cloud Provider , attached to system.
func (ctl *TcaCtl) CmdDescribeVim() *cobra.Command {

var (
Expand All @@ -75,9 +75,7 @@ func (ctl *TcaCtl) CmdDescribeVim() *cobra.Command {
Aliases: []string{"vims"},
Short: "Command retrieves a vim-cloud provider information.",
Long: templates.LongDesc(`
Command retrieves a list of cloud providers.
`),
Example: " - tcactl describe vim vmware_FB40D3DE2967483FBF9033B451DC7571",
Args: cobra.MinimumNArgs(1),
Expand Down
5 changes: 5 additions & 0 deletions app/main/cmds/tcactl.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ func (ctl *TcaCtl) SetPassword(password string) {
}
}

// GetApi returns TcaApi api.TcaApi
func (ctl *TcaCtl) GetApi() *api.TcaApi {
return ctl.tca
}

// CheckErrLogError , print error and log error
func CheckErrLogError(msg interface{}) {
if msg != nil {
Expand Down
Loading

0 comments on commit 9b43c5c

Please sign in to comment.