Skip to content

Commit

Permalink
Merge pull request #609 from CS-SI/pr/bugfixes
Browse files Browse the repository at this point in the history
Several Bugfixes
  • Loading branch information
oscarpicas authored Jan 31, 2023
2 parents e3f60eb + bbe65b6 commit fa8745c
Show file tree
Hide file tree
Showing 29 changed files with 151 additions and 709 deletions.
78 changes: 3 additions & 75 deletions cli/safescale/commands/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func formatClusterConfig(config map[string]interface{}, detailed bool) (map[stri
return nil, fail.InconsistentError("'nodes' should be a map[string][]*protocol.Host")
}
} else {
config["remote_desktop"] = fmt.Sprintf("no remote desktop available; to install on all masters, run 'safescale cluster feature add %s remotedesktop'", config["name"].(string))
config["remote_desktop"] = fmt.Sprintf("no remote desktop available")
}
}
return config, nil
Expand Down Expand Up @@ -1487,7 +1487,7 @@ var clusterNodeStateCommand = cli.Command{

const clusterMasterCmdLabel = "master"

// clusterMasterCommands handles 'safescale cluster master ...
// clusterMasterCommands handles 'safescale cluster master ...'
var clusterMasterCommands = cli.Command{
Name: clusterMasterCmdLabel,
Usage: "manage cluster masters",
Expand Down Expand Up @@ -1596,7 +1596,7 @@ var clusterMasterInspectCommand = cli.Command{
}()
}

host, err := ClientSession.Cluster.InspectNode(clusterName, hostName, 0)
host, err := ClientSession.Cluster.InspectMaster(clusterName, hostName, 0)
if err != nil {
err = fail.FromGRPCStatus(err)
return clitools.FailureResponse(clitools.ExitOnRPC(err.Error()))
Expand Down Expand Up @@ -1724,7 +1724,6 @@ var clusterFeatureCommands = cli.Command{
ArgsUsage: "COMMAND",
Subcommands: cli.Commands{
clusterFeatureListCommand,
clusterFeatureExportCommand,
clusterFeatureCheckCommand,
clusterFeatureAddCommand,
clusterFeatureRemoveCommand,
Expand Down Expand Up @@ -1787,77 +1786,6 @@ func clusterFeatureListAction(c *cli.Context) (ferr error) {
return clitools.SuccessResponse(features)
}

// clusterFeatureExportCommand handles 'safescale cluster feature export <cluster name or id> <feature name>'
var clusterFeatureExportCommand = cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "List features installed on the cluster",
ArgsUsage: "",

Flags: []cli.Flag{
cli.BoolFlag{
Name: "embedded",
// Value: false,
Usage: "if used, tells to export embedded feature (if it exists)",
},
cli.BoolFlag{
Name: "raw",
// Value: false,
Usage: "outputs only the feature content, without json",
},
},

Action: clusterFeatureExportAction,
}

func clusterFeatureExportAction(c *cli.Context) (ferr error) {
defer fail.OnPanic(&ferr)
logrus.Tracef("SafeScale command: %s %s with args '%s'", clusterCmdLabel, c.Command.Name, c.Args())

if err := extractClusterName(c); err != nil {
return clitools.FailureResponse(err)
}

featureName := c.Args().Get(1)
if featureName == "" {
_ = cli.ShowSubcommandHelp(c)
return clitools.ExitOnInvalidArgument("Invalid argument FEATURENAME.")
}

if beta := os.Getenv("SAFESCALE_BETA"); beta != "" {
description := "Exporting feature"
pb := progressbar.NewOptions(-1, progressbar.OptionFullWidth(), progressbar.OptionClearOnFinish(), progressbar.OptionSetDescription(description))
go func() {
for {
if pb.IsFinished() {
return
}
err := pb.Add(1)
if err != nil {
return
}
time.Sleep(100 * time.Millisecond)
}
}()

defer func() {
_ = pb.Finish()
}()
}

export, err := ClientSession.Cluster.ExportFeature(clusterName, featureName, c.Bool("embedded"), 0) // FIXME: set timeout
if err != nil {
err = fail.FromGRPCStatus(err)
return clitools.FailureResponse(clitools.ExitOnRPC(err.Error()))
}

if c.Bool("raw") {
return clitools.SuccessResponse(export.Export)
}

return clitools.SuccessResponse(export)
}

// clusterFeatureAddCommand handles 'safescale cluster feature add CLUSTERNAME FEATURENAME'
var clusterFeatureAddCommand = cli.Command{
Name: "add",
Expand Down
70 changes: 0 additions & 70 deletions cli/safescale/commands/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,6 @@ var hostFeatureCommands = cli.Command{
Usage: hostFeatureCmdLabel + " COMMAND",
Subcommands: cli.Commands{
hostFeatureCheckCommand,
hostFeatureExportCommand,
hostFeatureAddCommand,
hostFeatureRemoveCommand,
hostFeatureListCommand,
Expand Down Expand Up @@ -909,75 +908,6 @@ func hostFeatureListAction(c *cli.Context) (ferr error) {
return clitools.SuccessResponse(list)
}

// hostFeatureExportCommand handles 'safescale cluster feature export <cluster name or id> <feature name>'
var hostFeatureExportCommand = cli.Command{
Name: "export",
Aliases: []string{"dump"},
Usage: "Export feature file content",
ArgsUsage: "",

Flags: []cli.Flag{
cli.BoolFlag{
Name: "embedded",
Usage: "if used, tells to export embedded feature (if it exists)",
},
cli.BoolFlag{
Name: "raw",
Usage: "outputs only the feature content, without json",
},
},

Action: hostFeatureExportAction,
}

func hostFeatureExportAction(c *cli.Context) (ferr error) {
defer fail.OnPanic(&ferr)
logrus.Tracef("SafeScale command: %s %s with args '%s'", hostCmdLabel, c.Command.Name, c.Args())

hostName, _, err := extractHostArgument(c, 0, DoNotInstanciate)
if err != nil {
return clitools.FailureResponse(err)
}

featureName, err := extractFeatureArgument(c)
if err != nil {
return clitools.FailureResponse(err)
}

if beta := os.Getenv("SAFESCALE_BETA"); beta != "" {
description := "Exporting host features"
pb := progressbar.NewOptions(-1, progressbar.OptionFullWidth(), progressbar.OptionClearOnFinish(), progressbar.OptionSetDescription(description))
go func() {
for {
if pb.IsFinished() {
return
}
err := pb.Add(1)
if err != nil {
return
}
time.Sleep(100 * time.Millisecond)
}
}()

defer func() {
_ = pb.Finish()
}()
}

export, err := ClientSession.Host.ExportFeature(hostName, featureName, c.Bool("embedded"), 0) // FIXME: set timeout
if err != nil {
err = fail.FromGRPCStatus(err)
return clitools.FailureResponse(clitools.ExitOnRPC(err.Error()))
}

if c.Bool("raw") {
return clitools.SuccessResponse(export.Export)
}

return clitools.SuccessResponse(export)
}

// hostAddFeatureCommand handles 'deploy host <host name or id> package <pkgname> add'
var hostFeatureAddCommand = cli.Command{
Name: "add",
Expand Down
42 changes: 0 additions & 42 deletions cli/safescale/commands/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var TenantCommand = cli.Command{
tenantSetCommand,
tenantInspectCommand,
tenantScanCommand,
tenantMetadataCommands,
},
}

Expand Down Expand Up @@ -221,44 +220,3 @@ var tenantScanCommand = cli.Command{
return clitools.SuccessResponse(results.GetResults())
},
}

const tenantMetadataCmdLabel = "metadata"

// tenantMetadataCommands handles 'safescale tenant metadata' commands
var tenantMetadataCommands = cli.Command{
Name: tenantMetadataCmdLabel,
Usage: "manage tenant metadata",
ArgsUsage: "COMMAND",

Subcommands: cli.Commands{
// tenantMetadataUpgradeCommand,
// tenantMetadataBackupCommand,
// tenantMetadataRestoreCommand,
tenantMetadataDeleteCommand,
},
}

const tenantMetadataDeleteCmdLabel = "delete"

var tenantMetadataDeleteCommand = cli.Command{
Name: tenantMetadataDeleteCmdLabel,
Aliases: []string{"remove", "rm", "destroy", "cleanup"},
Usage: "Remove SafeScale metadata (making SafeScale unable to manage resources anymore); use with caution",
Action: func(c *cli.Context) (ferr error) {
defer fail.OnPanic(&ferr)
if c.NArg() != 1 {
_ = cli.ShowSubcommandHelp(c)
return clitools.FailureResponse(clitools.ExitOnInvalidArgument("Missing mandatory argument <tenant_name>."))
}

logrus.Tracef("SafeScale command: %s %s with args '%s'", tenantCmdLabel, c.Command.Name, c.Args())

err := ClientSession.Tenant.Cleanup(c.Args().First(), 0)
if err != nil {
err = fail.FromGRPCStatus(err)
return clitools.FailureResponse(clitools.ExitOnRPC(strprocess.Capitalize(client.DecorateTimeoutError(err, "set tenant", false).Error())))
}

return clitools.SuccessResponse(nil)
},
}
Loading

0 comments on commit fa8745c

Please sign in to comment.