Skip to content

Commit

Permalink
Merge pull request #208 from equinix/metro-ips
Browse files Browse the repository at this point in the history
Create IP Reservations in a Metro
  • Loading branch information
cprivitere authored Jun 16, 2022
2 parents acd469d + 6d584e5 commit aba93a7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
11 changes: 6 additions & 5 deletions docs/metal_ip_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <project_id> -t <ip_address_type> -q <quantity> -f <facility_code> [-f <flags>] [-c <comments>] [flags]
metal ip request -p <project_id> -t <ip_address_type> -q <quantity> (-m <metro> | -f <facility>) [-f <flags>] [-c <comments>] [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.
Expand Down
7 changes: 3 additions & 4 deletions internal/devices/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
)

func (c *Client) Create() *cobra.Command {

var (
projectID string
metro string
Expand All @@ -55,15 +54,15 @@ func (c *Client) Create() *cobra.Command {
terminationTime string
)

var createDeviceCmd = &cobra.Command{
createDeviceCmd := &cobra.Command{
Use: `create -p <project_id> (-m <metro> | -f <facility>) -P <plan> -H <hostname> -O <operating_system> [-u <userdata> | --userdata-file <filepath>] [-c <customdata>] [-t <tags>] [-r <hardware_reservation_id>] [-I <ipxe_script_url>] [--always-pxe] [--spot-instance] [--spot-price-max=<max_price>]`,
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
Expand Down
2 changes: 1 addition & 1 deletion internal/devices/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func (c *Client) Retrieve() *cobra.Command {
var retrieveDeviceCmd = &cobra.Command{
retrieveDeviceCmd := &cobra.Command{
Use: `get [-p <project_id>] | [-i <device_id>]`,
Aliases: []string{"list"},
Short: "Retrieves device list or device details.",
Expand Down
17 changes: 9 additions & 8 deletions internal/ips/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,31 @@ 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 <project_id> -t <ip_address_type> -q <quantity> -f <facility_code> [-f <flags>] [-c <comments>]`,
requestIPCmd := &cobra.Command{
Use: `request -p <project_id> -t <ip_address_type> -q <quantity> (-m <metro> | -f <facility>) [-f <flags>] [-c <comments>]`,
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
req := &packngo.IPReservationRequest{
Type: ttype,
Quantity: quantity,
Facility: &facility,
Metro: &metro,
Tags: tags,
}

Expand All @@ -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
Expand Down
23 changes: 17 additions & 6 deletions internal/ips/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <project_UUID> | -a <assignment_UUID> | -r <reservation_UUID>`,
Aliases: []string{"list"},
Short: "Retrieves information about IP addresses, IP address reservations, and IP address assignments.",
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
},
Expand Down

0 comments on commit aba93a7

Please sign in to comment.