-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bcache related entities and API endpoint interactions
- Loading branch information
1 parent
8123a5d
commit 591bb0f
Showing
12 changed files
with
287 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" | ||
) | ||
|
||
// BCache declares the API operations related to MAAS `nodes/{systemID}/bcache/{id}` endpoint. | ||
type BCache interface { | ||
Get(systemID string, id int) (*entity.BCache, error) | ||
Update(systemID string, id int, params *entity.BCacheParams) (*entity.BCache, error) | ||
Delete(systemID string, 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" | ||
) | ||
|
||
// BCacheCacheSet declares the API operations related to MAAS `nodes/{systemID}/bcache-cache-set/{id}` endpoint. | ||
type BCacheCacheSet interface { | ||
Get(systemID string, id int) (*entity.BCacheCacheSet, error) | ||
Update(systemID string, id int, params *entity.BCacheCacheSetParams) (*entity.BCacheCacheSet, error) | ||
Delete(systemID string, 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,11 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// BCacheCacheSets declares the API operations related to MAAS `nodes/{systemID}/bcache-cache-sets` endpoint. | ||
type BCacheCacheSets interface { | ||
Get(systemID string) ([]entity.BCacheCacheSet, error) | ||
Create(systemID string, params *entity.BCacheCacheSetParams) (*entity.BCacheCacheSet, 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,11 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// BCaches declares the API operations related to MAAS `nodes/{systemID}/bcaches` endpoint. | ||
type BCaches interface { | ||
Get(systemID string) ([]entity.BCache, error) | ||
Create(systemID string, params *entity.BCacheParams) (*entity.BCache, 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,52 @@ | ||
//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" | ||
) | ||
|
||
// BCache Contains functionality for manipulating the BCache entity. | ||
type BCache struct { | ||
APIClient APIClient | ||
} | ||
|
||
func (b *BCache) client(systemID string, id int) APIClient { | ||
return b.APIClient. | ||
GetSubObject("nodes").GetSubObject(systemID). | ||
GetSubObject("bcache").GetSubObject(fmt.Sprintf("%v", id)) | ||
} | ||
|
||
// Get BCache details. | ||
func (b *BCache) Get(systemID string, id int) (*entity.BCache, error) { | ||
bCache := new(entity.BCache) | ||
err := b.client(systemID, id).Get("", url.Values{}, func(data []byte) error { | ||
return json.Unmarshal(data, bCache) | ||
}) | ||
|
||
return bCache, err | ||
} | ||
|
||
// Update BCache. | ||
func (b *BCache) Update(systemID string, id int, params *entity.BCacheParams) (*entity.BCache, error) { | ||
qsp, err := query.Values(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
bCache := new(entity.BCache) | ||
err = b.client(systemID, id).Put(qsp, func(data []byte) error { | ||
return json.Unmarshal(data, bCache) | ||
}) | ||
|
||
return bCache, err | ||
} | ||
|
||
// Delete BCache. | ||
func (b *BCache) Delete(systemID string, id int) error { | ||
return b.client(systemID, 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 @@ | ||
//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" | ||
) | ||
|
||
// BCacheCacheSet Contains functionality for manipulating the BCacheCacheSet entity. | ||
type BCacheCacheSet struct { | ||
APIClient APIClient | ||
} | ||
|
||
func (b *BCacheCacheSet) client(systemID string, id int) APIClient { | ||
return b.APIClient. | ||
GetSubObject("nodes").GetSubObject(systemID). | ||
GetSubObject("bcache-cache-set").GetSubObject(fmt.Sprintf("%v", id)) | ||
} | ||
|
||
// Get BCacheCacheSet details. | ||
func (b *BCacheCacheSet) Get(systemID string, id int) (*entity.BCacheCacheSet, error) { | ||
bCacheCacheSet := new(entity.BCacheCacheSet) | ||
err := b.client(systemID, id).Get("", url.Values{}, func(data []byte) error { | ||
return json.Unmarshal(data, bCacheCacheSet) | ||
}) | ||
|
||
return bCacheCacheSet, err | ||
} | ||
|
||
// Update BCacheCacheSet. | ||
func (b *BCacheCacheSet) Update(systemID string, id int, params *entity.BCacheCacheSetParams) (*entity.BCacheCacheSet, error) { | ||
qsp, err := query.Values(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
bCacheCacheSet := new(entity.BCacheCacheSet) | ||
err = b.client(systemID, id).Put(qsp, func(data []byte) error { | ||
return json.Unmarshal(data, bCacheCacheSet) | ||
}) | ||
|
||
return bCacheCacheSet, err | ||
} | ||
|
||
// Delete BCacheCacheSet. | ||
func (b *BCacheCacheSet) Delete(systemID string, id int) error { | ||
return b.client(systemID, 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,45 @@ | ||
//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" | ||
) | ||
|
||
// BCacheCacheSets contains functionality for manipulating the BCacheCacheSets entity. | ||
type BCacheCacheSets struct { | ||
APIClient APIClient | ||
} | ||
|
||
func (b *BCacheCacheSets) client(systemID string) APIClient { | ||
return b.APIClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("bcache-cache-sets") | ||
} | ||
|
||
// Get BCacheCacheSets of a machine. | ||
func (b *BCacheCacheSets) Get(systemID string) ([]entity.BCacheCacheSet, error) { | ||
bCacheCacheSets := make([]entity.BCacheCacheSet, 0) | ||
err := b.client(systemID).Get("", url.Values{}, func(data []byte) error { | ||
return json.Unmarshal(data, &bCacheCacheSets) | ||
}) | ||
|
||
return bCacheCacheSets, err | ||
} | ||
|
||
// Create a BCacheCacheSet of a machine. | ||
func (b *BCacheCacheSets) Create(systemID string, params *entity.BCacheCacheSetParams) (*entity.BCacheCacheSet, error) { | ||
qsp, err := query.Values(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
bCacheCacheSet := new(entity.BCacheCacheSet) | ||
err = b.client(systemID).Post("", qsp, func(data []byte) error { | ||
return json.Unmarshal(data, bCacheCacheSet) | ||
}) | ||
|
||
return bCacheCacheSet, 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,45 @@ | ||
//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" | ||
) | ||
|
||
// BCaches contains functionality for manipulating the BCaches entity. | ||
type BCaches struct { | ||
APIClient APIClient | ||
} | ||
|
||
func (b *BCaches) client(systemID string) APIClient { | ||
return b.APIClient.GetSubObject("nodes").GetSubObject(systemID).GetSubObject("bcaches") | ||
} | ||
|
||
// Get BCaches of a machine. | ||
func (b *BCaches) Get(systemID string) ([]entity.BCache, error) { | ||
bCaches := make([]entity.BCache, 0) | ||
err := b.client(systemID).Get("", url.Values{}, func(data []byte) error { | ||
return json.Unmarshal(data, &bCaches) | ||
}) | ||
|
||
return bCaches, err | ||
} | ||
|
||
// Create a BCache of a machine. | ||
func (b *BCaches) Create(systemID string, params *entity.BCacheParams) (*entity.BCache, error) { | ||
qsp, err := query.Values(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
bCache := new(entity.BCache) | ||
err = b.client(systemID).Post("", qsp, func(data []byte) error { | ||
return json.Unmarshal(data, bCache) | ||
}) | ||
|
||
return bCache, 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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//nolint:dupl // disable dupl check on client for now | ||
package client | ||
|
||
import ( | ||
|
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,24 @@ | ||
package entity | ||
|
||
type BCache struct { | ||
HumanSize string `json:"human_size,omitempty"` | ||
UUID string `json:"uuid,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
SystemID string `json:"system_id"` | ||
CacheMode string `json:"cache_mode,omitempty"` | ||
ResourceURI string `json:"resource_uri,omitempty"` | ||
VirtualDevice BlockDevice `json:"virtual_device,omitempty"` | ||
BackingDevice BlockDevice `json:"backing_device,omitempty"` | ||
CacheSet BCacheCacheSet `json:"cache_set"` | ||
ID int `json:"id,omitempty"` | ||
Size int64 `json:"size,omitempty"` | ||
} | ||
|
||
type BCacheParams struct { | ||
Name string `url:"name,omitempty"` | ||
UUID string `url:"uuid,omitempty"` | ||
CacheSet string `url:"cache_set,omitempty"` | ||
BackingDevice string `url:"backing_device,omitempty"` | ||
BackingPartition string `url:"backing_partition,omitempty"` | ||
CacheMode string `url:"cache_mode,omitempty"` | ||
} |
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,14 @@ | ||
package entity | ||
|
||
type BCacheCacheSet struct { | ||
Name string `json:"name:omitempty"` | ||
SystemID string `json:"system_id,omitempty"` | ||
ResourceURI string `json:"resource_uri,omitempty"` | ||
CacheDevice BlockDevice `json:"cache_device,omitempty"` | ||
ID int `json:"id,omitempty"` | ||
} | ||
|
||
type BCacheCacheSetParams struct { | ||
CacheDevice string `url:"cache_device,omitempty"` | ||
CachePartition string `url:"cache_partition,omitempty"` | ||
} |