-
Notifications
You must be signed in to change notification settings - Fork 4
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 #178 from ans-group/lb-vip-support
Add VIP list/show support for LBs
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 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
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,77 @@ | ||
package loadbalancer | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/ans-group/cli/internal/pkg/factory" | ||
"github.com/ans-group/cli/internal/pkg/helper" | ||
"github.com/ans-group/cli/internal/pkg/output" | ||
"github.com/ans-group/sdk-go/pkg/service/loadbalancer" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func loadbalancerVipsCmd(f factory.ClientFactory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "vips", | ||
Short: "sub-commands relating to VIPs", | ||
} | ||
|
||
cmd.AddCommand(loadbalancerVipsListCmd(f)) | ||
cmd.AddCommand(loadbalancerVipsShowCmd(f)) | ||
|
||
return cmd | ||
} | ||
|
||
func loadbalancerVipsListCmd(f factory.ClientFactory) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "list", | ||
Short: "Lists VIPs assigned to your LB clusters", | ||
Example: "ans loadbalancer vips list", | ||
RunE: loadbalancerCobraRunEFunc(f, loadbalancerVipsList), | ||
} | ||
} | ||
|
||
func loadbalancerVipsList(service loadbalancer.LoadBalancerService, cmd *cobra.Command, args []string) error { | ||
params, err := helper.GetAPIRequestParametersFromFlags(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
vips, err := service.GetVIPs(params) | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving VIPs: %s", err) | ||
} | ||
|
||
return output.CommandOutput(cmd, OutputLoadBalancerVIPsProvider(vips)) | ||
} | ||
|
||
func loadbalancerVipsShowCmd(f factory.ClientFactory) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "show", | ||
Short: "Show details about a VIP", | ||
Example: "ans loadbalancer vips show 12345", | ||
RunE: loadbalancerCobraRunEFunc(f, loadbalancerVipsShow), | ||
} | ||
} | ||
|
||
func loadbalancerVipsShow(service loadbalancer.LoadBalancerService, cmd *cobra.Command, args []string) error { | ||
var vips []loadbalancer.VIP | ||
for _, arg := range args { | ||
vipID, err := strconv.Atoi(arg) | ||
if err != nil { | ||
output.OutputWithErrorLevelf("Invalid VIP ID [%s]", arg) | ||
continue | ||
} | ||
|
||
vip, err := service.GetVIP(vipID) | ||
if err != nil { | ||
output.OutputWithErrorLevelf("Error retrieving VIP [%d]: %s", vip, err) | ||
continue | ||
} | ||
|
||
vips = append(vips, vip) | ||
} | ||
|
||
return output.CommandOutput(cmd, OutputLoadBalancerVIPsProvider(vips)) | ||
} |
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