Skip to content

Commit

Permalink
Implement updating Ports
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitrios Karagiannis <[email protected]>
  • Loading branch information
alkar committed Oct 24, 2019
1 parent 413695f commit 99fd6d8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
31 changes: 29 additions & 2 deletions megaport/api/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ type portCreatePayload struct {
Virtual *bool `json:"virtual"` // TODO: False for port, true for MCR1.0 (https://dev.megaport.com/#standard-api-orders-validate-port-order)
}

type portUpdatePayload struct {
Name *string `json:"name,omitempty"`
CostCentre *string `json:"costCentre,omitempty"`
MarketplaceVisibility *bool `json:"marketplaceVisibility,omitempty"`
// RateLimit *uint64 `json:"rateLimit,omitempty"` // Only applicable to MCR. Must be one of 100, 500, 1000, 2000, 3000, 4000, 5000
}

type PortCreateInput struct {
LocationId *uint64
Name *string
Expand All @@ -53,6 +60,26 @@ func (v *PortCreateInput) toPayload() ([]byte, error) {
return json.Marshal(payload)
}

type PortUpdateInput struct {
InvoiceReference *string
MarketplaceVisibility *bool
Name *string
ProductUid *string
}

func (v *PortUpdateInput) productType() string {
return ProductTypePort
}

func (v *PortUpdateInput) toPayload() ([]byte, error) {
payload := &portUpdatePayload{
Name: v.Name,
CostCentre: v.InvoiceReference,
MarketplaceVisibility: v.MarketplaceVisibility,
}
return json.Marshal(payload)
}

func (c *Client) CreatePort(v *PortCreateInput) (*string, error) {
d, err := c.create(v)
if err != nil {
Expand All @@ -70,8 +97,8 @@ func (c *Client) GetPort(uid string) (*Product, error) {
return d, nil
}

func (c *Client) UpdatePort() error {
return nil
func (c *Client) UpdatePort(v *PortUpdateInput) error {
return c.update(*v.ProductUid, v)
}

func (c *Client) DeletePort(uid string) error {
Expand Down
11 changes: 10 additions & 1 deletion megaport/resource_megaport_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,16 @@ func resourceMegaportPortCreate(d *schema.ResourceData, m interface{}) error {
}

func resourceMegaportPortUpdate(d *schema.ResourceData, m interface{}) error {
return nil // TODO
cfg := m.(*Config)
if err := cfg.Client.UpdatePort(&api.PortUpdateInput{
InvoiceReference: api.String(d.Get("invoice_reference")),
Name: api.String(d.Get("name")),
ProductUid: api.String(d.Id()),
//RateLimit: api.Uint64FromInt(d.Get("rate_limit")),
}); err != nil {
return err
}
return resourceMegaportPortRead(d, m)
}

func resourceMegaportPortDelete(d *schema.ResourceData, m interface{}) error {
Expand Down

0 comments on commit 99fd6d8

Please sign in to comment.