Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add VM create flow #63

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -58,7 +58,7 @@ Before you submit, we would like to ask you to run your tests against the live o
```
OVIRT_URL=https://url-of-your-engine
OVIRT_USERNAME=admin@internal
OVIRT_PASSWRD=your-ovirt-password
OVIRT_PASSWORD=your-ovirt-password
# Use the system certificate store to verify the engine certificate.
OVIRT_SYSTEM=1
# Alternatively, use one of these options:
Expand Down
167 changes: 167 additions & 0 deletions client_affinitygroup.go
@@ -0,0 +1,167 @@
package ovirtclient

import (
ovirtsdk4 "github.com/ovirt/go-ovirt"
)

//go:generate go run scripts/rest.go -i "AffinityGroup" -n "affinity group"

// AffinityGroupClient describes the functions related to oVirt affinity groups.
type AffinityGroupClient interface {
// GetAffinityGroup returns a single affinity group based on its ID.
GetAffinityGroup(id string, retries ...RetryStrategy) (AffinityGroup, error)
// ListAffinityGroups returns all affinity groups on the oVirt engine.
ListAffinityGroups(retries ...RetryStrategy) ([]AffinityGroup, error)
}

// AffinityGroupData is the core of affinity group, providing only the data access functions, but not the client
// functions.
type AffinityGroupData interface {
// ID returns the auto-generated identifier for this affinity group.
ID() string
// Name returns the user-give name for this affinity group.
Name() string
// Enforcing specifies whether the affinity group uses hard or soft enforcement of the affinity
//applied to virtual machines that are members of that affinity group.
Enforcing() bool
// Positive returns whether the affinity group applies positive affinity or negative affinity
// to virtual machines that are members of that affinity group
Positive() bool
// Priority returns the priority of this affinity group.
Priority() uint64
// VmsRule returns the affinity rule applied to virtual machines that are members
// of this affinity group.
VmsRule() AffinityRule
// HostsRule returns the affinity rule applied between virtual machines and hosts
// that are members of this affinity group.
HostsRule() AffinityRule
}

// AffinityGroup is the interface defining the fields for an affinity group.
type AffinityGroup interface {
AffinityGroupData
}

type affinityGroup struct {
client Client

id string
name string
description string
enforcing bool
positive bool
priority uint64
vmsRule AffinityRule
hostsRule AffinityRule
}

func convertSDKAffinityGroup(sdkObject *ovirtsdk4.AffinityGroup, client *oVirtClient) (AffinityGroup, error) {
id, ok := sdkObject.Id()
if !ok {
return nil, newFieldNotFound("tag", "id")
}
name, ok := sdkObject.Name()
if !ok {
return nil, newFieldNotFound("affinityGroup", "name")
}
description, ok := sdkObject.Description()
if !ok {
return nil, newFieldNotFound("affinityGroup", "description")
}
enforcing, ok := sdkObject.Enforcing()
if !ok {
return nil, newFieldNotFound("affinityGroup", "enforcing")
}
positive, ok := sdkObject.Positive()
if !ok {
return nil, newFieldNotFound("affinityGroup", "positive")
}
priority, ok := sdkObject.Priority()
if !ok {
return nil, newFieldNotFound("affinityGroup", "priority")
}
vmsRuleSDK, ok := sdkObject.VmsRule()
if !ok {
return nil, newFieldNotFound("affinityGroup", "vmsRule")
}
hostsRuleSDK, ok := sdkObject.HostsRule()
if !ok {
return nil, newFieldNotFound("affinityGroup", "hostsRule")
}
return &affinityGroup{
client: client,
id: id,
name: name,
description: description,
enforcing: enforcing,
positive: positive,
priority: priority,
vmsRule: vmsRule,
hostsRule: hostsRule,
}, nil
}

func (a affinityGroup) ID() string {
return a.id
}

func (a affinityGroup) Name() string {
return a.name
}

func (a affinityGroup) Description() string {
return a.description
}

func (a affinityGroup) Enforcing() bool {
return a.enforcing
}

func (a affinityGroup) Positive() bool {
return a.positive
}

func (a affinityGroup) Priority() uint64 {
return a.priority
}

func (a affinityGroup) VmsRule() AffinityRule {
return a.vmsRule
}

func (a affinityGroup) HostsRule() AffinityRule {
return a.hostsRule
}

type AffinityRule interface {
// Enabled returns whether the affinity group uses this rule or not
Enabled() bool
// Enforcing specifies whether the affinity group uses hard or soft enforcement of the affinity
// applied to the resources that are controlled by this rule.
Enforcing() bool
// Positive returns whether the affinity group applies positive affinity or negative affinity
// to the resources that are controlled by this rule
Positive() bool
}

type affinityRule struct {
enabled bool
enforcing bool
positive bool
}

func NewAffinityRule() AffinityRule {
return &affinityRule{}
}

func (a affinityRule) Enabled() bool {
return a.enabled
}

func (a affinityRule) Enforcing() bool {
return a.enforcing
}

func (a affinityRule) Positive() bool {
return a.positive
}
4 changes: 2 additions & 2 deletions client_cluster.go
Expand Up @@ -7,8 +7,8 @@ import (
//go:generate go run scripts/rest.go -i "Cluster" -n "cluster"

// ClusterClient is a part of the Client that deals with clusters in the oVirt Engine. A cluster is a logical grouping
// of hosts that share the same storage domains and have the same type of CPU (either Intel or AMD). If the hosts have
// different generations of CPU models, they use only the features present in all models.
// of hosts that share the same storage domains and have the same type of cpu (either Intel or AMD). If the hosts have
// different generations of cpu models, they use only the features present in all models.
Gal-Zaidman marked this conversation as resolved.
Show resolved Hide resolved
//
// See https://www.ovirt.org/documentation/administration_guide/#chap-Clusters for details.
type ClusterClient interface {
Expand Down
9 changes: 6 additions & 3 deletions client_disk_attachment_test.go
Expand Up @@ -15,7 +15,8 @@ func TestDiskAttachmentCreation(t *testing.T) {
vm := assertCanCreateVM(
t,
helper,
ovirtclient.CreateVMParams().MustWithName(fmt.Sprintf("disk_attachment_test_%s", helper.GenerateRandomID(5))),
fmt.Sprintf("disk_attachment_test_%s", helper.GenerateRandomID(5)),
ovirtclient.CreateVMParams(),
)
disk := assertCanCreateDisk(t, client, helper)
assertDiskAttachmentCount(t, vm, 0)
Expand All @@ -32,12 +33,14 @@ func TestDiskAttachmentCannotBeAttachedToSecondVM(t *testing.T) {
vm1 := assertCanCreateVM(
t,
helper,
ovirtclient.CreateVMParams().MustWithName(fmt.Sprintf("disk_attachment_test_%s", helper.GenerateRandomID(5))),
fmt.Sprintf("disk_attachment_test_%s", helper.GenerateRandomID(5)),
ovirtclient.CreateVMParams(),
)
vm2 := assertCanCreateVM(
t,
helper,
ovirtclient.CreateVMParams().MustWithName(fmt.Sprintf("disk_attachment_test_%s", helper.GenerateRandomID(5))),
fmt.Sprintf("disk_attachment_test_%s", helper.GenerateRandomID(5)),
ovirtclient.CreateVMParams(),
)
disk := assertCanCreateDisk(t, client, helper)
_ = assertCanAttachDisk(t, vm1, disk)
Expand Down
16 changes: 16 additions & 0 deletions client_host.go
Expand Up @@ -154,3 +154,19 @@ func (h host) ClusterID() string {
func (h host) Status() HostStatus {
return h.status
}

func (h host) convertToSDK() (*ovirtsdk4.Host, error) {
hostBuilder := ovirtsdk4.NewHostBuilder()
cluster, err := ovirtsdk4.NewClusterBuilder().Id(h.clusterID).Build()
if err != nil {
return nil, newError(EBug, "failed building cluster with ID %s", h.clusterID)
}
hostBuilder.Id(h.id)
hostBuilder.Cluster(cluster)
hostBuilder.Status(ovirtsdk4.HostStatus(h.status))
host, err := hostBuilder.Build()
if err != nil {
return nil, newError(EBug, "failed building host")
}
return host, nil
}
3 changes: 2 additions & 1 deletion client_nic_create_test.go
Expand Up @@ -13,7 +13,8 @@ func TestVMNICCreation(t *testing.T) {
vm := assertCanCreateVM(
t,
helper,
ovirtclient.CreateVMParams().MustWithName(fmt.Sprintf("nic_test_%s", helper.GenerateRandomID(5))),
fmt.Sprintf("nic_test_%s", helper.GenerateRandomID(5)),
ovirtclient.CreateVMParams(),
)
assertNICCount(t, vm, 0)
nic := assertCanCreateNIC(t, helper, vm, "test", ovirtclient.CreateNICParams())
Expand Down
3 changes: 2 additions & 1 deletion client_nic_update_test.go
Expand Up @@ -13,7 +13,8 @@ func TestVMNICUpdate(t *testing.T) {
vm := assertCanCreateVM(
t,
helper,
ovirtclient.CreateVMParams().MustWithName(fmt.Sprintf("nic_test_%s", helper.GenerateRandomID(5))),
fmt.Sprintf("nic_test_%s", helper.GenerateRandomID(5)),
ovirtclient.CreateVMParams(),
)
assertNICCount(t, vm, 0)
nic := assertCanCreateNIC(t, helper, vm, "test", ovirtclient.CreateNICParams())
Expand Down
72 changes: 72 additions & 0 deletions client_tag.go
@@ -0,0 +1,72 @@
package ovirtclient

import (
ovirtsdk4 "github.com/ovirt/go-ovirt"
)

//go:generate go run scripts/rest.go -i "Tag" -n "tag"

// TagClient describes the functions related to oVirt tags.
type TagClient interface {
// GetTag returns a single network based on its ID.
GetTag(id string, retries ...RetryStrategy) (Tag, error)
// ListTags returns all tags on the oVirt engine.
ListTags(retries ...RetryStrategy) ([]Tag, error)
}

// TagData is the core of Tag, providing only the data access functions, but not the client
// functions.
type TagData interface {
// ID returns the auto-generated identifier for this tag.
ID() string
// Name returns the user-give name for this tag.
Name() string
// Description returns the user-give description for this tag.
Description() string
}

// Tag is the interface defining the fields for tag.
type Tag interface {
TagData
}

func convertSDKTag(sdkObject *ovirtsdk4.Tag, client *oVirtClient) (Tag, error) {
id, ok := sdkObject.Id()
if !ok {
return nil, newFieldNotFound("tag", "id")
}
name, ok := sdkObject.Name()
if !ok {
return nil, newFieldNotFound("tag", name)
}
description, ok := sdkObject.Description()
if !ok {
return nil, newFieldNotFound("tag", description)
}
return &tag{
client: client,
id: id,
name: name,
description: description,
}, nil
}

type tag struct {
client Client

id string
name string
description string
}

func (n tag) ID() string {
return n.id
}

func (n tag) Name() string {
return n.name
}

func (n tag) Description() string {
return n.description
}
40 changes: 40 additions & 0 deletions client_tag_get.go

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