-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
220 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,56 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/replicatedhq/replicated/pkg/platformclient" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (r *runners) InitNetworkUpdateCommand(parent *cobra.Command) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update", | ||
Short: "Update network settings.", | ||
Long: `The 'update' command allows you to update various settings of a test network. | ||
You can either specify the network ID directly or provide the network name, and the command will resolve the corresponding network ID.`, | ||
Example: `# Update a network using its ID | ||
replicated network update --id <network-id> [subcommand] | ||
# Update a network using its name | ||
replicated network update --name <network-name> [subcommand]`, | ||
} | ||
parent.AddCommand(cmd) | ||
|
||
cmd.PersistentFlags().StringVar(&r.args.updateNetworkName, "name", "", "Name of the network to update.") | ||
cmd.RegisterFlagCompletionFunc("name", r.completeNetworkNames) | ||
|
||
cmd.PersistentFlags().StringVar(&r.args.updateNetworkID, "id", "", "id of the network to update (when name is not provided)") | ||
cmd.RegisterFlagCompletionFunc("id", r.completeNetworkIDs) | ||
|
||
return cmd | ||
} | ||
|
||
func (r *runners) ensureUpdateNetworkIDArg(args []string) error { | ||
if len(args) > 0 { | ||
r.args.updateNetworkID = args[0] | ||
} else if r.args.updateNetworkName != "" { | ||
networks, err := r.kotsAPI.ListNetworks(nil, nil) | ||
if errors.Cause(err) == platformclient.ErrForbidden { | ||
return ErrCompatibilityMatrixTermsNotAccepted | ||
} else if err != nil { | ||
return errors.Wrap(err, "list networks") | ||
} | ||
for _, network := range networks { | ||
if network.Name == r.args.updateNetworkName { | ||
r.args.updateNetworkID = network.ID | ||
break | ||
} | ||
} | ||
} else if r.args.updateNetworkID != "" { | ||
// do nothing | ||
} else { | ||
return errors.New("must provide network id or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/replicatedhq/replicated/cli/print" | ||
"github.com/replicatedhq/replicated/pkg/kotsclient" | ||
"github.com/replicatedhq/replicated/pkg/platformclient" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (r *runners) InitNetworkUpdateOutbound(parent *cobra.Command) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "outbound [ID]", | ||
Short: "Update outbound setting for a test network.", | ||
Long: `The 'outbound' command allows you to update the outbound setting of a test network. The outbound setting can be either 'none' or 'any'.`, | ||
Example: `# Update the outbound setting for a specific network | ||
replicated network update outbound NETWORK_ID --outbound any`, | ||
RunE: r.updateNetworkOutbound, | ||
SilenceUsage: true, | ||
ValidArgsFunction: r.completeNetworkIDs, | ||
} | ||
parent.AddCommand(cmd) | ||
|
||
cmd.Flags().StringVar(&r.args.updateNetworkOutbound, "outbound", "", "Update outbound setting (must be 'none' or 'any')") | ||
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table|wide (default: table)") | ||
|
||
cmd.MarkFlagRequired("outbound") | ||
|
||
return cmd | ||
} | ||
|
||
func (r *runners) updateNetworkOutbound(cmd *cobra.Command, args []string) error { | ||
if err := r.ensureUpdateNetworkIDArg(args); err != nil { | ||
return errors.Wrap(err, "ensure network id arg") | ||
} | ||
|
||
if r.args.updateNetworkOutbound != "none" && r.args.updateNetworkOutbound != "any" { | ||
return errors.New("outbound must be either 'none' or 'any'") | ||
} | ||
|
||
opts := kotsclient.UpdateNetworkOutboundOpts{ | ||
Outbound: r.args.updateNetworkOutbound, | ||
} | ||
network, err := r.kotsAPI.UpdateNetworkOutbound(r.args.updateNetworkID, opts) | ||
if errors.Cause(err) == platformclient.ErrForbidden { | ||
return ErrCompatibilityMatrixTermsNotAccepted | ||
} else if err != nil { | ||
return errors.Wrap(err, "update network outbound") | ||
} | ||
|
||
return print.Network(r.outputFormat, r.w, network) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package kotsclient | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/replicatedhq/replicated/pkg/types" | ||
) | ||
|
||
type UpdateNetworkOutboundRequest struct { | ||
Outbound string `json:"outbound"` | ||
} | ||
|
||
type UpdateNetworkOutboundResponse struct { | ||
Network *types.Network `json:"network"` | ||
Errors []string `json:"errors"` | ||
} | ||
|
||
type UpdateNetworkOutboundOpts struct { | ||
Outbound string | ||
} | ||
|
||
func (c *VendorV3Client) UpdateNetworkOutbound(networkID string, opts UpdateNetworkOutboundOpts) (*types.Network, error) { | ||
req := UpdateNetworkOutboundRequest{ | ||
Outbound: opts.Outbound, | ||
} | ||
|
||
return c.doUpdateNetworkOutboundRequest(networkID, req) | ||
} | ||
|
||
func (c *VendorV3Client) doUpdateNetworkOutboundRequest(networkID string, req UpdateNetworkOutboundRequest) (*types.Network, error) { | ||
resp := UpdateNetworkOutboundResponse{} | ||
endpoint := fmt.Sprintf("/v3/network/%s/outbound", networkID) | ||
err := c.DoJSON(context.TODO(), "PUT", endpoint, http.StatusOK, req, &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return resp.Network, 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