Skip to content

Commit

Permalink
Merge pull request #650 from mpolednik/q35
Browse files Browse the repository at this point in the history
expose machine type in API & default to q35
  • Loading branch information
fabiand committed Jan 24, 2018
2 parents 07a16aa + 9dc749e commit 6adfa0b
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 4 deletions.
15 changes: 15 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,10 @@
"description": "Firmware\n+optional",
"$ref": "#/definitions/v1.Firmware"
},
"machine": {
"description": "Machine type\n+optional",
"$ref": "#/definitions/v1.Machine"
},
"resources": {
"description": "Resources describes the Compute Resources required by this vm.",
"$ref": "#/definitions/v1.ResourceRequirements"
Expand Down Expand Up @@ -2305,6 +2309,17 @@
}
}
},
"v1.Machine": {
"required": [
"type"
],
"properties": {
"type": {
"description": "QEMU machine type is the actual chipset of the VM.",
"type": "string"
}
}
},
"v1.Migration": {
"description": "A Migration is a job that moves a Virtual Machine from one node to another\n+k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object",
"properties": {
Expand Down
25 changes: 25 additions & 0 deletions pkg/api/v1/deepcopy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ func (in *DomainSpec) DeepCopyInto(out *DomainSpec) {
**out = **in
}
}
if in.Machine != nil {
in, out := &in.Machine, &out.Machine
if *in == nil {
*out = nil
} else {
*out = new(Machine)
**out = **in
}
}
if in.Firmware != nil {
in, out := &in.Firmware, &out.Firmware
if *in == nil {
Expand Down Expand Up @@ -754,6 +763,22 @@ func (in *LunTarget) DeepCopy() *LunTarget {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Machine) DeepCopyInto(out *Machine) {
*out = *in
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Machine.
func (in *Machine) DeepCopy() *Machine {
if in == nil {
return nil
}
out := new(Machine)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Migration) DeepCopyInto(out *Migration) {
*out = *in
Expand Down
8 changes: 8 additions & 0 deletions pkg/api/v1/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type DomainSpec struct {
// CPU allow specified the detailed CPU topology inside the vm.
// +optional
CPU *CPU `json:"cpu,omitempty"`
// Machine type
// +optional
Machine *Machine `json:"machine,omitempty"`
// Firmware
// +optional
Firmware *Firmware `json:"firmware,omitempty"`
Expand Down Expand Up @@ -75,6 +78,11 @@ type CPU struct {
Cores uint32 `json:"cores,omitempty"`
}

type Machine struct {
// QEMU machine type is the actual chipset of the VM.
Type string `json:"type"`
}

type Firmware struct {
// UID reported by the vm bios
// Defaults to a random generated uid
Expand Down
7 changes: 7 additions & 0 deletions pkg/api/v1/schema_swagger_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (DomainSpec) SwaggerDoc() map[string]string {
return map[string]string{
"resources": "Resources describes the Compute Resources required by this vm.",
"cpu": "CPU allow specified the detailed CPU topology inside the vm.\n+optional",
"machine": "Machine type\n+optional",
"firmware": "Firmware\n+optional",
"clock": "Clock sets the clock and timers of the vm.\n+optional",
"features": "Features like acpi, apic, hyperv\n+optional",
Expand All @@ -34,6 +35,12 @@ func (CPU) SwaggerDoc() map[string]string {
}
}

func (Machine) SwaggerDoc() map[string]string {
return map[string]string{
"type": "QEMU machine type is the actual chipset of the VM.",
}
}

func (Firmware) SwaggerDoc() map[string]string {
return map[string]string{
"uid": "UID reported by the vm bios\nDefaults to a random generated uid",
Expand Down
13 changes: 13 additions & 0 deletions pkg/virt-handler/virtwrap/api/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ func Convert_v1_Features_To_api_Features(source *v1.Features, features *Features
return nil
}

func Convert_v1_Machine_To_api_OSType(source *v1.Machine, ost *OSType, c *ConverterContext) error {
ost.Machine = source.Type

return nil
}

func Convert_v1_FeatureHyperv_To_api_FeatureHyperv(source *v1.FeatureHyperv, hyperv *FeatureHyperv, c *ConverterContext) error {
if source.Spinlocks != nil {
hyperv.Spinlocks = &FeatureSpinlocks{
Expand Down Expand Up @@ -324,6 +330,13 @@ func Convert_v1_VirtualMachine_To_api_Domain(vm *v1.VirtualMachine, domain *Doma
return err
}
}
if vm.Spec.Domain.Machine != nil {
apiOst := vm.Spec.Domain.Machine
err := Convert_v1_Machine_To_api_OSType(apiOst, &domain.Spec.OS.Type, c)
if err != nil {
return err
}
}

if vm.Spec.Domain.CPU != nil {
domain.Spec.CPU.Topology = &CPUTopology{
Expand Down
5 changes: 4 additions & 1 deletion pkg/virt-handler/virtwrap/api/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ var _ = Describe("Converter", func() {
},
}
v1.SetObjectDefaults_VirtualMachine(vm)
vm.Spec.Domain.Machine = &v1.Machine{
Type: "pc",
}
vm.Spec.Domain.Devices.Watchdog = &v1.Watchdog{
Name: "mywatchdog",
WatchdogDevice: v1.WatchdogDevice{
Expand Down Expand Up @@ -254,7 +257,7 @@ var _ = Describe("Converter", func() {
<name>mynamespace_testvm</name>
<memory unit="MB">9</memory>
<os>
<type>hvm</type>
<type machine="pc">hvm</type>
</os>
<sysinfo type="smbios">
<system>
Expand Down
5 changes: 5 additions & 0 deletions pkg/virt-handler/virtwrap/api/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func SetDefaults_Devices(devices *Devices) {

func SetDefaults_OSType(ostype *OSType) {
ostype.OS = "hvm"
// q35 is an alias of the newest q35 machine type.
// TODO: we probably want to select concrete type in the future for "future-backwards" compatibility.
if ostype.Machine == "" {
ostype.Machine = "q35"
}
}

func SetDefaults_DomainSpec(spec *DomainSpec) {
Expand Down
23 changes: 23 additions & 0 deletions pkg/virt-handler/virtwrap/api/defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package api

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Defaults", func() {

It("should set q35 machine type and hvm domain type", func() {
domain := &Domain{}
SetDefaults_OSType(&domain.Spec.OS.Type)
Expect(domain.Spec.OS.Type.Machine).To(Equal("q35"))
Expect(domain.Spec.OS.Type.OS).To(Equal("hvm"))
})

It("should set libvirt namespace and use QEMU as emulator", func() {
domain := &Domain{}
SetDefaults_DomainSpec(&domain.Spec)
Expect(domain.Spec.XmlNS).To(Equal("http://libvirt.org/schemas/domain/qemu/1.0"))
Expect(domain.Spec.Type).To(Equal("qemu"))
})
})
2 changes: 1 addition & 1 deletion pkg/virt-handler/virtwrap/api/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var exampleXML = `<domain type="qemu" xmlns:qemu="http://libvirt.org/schemas/dom
<name>mynamespace_testvm</name>
<memory unit="MB">9</memory>
<os>
<type>hvm</type>
<type machine="q35">hvm</type>
</os>
<sysinfo type="smbios">
<system>
Expand Down
14 changes: 12 additions & 2 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ func NewRandomVMWithNS(namespace string) *v1.VirtualMachine {

func NewRandomVMWithEphemeralDisk(containerImage string) *v1.VirtualMachine {
vm := NewRandomVM()

vm.Spec.Domain.Machine = &v1.Machine{
Type: "pc",
}
vm.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("64M")
vm.Spec.Domain.Devices.Disks = append(vm.Spec.Domain.Devices.Disks, v1.Disk{
Name: "vda",
Expand Down Expand Up @@ -585,8 +589,11 @@ func NewRandomVMWithUserData(userData string) *v1.VirtualMachine {

func NewRandomVMWithDirectLun(lun int, withAuth bool) *v1.VirtualMachine {
vm := NewRandomVM()
vm.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("64M")

vm.Spec.Domain.Machine = &v1.Machine{
Type: "pc",
}
vm.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("64M")
vm.Spec.Domain.Devices.Disks = append(vm.Spec.Domain.Devices.Disks, v1.Disk{
Name: "vda",
VolumeName: "vda",
Expand Down Expand Up @@ -619,8 +626,11 @@ func NewRandomVMWithDirectLun(lun int, withAuth bool) *v1.VirtualMachine {

func NewRandomVMWithPVC(claimName string) *v1.VirtualMachine {
vm := NewRandomVM()
vm.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("64M")

vm.Spec.Domain.Machine = &v1.Machine{
Type: "pc",
}
vm.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("64M")
vm.Spec.Domain.Devices.Disks = append(vm.Spec.Domain.Devices.Disks, v1.Disk{
Name: "vda",
VolumeName: "vda",
Expand Down

0 comments on commit 6adfa0b

Please sign in to comment.