-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from shmel1k/feature/configurable_parameters_fo…
…r_commands Feature/configurable parameters for commands
- Loading branch information
Showing
61 changed files
with
1,720 additions
and
1,275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
ydbops | ||
vendor |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package complete | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/ydb-platform/ydbops/pkg/cli" | ||
"github.com/ydb-platform/ydbops/pkg/cmdutil" | ||
"github.com/ydb-platform/ydbops/pkg/prettyprint" | ||
) | ||
|
||
func New(f cmdutil.Factory) *cobra.Command { | ||
opts := &Options{} | ||
|
||
cmd := cli.SetDefaultsOn(&cobra.Command{ | ||
Use: "complete", | ||
Short: "Declare the maintenance task completed", | ||
Long: `ydbops maintenance complete: | ||
Any hosts that have been given to you within the task will be considered returned to the cluster. | ||
You must not perform any host maintenance after you called this command.`, | ||
PreRunE: cli.PopulateProfileDefaultsAndValidate( | ||
f.GetBaseOptions(), opts, | ||
), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
result, err := f.GetCMSClient().CompleteActions(opts.TaskID, opts.HostFQDNs) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(prettyprint.ResultToString(result)) | ||
|
||
return nil | ||
}, | ||
}) | ||
|
||
opts.DefineFlags(cmd.PersistentFlags()) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package complete | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/pflag" | ||
) | ||
|
||
type Options struct { | ||
TaskID string | ||
HostFQDNs []string | ||
} | ||
|
||
func (o *Options) DefineFlags(fs *pflag.FlagSet) { | ||
fs.StringSliceVar(&o.HostFQDNs, "hosts", []string{}, | ||
"FQDNs of hosts with completed maintenance") | ||
fs.StringVar(&o.TaskID, "task-id", "", | ||
"ID of your maintenance task (result of `ydbops maintenance host`)") | ||
} | ||
|
||
func (o *Options) Validate() error { | ||
// TODO(shmel1k@): remove copypaste between drop, create & refresh methods. | ||
if len(o.HostFQDNs) == 0 { | ||
return fmt.Errorf("--hosts unspecified") | ||
} | ||
if o.TaskID == "" { | ||
return fmt.Errorf("--task-id unspecified, argument required") | ||
} | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package create | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/spf13/cobra" | ||
"google.golang.org/protobuf/types/known/durationpb" | ||
|
||
"github.com/ydb-platform/ydbops/pkg/cli" | ||
"github.com/ydb-platform/ydbops/pkg/client/cms" | ||
"github.com/ydb-platform/ydbops/pkg/cmdutil" | ||
"github.com/ydb-platform/ydbops/pkg/rolling" | ||
) | ||
|
||
func New(f cmdutil.Factory) *cobra.Command { | ||
opts := &Options{ | ||
RestartOptions: &rolling.RestartOptions{}, | ||
} | ||
|
||
cmd := cli.SetDefaultsOn(&cobra.Command{ | ||
Use: "create", | ||
Short: "Create a maintenance task to obtain a set of hosts", | ||
Long: `ydbops maintenance create: | ||
Create a maintenance task, which allows taking the set of hosts out of the cluster.`, | ||
PreRunE: cli.PopulateProfileDefaultsAndValidate( | ||
f.GetBaseOptions(), opts, | ||
), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
taskUID := cms.TaskUuidPrefix + uuid.New().String() | ||
duration := time.Duration(opts.RestartOptions.RestartDuration) * time.Minute | ||
taskId, err := f.GetCMSClient().CreateMaintenanceTask(cms.MaintenanceTaskParams{ | ||
Hosts: opts.RestartOptions.Hosts, | ||
Duration: durationpb.New(duration), | ||
AvailabilityMode: opts.RestartOptions.GetAvailabilityMode(), | ||
ScopeType: cms.HostScope, | ||
TaskUID: taskUID, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf( | ||
"Your task id is:\n\n%s\n\nPlease write it down for refreshing and completing the task later.\n", | ||
taskId.GetTaskUid(), | ||
) | ||
|
||
return nil | ||
}, | ||
}) | ||
|
||
opts.DefineFlags(cmd.PersistentFlags()) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package create | ||
|
||
import ( | ||
"github.com/spf13/pflag" | ||
"github.com/ydb-platform/ydbops/pkg/rolling" | ||
) | ||
|
||
type Options struct { | ||
*rolling.RestartOptions | ||
} | ||
|
||
func (o *Options) DefineFlags(fs *pflag.FlagSet) { | ||
o.RestartOptions.DefineFlags(fs) | ||
} | ||
|
||
func (o *Options) Validate() error { | ||
return o.RestartOptions.Validate() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package drop | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/ydb-platform/ydbops/pkg/cli" | ||
"github.com/ydb-platform/ydbops/pkg/cmdutil" | ||
) | ||
|
||
func New(f cmdutil.Factory) *cobra.Command { | ||
taskIdOpts := &Options{} | ||
|
||
cmd := cli.SetDefaultsOn(&cobra.Command{ | ||
Use: "drop", | ||
Short: "Drop an existing maintenance task", | ||
Long: `ydbops maintenance drop: | ||
Drops the maintenance task, meaning two things: | ||
1. Any hosts given within the maintenance task will be considered returned. | ||
2. Any hosts requested, but not yet given, will not be reserved for you any longer.`, | ||
PreRunE: cli.PopulateProfileDefaultsAndValidate( | ||
f.GetBaseOptions(), taskIdOpts, | ||
), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return f.GetCMSClient().DropTask(taskIdOpts.TaskID) | ||
}, | ||
}) | ||
|
||
taskIdOpts.DefineFlags(cmd.PersistentFlags()) | ||
|
||
return cmd | ||
} |
Oops, something went wrong.