This repository has been archived by the owner on Jan 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
706 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
data "megaport_location" "foo" { | ||
name_regex = "{{ .location }}" | ||
mcr_available = {{ .mcr_version }} | ||
} | ||
|
||
resource "megaport_mcr" "foo" { | ||
mcr_version = {{ .mcr_version }} | ||
name = "terraform_acctest_{{ .uid }}" | ||
location_id = data.megaport_location.foo.id | ||
rate_limit = {{ .rate_limit }} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
data "megaport_location" "foo" { | ||
name_regex = "{{ .location }}" | ||
mcr_available = {{ .mcr_version }} | ||
} | ||
|
||
resource "megaport_mcr" "foo" { | ||
mcr_version = {{ .mcr_version }} | ||
name = "terraform_acctest_{{ .uid }}" | ||
location_id = data.megaport_location.foo.id | ||
rate_limit = {{ .rate_limit }} | ||
invoice_reference = "{{ .uid }}" | ||
{{- if .term }} | ||
term = {{ .term }} | ||
{{- end }} | ||
{{- if .asn }} | ||
asn = {{ .asn }} | ||
{{- end }} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type McrCreateInput interface { | ||
networkDesignInput | ||
mcrVersion() uint64 | ||
} | ||
|
||
type Mcr1CreateInput struct { | ||
Asn *uint64 | ||
InvoiceReference *string | ||
LocationId *uint64 | ||
Name *string | ||
RateLimit *uint64 | ||
Term *uint64 | ||
} | ||
|
||
func (v *Mcr1CreateInput) mcrVersion() uint64 { | ||
return 1 | ||
} | ||
|
||
func (v *Mcr1CreateInput) productType() string { | ||
return ProductTypeMcr1 | ||
} | ||
|
||
func (v *Mcr1CreateInput) toPayload() ([]byte, error) { | ||
payload := []*portCreatePayload{{ | ||
LocationId: v.LocationId, | ||
Config: &portCreatePayloadPortConfig{}, | ||
CostCentre: v.InvoiceReference, | ||
PortSpeed: v.RateLimit, | ||
ProductName: v.Name, | ||
ProductType: String(ProductTypeMcr1), | ||
Term: v.Term, | ||
Virtual: Bool(true), | ||
}} | ||
if v.Asn != nil && *v.Asn > 0 { | ||
payload[0].Config.McrAsn = v.Asn | ||
} | ||
return json.Marshal(payload) | ||
} | ||
|
||
type Mcr2CreateInput struct { | ||
Asn *uint64 | ||
InvoiceReference *string | ||
LocationId *uint64 | ||
Name *string | ||
RateLimit *uint64 | ||
} | ||
|
||
func (v *Mcr2CreateInput) mcrVersion() uint64 { | ||
return 2 | ||
} | ||
|
||
func (v *Mcr2CreateInput) productType() string { | ||
return ProductTypeMcr2 | ||
} | ||
|
||
func (v *Mcr2CreateInput) toPayload() ([]byte, error) { | ||
payload := []*portCreatePayload{{ | ||
LocationId: v.LocationId, | ||
Config: &portCreatePayloadPortConfig{}, | ||
CostCentre: v.InvoiceReference, | ||
PortSpeed: v.RateLimit, | ||
ProductName: v.Name, | ||
ProductType: String(ProductTypeMcr2), | ||
}} | ||
if v.Asn != nil && *v.Asn > 0 { | ||
payload[0].Config.McrAsn = v.Asn | ||
} | ||
return json.Marshal(payload) | ||
} | ||
|
||
type McrUpdateInput interface { | ||
networkDesignInput | ||
productUid() string | ||
} | ||
|
||
type Mcr1UpdateInput struct { | ||
InvoiceReference *string | ||
Name *string | ||
ProductUid *string | ||
} | ||
|
||
func (v *Mcr1UpdateInput) productUid() string { | ||
return *v.ProductUid | ||
} | ||
|
||
func (v *Mcr1UpdateInput) productType() string { | ||
return ProductTypeMcr1 | ||
} | ||
|
||
func (v *Mcr1UpdateInput) toPayload() ([]byte, error) { | ||
payload := &portUpdatePayload{ | ||
Name: v.Name, | ||
CostCentre: v.InvoiceReference, | ||
} | ||
return json.Marshal(payload) | ||
} | ||
|
||
type Mcr2UpdateInput struct { | ||
InvoiceReference *string | ||
Name *string | ||
ProductUid *string | ||
} | ||
|
||
func (v *Mcr2UpdateInput) productUid() string { | ||
return *v.ProductUid | ||
} | ||
|
||
func (v *Mcr2UpdateInput) productType() string { | ||
return ProductTypeMcr2 | ||
} | ||
|
||
func (v *Mcr2UpdateInput) toPayload() ([]byte, error) { | ||
payload := &portUpdatePayload{ | ||
Name: v.Name, | ||
CostCentre: v.InvoiceReference, | ||
} | ||
return json.Marshal(payload) | ||
} | ||
|
||
func (c *Client) CreateMcr(v McrCreateInput) (*string, error) { | ||
d, err := c.create(v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
uid := d[0]["technicalServiceUid"].(string) | ||
return &uid, nil | ||
} | ||
|
||
func (c *Client) GetMcr(uid string) (*Product, error) { | ||
d := &Product{} | ||
if err := c.get(uid, d); err != nil { | ||
return nil, err | ||
} | ||
return d, nil | ||
} | ||
|
||
func (c *Client) UpdateMcr(v McrUpdateInput) error { | ||
return c.update(v.productUid(), v) | ||
} | ||
|
||
func (c *Client) DeleteMcr(uid string) error { | ||
return c.delete(uid) | ||
} | ||
|
||
func (c *Client) ListMcrs() ([]*Product, error) { | ||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/v2/products", c.BaseURL), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
data := []*Product{} | ||
if err := c.do(req, &data); err != nil { | ||
return nil, err | ||
} | ||
return data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.