Skip to content

Commit

Permalink
Added the StorageDomainID type
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Bonic committed May 5, 2022
1 parent e04711b commit c130433
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 96 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func TestSomething(t *testing.T) {
params := ovirtclient.TestHelperParams().
WithClusterID(ovirtclient.ClusterID(os.Getenv("OVIRT_CLUSTER_ID"))).
WithBlankTemplateID(ovirtclient.TemplateID(os.Getenv("OVIRT_BLANK_TEMPLATE_ID"))).
WithStorageDomainID(os.Getenv("OVIRT_STORAGE_DOMAIN_ID")).
WithSecondaryStorageDomainID(os.Getenv("OVIRT_SECONDARY_STORAGE_DOMAIN_ID")).
WithStorageDomainID(ovirtclient.StorageDomainID(os.Getenv("OVIRT_STORAGE_DOMAIN_ID"))).
WithSecondaryStorageDomainID(ovirtclient.StorageDomainID(os.Getenv("OVIRT_SECONDARY_STORAGE_DOMAIN_ID"))).
WithVNICProfileID(os.Getenv("OVIRT_VNIC_PROFILE_ID"))

// Create the test helper
Expand Down
24 changes: 12 additions & 12 deletions disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type DiskClient interface {
// Deprecated: Use StartUploadToNewDisk instead.
StartImageUpload(
alias string,
storageDomainID string,
storageDomainID StorageDomainID,
sparse bool,
size uint64,
reader io.ReadSeekCloser,
Expand Down Expand Up @@ -75,7 +75,7 @@ type DiskClient interface {
// //...
// }
StartUploadToNewDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand All @@ -89,7 +89,7 @@ type DiskClient interface {
// Deprecated: Use UploadToNewDisk instead.
UploadImage(
alias string,
storageDomainID string,
storageDomainID StorageDomainID,
sparse bool,
size uint64,
reader io.ReadSeekCloser,
Expand All @@ -99,7 +99,7 @@ type DiskClient interface {
// UploadToNewDisk is identical to StartUploadToNewDisk, but waits until the upload is complete. It
// returns the disk ID as a result, or the error if one happened.
UploadToNewDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand Down Expand Up @@ -204,7 +204,7 @@ type DiskClient interface {
// StartCreateDisk starts creating an empty disk with the specified parameters and returns a DiskCreation object,
// which can be queried for completion. Optional parameters can be created using CreateDiskParams().
StartCreateDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand All @@ -218,7 +218,7 @@ type DiskClient interface {
// the ready state. Since the disk is almost certainly in a locked state, this may mean that there is a disk left
// behind.
CreateDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand Down Expand Up @@ -465,7 +465,7 @@ type DiskData interface {
// StorageDomainIDs returns a list of storage domains this disk is present on. This will typically be a single
// disk, but may have multiple disk when the disk has been copied over to other storage domains. The disk is always
// present on at least one disk, so this list will never be empty.
StorageDomainIDs() []string
StorageDomainIDs() []StorageDomainID
// Status returns the status the disk is in.
Status() DiskStatus
// Sparse indicates sparse provisioning on the disk.
Expand Down Expand Up @@ -640,15 +640,15 @@ func convertSDKDisk(sdkDisk *ovirtsdk4.Disk, client Client) (Disk, error) {
if !ok {
return nil, newError(EFieldMissing, "disk does not contain an ID")
}
var storageDomainIDs []string
var storageDomainIDs []StorageDomainID
if sdkStorageDomain, ok := sdkDisk.StorageDomain(); ok {
storageDomainID, _ := sdkStorageDomain.Id()
storageDomainIDs = append(storageDomainIDs, storageDomainID)
storageDomainIDs = append(storageDomainIDs, StorageDomainID(storageDomainID))
}
if sdkStorageDomains, ok := sdkDisk.StorageDomains(); ok {
for _, sd := range sdkStorageDomains.Slice() {
storageDomainID, _ := sd.Id()
storageDomainIDs = append(storageDomainIDs, storageDomainID)
storageDomainIDs = append(storageDomainIDs, StorageDomainID(storageDomainID))
}
}
if len(storageDomainIDs) == 0 {
Expand Down Expand Up @@ -699,7 +699,7 @@ type disk struct {
alias string
provisionedSize uint64
format ImageFormat
storageDomainIDs []string
storageDomainIDs []StorageDomainID
status DiskStatus
totalSize uint64
sparse bool
Expand All @@ -709,7 +709,7 @@ func (d *disk) WaitForOK(retries ...RetryStrategy) (Disk, error) {
return d.client.WaitForDiskOK(d.id, retries...)
}

func (d *disk) StorageDomainIDs() []string {
func (d *disk) StorageDomainIDs() []StorageDomainID {
return d.storageDomainIDs
}

Expand Down
10 changes: 5 additions & 5 deletions disk_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func (o *oVirtClient) StartCreateDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand Down Expand Up @@ -78,7 +78,7 @@ func validateDiskCreationParameters(format ImageFormat, size uint64) error {
}

func (o *oVirtClient) createDisk(
storageDomainID string,
storageDomainID StorageDomainID,
size uint64,
format ImageFormat,
correlationID string,
Expand All @@ -102,12 +102,12 @@ func (o *oVirtClient) createDisk(
}

func (o *oVirtClient) buildDiskObjectForCreation(
storageDomainID string,
storageDomainID StorageDomainID,
size uint64,
format ImageFormat,
params CreateDiskOptionalParameters,
) (*ovirtsdk4.Disk, error) {
storageDomain, err := ovirtsdk4.NewStorageDomainBuilder().Id(storageDomainID).Build()
storageDomain, err := ovirtsdk4.NewStorageDomainBuilder().Id(string(storageDomainID)).Build()
if err != nil {
return nil, wrap(
err,
Expand All @@ -133,7 +133,7 @@ func (o *oVirtClient) buildDiskObjectForCreation(
}

func (o *oVirtClient) CreateDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand Down
8 changes: 4 additions & 4 deletions disk_create_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func (m *mockClient) StartCreateDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand All @@ -30,7 +30,7 @@ func (m *mockClient) StartCreateDisk(
}

func (m *mockClient) createDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand All @@ -50,7 +50,7 @@ func (m *mockClient) createDisk(
format: format,
provisionedSize: size,
totalSize: size,
storageDomainIDs: []string{storageDomainID},
storageDomainIDs: []StorageDomainID{storageDomainID},
status: DiskStatusLocked,
},
lock: &sync.Mutex{},
Expand All @@ -72,7 +72,7 @@ func (m *mockClient) createDisk(
}

func (m *mockClient) CreateDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand Down
18 changes: 9 additions & 9 deletions disk_uploadimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// Deprecated: use UploadToNewDisk instead.
func (o *oVirtClient) UploadImage(
alias string,
storageDomainID string,
storageDomainID StorageDomainID,
sparse bool,
size uint64,
reader io.ReadSeekCloser,
Expand All @@ -36,7 +36,7 @@ func (o *oVirtClient) UploadImage(
}

func (o *oVirtClient) UploadToNewDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand All @@ -58,7 +58,7 @@ func (o *oVirtClient) UploadToNewDisk(
// Deprecated: use StartUploadToNewDisk instead.
func (o *oVirtClient) StartImageUpload(
alias string,
storageDomainID string,
storageDomainID StorageDomainID,
sparse bool,
size uint64,
reader io.ReadSeekCloser,
Expand Down Expand Up @@ -296,7 +296,7 @@ func (u *uploadToDiskProgress) Read(p []byte) (n int, err error) {
}

func (o *oVirtClient) StartUploadToNewDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand Down Expand Up @@ -348,7 +348,7 @@ func (o *oVirtClient) StartUploadToNewDisk(
type uploadToNewDiskProgress struct {
uploadToDiskProgress

storageDomainID string
storageDomainID StorageDomainID
diskFormat ImageFormat
diskParams CreateDiskOptionalParameters
}
Expand Down Expand Up @@ -399,7 +399,7 @@ func (u *uploadToNewDiskProgress) Do() {

func (m *mockClient) StartImageUpload(
alias string,
storageDomainID string,
storageDomainID StorageDomainID,
sparse bool,
size uint64,
reader io.ReadSeekCloser,
Expand All @@ -417,7 +417,7 @@ func (m *mockClient) StartImageUpload(

func (m *mockClient) UploadImage(
alias string,
storageDomainID string,
storageDomainID StorageDomainID,
sparse bool,
size uint64,
reader io.ReadSeekCloser,
Expand Down Expand Up @@ -498,7 +498,7 @@ func (m *mockClient) UploadToDisk(diskID string, size uint64, reader io.ReadSeek
}

func (m *mockClient) StartUploadToNewDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand Down Expand Up @@ -558,7 +558,7 @@ func (m *mockClient) StartUploadToNewDisk(
}

func (m *mockClient) UploadToNewDisk(
storageDomainID string,
storageDomainID StorageDomainID,
format ImageFormat,
size uint64,
params CreateDiskOptionalParameters,
Expand Down
2 changes: 1 addition & 1 deletion mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type mockClient struct {
lock *sync.Mutex
nonSecureRandom *rand.Rand
vms map[VMID]*vm
storageDomains map[string]*storageDomain
storageDomains map[StorageDomainID]*storageDomain
disks map[string]*diskWithData
clusters map[ClusterID]*cluster
hosts map[string]*host
Expand Down
4 changes: 2 additions & 2 deletions newmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func getClient(
vms: map[VMID]*vm{},
tags: map[string]*tag{},
nonSecureRandom: rand.New(rand.NewSource(time.Now().UnixNano())), //nolint:gosec
storageDomains: map[string]*storageDomain{
storageDomains: map[StorageDomainID]*storageDomain{
testStorageDomain.ID(): testStorageDomain,
secondaryStorageDomain.ID(): secondaryStorageDomain,
},
Expand Down Expand Up @@ -185,7 +185,7 @@ func generateTestDatacenter(testCluster *cluster) *datacenterWithClusters {

func generateTestStorageDomain() *storageDomain {
return &storageDomain{
id: uuid.NewString(),
id: StorageDomainID(uuid.NewString()),
name: "Test storage domain",
available: 10 * 1024 * 1024 * 1024,
status: StorageDomainStatusActive,
Expand Down
19 changes: 11 additions & 8 deletions storagedomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@ import (
ovirtsdk4 "github.com/ovirt/go-ovirt"
)

//go:generate go run scripts/rest/rest.go -i "StorageDomain" -n "storage domain"
//go:generate go run scripts/rest/rest.go -i "StorageDomain" -n "storage domain" -T StorageDomainID

// StorageDomainID is a specialized type for storage domain IDs.
type StorageDomainID string

// StorageDomainClient contains the portion of the goVirt API that deals with storage domains.
type StorageDomainClient interface {
// ListStorageDomains lists all storage domains.
ListStorageDomains(retries ...RetryStrategy) ([]StorageDomain, error)
// GetStorageDomain returns a single storage domain, or an error if the storage domain could not be found.
GetStorageDomain(id string, retries ...RetryStrategy) (StorageDomain, error)
GetStorageDomain(id StorageDomainID, retries ...RetryStrategy) (StorageDomain, error)
// GetDiskFromStorageDomain returns a single disk from a specific storage domain, or an error if no disk can be found.
GetDiskFromStorageDomain(id string, diskID string, retries ...RetryStrategy) (result Disk, err error)
GetDiskFromStorageDomain(id StorageDomainID, diskID string, retries ...RetryStrategy) (result Disk, err error)
// RemoveDiskFromStorageDomain removes a disk from a specific storage domain, but leaves the disk on other storage
// domains if any. If the disk is not present on any more storage domains, the entire disk will be removed.
RemoveDiskFromStorageDomain(id string, diskID string, retries ...RetryStrategy) error
RemoveDiskFromStorageDomain(id StorageDomainID, diskID string, retries ...RetryStrategy) error
}

// StorageDomainData is the core of StorageDomain, providing only data access functions.
type StorageDomainData interface {
// ID is the unique identified for the storage system connected to oVirt.
ID() string
ID() StorageDomainID
// Name is the user-given name for the storage domain.
Name() string
// Available returns the number of available bytes on the storage domain
Expand Down Expand Up @@ -263,7 +266,7 @@ func convertSDKStorageDomain(sdkStorageDomain *ovirtsdk4.StorageDomain, client C
return &storageDomain{
client: client,

id: id,
id: StorageDomainID(id),
name: name,
available: uint64(available),
storageType: StorageDomainType(storageType),
Expand All @@ -275,15 +278,15 @@ func convertSDKStorageDomain(sdkStorageDomain *ovirtsdk4.StorageDomain, client C
type storageDomain struct {
client Client

id string
id StorageDomainID
name string
available uint64
storageType StorageDomainType
status StorageDomainStatus
externalStatus StorageDomainExternalStatus
}

func (s storageDomain) ID() string {
func (s storageDomain) ID() StorageDomainID {
return s.id
}

Expand Down
6 changes: 3 additions & 3 deletions storagedomain_get.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c130433

Please sign in to comment.