From 6d584e5f0b048577d1a960af87f7e32a45f03740 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Wed, 15 Jun 2022 21:57:30 -0400 Subject: [PATCH] add --metro to ip request command Signed-off-by: Marques Johansson --- docs/metal_ip_request.md | 11 ++++++----- internal/ips/request.go | 17 +++++++++-------- internal/ips/retrieve.go | 23 +++++++++++++++++------ 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/docs/metal_ip_request.md b/docs/metal_ip_request.md index 3fe2c9f5..d01dd976 100644 --- a/docs/metal_ip_request.md +++ b/docs/metal_ip_request.md @@ -4,25 +4,26 @@ Request a block of IP addresses. ### Synopsis -Requests either a block of public IPv4 addresses or global IPv4 addresses for your project in a specific facility. +Requests either a block of public IPv4 addresses or global IPv4 addresses for your project in a specific metro or facility. ``` -metal ip request -p -t -q -f [-f ] [-c ] [flags] +metal ip request -p -t -q (-m | -f ) [-f ] [-c ] [flags] ``` ### Examples ``` - # Requests a block of 4 public IPv4 addresses in DA11: - metal ip request -p $METAL_PROJECT_ID -t public_ipv4 -q 4 -f da11 + # Requests a block of 4 public IPv4 addresses in Dallas: + metal ip request -p $METAL_PROJECT_ID -t public_ipv4 -q 4 -m da ``` ### Options ``` -c, --comments string General comments or description. - -f, --facility string Code of the facility. + -f, --facility string Code of the facility where the IP Reservation will be created -h, --help help for request + -m, --metro string Code of the metro where the IP Reservation will be created -p, --project-id string The project's UUID. This flag is required, unless specified in the config created by metal init or set as METAL_PROJECT_ID environment variable. -q, --quantity int Number of IP addresses to reserve. --tags strings Tag or Tags to add to the reservation, in a comma-separated list. diff --git a/internal/ips/request.go b/internal/ips/request.go index d2c38ee2..6b177081 100644 --- a/internal/ips/request.go +++ b/internal/ips/request.go @@ -29,23 +29,23 @@ import ( ) func (c *Client) Request() *cobra.Command { - var ( ttype string quantity int comments string facility string + metro string projectID string tags []string ) // requestIPCmd represents the requestIp command - var requestIPCmd = &cobra.Command{ - Use: `request -p -t -q -f [-f ] [-c ]`, + requestIPCmd := &cobra.Command{ + Use: `request -p -t -q (-m | -f ) [-f ] [-c ]`, Short: "Request a block of IP addresses.", - Long: "Requests either a block of public IPv4 addresses or global IPv4 addresses for your project in a specific facility.", - Example: ` # Requests a block of 4 public IPv4 addresses in DA11: - metal ip request -p $METAL_PROJECT_ID -t public_ipv4 -q 4 -f da11`, + Long: "Requests either a block of public IPv4 addresses or global IPv4 addresses for your project in a specific metro or facility.", + Example: ` # Requests a block of 4 public IPv4 addresses in Dallas: + metal ip request -p $METAL_PROJECT_ID -t public_ipv4 -q 4 -m da`, RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true @@ -53,6 +53,7 @@ func (c *Client) Request() *cobra.Command { Type: ttype, Quantity: quantity, Facility: &facility, + Metro: &metro, Tags: tags, } @@ -72,14 +73,14 @@ func (c *Client) Request() *cobra.Command { requestIPCmd.Flags().StringVarP(&projectID, "project-id", "p", "", "The project's UUID. This flag is required, unless specified in the config created by metal init or set as METAL_PROJECT_ID environment variable.") requestIPCmd.Flags().StringVarP(&ttype, "type", "t", "", "The type of IP Address, either public_ipv4 or global_ipv4.") - requestIPCmd.Flags().StringVarP(&facility, "facility", "f", "", "Code of the facility.") + requestIPCmd.Flags().StringVarP(&facility, "facility", "f", "", "Code of the facility where the IP Reservation will be created") + requestIPCmd.Flags().StringVarP(&metro, "metro", "m", "", "Code of the metro where the IP Reservation will be created") requestIPCmd.Flags().IntVarP(&quantity, "quantity", "q", 0, "Number of IP addresses to reserve.") requestIPCmd.Flags().StringSliceVar(&tags, "tags", nil, "Tag or Tags to add to the reservation, in a comma-separated list.") _ = requestIPCmd.MarkFlagRequired("project-id") _ = requestIPCmd.MarkFlagRequired("type") _ = requestIPCmd.MarkFlagRequired("quantity") - _ = requestIPCmd.MarkFlagRequired("facility") requestIPCmd.Flags().StringVarP(&comments, "comments", "c", "", "General comments or description.") return requestIPCmd diff --git a/internal/ips/retrieve.go b/internal/ips/retrieve.go index 83bbc5cf..e8346a64 100644 --- a/internal/ips/retrieve.go +++ b/internal/ips/retrieve.go @@ -36,7 +36,7 @@ func (c *Client) Retrieve() *cobra.Command { ) // ipCmd represents the ip command - var retrieveIPCmd = &cobra.Command{ + retrieveIPCmd := &cobra.Command{ Use: `get -p | -a | -r `, Aliases: []string{"list"}, Short: "Retrieves information about IP addresses, IP address reservations, and IP address assignments.", @@ -79,9 +79,16 @@ func (c *Client) Retrieve() *cobra.Command { } data := make([][]string, 1) - - data[0] = []string{ip.ID, ip.Address, ip.Facility.Code, strconv.FormatBool(ip.Public), ip.Created} - header := []string{"ID", "Address", "Facility", "Public", "Created"} + code := "" + metro := "" + if ip.Facility != nil { + code = ip.Facility.Code + } + if ip.Metro != nil { + metro = ip.Metro.Code + } + data[0] = []string{ip.ID, ip.Address, metro, code, strconv.FormatBool(ip.Public), ip.Created} + header := []string{"ID", "Address", "Metro", "Facility", "Public", "Created"} return c.Out.Output(ip, header, &data) } @@ -95,12 +102,16 @@ func (c *Client) Retrieve() *cobra.Command { for i, ip := range ips { code := "" + metro := "" if ip.Facility != nil { code = ip.Facility.Code } - data[i] = []string{ip.ID, ip.Address, code, strconv.FormatBool(ip.Public), ip.Created} + if ip.Metro != nil { + metro = ip.Metro.Code + } + data[i] = []string{ip.ID, ip.Address, metro, code, strconv.FormatBool(ip.Public), ip.Created} } - header := []string{"ID", "Address", "Facility", "Public", "Created"} + header := []string{"ID", "Address", "Metro", "Facility", "Public", "Created"} return c.Out.Output(ips, header, &data) },