From dce7f70e3c0c726cd73a6c5d3214e60b8ea84691 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Wed, 15 Jun 2022 21:56:11 -0400 Subject: [PATCH 1/2] revise device example snippets to match markdown changes Signed-off-by: Marques Johansson --- internal/devices/create.go | 7 +++---- internal/devices/retrieve.go | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/devices/create.go b/internal/devices/create.go index a96afa4c..1087d7c6 100644 --- a/internal/devices/create.go +++ b/internal/devices/create.go @@ -32,7 +32,6 @@ import ( ) func (c *Client) Create() *cobra.Command { - var ( projectID string metro string @@ -55,15 +54,15 @@ func (c *Client) Create() *cobra.Command { terminationTime string ) - var createDeviceCmd = &cobra.Command{ + createDeviceCmd := &cobra.Command{ Use: `create -p (-m | -f ) -P -H -O [-u | --userdata-file ] [-c ] [-t ] [-r ] [-I ] [--always-pxe] [--spot-instance] [--spot-price-max=]`, Short: "Creates a device.", Long: "Creates a device in the specified project. A plan, hostname, operating system, and either metro or facility is required.", Example: ` # Provisions a c3.small.x86 in the Dallas metro running Ubuntu 20.04: - metal device create -p $METAL_PROJECT_ID -p c3.small.x86 -m da -H test-staging-2 -O ubuntu_20_04, + metal device create -p $METAL_PROJECT_ID -P c3.small.x86 -m da -H test-staging-2 -O ubuntu_20_04 # Provisions a c3.medium.x86 in Silicon Valley, running Rocky Linux, from a hardware reservation: - metal device create -p $METAL_PROJECT_ID -p c3.medium.x86 -m sv -H test-rocky -O rocky_8 -r 47161704-1715-4b45-8549-fb3f4b2c32c7`, + metal device create -p $METAL_PROJECT_ID -P c3.medium.x86 -m sv -H test-rocky -O rocky_8 -r 47161704-1715-4b45-8549-fb3f4b2c32c7`, RunE: func(cmd *cobra.Command, args []string) error { var endDt *packngo.Timestamp diff --git a/internal/devices/retrieve.go b/internal/devices/retrieve.go index 52ab6350..02b376a3 100644 --- a/internal/devices/retrieve.go +++ b/internal/devices/retrieve.go @@ -28,7 +28,7 @@ import ( ) func (c *Client) Retrieve() *cobra.Command { - var retrieveDeviceCmd = &cobra.Command{ + retrieveDeviceCmd := &cobra.Command{ Use: `get [-p ] | [-i ]`, Aliases: []string{"list"}, Short: "Retrieves device list or device details.", From 6d584e5f0b048577d1a960af87f7e32a45f03740 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Wed, 15 Jun 2022 21:57:30 -0400 Subject: [PATCH 2/2] 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) },