-
Notifications
You must be signed in to change notification settings - Fork 31
Vpc integration #880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Vpc integration #880
Changes from all commits
63793eb
bfd0888
0dc929f
851fb14
8b9b458
75b3838
00e0d40
cdb4c4a
a2c8760
c688367
7e674f4
c132592
eaa3ae5
ccbae2b
d945eff
c1989e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package instance | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| exocmd "github.com/exoscale/cli/cmd" | ||
| "github.com/exoscale/cli/cmd/networking/vpc" | ||
| "github.com/exoscale/cli/pkg/globalstate" | ||
| "github.com/exoscale/cli/utils" | ||
| v3 "github.com/exoscale/egoscale/v3" | ||
| ) | ||
|
|
||
| type instanceAttachToSubnetCmd struct { | ||
| exocmd.CliCommandSettings `cli-cmd:"-"` | ||
|
|
||
| _ bool `cli-cmd:"attach-to-subnet"` | ||
|
|
||
| Instance string `cli-arg:"#" cli-usage:"INSTANCE-NAME|ID"` | ||
| VPC string `cli-arg:"#" cli-usage:"VPC-NAME|ID"` | ||
| Subnet string `cli-arg:"#" cli-usage:"SUBNET-NAME|ID"` | ||
|
|
||
| IPv4 string `cli-flag:"ipv4" cli-usage:"IPv4 address to assign to the Compute instance in the Subnet"` | ||
| Zone v3.ZoneName `cli-short:"z" cli-usage:"instance zone"` | ||
| } | ||
|
|
||
| func (c *instanceAttachToSubnetCmd) CmdAliases() []string { return nil } | ||
|
|
||
| func (c *instanceAttachToSubnetCmd) CmdShort() string { | ||
| return "Attach a Compute instance to a VPC Subnet" | ||
| } | ||
|
|
||
| func (c *instanceAttachToSubnetCmd) CmdLong() string { | ||
| return "This command attaches a Compute instance to a VPC Subnet." | ||
| } | ||
|
|
||
| func (c *instanceAttachToSubnetCmd) CmdPreRun(cmd *cobra.Command, args []string) error { | ||
| exocmd.CmdSetZoneFlagFromDefault(cmd) | ||
| return exocmd.CliCommandDefaultPreRun(c, cmd, args) | ||
| } | ||
|
|
||
| func (c *instanceAttachToSubnetCmd) CmdRun(_ *cobra.Command, _ []string) error { | ||
| ctx := exocmd.GContext | ||
| client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| instances, err := client.ListInstances(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| instance, err := findInstance(instances, c.Instance, string(c.Zone)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| vpcEntry, err := vpc.FindVPC(ctx, client, c.VPC) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| subnetEntry, err := vpc.FindSubnet(ctx, client, vpcEntry.ID, c.Subnet) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| req := v3.AttachInstanceToSubnetRequest{ | ||
| Instance: &v3.InstanceRef{ID: instance.ID}, | ||
| } | ||
|
|
||
| if c.IPv4 != "" { | ||
| ip := net.ParseIP(c.IPv4) | ||
| if ip == nil || ip.To4() == nil { | ||
| return fmt.Errorf("invalid IPv4 address: %q", c.IPv4) | ||
| } | ||
| req.Ipv4 = ip | ||
| } | ||
|
|
||
| if err := utils.RunAsync( | ||
| ctx, | ||
| client, | ||
| fmt.Sprintf("Attaching instance %q to Subnet %q...", c.Instance, c.Subnet), | ||
| func(ctx context.Context, client *v3.Client) (*v3.Operation, error) { | ||
| return client.AttachInstanceToSubnet(ctx, vpcEntry.ID, subnetEntry.ID, req) | ||
| }, | ||
| ); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if !globalstate.Quiet { | ||
| return (&instanceShowCmd{ | ||
| CliCommandSettings: c.CliCommandSettings, | ||
| Instance: instance.ID.String(), | ||
| Zone: c.Zone, | ||
| }).CmdRun(nil, nil) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func init() { | ||
| cobra.CheckErr(exocmd.RegisterCLICommand(instanceCmd, &instanceAttachToSubnetCmd{ | ||
| CliCommandSettings: exocmd.DefaultCLICmdSettings(), | ||
| })) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package instance | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| exocmd "github.com/exoscale/cli/cmd" | ||
| "github.com/exoscale/cli/cmd/networking/vpc" | ||
| "github.com/exoscale/cli/pkg/globalstate" | ||
| "github.com/exoscale/cli/utils" | ||
| v3 "github.com/exoscale/egoscale/v3" | ||
| ) | ||
|
|
||
| type instanceDetachFromSubnetCmd struct { | ||
| exocmd.CliCommandSettings `cli-cmd:"-"` | ||
|
|
||
| _ bool `cli-cmd:"detach-from-subnet"` | ||
|
|
||
| Instance string `cli-arg:"#" cli-usage:"INSTANCE-NAME|ID"` | ||
| VPC string `cli-arg:"#" cli-usage:"VPC-NAME|ID"` | ||
| Subnet string `cli-arg:"#" cli-usage:"SUBNET-NAME|ID"` | ||
|
|
||
| Zone v3.ZoneName `cli-short:"z" cli-usage:"instance zone"` | ||
| } | ||
|
|
||
| func (c *instanceDetachFromSubnetCmd) CmdAliases() []string { return nil } | ||
|
|
||
| func (c *instanceDetachFromSubnetCmd) CmdShort() string { | ||
| return "Detach a Compute instance from a VPC Subnet" | ||
| } | ||
|
|
||
| func (c *instanceDetachFromSubnetCmd) CmdLong() string { | ||
| return "This command detaches a Compute instance from a VPC Subnet." | ||
| } | ||
|
|
||
| func (c *instanceDetachFromSubnetCmd) CmdPreRun(cmd *cobra.Command, args []string) error { | ||
| exocmd.CmdSetZoneFlagFromDefault(cmd) | ||
| return exocmd.CliCommandDefaultPreRun(c, cmd, args) | ||
| } | ||
|
|
||
| func (c *instanceDetachFromSubnetCmd) CmdRun(_ *cobra.Command, _ []string) error { | ||
| ctx := exocmd.GContext | ||
| client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| instances, err := client.ListInstances(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| instance, err := findInstance(instances, c.Instance, string(c.Zone)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| vpcEntry, err := vpc.FindVPC(ctx, client, c.VPC) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| subnetEntry, err := vpc.FindSubnet(ctx, client, vpcEntry.ID, c.Subnet) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| req := v3.DetachInstanceFromSubnetRequest{ | ||
| Instance: &v3.InstanceRef{ID: instance.ID}, | ||
| } | ||
|
|
||
| if err := utils.RunAsync( | ||
| ctx, | ||
| client, | ||
| fmt.Sprintf("Detaching instance %q from Subnet %q...", c.Instance, c.Subnet), | ||
| func(ctx context.Context, client *v3.Client) (*v3.Operation, error) { | ||
| return client.DetachInstanceFromSubnet(ctx, vpcEntry.ID, subnetEntry.ID, req) | ||
| }, | ||
| ); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if !globalstate.Quiet { | ||
| return (&instanceShowCmd{ | ||
| CliCommandSettings: c.CliCommandSettings, | ||
| Instance: instance.ID.String(), | ||
| Zone: c.Zone, | ||
| }).CmdRun(nil, nil) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func init() { | ||
| cobra.CheckErr(exocmd.RegisterCLICommand(instanceCmd, &instanceDetachFromSubnetCmd{ | ||
| CliCommandSettings: exocmd.DefaultCLICmdSettings(), | ||
| })) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package networking | ||
|
|
||
| import ( | ||
| exocmd "github.com/exoscale/cli/cmd" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // NetworkingCmd is the root command for networking services. | ||
| var NetworkingCmd = &cobra.Command{ | ||
| Use: "networking", | ||
| Short: "Networking services management", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a note in the descriptions of this command(and perhaps all VPC commands), indicating that these features are still BETA?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think it's a good idea
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know about this. My understanding was that we don't market VPC to be beta at all. It's either not there yet or available & we commit on it So I think it make sense to just merge that & enable all VPC operation on october 31st. Which means that between the next release of the CLI & the MVP data customer can have a CLI that appears to support VPC but the API rejects all call Wdyt ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good to me. I think as long as we don't announce VPC officially, customers won't try these commands anyway. |
||
| Aliases: []string{"net"}, | ||
| SuggestFor: []string{"network", "vpc"}, | ||
| } | ||
|
|
||
| func init() { | ||
| exocmd.RootCmd.AddCommand(NetworkingCmd) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.