Skip to content

Commit

Permalink
write main direct access functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bcambl committed Apr 7, 2020
1 parent 299ad04 commit 0e0ccfe
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 45 deletions.
48 changes: 42 additions & 6 deletions cmd/finish.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ var finishCmd = &cobra.Command{
Long: `Return a conistency group to a full replication state
examples:
rpda finish --group EXAMPLE_CG
rpda finish --group EXAMPLE_CG --latest-test
rpda finish --all
rpda finish --all --latest-test
`,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -61,20 +61,34 @@ rpda finish --all
a.Username = viper.GetString("api.username")
a.Password = viper.GetString("api.password")
a.Delay = viper.GetInt("api.delay")
a.Debug = viper.GetBool("debug")
a.Identifiers.ProductionNode = viper.GetString("identifiers.production_node_name_contains")
a.Identifiers.CopyNode = viper.GetString("identifiers.dr_copy_name_contains")
a.Identifiers.TestCopy = viper.GetString("identifiers.test_copy_name_contains")

group, err := cmd.Flags().GetString("group")
if err != nil {
log.Fatal(err)
}
latestTest, err := cmd.Flags().GetBool("latest-test")
if err != nil {
log.Fatal(err)
}
latestDR, err := cmd.Flags().GetBool("latest-dr")
if err != nil {
log.Fatal(err)
}
all, err := cmd.Flags().GetBool("all")
if err != nil {
log.Fatal(err)
}

if viper.GetBool("debug") {
a.Debug()
fmt.Println("status command 'group' flag value: ", group)
fmt.Println("status command 'all' flag value: ", all)
if a.Debug {
a.Debugger()
fmt.Println("start command 'group' flag value: ", group)
fmt.Println("start command 'latest-test' flag value: ", latestTest)
fmt.Println("start command 'latest-dr' flag value: ", latestDR)
fmt.Println("start command 'all' flag value: ", all)
}

// preflight checks
Expand All @@ -86,6 +100,26 @@ rpda finish --all
}
a.Group = group

// ensure A image copy flag was provided
if latestTest == false && latestDR == false {
cmd.Usage()
os.Exit(1)
}

// ensure user did not provide BOTH image copy flags
if latestTest == true && latestDR == true {
cmd.Usage()
os.Exit(1)
}

// assign the image copy flag
if latestDR == true {
a.Copy = a.Identifiers.CopyNode
}
if latestTest == true {
a.Copy = a.Identifiers.TestCopy
}

if group != "" {
// display status of single group if a group name was provided
a.FinishOne()
Expand All @@ -106,4 +140,6 @@ func init() {
// command flags and configuration settings.
finishCmd.PersistentFlags().Bool("all", false, "Display Status for All Consistency Groups")
finishCmd.PersistentFlags().String("group", "", "Display Status of Consistency Group by Name")
finishCmd.PersistentFlags().Bool("latest-test", false, "Use Latest Test Copy Image")
finishCmd.PersistentFlags().Bool("latest-dr", false, "Use Latest DR Copy Image")
}
5 changes: 3 additions & 2 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ rpda list
a.Username = viper.GetString("api.username")
a.Password = viper.GetString("api.password")
a.Delay = viper.GetInt("api.delay")
a.Debug = viper.GetBool("debug")

if viper.GetBool("debug") {
a.Debug()
if a.Debug {
a.Debugger()
}

a.ListGroups()
Expand Down
9 changes: 5 additions & 4 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ rpda start --all --latest-dr
a.Username = viper.GetString("api.username")
a.Password = viper.GetString("api.password")
a.Delay = viper.GetInt("api.delay")
a.Debug = viper.GetBool("debug")
a.Identifiers.ProductionNode = viper.GetString("identifiers.production_node_name_contains")
a.Identifiers.CopyNode = viper.GetString("identifiers.dr_copy_name_contains")
a.Identifiers.TestCopy = viper.GetString("identifiers.test_copy_name_contains")
Expand All @@ -86,8 +87,8 @@ rpda start --all --latest-dr
log.Fatal(err)
}

if viper.GetBool("debug") {
a.Debug()
if a.Debug {
a.Debugger()
fmt.Println("start command 'group' flag value: ", group)
fmt.Println("start command 'latest-test' flag value: ", latestTest)
fmt.Println("start command 'latest-dr' flag value: ", latestDR)
Expand Down Expand Up @@ -117,10 +118,10 @@ rpda start --all --latest-dr

// assign the image copy flag
if latestDR == true {
a.Copy = "DR"
a.Copy = a.Identifiers.CopyNode
}
if latestTest == true {
a.Copy = "TEST"
a.Copy = a.Identifiers.TestCopy
}

if group != "" {
Expand Down
8 changes: 6 additions & 2 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ rpda status --group Example_CG
a.Username = viper.GetString("api.username")
a.Password = viper.GetString("api.password")
a.Delay = viper.GetInt("api.delay")
a.Debug = viper.GetBool("debug")
a.Identifiers.ProductionNode = viper.GetString("identifiers.production_node_name_contains")
a.Identifiers.CopyNode = viper.GetString("identifiers.dr_copy_name_contains")
a.Identifiers.TestCopy = viper.GetString("identifiers.test_copy_name_contains")

group, err := cmd.Flags().GetString("group")
if err != nil {
Expand All @@ -70,8 +74,8 @@ rpda status --group Example_CG
log.Fatal(err)
}

if viper.GetBool("debug") {
a.Debug()
if a.Debug {
a.Debugger()
fmt.Println("status command 'group' flag value: ", group)
fmt.Println("status command 'all' flag value: ", all)
}
Expand Down
Loading

0 comments on commit 0e0ccfe

Please sign in to comment.