Skip to content

Commit

Permalink
Add boot sources, boot source selections and boot resources
Browse files Browse the repository at this point in the history
  • Loading branch information
skatsaounis committed Jan 8, 2024
1 parent a1acb1f commit 7744474
Show file tree
Hide file tree
Showing 17 changed files with 462 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/boot_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package api

import (
"github.com/maas/gomaasclient/entity"
)

// BootResource is an interface defining API behaviour for
// boot resources
type BootResource interface {
Get(id int) (*entity.BootResource, error)
Delete(id int) error
}
15 changes: 15 additions & 0 deletions api/boot_resources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package api

import (
"github.com/maas/gomaasclient/entity"
)

// BootResources is an interface for listing and creating
// BootResource objects
type BootResources interface {
Get(params *entity.BootResourcesReadParams) ([]entity.BootResource, error)
Create(params *entity.BootResourceParams) (*entity.BootResource, error)
Import() error
IsImporting() (bool, error)
StopImport() error
}
13 changes: 13 additions & 0 deletions api/boot_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package api

import (
"github.com/maas/gomaasclient/entity"
)

// BootSource is an interface defining API behaviour for
// boot sources
type BootSource interface {
Get(id int) (*entity.BootSource, error)
Update(id int, params *entity.BootSourceParams) (*entity.BootSource, error)
Delete(id int) error
}
13 changes: 13 additions & 0 deletions api/boot_source_selection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package api

import (
"github.com/maas/gomaasclient/entity"
)

// BootSourceSelection is an interface defining API behaviour for
// boot source selections
type BootSourceSelection interface {
Get(bootSourceID int, id int) (*entity.BootSourceSelection, error)
Update(bootSourceID int, id int, params *entity.BootSourceSelectionParams) (*entity.BootSourceSelection, error)
Delete(bootSourceID int, id int) error
}
12 changes: 12 additions & 0 deletions api/boot_source_selections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package api

import (
"github.com/maas/gomaasclient/entity"
)

// BootSourceSelections is an interface for listing and creating
// BootSourceSelection objects
type BootSourceSelections interface {
Get(bootSourceID int) ([]entity.BootSourceSelection, error)
Create(bootSourceID int, params *entity.BootSourceSelectionParams) (*entity.BootSourceSelection, error)
}
12 changes: 12 additions & 0 deletions api/boot_sources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package api

import (
"github.com/maas/gomaasclient/entity"
)

// BootSources is an interface for listing and creating
// BootSource objects
type BootSources interface {
Get() ([]entity.BootSource, error)
Create(params *entity.BootSourceParams) (*entity.BootSource, error)
}
33 changes: 33 additions & 0 deletions client/boot_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package client

import (
"encoding/json"
"fmt"
"net/url"

"github.com/maas/gomaasclient/entity"
)

// BootResource implements api.BootResource
type BootResource struct {
APIClient APIClient
}

func (b *BootResource) client(id int) APIClient {
return b.APIClient.GetSubObject("boot-resources").GetSubObject(fmt.Sprintf("%v", id))
}

// Get fetches a boot resource with a given id
func (b *BootResource) Get(id int) (*entity.BootResource, error) {
bootResource := new(entity.BootResource)
err := b.client(id).Get("", url.Values{}, func(data []byte) error {
return json.Unmarshal(data, bootResource)
})

return bootResource, err
}

// Delete deletes a given boot resource
func (b *BootResource) Delete(id int) error {
return b.client(id).Delete()
}
63 changes: 63 additions & 0 deletions client/boot_resources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package client

import (
"encoding/json"
"fmt"
"net/url"

"github.com/google/go-querystring/query"
"github.com/maas/gomaasclient/entity"
)

// BootResources implements api.BootResources
type BootResources struct {
APIClient APIClient
}

func (b *BootResources) client() APIClient {
return b.APIClient.GetSubObject("boot-resources")
}

// Get fetches a list of boot resources
func (b *BootResources) Get(params *entity.BootResourcesReadParams) ([]entity.BootResource, error) {
qsp, err := query.Values(params)
if err != nil {
return nil, err
}

bootResources := make([]entity.BootResource, 0)
err = b.client().Get("", qsp, func(data []byte) error {
return json.Unmarshal(data, &bootResources)
})

return bootResources, err
}

// Create creates a new boot source
func (b *BootResources) Create(params *entity.BootResourceParams) (*entity.BootResource, error) {
return nil, fmt.Errorf("not implemented")
}

// Import imports boot resources to rack controllers
func (b *BootResources) Import() error {
return b.client().Post("import", url.Values{}, func(data []byte) error {
return nil
})
}

// IsImporting returns importing status of boot resources importing to rack controllers
func (b *BootResources) IsImporting() (bool, error) {
isImporting := new(bool)
err := b.client().Get("is-importing", url.Values{}, func(data []byte) error {
return json.Unmarshal(data, isImporting)
})

return *isImporting, err
}

// StopImport stops importing boot resources to rack controllers
func (b *BootResources) StopImport() error {
return b.client().Post("stop-import", url.Values{}, func(data []byte) error {
return nil
})
}
50 changes: 50 additions & 0 deletions client/boot_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//nolint:dupl // disable dupl check on client for now
package client

import (
"encoding/json"
"fmt"
"net/url"

"github.com/google/go-querystring/query"
"github.com/maas/gomaasclient/entity"
)

// BootSource implements api.BootSource
type BootSource struct {
APIClient APIClient
}

