-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose the new traffic fields and add load-balancer change-type comma…
…nd (#256) * Update hcloud-go to latest version and expose the new traffic fields * Add load-balancer change-type command
- Loading branch information
1 parent
143be6c
commit d5a31ce
Showing
6 changed files
with
84 additions
and
4 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,57 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hetznercloud/hcloud-go/hcloud" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newLoadBalancerChangeTypeCommand(cli *CLI) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "change-type [FLAGS] LOADBALANCER LOADBALANCERTYPE", | ||
Short: "Change type of a Load Balancer", | ||
Args: cobra.ExactArgs(2), | ||
TraverseChildren: true, | ||
DisableFlagsInUseLine: true, | ||
PreRunE: cli.ensureToken, | ||
RunE: cli.wrap(runLoadBalancerChangeType), | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runLoadBalancerChangeType(cli *CLI, cmd *cobra.Command, args []string) error { | ||
idOrName := args[0] | ||
loadBalancer, _, err := cli.Client().LoadBalancer.Get(cli.Context, idOrName) | ||
if err != nil { | ||
return err | ||
} | ||
if loadBalancer == nil { | ||
return fmt.Errorf("Load Balancer not found: %s", idOrName) | ||
} | ||
|
||
loadBalancerTypeIDOrName := args[1] | ||
loadBalancerType, _, err := cli.Client().LoadBalancerType.Get(cli.Context, loadBalancerTypeIDOrName) | ||
if err != nil { | ||
return err | ||
} | ||
if loadBalancerType == nil { | ||
return fmt.Errorf("Load Balancer type not found: %s", loadBalancerTypeIDOrName) | ||
} | ||
|
||
opts := hcloud.LoadBalancerChangeTypeOpts{ | ||
LoadBalancerType: loadBalancerType, | ||
} | ||
action, _, err := cli.Client().LoadBalancer.ChangeType(cli.Context, loadBalancer, opts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := cli.ActionProgress(cli.Context, action); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("LoadBalancer %d changed to type %s\n", loadBalancer.ID, loadBalancerType.Name) | ||
return nil | ||
} |
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
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