Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Features

- NLB: Add ipv6 support- #910
- EIP: allows labels + reverse dns at creation - #913

### Bug fixes

Expand Down
64 changes: 42 additions & 22 deletions cmd/compute/elastic_ip/elastic_ip_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ type elasticIPCreateCmd struct {

_ bool `cli-cmd:"create"`

Description string `cli-usage:"Elastic IP description"`
IPv6 bool `cli-flag:"ipv6" cli-usage:"create Elastic IPv6 prefix"`
HealthcheckInterval int64 `cli-usage:"managed Elastic IP health checking interval in seconds"`
HealthcheckMode string `cli-usage:"managed Elastic IP health checking mode (tcp|http|https)"`
HealthcheckPort int64 `cli-usage:"managed Elastic IP health checking port"`
HealthcheckStrikesFail int64 `cli-usage:"number of failed attempts before considering a managed Elastic IP health check unhealthy"`
HealthcheckStrikesOK int64 `cli-usage:"number of successful attempts before considering a managed Elastic IP health check healthy"`
HealthcheckTLSSNI string `cli-flag:"healthcheck-tls-sni" cli-usage:"managed Elastic IP health checking server name to present with SNI in https mode"`
HealthcheckTLSSSkipVerify bool `cli-flag:"healthcheck-tls-skip-verify" cli-usage:"disable TLS certificate verification for managed Elastic IP health checking in https mode"`
HealthcheckTimeout int64 `cli-usage:"managed Elastic IP health checking timeout in seconds"`
HealthcheckURI string `cli-usage:"managed Elastic IP health checking URI (required in http(s) mode)"`
Zone string `cli-short:"z" cli-usage:"Elastic IP zone"`
Description string `cli-usage:"Elastic IP description"`
IPv6 bool `cli-flag:"ipv6" cli-usage:"create Elastic IPv6 prefix"`
HealthcheckInterval int64 `cli-usage:"managed Elastic IP health checking interval in seconds"`
HealthcheckMode string `cli-usage:"managed Elastic IP health checking mode (tcp|http|https)"`
HealthcheckPort int64 `cli-usage:"managed Elastic IP health checking port"`
HealthcheckStrikesFail int64 `cli-usage:"number of failed attempts before considering a managed Elastic IP health check unhealthy"`
HealthcheckStrikesOK int64 `cli-usage:"number of successful attempts before considering a managed Elastic IP health check healthy"`
HealthcheckTLSSNI string `cli-flag:"healthcheck-tls-sni" cli-usage:"managed Elastic IP health checking server name to present with SNI in https mode"`
HealthcheckTLSSSkipVerify bool `cli-flag:"healthcheck-tls-skip-verify" cli-usage:"disable TLS certificate verification for managed Elastic IP health checking in https mode"`
HealthcheckTimeout int64 `cli-usage:"managed Elastic IP health checking timeout in seconds"`
HealthcheckURI string `cli-usage:"managed Elastic IP health checking URI (required in http(s) mode)"`
Zone string `cli-short:"z" cli-usage:"Elastic IP zone"`
Labels map[string]string `cli-flag:"label" cli-usage:"Elastic IP labels (format: key=value, ex: a=1,b=2)"`
ReverseDNS string `cli-flag:"reverse-dns" cli-usage:"Domain name for reverse DNS record."`
}