func (b *BootSource) client(id int) APIClient {
return b.APIClient.GetSubObject("boot-sources").GetSubObject(fmt.Sprintf("%v", id))
}

// Get fetches a boot source with a given id
func (b *BootSource) Get(id int) (*entity.BootSource, error) {
bootSource := new(entity.BootSource)
err := b.client(id).Get("", url.Values{}, func(data []byte) error {
return json.Unmarshal(data, bootSource)
})

return bootSource, err
}

// Update updates a given boot source
func (b *BootSource) Update(id int, params *entity.BootSourceParams) (*entity.BootSource, error) {
qsp, err := query.Values(params)
if err != nil {
return nil, err
}

bootSource := new(entity.BootSource)
err = b.client(id).Put(qsp, func(data []byte) error {
return json.Unmarshal(data, bootSource)
})

return bootSource, err
}

// Delete deletes a given boot source
func (b *BootSource) Delete(id int) error {
return b.client(id).Delete()
}
52 changes: 52 additions & 0 deletions client/boot_source_selection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package client

import (
"encoding/json"
"fmt"
"net/url"

"github.com/google/go-querystring/query"
"github.com/maas/gomaasclient/entity"
)

// BootSourceSelection implements api.BootSourceSelection
type BootSourceSelection struct {
APIClient APIClient
}

func (b *BootSourceSelection) client(bootSourceID int, id int) APIClient {
return b.APIClient.GetSubObject("boot-sources").
GetSubObject(fmt.Sprintf("%v", bootSourceID)).
GetSubObject("selections").
GetSubObject(fmt.Sprintf("%v", id))
}

// Get fetches a BootSourceSelection for the given bootSourceID and BootSourceSelection id
func (b *BootSourceSelection) Get(bootSourceID int, id int) (*entity.BootSourceSelection, error) {
bootSourceSelection := new(entity.BootSourceSelection)
err := b.client(bootSourceID, id).Get("", url.Values{}, func(data []byte) error {
return json.Unmarshal(data, bootSourceSelection)
})

return bootSourceSelection, err
}

// Update updates a given BootSourceSelection
func (b *BootSourceSelection) Update(bootSourceID int, id int, params *entity.BootSourceSelectionParams) (*entity.BootSourceSelection, error) {
qsp, err := query.Values(params)
if err != nil {
return nil, err
}

bootSourceSelection := new(entity.BootSourceSelection)
err = b.client(bootSourceID, id).Put(qsp, func(data []byte) error {
return json.Unmarshal(data, bootSourceSelection)
})

return bootSourceSelection, err
}

// Delete deletes a given BootSourceSelection
func (b *BootSourceSelection) Delete(bootSourceID int, id int) error {
return b.client(bootSourceID, id).Delete()
}
46 changes: 46 additions & 0 deletions client/boot_source_selections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package client

import (
"encoding/json"
"fmt"
"net/url"

"github.com/google/go-querystring/query"
"github.com/maas/gomaasclient/entity"
)

// BootSourceSelections implements api.BootSourceSelections
type BootSourceSelections struct {
APIClient APIClient
}

func (b *BootSourceSelections) client(bootSourceID int) APIClient {
return b.APIClient.GetSubObject("boot-sources").
GetSubObject(fmt.Sprintf("%v", bootSourceID)).
GetSubObject("selections")
}

// Get fetches a list of BootSourceSelection objects
func (b *BootSourceSelections) Get(bootSourceID int) ([]entity.BootSourceSelection, error) {
bootSourceSelections := make([]entity.BootSourceSelection, 0)
err := b.client(bootSourceID).Get("", url.Values{}, func(data []byte) error {
return json.Unmarshal(data, &bootSourceSelections)
})

return bootSourceSelections, err
}

// Create creates a BootSourceSelection object
func (b *BootSourceSelections) Create(bootSourceID int, params *entity.BootSourceSelectionParams) (*entity.BootSourceSelection, error) {
qsp, err := query.Values(params)
if err != nil {
return nil, err
}

bootSourceSelection := new(entity.BootSourceSelection)
err = b.client(bootSourceID).Post("", qsp, func(data []byte) error {
return json.Unmarshal(data, bootSourceSelection)
})

return bootSourceSelection, err
}
44 changes: 44 additions & 0 deletions client/boot_sources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//nolint:dupl // disable dupl check on client for now
package client

import (
"encoding/json"
"net/url"

"github.com/google/go-querystring/query"
"github.com/maas/gomaasclient/entity"
)

// BootSources implements api.BootSources
type BootSources struct {
APIClient APIClient
}

func (b *BootSources) client() APIClient {
return b.APIClient.GetSubObject("boot-sources")
}

// Get fetches a list of boot sources
func (b *BootSources) Get() ([]entity.BootSource, error) {
bootSources := make([]entity.BootSource, 0)
err := b.client().Get("", url.Values{}, func(data []byte) error {
return json.Unmarshal(data, &bootSources)
})

return bootSources, err
}

// Create creates a new boot source
func (b *BootSources) Create(params *entity.BootSourceParams) (*entity.BootSource, error) {
qsp, err := query.Values(params)
if err != nil {
return nil, err
}

bootSource := new(entity.BootSource)
err = b.client().Post("", qsp, func(data []byte) error {
return json.Unmarshal(data, bootSource)
})

return bootSource, err
}
Loading

0 comments on commit 7744474

Please sign in to comment.