-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add boot sources, boot source selections and boot resources
- Loading branch information
1 parent
a1acb1f
commit 7744474
Showing
17 changed files
with
462 additions
and
0 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 @@ | ||
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 | ||
} |
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,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 | ||
} |
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,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 | ||
} |
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,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 | ||
} |
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 @@ | ||
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) | ||
} |
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 @@ | ||
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) | ||
} |
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,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() | ||
} |
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,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 | ||
}) | ||
} |
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,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() | ||
} |
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,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() | ||
} |
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,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 | ||
} |
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,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 | ||
} |
Oops, something went wrong.