func (c *elasticIPCreateCmd) CmdAliases() []string { return exocmd.GCreateAlias }
Expand Down Expand Up @@ -83,27 +85,45 @@ func (c *elasticIPCreateCmd) CmdRun(_ *cobra.Command, _ []string) error {
elasticIP := v3.CreateElasticIPRequest{
Healthcheck: healthcheck,
Description: c.Description,
Labels: c.Labels,
}

if c.IPv6 {
elasticIP.Addressfamily = "inet6"
}

op, err := client.CreateElasticIP(ctx, elasticIP)
if err != nil {
return err
}
var eipID v3.UUID
{
op, err := client.CreateElasticIP(ctx, elasticIP)
if err != nil {
return err
}

utils.DecorateAsyncOperation("Creating Elastic IP...", func() {
op, err = client.Wait(ctx, op, v3.OperationStateSuccess)
})
if err != nil {
return err
utils.DecorateAsyncOperation("Creating Elastic IP...", func() {
op, err = client.Wait(ctx, op, v3.OperationStateSuccess)
})
if err != nil {
return fmt.Errorf("unable to create elastic ip: %w", err)
}
eipID = op.Reference.ID
}
{
op, err := client.UpdateReverseDNSElasticIP(
ctx,
eipID,
v3.UpdateReverseDNSElasticIPRequest{DomainName: c.ReverseDNS},
)
utils.DecorateAsyncOperation("Updating Elastic IP reverse dns...", func() {
_, err = client.Wait(ctx, op, v3.OperationStateSuccess)
})
if err != nil {
return fmt.Errorf("unable to update elastic ip reverse dns: %w", err)
}
}

return (&elasticIPShowCmd{
CliCommandSettings: c.CliCommandSettings,
ElasticIP: op.Reference.ID.String(),
ElasticIP: eipID.String(),
Zone: c.Zone,
}).CmdRun(nil, nil)
}
Expand Down
50 changes: 32 additions & 18 deletions cmd/compute/elastic_ip/elastic_ip_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@ import (
)

type elasticIPShowOutput struct {
ID string `json:"id"`
IPAddress string `json:"ip_address"`
AddressFamily string `json:"address_family"`
CIDR string `json:"cidr"`
Description string `json:"description"`
Zone string `json:"zone"`
Type string `json:"type"`
ReverseDNS string `json:"reverse_dns"`
Instances []string `json:"instances"`
HealthcheckMode string `json:"healthcheck_mode,omitempty"`
HealthcheckPort int64 `json:"healthcheck_port,omitempty"`
HealthcheckURI string `json:"healthcheck_uri,omitempty"`
HealthcheckInterval time.Duration `json:"healthcheck_interval,omitempty"`
HealthcheckTimeout time.Duration `json:"healthcheck_timeout,omitempty"`
HealthcheckStrikesOK int64 `json:"healthcheck_strikes_ok,omitempty"`
HealthcheckStrikesFail int64 `json:"healthcheck_strikes_fail,omitempty"`
HealthcheckTLSSNI string `json:"healthcheck_tls_sni,omitempty"`
HealthcheckTLSSkipVerify *bool `json:"healthcheck_tls_skip_verify,omitempty"`
ID string `json:"id"`
IPAddress string `json:"ip_address"`
AddressFamily string `json:"address_family"`
CIDR string `json:"cidr"`
Description string `json:"description"`
Zone string `json:"zone"`
Type string `json:"type"`
ReverseDNS string `json:"reverse_dns"`
Instances []string `json:"instances"`
HealthcheckMode string `json:"healthcheck_mode,omitempty"`
HealthcheckPort int64 `json:"healthcheck_port,omitempty"`
HealthcheckURI string `json:"healthcheck_uri,omitempty"`
HealthcheckInterval time.Duration `json:"healthcheck_interval,omitempty"`
HealthcheckTimeout time.Duration `json:"healthcheck_timeout,omitempty"`
HealthcheckStrikesOK int64 `json:"healthcheck_strikes_ok,omitempty"`
HealthcheckStrikesFail int64 `json:"healthcheck_strikes_fail,omitempty"`
HealthcheckTLSSNI string `json:"healthcheck_tls_sni,omitempty"`
HealthcheckTLSSkipVerify *bool `json:"healthcheck_tls_skip_verify,omitempty"`
Labels map[string]string `json:"labels"`
}

func (o *elasticIPShowOutput) ToJSON() { output.JSON(o) }
Expand Down Expand Up @@ -75,6 +76,18 @@ func (o *elasticIPShowOutput) ToTable() {
t.Append([]string{"Healthcheck TLS Skip Verification", fmt.Sprint(o.HealthcheckTLSSkipVerify)})
}
}

var labelsOutput string
if len(o.Labels) > 0 {
var labels []string
for k, v := range o.Labels {
labels = append(labels, fmt.Sprintf("%s:%s", k, v))
}
labelsOutput = strings.Join(labels, "\n")
} else {
labelsOutput = "n/a"
}
t.Append([]string{"Labels", labelsOutput})
}

type elasticIPShowCmd struct {
Expand Down Expand Up @@ -133,6 +146,7 @@ func (c *elasticIPShowCmd) CmdRun(_ *cobra.Command, _ []string) error {
Description: elasticIp.Description,
Zone: c.Zone,
Type: "manual",
Labels: elasticIp.Labels,
}

rdns, err := client.GetReverseDNSElasticIP(ctx, elasticIp.ID)
Expand Down
Loading