From a6b0be0e50ec7f569f980bcab45d2e9b595c51b2 Mon Sep 17 00:00:00 2001 From: Kaley Date: Tue, 22 Nov 2016 15:06:24 -0500 Subject: [PATCH] Refactor resource objects & add in a connection check --- client/client.go | 32 ++++++++++++------------------- client/client_test.go | 32 +++++++++++++++---------------- client/leases.go | 27 +++++++++++--------------- client/pools.go | 43 +++++++++++++++++++----------------------- client/reservations.go | 43 +++++++++++++++++++----------------------- client/subnets.go | 43 +++++++++++++++++++----------------------- 6 files changed, 96 insertions(+), 124 deletions(-) diff --git a/client/client.go b/client/client.go index 833141b..c520f52 100644 --- a/client/client.go +++ b/client/client.go @@ -6,9 +6,10 @@ import ( "errors" "fmt" "io" + "log" "mime" - "net/http" + "time" "github.com/RackHD/ipam/controllers/helpers" "github.com/RackHD/ipam/interfaces" @@ -29,27 +30,18 @@ func NewClient(address string) *Client { Address: address, Scheme: "http", } - return c -} - -//Leases returns a handle to the Leases routes -func (c *Client) Leases() *Leases { - return &Leases{c} -} -//Reservations returns a handle to the Reservations routes -func (c *Client) Reservations() *Reservations { - return &Reservations{c} -} - -//Subnets returns a handle to the Subnets routes -func (c *Client) Subnets() *Subnets { - return &Subnets{c} -} + // Make sure IPAM connection is alive, with retries + for i := 0; i < 5; i++ { + _, err := c.IndexPools() + if err == nil { + return c + } + log.Println("Could not connect to IPAM, retrying in 5 Seconds...") + time.Sleep(5 * time.Second) + } -//Pools returns a handle to the Pools routes -func (c *Client) Pools() *Pools { - return &Pools{c} + return nil } // SendResource is used to send a generic resource type diff --git a/client/client_test.go b/client/client_test.go index 59820fb..fd642a7 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -27,7 +27,7 @@ var _ = Describe("Client tests", func() { }) AfterEach(func() { - poolLocation, err := ipamClient.Pools().Delete(pool.ID, pool) + poolLocation, err := ipamClient.DeletePool(pool.ID, pool) Expect(err).To(BeNil()) Expect(poolLocation).To(Equal("/pools")) }) @@ -38,7 +38,7 @@ var _ = Describe("Client tests", func() { Metadata: "yodawg I heard you like interfaces", } - pool, err = ipamClient.Pools().CreateShowPool(pool) + pool, err = ipamClient.CreateShowPool(pool) Expect(err).To(BeNil()) Expect(pool.ID).ToNot(Equal("")) Expect(pool.Name).To(Equal("Pool1")) @@ -59,7 +59,7 @@ var _ = Describe("Client tests", func() { Name: "SubnetTestPool1", } - pool, err = ipamClient.Pools().CreateShowPool(pool) + pool, err = ipamClient.CreateShowPool(pool) Expect(err).To(BeNil()) Expect(pool.ID).ToNot(Equal("")) Expect(pool.Name).To(Equal("SubnetTestPool1")) @@ -67,7 +67,7 @@ var _ = Describe("Client tests", func() { }) AfterEach(func() { - poolLocation, err := ipamClient.Pools().Delete(pool.ID, pool) + poolLocation, err := ipamClient.DeletePool(pool.ID, pool) Expect(err).To(BeNil()) Expect(poolLocation).To(Equal("/pools")) }) @@ -81,7 +81,7 @@ var _ = Describe("Client tests", func() { End: end, } - subnet, err = ipamClient.Subnets().CreateShowSubnet(pool.ID, subnet) + subnet, err = ipamClient.CreateShowSubnet(pool.ID, subnet) Expect(err).To(BeNil()) Expect(subnet.ID).ToNot(Equal("")) Expect(subnet.Name).To(Equal("Subnet1")) @@ -105,7 +105,7 @@ var _ = Describe("Client tests", func() { Name: "ReservationTestPool1", } - pool, err = ipamClient.Pools().CreateShowPool(pool) + pool, err = ipamClient.CreateShowPool(pool) Expect(err).To(BeNil()) Expect(pool.ID).ToNot(Equal("")) Expect(pool.Name).To(Equal("ReservationTestPool1")) @@ -117,7 +117,7 @@ var _ = Describe("Client tests", func() { End: end, } - subnet, err = ipamClient.Subnets().CreateShowSubnet(pool.ID, subnet) + subnet, err = ipamClient.CreateShowSubnet(pool.ID, subnet) Expect(err).To(BeNil()) Expect(subnet.ID).ToNot(Equal("")) Expect(subnet.Name).To(Equal("ReservationTestSubnet1")) @@ -126,7 +126,7 @@ var _ = Describe("Client tests", func() { }) AfterEach(func() { - poolLocation, err := ipamClient.Pools().Delete(pool.ID, pool) + poolLocation, err := ipamClient.DeletePool(pool.ID, pool) Expect(err).To(BeNil()) Expect(poolLocation).To(Equal("/pools")) }) @@ -138,7 +138,7 @@ var _ = Describe("Client tests", func() { Subnet: subnet.ID, } - reservation, err = ipamClient.Reservations().CreateShowReservation(subnet.ID, reservation) + reservation, err = ipamClient.CreateShowReservation(subnet.ID, reservation) Expect(err).To(BeNil()) Expect(reservation.ID).ToNot(Equal("")) Expect(reservation.Name).To(Equal("Reservation1")) @@ -162,7 +162,7 @@ var _ = Describe("Client tests", func() { Name: "LeaseTestPool1", } - pool, err = ipamClient.Pools().CreateShowPool(pool) + pool, err = ipamClient.CreateShowPool(pool) Expect(err).To(BeNil()) Expect(pool.ID).ToNot(Equal("")) Expect(pool.Name).To(Equal("LeaseTestPool1")) @@ -174,7 +174,7 @@ var _ = Describe("Client tests", func() { End: end, } - subnet, err = ipamClient.Subnets().CreateShowSubnet(pool.ID, subnet) + subnet, err = ipamClient.CreateShowSubnet(pool.ID, subnet) Expect(err).To(BeNil()) Expect(subnet.ID).ToNot(Equal("")) Expect(subnet.Name).To(Equal("LeaseTestSubnet1")) @@ -185,7 +185,7 @@ var _ = Describe("Client tests", func() { Subnet: subnet.ID, } - reservation, err = ipamClient.Reservations().CreateShowReservation(subnet.ID, reservation) + reservation, err = ipamClient.CreateShowReservation(subnet.ID, reservation) Expect(err).To(BeNil()) Expect(reservation.ID).ToNot(Equal("")) Expect(reservation.Name).To(Equal("LeaseTestReservation1")) @@ -196,7 +196,7 @@ var _ = Describe("Client tests", func() { Subnet: subnet.ID, } - reservation2, err = ipamClient.Reservations().CreateShowReservation(subnet.ID, reservation2) + reservation2, err = ipamClient.CreateShowReservation(subnet.ID, reservation2) Expect(err).To(BeNil()) Expect(reservation2.ID).ToNot(Equal("")) Expect(reservation2.Name).To(Equal("LeaseTestReservation2")) @@ -205,18 +205,18 @@ var _ = Describe("Client tests", func() { }) AfterEach(func() { - poolLocation, err := ipamClient.Pools().Delete(pool.ID, pool) + poolLocation, err := ipamClient.DeletePool(pool.ID, pool) Expect(err).To(BeNil()) Expect(poolLocation).To(Equal("/pools")) }) It("Should show all leases", func() { - leases, err = ipamClient.Leases().Index(reservation.ID) + leases, err = ipamClient.IndexLeases(reservation.ID) Expect(err).To(BeNil()) Expect(leases.Leases[0].ID).ToNot(Equal("")) Expect(leases.Leases[0].Reservation).To(Equal(reservation.ID)) - leases2, err = ipamClient.Leases().Index(reservation2.ID) + leases2, err = ipamClient.IndexLeases(reservation2.ID) Expect(err).To(BeNil()) Expect(leases2.Leases[0].ID).ToNot(Equal("")) Expect(leases2.Leases[0].Reservation).To(Equal(reservation2.ID)) diff --git a/client/leases.go b/client/leases.go index e7e458b..e11018f 100644 --- a/client/leases.go +++ b/client/leases.go @@ -6,14 +6,9 @@ import ( "github.com/RackHD/ipam/resources" ) -//Leases can be used to query the Leases routes -type Leases struct { - client *Client -} - -// Index returns a list of Leases. -func (l *Leases) Index(reservationID string) (resources.LeasesV1, error) { - returnedLeases, err := l.client.ReceiveResource("GET", "/reservations/"+reservationID+"/leases", "", "") +// IndexLeases returns a list of Leases. +func (c *Client) IndexLeases(reservationID string) (resources.LeasesV1, error) { + returnedLeases, err := c.ReceiveResource("GET", "/reservations/"+reservationID+"/leases", "", "") if err != nil { return resources.LeasesV1{}, err } @@ -23,9 +18,9 @@ func (l *Leases) Index(reservationID string) (resources.LeasesV1, error) { return resources.LeasesV1{}, errors.New("Lease Index call error.") } -// Show returns the requested Lease. -func (l *Leases) Show(leaseID string, leaseToShow resources.LeaseV1) (resources.LeaseV1, error) { - returnedLease, err := l.client.ReceiveResource("GET", "/leases/"+leaseID, leaseToShow.Type(), leaseToShow.Version()) +// ShowLease returns the requested Lease. +func (c *Client) ShowLease(leaseID string, leaseToShow resources.LeaseV1) (resources.LeaseV1, error) { + returnedLease, err := c.ReceiveResource("GET", "/leases/"+leaseID, leaseToShow.Type(), leaseToShow.Version()) if err != nil { return resources.LeaseV1{}, err } @@ -35,9 +30,9 @@ func (l *Leases) Show(leaseID string, leaseToShow resources.LeaseV1) (resources. return resources.LeaseV1{}, errors.New("Lease Show call error.") } -// Update updates the requested Lease and returns its location. -func (l *Leases) Update(leaseID string, leaseToUpdate resources.LeaseV1) (string, error) { - leaseLocation, err := l.client.SendResource("PATCH", "/leases/"+leaseID, &leaseToUpdate) +// UpdateLease updates the requested Lease and returns its location. +func (c *Client) UpdateLease(leaseID string, leaseToUpdate resources.LeaseV1) (string, error) { + leaseLocation, err := c.SendResource("PATCH", "/leases/"+leaseID, &leaseToUpdate) if err != nil { return "", err } @@ -45,8 +40,8 @@ func (l *Leases) Update(leaseID string, leaseToUpdate resources.LeaseV1) (string } // UpdateShowLease updates a Lease and then returns that Lease. -func (l *Leases) UpdateShowLease(leaseID string, leaseToUpdate resources.LeaseV1) (resources.LeaseV1, error) { - returnedLease, err := l.client.SendReceiveResource("PATCH", "GET", "/leases/"+leaseID, &leaseToUpdate) +func (c *Client) UpdateShowLease(leaseID string, leaseToUpdate resources.LeaseV1) (resources.LeaseV1, error) { + returnedLease, err := c.SendReceiveResource("PATCH", "GET", "/leases/"+leaseID, &leaseToUpdate) if err != nil { return resources.LeaseV1{}, err } diff --git a/client/pools.go b/client/pools.go index ded4302..5473c56 100644 --- a/client/pools.go +++ b/client/pools.go @@ -6,14 +6,9 @@ import ( "github.com/RackHD/ipam/resources" ) -//Pools can be used to query the Pools routes -type Pools struct { - client *Client -} - -// Index returns a list of Pools. -func (p *Pools) Index() (resources.PoolsV1, error) { - pools, err := p.client.ReceiveResource("GET", "/pools", "", "") +// IndexPools returns a list of Pools. +func (c *Client) IndexPools() (resources.PoolsV1, error) { + pools, err := c.ReceiveResource("GET", "/pools", "", "") if err != nil { return resources.PoolsV1{}, err } @@ -24,10 +19,10 @@ func (p *Pools) Index() (resources.PoolsV1, error) { return resources.PoolsV1{}, errors.New("Pool Index call error.") } -// Create a pool and returns the location. -func (p *Pools) Create(poolToCreate resources.PoolV1) (string, error) { +// CreatePool a pool and returns the location. +func (c *Client) CreatePool(poolToCreate resources.PoolV1) (string, error) { - poolLocation, err := p.client.SendResource("POST", "/pools", &poolToCreate) + poolLocation, err := c.SendResource("POST", "/pools", &poolToCreate) if err != nil { return "", err } @@ -35,8 +30,8 @@ func (p *Pools) Create(poolToCreate resources.PoolV1) (string, error) { } // CreateShowPool creates a pool and then returns that pool. -func (p *Pools) CreateShowPool(poolToCreate resources.PoolV1) (resources.PoolV1, error) { - receivedPool, err := p.client.SendReceiveResource("POST", "GET", "/pools", &poolToCreate) +func (c *Client) CreateShowPool(poolToCreate resources.PoolV1) (resources.PoolV1, error) { + receivedPool, err := c.SendReceiveResource("POST", "GET", "/pools", &poolToCreate) if err != nil { return resources.PoolV1{}, err } @@ -46,9 +41,9 @@ func (p *Pools) CreateShowPool(poolToCreate resources.PoolV1) (resources.PoolV1, return resources.PoolV1{}, errors.New("CreateShowPool call error.") } -// Show returns the requested Pool. -func (p *Pools) Show(poolID string, poolToShow resources.PoolV1) (resources.PoolV1, error) { - receivedPool, err := p.client.ReceiveResource("GET", "/pools/"+poolID, poolToShow.Type(), poolToShow.Version()) +// ShowPool returns the requested Pool. +func (c *Client) ShowPool(poolID string, poolToShow resources.PoolV1) (resources.PoolV1, error) { + receivedPool, err := c.ReceiveResource("GET", "/pools/"+poolID, poolToShow.Type(), poolToShow.Version()) if err != nil { return resources.PoolV1{}, err } @@ -58,9 +53,9 @@ func (p *Pools) Show(poolID string, poolToShow resources.PoolV1) (resources.Pool return resources.PoolV1{}, errors.New("Pools Show call error.") } -// Update updates the requested Pool and returns its location. -func (p *Pools) Update(poolID string, poolToUpdate resources.PoolV1) (string, error) { - location, err := p.client.SendResource("PATCH", "/pools/"+poolID, &poolToUpdate) +// UpdatePool updates the requested Pool and returns its location. +func (c *Client) UpdatePool(poolID string, poolToUpdate resources.PoolV1) (string, error) { + location, err := c.SendResource("PATCH", "/pools/"+poolID, &poolToUpdate) if err != nil { return "", err } @@ -68,8 +63,8 @@ func (p *Pools) Update(poolID string, poolToUpdate resources.PoolV1) (string, er } // UpdateShowPool updates a pool and then returns that pool. -func (p *Pools) UpdateShowPool(poolID string, poolToUpdate resources.PoolV1) (resources.PoolV1, error) { - receivedPool, err := p.client.SendReceiveResource("PATCH", "GET", "/pools/"+poolID, &poolToUpdate) +func (c *Client) UpdateShowPool(poolID string, poolToUpdate resources.PoolV1) (resources.PoolV1, error) { + receivedPool, err := c.SendReceiveResource("PATCH", "GET", "/pools/"+poolID, &poolToUpdate) if err != nil { return resources.PoolV1{}, err } @@ -79,9 +74,9 @@ func (p *Pools) UpdateShowPool(poolID string, poolToUpdate resources.PoolV1) (re return resources.PoolV1{}, errors.New("UpdateShowPool call error.") } -// Delete removes the requested Pool and returns the location. -func (p *Pools) Delete(poolID string, poolToDelete resources.PoolV1) (string, error) { - location, err := p.client.SendResource("DELETE", "/pools/"+poolID, &poolToDelete) +// DeletePool removes the requested Pool and returns the location. +func (c *Client) DeletePool(poolID string, poolToDelete resources.PoolV1) (string, error) { + location, err := c.SendResource("DELETE", "/pools/"+poolID, &poolToDelete) if err != nil { return "", err } diff --git a/client/reservations.go b/client/reservations.go index e9dc8de..10830a8 100644 --- a/client/reservations.go +++ b/client/reservations.go @@ -6,14 +6,9 @@ import ( "github.com/RackHD/ipam/resources" ) -//Reservations can be used to query the Reservations routes -type Reservations struct { - client *Client -} - -// Index returns a list of Reservations. -func (r *Reservations) Index(subnetID string) (resources.ReservationsV1, error) { - receivedReservations, err := r.client.ReceiveResource("GET", "/subnets/"+subnetID+"/reservations", "", "") +// IndexReservations returns a list of Reservations. +func (c *Client) IndexReservations(subnetID string) (resources.ReservationsV1, error) { + receivedReservations, err := c.ReceiveResource("GET", "/subnets/"+subnetID+"/reservations", "", "") if err != nil { return resources.ReservationsV1{}, err } @@ -23,9 +18,9 @@ func (r *Reservations) Index(subnetID string) (resources.ReservationsV1, error) return resources.ReservationsV1{}, errors.New("Reservation Index call error.") } -// Create a Reservation and return the location. -func (r *Reservations) Create(subnetID string, reservationToCreate resources.ReservationV1) (string, error) { - reservationLocation, err := r.client.SendResource("POST", "/subnets/"+subnetID+"/reservations", &reservationToCreate) +// CreateReservation a Reservation and return the location. +func (c *Client) CreateReservation(subnetID string, reservationToCreate resources.ReservationV1) (string, error) { + reservationLocation, err := c.SendResource("POST", "/subnets/"+subnetID+"/reservations", &reservationToCreate) if err != nil { return "", err } @@ -33,8 +28,8 @@ func (r *Reservations) Create(subnetID string, reservationToCreate resources.Res } // CreateShowReservation creates a Reservation and then returns that Reservation. -func (r *Reservations) CreateShowReservation(subnetID string, reservationToCreate resources.ReservationV1) (resources.ReservationV1, error) { - receivedReservation, err := r.client.SendReceiveResource("POST", "GET", "/subnets/"+subnetID+"/reservations", &reservationToCreate) +func (c *Client) CreateShowReservation(subnetID string, reservationToCreate resources.ReservationV1) (resources.ReservationV1, error) { + receivedReservation, err := c.SendReceiveResource("POST", "GET", "/subnets/"+subnetID+"/reservations", &reservationToCreate) if err != nil { return resources.ReservationV1{}, err } @@ -44,9 +39,9 @@ func (r *Reservations) CreateShowReservation(subnetID string, reservationToCreat return resources.ReservationV1{}, errors.New("CreateShowReservation call error.") } -// Show returns the requested Reservation. -func (r *Reservations) Show(reservationID string, reservationToShow resources.ReservationV1) (resources.ReservationV1, error) { - receivedReservation, err := r.client.ReceiveResource("GET", "/reservations/"+reservationID, reservationToShow.Type(), reservationToShow.Version()) +// ShowReservation returns the requested Reservation. +func (c *Client) ShowReservation(reservationID string, reservationToShow resources.ReservationV1) (resources.ReservationV1, error) { + receivedReservation, err := c.ReceiveResource("GET", "/reservations/"+reservationID, reservationToShow.Type(), reservationToShow.Version()) if err != nil { return resources.ReservationV1{}, err } @@ -56,9 +51,9 @@ func (r *Reservations) Show(reservationID string, reservationToShow resources.Re return resources.ReservationV1{}, errors.New("Reservation Show call error.") } -// Update updates the requested Reservation and returns its location. -func (r *Reservations) Update(reservationID string, reservationToUpdate resources.ReservationV1) (string, error) { - reservationLocation, err := r.client.SendResource("PATCH", "/reservations/"+reservationID, &reservationToUpdate) +// UpdateReservation updates the requested Reservation and returns its location. +func (c *Client) UpdateReservation(reservationID string, reservationToUpdate resources.ReservationV1) (string, error) { + reservationLocation, err := c.SendResource("PATCH", "/reservations/"+reservationID, &reservationToUpdate) if err != nil { return "", err } @@ -66,8 +61,8 @@ func (r *Reservations) Update(reservationID string, reservationToUpdate resource } // UpdateShowReservation updates a Reservation and then returns that Reservation. -func (r *Reservations) UpdateShowReservation(reservationID string, reservationToUpdate resources.ReservationV1) (resources.ReservationV1, error) { - receivedReservation, err := r.client.SendReceiveResource("PATCH", "GET", "/reservations/"+reservationID, &reservationToUpdate) +func (c *Client) UpdateShowReservation(reservationID string, reservationToUpdate resources.ReservationV1) (resources.ReservationV1, error) { + receivedReservation, err := c.SendReceiveResource("PATCH", "GET", "/reservations/"+reservationID, &reservationToUpdate) if err != nil { return resources.ReservationV1{}, err } @@ -77,9 +72,9 @@ func (r *Reservations) UpdateShowReservation(reservationID string, reservationTo return resources.ReservationV1{}, errors.New("UpdateShowReservation call error.") } -// Delete removed the requested Reservation and returns the location. -func (r *Reservations) Delete(reservationID string, reservationToDelete resources.ReservationV1) (string, error) { - reservationLocation, err := r.client.SendResource("DELETE", "/reservations/"+reservationID, &reservationToDelete) +// DeleteReservation removed the requested Reservation and returns the location. +func (c *Client) DeleteReservation(reservationID string, reservationToDelete resources.ReservationV1) (string, error) { + reservationLocation, err := c.SendResource("DELETE", "/reservations/"+reservationID, &reservationToDelete) if err != nil { return "", err } diff --git a/client/subnets.go b/client/subnets.go index ba15b50..ce2d71b 100644 --- a/client/subnets.go +++ b/client/subnets.go @@ -6,14 +6,9 @@ import ( "github.com/RackHD/ipam/resources" ) -//Subnets can be used to query the Subnets routes -type Subnets struct { - client *Client -} - -// Index returns a list of Subnets. -func (s *Subnets) Index(poolID string) (resources.SubnetsV1, error) { - receivedSubnets, err := s.client.ReceiveResource("GET", "/pools/"+poolID+"/subnets", "", "") +// IndexSubnets returns a list of Subnets. +func (c *Client) IndexSubnets(poolID string) (resources.SubnetsV1, error) { + receivedSubnets, err := c.ReceiveResource("GET", "/pools/"+poolID+"/subnets", "", "") if err != nil { return resources.SubnetsV1{}, err } @@ -23,9 +18,9 @@ func (s *Subnets) Index(poolID string) (resources.SubnetsV1, error) { return resources.SubnetsV1{}, errors.New("Subnet Index call error.") } -// Creates a subnet and return the location. -func (s *Subnets) Creates(poolID string, subnetToCreate resources.SubnetV1) (string, error) { - subnetLocation, err := s.client.SendResource("POST", "/pools/"+poolID+"/subnets", &subnetToCreate) +// CreateSubnet a subnet and return the location. +func (c *Client) CreateSubnet(poolID string, subnetToCreate resources.SubnetV1) (string, error) { + subnetLocation, err := c.SendResource("POST", "/pools/"+poolID+"/subnets", &subnetToCreate) if err != nil { return "", err } @@ -33,8 +28,8 @@ func (s *Subnets) Creates(poolID string, subnetToCreate resources.SubnetV1) (str } // CreateShowSubnet creates a subnet and then returns that subnet. -func (s *Subnets) CreateShowSubnet(poolID string, subnetToCreate resources.SubnetV1) (resources.SubnetV1, error) { - receivedSubnet, err := s.client.SendReceiveResource("POST", "GET", "/pools/"+poolID+"/subnets", &subnetToCreate) +func (c *Client) CreateShowSubnet(poolID string, subnetToCreate resources.SubnetV1) (resources.SubnetV1, error) { + receivedSubnet, err := c.SendReceiveResource("POST", "GET", "/pools/"+poolID+"/subnets", &subnetToCreate) if err != nil { return resources.SubnetV1{}, err } @@ -44,9 +39,9 @@ func (s *Subnets) CreateShowSubnet(poolID string, subnetToCreate resources.Subne return resources.SubnetV1{}, errors.New("CreateShowSubnet call error.") } -// Show returns the requested subnet. -func (s *Subnets) Show(subnetID string, subnetToGet resources.SubnetV1) (resources.SubnetV1, error) { - receivedSubnet, err := s.client.ReceiveResource("GET", "/subnets/"+subnetID, subnetToGet.Type(), subnetToGet.Version()) +// ShowSubnet returns the requested subnet. +func (c *Client) ShowSubnet(subnetID string, subnetToGet resources.SubnetV1) (resources.SubnetV1, error) { + receivedSubnet, err := c.ReceiveResource("GET", "/subnets/"+subnetID, subnetToGet.Type(), subnetToGet.Version()) if err != nil { return resources.SubnetV1{}, err } @@ -56,9 +51,9 @@ func (s *Subnets) Show(subnetID string, subnetToGet resources.SubnetV1) (resourc return resources.SubnetV1{}, errors.New("Subnet Show call error.") } -// Update updates the requested subnet and returns its location. -func (s *Subnets) Update(subnetID string, subnetToUpdate resources.SubnetV1) (string, error) { - subnetLocation, err := s.client.SendResource("PATCH", "/subnets/"+subnetID, &subnetToUpdate) +// UpdateSubnet updates the requested subnet and returns its location. +func (c *Client) UpdateSubnet(subnetID string, subnetToUpdate resources.SubnetV1) (string, error) { + subnetLocation, err := c.SendResource("PATCH", "/subnets/"+subnetID, &subnetToUpdate) if err != nil { return "", err } @@ -66,8 +61,8 @@ func (s *Subnets) Update(subnetID string, subnetToUpdate resources.SubnetV1) (st } // UpdateShowSubnet updates a Subnet and then returns that Subnet. -func (s *Subnets) UpdateShowSubnet(subnetID string, subnetToUpdate resources.SubnetV1) (resources.SubnetV1, error) { - receivedSubnet, err := s.client.SendReceiveResource("PATCH", "GET", "/subnets/"+subnetID, &subnetToUpdate) +func (c *Client) UpdateShowSubnet(subnetID string, subnetToUpdate resources.SubnetV1) (resources.SubnetV1, error) { + receivedSubnet, err := c.SendReceiveResource("PATCH", "GET", "/subnets/"+subnetID, &subnetToUpdate) if err != nil { return resources.SubnetV1{}, err } @@ -77,9 +72,9 @@ func (s *Subnets) UpdateShowSubnet(subnetID string, subnetToUpdate resources.Sub return resources.SubnetV1{}, errors.New("UpdateShowSubnet call error.") } -// Delete removed the requested subnet and returns the location. -func (s *Subnets) Delete(subnetID string, subnetToDelete resources.SubnetV1) (string, error) { - subnetLocation, err := s.client.SendResource("DELETE", "/subnets/"+subnetID, &subnetToDelete) +// DeleteSubnet removed the requested subnet and returns the location. +func (c *Client) DeleteSubnet(subnetID string, subnetToDelete resources.SubnetV1) (string, error) { + subnetLocation, err := c.SendResource("DELETE", "/subnets/"+subnetID, &subnetToDelete) if err != nil { return "", err }