diff --git a/Makefile b/Makefile index 73e007a4..4a653e1a 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ JAILER_BIN=$(FC_TEST_DATA_PATH)/jailer-main UID = $(shell id -u) GID = $(shell id -g) -firecracker_version=v0.24.3 +firecracker_version=v1.0.0 arch=$(shell uname -m) # The below files are needed and can be downloaded from the internet @@ -74,8 +74,8 @@ $(FC_TEST_DATA_PATH)/firecracker $(FC_TEST_DATA_PATH)/jailer: $(FC_TEST_DATA_PAT $(FC_TEST_DATA_PATH)/fc.stamp: $(curl) ${release_url} | tar -xvzf - -C $(FC_TEST_DATA_PATH) - mv $(FC_TEST_DATA_PATH)/firecracker-$(firecracker_version)-$(arch) $(FC_TEST_DATA_PATH)/firecracker - mv $(FC_TEST_DATA_PATH)/jailer-$(firecracker_version)-$(arch) $(FC_TEST_DATA_PATH)/jailer + mv $(FC_TEST_DATA_PATH)/release-$(firecracker_version)-$(arch)/firecracker-$(firecracker_version)-$(arch) $(FC_TEST_DATA_PATH)/firecracker + mv $(FC_TEST_DATA_PATH)/release-$(firecracker_version)-$(arch)/jailer-$(firecracker_version)-$(arch) $(FC_TEST_DATA_PATH)/jailer touch $@ $(FC_TEST_DATA_PATH)/root-drive.img: diff --git a/benchmark_test.go b/benchmark_test.go index c830aa72..3dbfa9e9 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -53,7 +53,7 @@ func createMachine(ctx context.Context, name string, forwardSignals []os.Signal) VcpuCount: Int64(1), CPUTemplate: models.CPUTemplate(models.CPUTemplateT2), MemSizeMib: Int64(256), - HtEnabled: Bool(false), + Smt: Bool(false), }, Drives: []models.Drive{ { diff --git a/client/models/balloon_stats_update.go b/client/models/balloon_stats_update.go index 6f0c55aa..571687ff 100644 --- a/client/models/balloon_stats_update.go +++ b/client/models/balloon_stats_update.go @@ -26,7 +26,7 @@ import ( "github.com/go-openapi/validate" ) -// BalloonStatsUpdate Update the statistics polling interval. Statistics cannot be turned on/off after boot. +// BalloonStatsUpdate Update the statistics polling interval, with the first statistics update scheduled immediately. Statistics cannot be turned on/off after boot. // swagger:model BalloonStatsUpdate type BalloonStatsUpdate struct { diff --git a/client/models/cpu_template.go b/client/models/cpu_template.go index dc5e2923..f00f36b6 100644 --- a/client/models/cpu_template.go +++ b/client/models/cpu_template.go @@ -27,7 +27,7 @@ import ( "github.com/go-openapi/validate" ) -// CPUTemplate The CPU Template defines a set of flags to be disabled from the microvm so that the features exposed to the guest are the same as in the selected instance type. +// CPUTemplate The CPU Template defines a set of flags to be disabled from the microvm so that the features exposed to the guest are the same as in the selected instance type. Works only on Intel. // swagger:model CpuTemplate type CPUTemplate string diff --git a/client/models/drive.go b/client/models/drive.go index 3712823b..310891b2 100644 --- a/client/models/drive.go +++ b/client/models/drive.go @@ -19,6 +19,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "encoding/json" + strfmt "github.com/go-openapi/strfmt" "github.com/go-openapi/errors" @@ -30,10 +32,18 @@ import ( // swagger:model Drive type Drive struct { + // Represents the caching strategy for the block device. + // Enum: [Unsafe Writeback] + CacheType *string `json:"cache_type,omitempty"` + // drive id // Required: true DriveID *string `json:"drive_id"` + // Type of the IO engine used by the device. "Async" is supported on host kernels newer than 5.10.51. + // Enum: [Sync Async] + IoEngine *string `json:"io_engine,omitempty"` + // is read only // Required: true IsReadOnly *bool `json:"is_read_only"` @@ -57,10 +67,18 @@ type Drive struct { func (m *Drive) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateCacheType(formats); err != nil { + res = append(res, err) + } + if err := m.validateDriveID(formats); err != nil { res = append(res, err) } + if err := m.validateIoEngine(formats); err != nil { + res = append(res, err) + } + if err := m.validateIsReadOnly(formats); err != nil { res = append(res, err) } @@ -83,6 +101,49 @@ func (m *Drive) Validate(formats strfmt.Registry) error { return nil } +var driveTypeCacheTypePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["Unsafe","Writeback"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + driveTypeCacheTypePropEnum = append(driveTypeCacheTypePropEnum, v) + } +} + +const ( + + // DriveCacheTypeUnsafe captures enum value "Unsafe" + DriveCacheTypeUnsafe string = "Unsafe" + + // DriveCacheTypeWriteback captures enum value "Writeback" + DriveCacheTypeWriteback string = "Writeback" +) + +// prop value enum +func (m *Drive) validateCacheTypeEnum(path, location string, value string) error { + if err := validate.Enum(path, location, value, driveTypeCacheTypePropEnum); err != nil { + return err + } + return nil +} + +func (m *Drive) validateCacheType(formats strfmt.Registry) error { + + if swag.IsZero(m.CacheType) { // not required + return nil + } + + // value enum + if err := m.validateCacheTypeEnum("cache_type", "body", *m.CacheType); err != nil { + return err + } + + return nil +} + func (m *Drive) validateDriveID(formats strfmt.Registry) error { if err := validate.Required("drive_id", "body", m.DriveID); err != nil { @@ -92,6 +153,49 @@ func (m *Drive) validateDriveID(formats strfmt.Registry) error { return nil } +var driveTypeIoEnginePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["Sync","Async"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + driveTypeIoEnginePropEnum = append(driveTypeIoEnginePropEnum, v) + } +} + +const ( + + // DriveIoEngineSync captures enum value "Sync" + DriveIoEngineSync string = "Sync" + + // DriveIoEngineAsync captures enum value "Async" + DriveIoEngineAsync string = "Async" +) + +// prop value enum +func (m *Drive) validateIoEngineEnum(path, location string, value string) error { + if err := validate.Enum(path, location, value, driveTypeIoEnginePropEnum); err != nil { + return err + } + return nil +} + +func (m *Drive) validateIoEngine(formats strfmt.Registry) error { + + if swag.IsZero(m.IoEngine) { // not required + return nil + } + + // value enum + if err := m.validateIoEngineEnum("io_engine", "body", *m.IoEngine); err != nil { + return err + } + + return nil +} + func (m *Drive) validateIsReadOnly(formats strfmt.Registry) error { if err := validate.Required("is_read_only", "body", m.IsReadOnly); err != nil { diff --git a/client/models/firecracker_version.go b/client/models/firecracker_version.go new file mode 100644 index 00000000..52325721 --- /dev/null +++ b/client/models/firecracker_version.go @@ -0,0 +1,77 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// FirecrackerVersion Describes the Firecracker version. +// swagger:model FirecrackerVersion +type FirecrackerVersion struct { + + // Firecracker build version. + // Required: true + FirecrackerVersion *string `json:"firecracker_version"` +} + +// Validate validates this firecracker version +func (m *FirecrackerVersion) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateFirecrackerVersion(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *FirecrackerVersion) validateFirecrackerVersion(formats strfmt.Registry) error { + + if err := validate.Required("firecracker_version", "body", m.FirecrackerVersion); err != nil { + return err + } + + return nil +} + +// MarshalBinary interface implementation +func (m *FirecrackerVersion) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *FirecrackerVersion) UnmarshalBinary(b []byte) error { + var res FirecrackerVersion + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/client/models/full_vm_configuration.go b/client/models/full_vm_configuration.go new file mode 100644 index 00000000..42a1becc --- /dev/null +++ b/client/models/full_vm_configuration.go @@ -0,0 +1,300 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "strconv" + + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/errors" + "github.com/go-openapi/swag" +) + +// FullVMConfiguration full Vm configuration +// swagger:model FullVmConfiguration +type FullVMConfiguration struct { + + // balloon device + BalloonDevice *Balloon `json:"balloon_device,omitempty"` + + // Configurations for all block devices. + BlockDevices []*Drive `json:"block_devices"` + + // boot source + BootSource *BootSource `json:"boot_source,omitempty"` + + // logger + Logger *Logger `json:"logger,omitempty"` + + // machine config + MachineConfig *MachineConfiguration `json:"machine_config,omitempty"` + + // metrics + Metrics *Metrics `json:"metrics,omitempty"` + + // mmds config + MmdsConfig *MmdsConfig `json:"mmds_config,omitempty"` + + // Configurations for all net devices. + NetDevices []*NetworkInterface `json:"net_devices"` + + // vsock device + VsockDevice *Vsock `json:"vsock_device,omitempty"` +} + +// Validate validates this full Vm configuration +func (m *FullVMConfiguration) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateBalloonDevice(formats); err != nil { + res = append(res, err) + } + + if err := m.validateBlockDevices(formats); err != nil { + res = append(res, err) + } + + if err := m.validateBootSource(formats); err != nil { + res = append(res, err) + } + + if err := m.validateLogger(formats); err != nil { + res = append(res, err) + } + + if err := m.validateMachineConfig(formats); err != nil { + res = append(res, err) + } + + if err := m.validateMetrics(formats); err != nil { + res = append(res, err) + } + + if err := m.validateMmdsConfig(formats); err != nil { + res = append(res, err) + } + + if err := m.validateNetDevices(formats); err != nil { + res = append(res, err) + } + + if err := m.validateVsockDevice(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *FullVMConfiguration) validateBalloonDevice(formats strfmt.Registry) error { + + if swag.IsZero(m.BalloonDevice) { // not required + return nil + } + + if m.BalloonDevice != nil { + if err := m.BalloonDevice.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("balloon_device") + } + return err + } + } + + return nil +} + +func (m *FullVMConfiguration) validateBlockDevices(formats strfmt.Registry) error { + + if swag.IsZero(m.BlockDevices) { // not required + return nil + } + + for i := 0; i < len(m.BlockDevices); i++ { + if swag.IsZero(m.BlockDevices[i]) { // not required + continue + } + + if m.BlockDevices[i] != nil { + if err := m.BlockDevices[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("block_devices" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *FullVMConfiguration) validateBootSource(formats strfmt.Registry) error { + + if swag.IsZero(m.BootSource) { // not required + return nil + } + + if m.BootSource != nil { + if err := m.BootSource.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("boot_source") + } + return err + } + } + + return nil +} + +func (m *FullVMConfiguration) validateLogger(formats strfmt.Registry) error { + + if swag.IsZero(m.Logger) { // not required + return nil + } + + if m.Logger != nil { + if err := m.Logger.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("logger") + } + return err + } + } + + return nil +} + +func (m *FullVMConfiguration) validateMachineConfig(formats strfmt.Registry) error { + + if swag.IsZero(m.MachineConfig) { // not required + return nil + } + + if m.MachineConfig != nil { + if err := m.MachineConfig.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("machine_config") + } + return err + } + } + + return nil +} + +func (m *FullVMConfiguration) validateMetrics(formats strfmt.Registry) error { + + if swag.IsZero(m.Metrics) { // not required + return nil + } + + if m.Metrics != nil { + if err := m.Metrics.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("metrics") + } + return err + } + } + + return nil +} + +func (m *FullVMConfiguration) validateMmdsConfig(formats strfmt.Registry) error { + + if swag.IsZero(m.MmdsConfig) { // not required + return nil + } + + if m.MmdsConfig != nil { + if err := m.MmdsConfig.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("mmds_config") + } + return err + } + } + + return nil +} + +func (m *FullVMConfiguration) validateNetDevices(formats strfmt.Registry) error { + + if swag.IsZero(m.NetDevices) { // not required + return nil + } + + for i := 0; i < len(m.NetDevices); i++ { + if swag.IsZero(m.NetDevices[i]) { // not required + continue + } + + if m.NetDevices[i] != nil { + if err := m.NetDevices[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("net_devices" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *FullVMConfiguration) validateVsockDevice(formats strfmt.Registry) error { + + if swag.IsZero(m.VsockDevice) { // not required + return nil + } + + if m.VsockDevice != nil { + if err := m.VsockDevice.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("vsock_device") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *FullVMConfiguration) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *FullVMConfiguration) UnmarshalBinary(b []byte) error { + var res FullVMConfiguration + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/client/models/machine_configuration.go b/client/models/machine_configuration.go index 8f93cbe6..31279cbb 100644 --- a/client/models/machine_configuration.go +++ b/client/models/machine_configuration.go @@ -26,21 +26,20 @@ import ( "github.com/go-openapi/validate" ) -// MachineConfiguration Describes the number of vCPUs, memory size, Hyperthreading capabilities and the CPU template. +// MachineConfiguration Describes the number of vCPUs, memory size, SMT capabilities and the CPU template. // swagger:model MachineConfiguration type MachineConfiguration struct { // cpu template CPUTemplate CPUTemplate `json:"cpu_template,omitempty"` - // Flag for enabling/disabling Hyperthreading - // Required: true - HtEnabled *bool `json:"ht_enabled"` - // Memory size of VM // Required: true MemSizeMib *int64 `json:"mem_size_mib"` + // Flag for enabling/disabling simultaneous multithreading. Can be enabled only on x86. + Smt *bool `json:"smt,omitempty"` + // Enable dirty page tracking. If this is enabled, then incremental guest memory snapshots can be created. These belong to diff snapshots, which contain, besides the microVM state, only the memory dirtied since a previous snapshot. Full snapshots each contain a full copy of the guest memory. TrackDirtyPages bool `json:"track_dirty_pages,omitempty"` @@ -59,10 +58,6 @@ func (m *MachineConfiguration) Validate(formats strfmt.Registry) error { res = append(res, err) } - if err := m.validateHtEnabled(formats); err != nil { - res = append(res, err) - } - if err := m.validateMemSizeMib(formats); err != nil { res = append(res, err) } @@ -93,15 +88,6 @@ func (m *MachineConfiguration) validateCPUTemplate(formats strfmt.Registry) erro return nil } -func (m *MachineConfiguration) validateHtEnabled(formats strfmt.Registry) error { - - if err := validate.Required("ht_enabled", "body", m.HtEnabled); err != nil { - return err - } - - return nil -} - func (m *MachineConfiguration) validateMemSizeMib(formats strfmt.Registry) error { if err := validate.Required("mem_size_mib", "body", m.MemSizeMib); err != nil { diff --git a/client/models/mmds_config.go b/client/models/mmds_config.go index 4148b500..659d9899 100644 --- a/client/models/mmds_config.go +++ b/client/models/mmds_config.go @@ -19,9 +19,13 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "encoding/json" + strfmt "github.com/go-openapi/strfmt" + "github.com/go-openapi/errors" "github.com/go-openapi/swag" + "github.com/go-openapi/validate" ) // MmdsConfig Defines the MMDS configuration. @@ -30,10 +34,83 @@ type MmdsConfig struct { // A valid IPv4 link-local address. IPV4Address *string `json:"ipv4_address,omitempty"` + + // List of the network interface IDs capable of forwarding packets to the MMDS. Network interface IDs mentioned must be valid at the time of this request. The net device model will reply to HTTP GET requests sent to the MMDS address via the interfaces mentioned. In this case, both ARP requests and TCP segments heading to `ipv4_address` are intercepted by the device model, and do not reach the associated TAP device. + // Required: true + NetworkInterfaces []string `json:"network_interfaces"` + + // Enumeration indicating the MMDS version to be configured. + // Enum: [V1 V2] + Version *string `json:"version,omitempty"` } // Validate validates this mmds config func (m *MmdsConfig) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateNetworkInterfaces(formats); err != nil { + res = append(res, err) + } + + if err := m.validateVersion(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *MmdsConfig) validateNetworkInterfaces(formats strfmt.Registry) error { + + if err := validate.Required("network_interfaces", "body", m.NetworkInterfaces); err != nil { + return err + } + + return nil +} + +var mmdsConfigTypeVersionPropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["V1","V2"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + mmdsConfigTypeVersionPropEnum = append(mmdsConfigTypeVersionPropEnum, v) + } +} + +const ( + + // MmdsConfigVersionV1 captures enum value "V1" + MmdsConfigVersionV1 string = "V1" + + // MmdsConfigVersionV2 captures enum value "V2" + MmdsConfigVersionV2 string = "V2" +) + +// prop value enum +func (m *MmdsConfig) validateVersionEnum(path, location string, value string) error { + if err := validate.Enum(path, location, value, mmdsConfigTypeVersionPropEnum); err != nil { + return err + } + return nil +} + +func (m *MmdsConfig) validateVersion(formats strfmt.Registry) error { + + if swag.IsZero(m.Version) { // not required + return nil + } + + // value enum + if err := m.validateVersionEnum("version", "body", *m.Version); err != nil { + return err + } + return nil } diff --git a/client/models/mmds_contents_object.go b/client/models/mmds_contents_object.go new file mode 100644 index 00000000..314ec9f8 --- /dev/null +++ b/client/models/mmds_contents_object.go @@ -0,0 +1,23 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +// MmdsContentsObject Describes the contents of MMDS in JSON format. +// swagger:model MmdsContentsObject +type MmdsContentsObject interface{} diff --git a/client/models/network_interface.go b/client/models/network_interface.go index 1b534e1f..1962d6f0 100644 --- a/client/models/network_interface.go +++ b/client/models/network_interface.go @@ -30,9 +30,6 @@ import ( // swagger:model NetworkInterface type NetworkInterface struct { - // If this field is set, the device model will reply to HTTP GET requests sent to the MMDS address via this interface. In this case, both ARP requests for 169.254.169.254 and TCP segments heading to the same address are intercepted by the device model, and do not reach the associated TAP device. - AllowMmdsRequests bool `json:"allow_mmds_requests,omitempty"` - // guest mac GuestMac string `json:"guest_mac,omitempty"` diff --git a/client/models/vsock.go b/client/models/vsock.go index 8d7f926c..55457fdc 100644 --- a/client/models/vsock.go +++ b/client/models/vsock.go @@ -39,9 +39,8 @@ type Vsock struct { // Required: true UdsPath *string `json:"uds_path"` - // vsock id - // Required: true - VsockID *string `json:"vsock_id"` + // This parameter has been deprecated since v1.0.0. + VsockID string `json:"vsock_id,omitempty"` } // Validate validates this vsock @@ -56,10 +55,6 @@ func (m *Vsock) Validate(formats strfmt.Registry) error { res = append(res, err) } - if err := m.validateVsockID(formats); err != nil { - res = append(res, err) - } - if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -88,15 +83,6 @@ func (m *Vsock) validateUdsPath(formats strfmt.Registry) error { return nil } -func (m *Vsock) validateVsockID(formats strfmt.Registry) error { - - if err := validate.Required("vsock_id", "body", m.VsockID); err != nil { - return err - } - - return nil -} - // MarshalBinary interface implementation func (m *Vsock) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/client/operations/get_export_vm_config_parameters.go b/client/operations/get_export_vm_config_parameters.go new file mode 100644 index 00000000..c2c4b92b --- /dev/null +++ b/client/operations/get_export_vm_config_parameters.go @@ -0,0 +1,126 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetExportVMConfigParams creates a new GetExportVMConfigParams object +// with the default values initialized. +func NewGetExportVMConfigParams() *GetExportVMConfigParams { + + return &GetExportVMConfigParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewGetExportVMConfigParamsWithTimeout creates a new GetExportVMConfigParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetExportVMConfigParamsWithTimeout(timeout time.Duration) *GetExportVMConfigParams { + + return &GetExportVMConfigParams{ + + timeout: timeout, + } +} + +// NewGetExportVMConfigParamsWithContext creates a new GetExportVMConfigParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetExportVMConfigParamsWithContext(ctx context.Context) *GetExportVMConfigParams { + + return &GetExportVMConfigParams{ + + Context: ctx, + } +} + +// NewGetExportVMConfigParamsWithHTTPClient creates a new GetExportVMConfigParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetExportVMConfigParamsWithHTTPClient(client *http.Client) *GetExportVMConfigParams { + + return &GetExportVMConfigParams{ + HTTPClient: client, + } +} + +/*GetExportVMConfigParams contains all the parameters to send to the API endpoint +for the get export Vm config operation typically these are written to a http.Request +*/ +type GetExportVMConfigParams struct { + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get export Vm config params +func (o *GetExportVMConfigParams) WithTimeout(timeout time.Duration) *GetExportVMConfigParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get export Vm config params +func (o *GetExportVMConfigParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get export Vm config params +func (o *GetExportVMConfigParams) WithContext(ctx context.Context) *GetExportVMConfigParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get export Vm config params +func (o *GetExportVMConfigParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get export Vm config params +func (o *GetExportVMConfigParams) WithHTTPClient(client *http.Client) *GetExportVMConfigParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get export Vm config params +func (o *GetExportVMConfigParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WriteToRequest writes these params to a swagger request +func (o *GetExportVMConfigParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/client/operations/get_export_vm_config_responses.go b/client/operations/get_export_vm_config_responses.go new file mode 100644 index 00000000..8a614527 --- /dev/null +++ b/client/operations/get_export_vm_config_responses.go @@ -0,0 +1,131 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + models "github.com/firecracker-microvm/firecracker-go-sdk/client/models" +) + +// GetExportVMConfigReader is a Reader for the GetExportVMConfig structure. +type GetExportVMConfigReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetExportVMConfigReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewGetExportVMConfigOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewGetExportVMConfigDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewGetExportVMConfigOK creates a GetExportVMConfigOK with default headers values +func NewGetExportVMConfigOK() *GetExportVMConfigOK { + return &GetExportVMConfigOK{} +} + +/*GetExportVMConfigOK handles this case with default header values. + +OK +*/ +type GetExportVMConfigOK struct { + Payload *models.FullVMConfiguration +} + +func (o *GetExportVMConfigOK) Error() string { + return fmt.Sprintf("[GET /vm/config][%d] getExportVmConfigOK %+v", 200, o.Payload) +} + +func (o *GetExportVMConfigOK) GetPayload() *models.FullVMConfiguration { + return o.Payload +} + +func (o *GetExportVMConfigOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.FullVMConfiguration) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetExportVMConfigDefault creates a GetExportVMConfigDefault with default headers values +func NewGetExportVMConfigDefault(code int) *GetExportVMConfigDefault { + return &GetExportVMConfigDefault{ + _statusCode: code, + } +} + +/*GetExportVMConfigDefault handles this case with default header values. + +Internal server error +*/ +type GetExportVMConfigDefault struct { + _statusCode int + + Payload *models.Error +} + +// Code gets the status code for the get export Vm config default response +func (o *GetExportVMConfigDefault) Code() int { + return o._statusCode +} + +func (o *GetExportVMConfigDefault) Error() string { + return fmt.Sprintf("[GET /vm/config][%d] getExportVmConfig default %+v", o._statusCode, o.Payload) +} + +func (o *GetExportVMConfigDefault) GetPayload() *models.Error { + return o.Payload +} + +func (o *GetExportVMConfigDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/client/operations/get_firecracker_version_parameters.go b/client/operations/get_firecracker_version_parameters.go new file mode 100644 index 00000000..5779fc12 --- /dev/null +++ b/client/operations/get_firecracker_version_parameters.go @@ -0,0 +1,126 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetFirecrackerVersionParams creates a new GetFirecrackerVersionParams object +// with the default values initialized. +func NewGetFirecrackerVersionParams() *GetFirecrackerVersionParams { + + return &GetFirecrackerVersionParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewGetFirecrackerVersionParamsWithTimeout creates a new GetFirecrackerVersionParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetFirecrackerVersionParamsWithTimeout(timeout time.Duration) *GetFirecrackerVersionParams { + + return &GetFirecrackerVersionParams{ + + timeout: timeout, + } +} + +// NewGetFirecrackerVersionParamsWithContext creates a new GetFirecrackerVersionParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetFirecrackerVersionParamsWithContext(ctx context.Context) *GetFirecrackerVersionParams { + + return &GetFirecrackerVersionParams{ + + Context: ctx, + } +} + +// NewGetFirecrackerVersionParamsWithHTTPClient creates a new GetFirecrackerVersionParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetFirecrackerVersionParamsWithHTTPClient(client *http.Client) *GetFirecrackerVersionParams { + + return &GetFirecrackerVersionParams{ + HTTPClient: client, + } +} + +/*GetFirecrackerVersionParams contains all the parameters to send to the API endpoint +for the get firecracker version operation typically these are written to a http.Request +*/ +type GetFirecrackerVersionParams struct { + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get firecracker version params +func (o *GetFirecrackerVersionParams) WithTimeout(timeout time.Duration) *GetFirecrackerVersionParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get firecracker version params +func (o *GetFirecrackerVersionParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get firecracker version params +func (o *GetFirecrackerVersionParams) WithContext(ctx context.Context) *GetFirecrackerVersionParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get firecracker version params +func (o *GetFirecrackerVersionParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get firecracker version params +func (o *GetFirecrackerVersionParams) WithHTTPClient(client *http.Client) *GetFirecrackerVersionParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get firecracker version params +func (o *GetFirecrackerVersionParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WriteToRequest writes these params to a swagger request +func (o *GetFirecrackerVersionParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/client/operations/get_firecracker_version_responses.go b/client/operations/get_firecracker_version_responses.go new file mode 100644 index 00000000..3651899f --- /dev/null +++ b/client/operations/get_firecracker_version_responses.go @@ -0,0 +1,131 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + models "github.com/firecracker-microvm/firecracker-go-sdk/client/models" +) + +// GetFirecrackerVersionReader is a Reader for the GetFirecrackerVersion structure. +type GetFirecrackerVersionReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetFirecrackerVersionReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewGetFirecrackerVersionOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewGetFirecrackerVersionDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewGetFirecrackerVersionOK creates a GetFirecrackerVersionOK with default headers values +func NewGetFirecrackerVersionOK() *GetFirecrackerVersionOK { + return &GetFirecrackerVersionOK{} +} + +/*GetFirecrackerVersionOK handles this case with default header values. + +OK +*/ +type GetFirecrackerVersionOK struct { + Payload *models.FirecrackerVersion +} + +func (o *GetFirecrackerVersionOK) Error() string { + return fmt.Sprintf("[GET /version][%d] getFirecrackerVersionOK %+v", 200, o.Payload) +} + +func (o *GetFirecrackerVersionOK) GetPayload() *models.FirecrackerVersion { + return o.Payload +} + +func (o *GetFirecrackerVersionOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.FirecrackerVersion) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetFirecrackerVersionDefault creates a GetFirecrackerVersionDefault with default headers values +func NewGetFirecrackerVersionDefault(code int) *GetFirecrackerVersionDefault { + return &GetFirecrackerVersionDefault{ + _statusCode: code, + } +} + +/*GetFirecrackerVersionDefault handles this case with default header values. + +Internal server error +*/ +type GetFirecrackerVersionDefault struct { + _statusCode int + + Payload *models.Error +} + +// Code gets the status code for the get firecracker version default response +func (o *GetFirecrackerVersionDefault) Code() int { + return o._statusCode +} + +func (o *GetFirecrackerVersionDefault) Error() string { + return fmt.Sprintf("[GET /version][%d] getFirecrackerVersion default %+v", o._statusCode, o.Payload) +} + +func (o *GetFirecrackerVersionDefault) GetPayload() *models.Error { + return o.Payload +} + +func (o *GetFirecrackerVersionDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/client/operations/get_mmds_responses.go b/client/operations/get_mmds_responses.go index 1100c397..f8f9a9c7 100644 --- a/client/operations/get_mmds_responses.go +++ b/client/operations/get_mmds_responses.go @@ -148,7 +148,7 @@ func (o *GetMmdsDefault) Code() int { } func (o *GetMmdsDefault) Error() string { - return fmt.Sprintf("[GET /mmds][%d] GetMmds default %+v", o._statusCode, o.Payload) + return fmt.Sprintf("[GET /mmds][%d] getMmds default %+v", o._statusCode, o.Payload) } func (o *GetMmdsDefault) GetPayload() *models.Error { diff --git a/client/operations/operations_client.go b/client/operations/operations_client.go index 0058638e..ed4dd348 100644 --- a/client/operations/operations_client.go +++ b/client/operations/operations_client.go @@ -46,288 +46,260 @@ func NewClient(transport runtime.ClientTransport, formats strfmt.Registry) *Clie } /* -GetMmds gets the m m d s data store -*/ -func (a *Client) GetMmds(params *GetMmdsParams) (*GetMmdsOK, error) { - // TODO: Validate the params before sending - if params == nil { - params = NewGetMmdsParams() - } - - result, err := a.transport.Submit(&runtime.ClientOperation{ - ID: "GetMmds", - Method: "GET", - PathPattern: "/mmds", - ProducesMediaTypes: []string{"application/json"}, - ConsumesMediaTypes: []string{"application/json"}, - Schemes: []string{"http"}, - Params: params, - Reader: &GetMmdsReader{formats: a.formats}, - Context: params.Context, - Client: params.HTTPClient, - }) - if err != nil { - return nil, err - } - return result.(*GetMmdsOK), nil - -} +CreateSnapshot creates a full or diff snapshot post boot only -/* -PatchMmds updates the m m d s data store +Creates a snapshot of the microVM state. The microVM should be in the `Paused` state. */ -func (a *Client) PatchMmds(params *PatchMmdsParams) (*PatchMmdsNoContent, error) { +func (a *Client) CreateSnapshot(params *CreateSnapshotParams) (*CreateSnapshotNoContent, error) { // TODO: Validate the params before sending if params == nil { - params = NewPatchMmdsParams() + params = NewCreateSnapshotParams() } result, err := a.transport.Submit(&runtime.ClientOperation{ - ID: "PatchMmds", - Method: "PATCH", - PathPattern: "/mmds", + ID: "createSnapshot", + Method: "PUT", + PathPattern: "/snapshot/create", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, - Reader: &PatchMmdsReader{formats: a.formats}, + Reader: &CreateSnapshotReader{formats: a.formats}, Context: params.Context, Client: params.HTTPClient, }) if err != nil { return nil, err } - return result.(*PatchMmdsNoContent), nil + return result.(*CreateSnapshotNoContent), nil } /* -PutMmds creates a m m d s microvm metadata service data store +CreateSyncAction creates a synchronous action */ -func (a *Client) PutMmds(params *PutMmdsParams) (*PutMmdsNoContent, error) { +func (a *Client) CreateSyncAction(params *CreateSyncActionParams) (*CreateSyncActionNoContent, error) { // TODO: Validate the params before sending if params == nil { - params = NewPutMmdsParams() + params = NewCreateSyncActionParams() } result, err := a.transport.Submit(&runtime.ClientOperation{ - ID: "PutMmds", + ID: "createSyncAction", Method: "PUT", - PathPattern: "/mmds", + PathPattern: "/actions", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, - Reader: &PutMmdsReader{formats: a.formats}, + Reader: &CreateSyncActionReader{formats: a.formats}, Context: params.Context, Client: params.HTTPClient, }) if err != nil { return nil, err } - return result.(*PutMmdsNoContent), nil + return result.(*CreateSyncActionNoContent), nil } /* -PutMmdsConfig sets m m d s configuration pre boot only - -Creates MMDS configuration to be used by the MMDS network stack. +DescribeBalloonConfig returns the current balloon device configuration */ -func (a *Client) PutMmdsConfig(params *PutMmdsConfigParams) (*PutMmdsConfigNoContent, error) { +func (a *Client) DescribeBalloonConfig(params *DescribeBalloonConfigParams) (*DescribeBalloonConfigOK, error) { // TODO: Validate the params before sending if params == nil { - params = NewPutMmdsConfigParams() + params = NewDescribeBalloonConfigParams() } result, err := a.transport.Submit(&runtime.ClientOperation{ - ID: "PutMmdsConfig", - Method: "PUT", - PathPattern: "/mmds/config", + ID: "describeBalloonConfig", + Method: "GET", + PathPattern: "/balloon", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, - Reader: &PutMmdsConfigReader{formats: a.formats}, + Reader: &DescribeBalloonConfigReader{formats: a.formats}, Context: params.Context, Client: params.HTTPClient, }) if err != nil { return nil, err } - return result.(*PutMmdsConfigNoContent), nil + return result.(*DescribeBalloonConfigOK), nil } /* -CreateSnapshot creates a full or diff snapshot post boot only - -Creates a snapshot of the microVM state. The microVM should be in the `Paused` state. +DescribeBalloonStats returns the latest balloon device statistics only if enabled pre boot */ -func (a *Client) CreateSnapshot(params *CreateSnapshotParams) (*CreateSnapshotNoContent, error) { +func (a *Client) DescribeBalloonStats(params *DescribeBalloonStatsParams) (*DescribeBalloonStatsOK, error) { // TODO: Validate the params before sending if params == nil { - params = NewCreateSnapshotParams() + params = NewDescribeBalloonStatsParams() } result, err := a.transport.Submit(&runtime.ClientOperation{ - ID: "createSnapshot", - Method: "PUT", - PathPattern: "/snapshot/create", + ID: "describeBalloonStats", + Method: "GET", + PathPattern: "/balloon/statistics", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, - Reader: &CreateSnapshotReader{formats: a.formats}, + Reader: &DescribeBalloonStatsReader{formats: a.formats}, Context: params.Context, Client: params.HTTPClient, }) if err != nil { return nil, err } - return result.(*CreateSnapshotNoContent), nil + return result.(*DescribeBalloonStatsOK), nil } /* -CreateSyncAction creates a synchronous action +DescribeInstance returns general information about an instance */ -func (a *Client) CreateSyncAction(params *CreateSyncActionParams) (*CreateSyncActionNoContent, error) { +func (a *Client) DescribeInstance(params *DescribeInstanceParams) (*DescribeInstanceOK, error) { // TODO: Validate the params before sending if params == nil { - params = NewCreateSyncActionParams() + params = NewDescribeInstanceParams() } result, err := a.transport.Submit(&runtime.ClientOperation{ - ID: "createSyncAction", - Method: "PUT", - PathPattern: "/actions", + ID: "describeInstance", + Method: "GET", + PathPattern: "/", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, - Reader: &CreateSyncActionReader{formats: a.formats}, + Reader: &DescribeInstanceReader{formats: a.formats}, Context: params.Context, Client: params.HTTPClient, }) if err != nil { return nil, err } - return result.(*CreateSyncActionNoContent), nil + return result.(*DescribeInstanceOK), nil } /* -DescribeBalloonConfig returns the current balloon device configuration +GetExportVMConfig gets the full VM configuration + +Gets configuration for all VM resources. */ -func (a *Client) DescribeBalloonConfig(params *DescribeBalloonConfigParams) (*DescribeBalloonConfigOK, error) { +func (a *Client) GetExportVMConfig(params *GetExportVMConfigParams) (*GetExportVMConfigOK, error) { // TODO: Validate the params before sending if params == nil { - params = NewDescribeBalloonConfigParams() + params = NewGetExportVMConfigParams() } result, err := a.transport.Submit(&runtime.ClientOperation{ - ID: "describeBalloonConfig", + ID: "getExportVmConfig", Method: "GET", - PathPattern: "/balloon", + PathPattern: "/vm/config", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, - Reader: &DescribeBalloonConfigReader{formats: a.formats}, + Reader: &GetExportVMConfigReader{formats: a.formats}, Context: params.Context, Client: params.HTTPClient, }) if err != nil { return nil, err } - return result.(*DescribeBalloonConfigOK), nil + return result.(*GetExportVMConfigOK), nil } /* -DescribeBalloonStats returns the latest balloon device statistics only if enabled pre boot +GetFirecrackerVersion gets the firecracker version */ -func (a *Client) DescribeBalloonStats(params *DescribeBalloonStatsParams) (*DescribeBalloonStatsOK, error) { +func (a *Client) GetFirecrackerVersion(params *GetFirecrackerVersionParams) (*GetFirecrackerVersionOK, error) { // TODO: Validate the params before sending if params == nil { - params = NewDescribeBalloonStatsParams() + params = NewGetFirecrackerVersionParams() } result, err := a.transport.Submit(&runtime.ClientOperation{ - ID: "describeBalloonStats", + ID: "getFirecrackerVersion", Method: "GET", - PathPattern: "/balloon/statistics", + PathPattern: "/version", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, - Reader: &DescribeBalloonStatsReader{formats: a.formats}, + Reader: &GetFirecrackerVersionReader{formats: a.formats}, Context: params.Context, Client: params.HTTPClient, }) if err != nil { return nil, err } - return result.(*DescribeBalloonStatsOK), nil + return result.(*GetFirecrackerVersionOK), nil } /* -DescribeInstance returns general information about an instance +GetMachineConfiguration gets the machine configuration of the VM + +Gets the machine configuration of the VM. When called before the PUT operation, it will return the default values for the vCPU count (=1), memory size (=128 MiB). By default SMT is disabled and there is no CPU Template. */ -func (a *Client) DescribeInstance(params *DescribeInstanceParams) (*DescribeInstanceOK, error) { +func (a *Client) GetMachineConfiguration(params *GetMachineConfigurationParams) (*GetMachineConfigurationOK, error) { // TODO: Validate the params before sending if params == nil { - params = NewDescribeInstanceParams() + params = NewGetMachineConfigurationParams() } result, err := a.transport.Submit(&runtime.ClientOperation{ - ID: "describeInstance", + ID: "getMachineConfiguration", Method: "GET", - PathPattern: "/", + PathPattern: "/machine-config", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, - Reader: &DescribeInstanceReader{formats: a.formats}, + Reader: &GetMachineConfigurationReader{formats: a.formats}, Context: params.Context, Client: params.HTTPClient, }) if err != nil { return nil, err } - return result.(*DescribeInstanceOK), nil + return result.(*GetMachineConfigurationOK), nil } /* -GetMachineConfiguration gets the machine configuration of the VM - -Gets the machine configuration of the VM. When called before the PUT operation, it will return the default values for the vCPU count (=1), memory size (=128 MiB). By default Hyperthreading is disabled and there is no CPU Template. +GetMmds gets the m m d s data store */ -func (a *Client) GetMachineConfiguration(params *GetMachineConfigurationParams) (*GetMachineConfigurationOK, error) { +func (a *Client) GetMmds(params *GetMmdsParams) (*GetMmdsOK, error) { // TODO: Validate the params before sending if params == nil { - params = NewGetMachineConfigurationParams() + params = NewGetMmdsParams() } result, err := a.transport.Submit(&runtime.ClientOperation{ - ID: "getMachineConfiguration", + ID: "getMmds", Method: "GET", - PathPattern: "/machine-config", + PathPattern: "/mmds", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, - Reader: &GetMachineConfigurationReader{formats: a.formats}, + Reader: &GetMmdsReader{formats: a.formats}, Context: params.Context, Client: params.HTTPClient, }) if err != nil { return nil, err } - return result.(*GetMachineConfigurationOK), nil + return result.(*GetMmdsOK), nil } @@ -511,6 +483,34 @@ func (a *Client) PatchMachineConfiguration(params *PatchMachineConfigurationPara } +/* +PatchMmds updates the m m d s data store +*/ +func (a *Client) PatchMmds(params *PatchMmdsParams) (*PatchMmdsNoContent, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewPatchMmdsParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "patchMmds", + Method: "PATCH", + PathPattern: "/mmds", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &PatchMmdsReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*PatchMmdsNoContent), nil + +} + /* PatchVM updates the micro VM state @@ -722,7 +722,7 @@ func (a *Client) PutLogger(params *PutLoggerParams) (*PutLoggerNoContent, error) /* PutMachineConfiguration updates the machine configuration of the VM pre boot only -Updates the Virtual Machine Configuration with the specified input. Firecracker starts with default values for vCPU count (=1) and memory size (=128 MiB). With Hyperthreading enabled, the vCPU count is restricted to be 1 or an even number, otherwise there are no restrictions regarding the vCPU count. If any of the parameters has an incorrect value, the whole update fails. +Updates the Virtual Machine Configuration with the specified input. Firecracker starts with default values for vCPU count (=1) and memory size (=128 MiB). With SMT enabled, the vCPU count is restricted to be 1 or an even number, otherwise there are no restrictions regarding the vCPU count. If any of the parameters has an incorrect value, the whole update fails. */ func (a *Client) PutMachineConfiguration(params *PutMachineConfigurationParams) (*PutMachineConfigurationNoContent, error) { // TODO: Validate the params before sending @@ -777,6 +777,64 @@ func (a *Client) PutMetrics(params *PutMetricsParams) (*PutMetricsNoContent, err } +/* +PutMmds creates a m m d s microvm metadata service data store +*/ +func (a *Client) PutMmds(params *PutMmdsParams) (*PutMmdsNoContent, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewPutMmdsParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "putMmds", + Method: "PUT", + PathPattern: "/mmds", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &PutMmdsReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*PutMmdsNoContent), nil + +} + +/* +PutMmdsConfig sets m m d s configuration pre boot only + +Configures MMDS version, IPv4 address used by the MMDS network stack and interfaces that allow MMDS requests. +*/ +func (a *Client) PutMmdsConfig(params *PutMmdsConfigParams) (*PutMmdsConfigNoContent, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewPutMmdsConfigParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "putMmdsConfig", + Method: "PUT", + PathPattern: "/mmds/config", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &PutMmdsConfigReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*PutMmdsConfigNoContent), nil + +} + // SetTransport changes the transport on the client func (a *Client) SetTransport(transport runtime.ClientTransport) { a.transport = transport @@ -785,22 +843,22 @@ func (a *Client) SetTransport(transport runtime.ClientTransport) { // ClientIface is an interface that can be used to mock out a Firecracker agent // for testing purposes. type ClientIface interface { - GetMmds(params *GetMmdsParams) (*GetMmdsOK, error) - PatchMmds(params *PatchMmdsParams) (*PatchMmdsNoContent, error) - PutMmds(params *PutMmdsParams) (*PutMmdsNoContent, error) - PutMmdsConfig(params *PutMmdsConfigParams) (*PutMmdsConfigNoContent, error) CreateSnapshot(params *CreateSnapshotParams) (*CreateSnapshotNoContent, error) CreateSyncAction(params *CreateSyncActionParams) (*CreateSyncActionNoContent, error) DescribeBalloonConfig(params *DescribeBalloonConfigParams) (*DescribeBalloonConfigOK, error) DescribeBalloonStats(params *DescribeBalloonStatsParams) (*DescribeBalloonStatsOK, error) DescribeInstance(params *DescribeInstanceParams) (*DescribeInstanceOK, error) + GetExportVMConfig(params *GetExportVMConfigParams) (*GetExportVMConfigOK, error) + GetFirecrackerVersion(params *GetFirecrackerVersionParams) (*GetFirecrackerVersionOK, error) GetMachineConfiguration(params *GetMachineConfigurationParams) (*GetMachineConfigurationOK, error) + GetMmds(params *GetMmdsParams) (*GetMmdsOK, error) LoadSnapshot(params *LoadSnapshotParams) (*LoadSnapshotNoContent, error) PatchBalloon(params *PatchBalloonParams) (*PatchBalloonNoContent, error) PatchBalloonStatsInterval(params *PatchBalloonStatsIntervalParams) (*PatchBalloonStatsIntervalNoContent, error) PatchGuestDriveByID(params *PatchGuestDriveByIDParams) (*PatchGuestDriveByIDNoContent, error) PatchGuestNetworkInterfaceByID(params *PatchGuestNetworkInterfaceByIDParams) (*PatchGuestNetworkInterfaceByIDNoContent, error) PatchMachineConfiguration(params *PatchMachineConfigurationParams) (*PatchMachineConfigurationNoContent, error) + PatchMmds(params *PatchMmdsParams) (*PatchMmdsNoContent, error) PatchVM(params *PatchVMParams) (*PatchVMNoContent, error) PutBalloon(params *PutBalloonParams) (*PutBalloonNoContent, error) PutGuestBootSource(params *PutGuestBootSourceParams) (*PutGuestBootSourceNoContent, error) @@ -810,4 +868,6 @@ type ClientIface interface { PutLogger(params *PutLoggerParams) (*PutLoggerNoContent, error) PutMachineConfiguration(params *PutMachineConfigurationParams) (*PutMachineConfigurationNoContent, error) PutMetrics(params *PutMetricsParams) (*PutMetricsNoContent, error) + PutMmds(params *PutMmdsParams) (*PutMmdsNoContent, error) + PutMmdsConfig(params *PutMmdsConfigParams) (*PutMmdsConfigNoContent, error) } diff --git a/client/operations/patch_mmds_parameters.go b/client/operations/patch_mmds_parameters.go index 48a83524..6534fde7 100644 --- a/client/operations/patch_mmds_parameters.go +++ b/client/operations/patch_mmds_parameters.go @@ -28,6 +28,8 @@ import ( cr "github.com/go-openapi/runtime/client" strfmt "github.com/go-openapi/strfmt" + + models "github.com/firecracker-microvm/firecracker-go-sdk/client/models" ) // NewPatchMmdsParams creates a new PatchMmdsParams object @@ -78,7 +80,7 @@ type PatchMmdsParams struct { The MMDS data store patch JSON. */ - Body interface{} + Body models.MmdsContentsObject timeout time.Duration Context context.Context @@ -119,13 +121,13 @@ func (o *PatchMmdsParams) SetHTTPClient(client *http.Client) { } // WithBody adds the body to the patch mmds params -func (o *PatchMmdsParams) WithBody(body interface{}) *PatchMmdsParams { +func (o *PatchMmdsParams) WithBody(body models.MmdsContentsObject) *PatchMmdsParams { o.SetBody(body) return o } // SetBody adds the body to the patch mmds params -func (o *PatchMmdsParams) SetBody(body interface{}) { +func (o *PatchMmdsParams) SetBody(body models.MmdsContentsObject) { o.Body = body } diff --git a/client/operations/patch_mmds_responses.go b/client/operations/patch_mmds_responses.go index 719985c5..6e545dfb 100644 --- a/client/operations/patch_mmds_responses.go +++ b/client/operations/patch_mmds_responses.go @@ -138,7 +138,7 @@ func (o *PatchMmdsDefault) Code() int { } func (o *PatchMmdsDefault) Error() string { - return fmt.Sprintf("[PATCH /mmds][%d] PatchMmds default %+v", o._statusCode, o.Payload) + return fmt.Sprintf("[PATCH /mmds][%d] patchMmds default %+v", o._statusCode, o.Payload) } func (o *PatchMmdsDefault) GetPayload() *models.Error { diff --git a/client/operations/put_mmds_config_responses.go b/client/operations/put_mmds_config_responses.go index 53c66007..8d1483f3 100644 --- a/client/operations/put_mmds_config_responses.go +++ b/client/operations/put_mmds_config_responses.go @@ -138,7 +138,7 @@ func (o *PutMmdsConfigDefault) Code() int { } func (o *PutMmdsConfigDefault) Error() string { - return fmt.Sprintf("[PUT /mmds/config][%d] PutMmdsConfig default %+v", o._statusCode, o.Payload) + return fmt.Sprintf("[PUT /mmds/config][%d] putMmdsConfig default %+v", o._statusCode, o.Payload) } func (o *PutMmdsConfigDefault) GetPayload() *models.Error { diff --git a/client/operations/put_mmds_parameters.go b/client/operations/put_mmds_parameters.go index ba0f420a..2bac5a88 100644 --- a/client/operations/put_mmds_parameters.go +++ b/client/operations/put_mmds_parameters.go @@ -28,6 +28,8 @@ import ( cr "github.com/go-openapi/runtime/client" strfmt "github.com/go-openapi/strfmt" + + models "github.com/firecracker-microvm/firecracker-go-sdk/client/models" ) // NewPutMmdsParams creates a new PutMmdsParams object @@ -78,7 +80,7 @@ type PutMmdsParams struct { The MMDS data store as JSON. */ - Body interface{} + Body models.MmdsContentsObject timeout time.Duration Context context.Context @@ -119,13 +121,13 @@ func (o *PutMmdsParams) SetHTTPClient(client *http.Client) { } // WithBody adds the body to the put mmds params -func (o *PutMmdsParams) WithBody(body interface{}) *PutMmdsParams { +func (o *PutMmdsParams) WithBody(body models.MmdsContentsObject) *PutMmdsParams { o.SetBody(body) return o } // SetBody adds the body to the put mmds params -func (o *PutMmdsParams) SetBody(body interface{}) { +func (o *PutMmdsParams) SetBody(body models.MmdsContentsObject) { o.Body = body } diff --git a/client/operations/put_mmds_responses.go b/client/operations/put_mmds_responses.go index 15da0882..2b204ca4 100644 --- a/client/operations/put_mmds_responses.go +++ b/client/operations/put_mmds_responses.go @@ -138,7 +138,7 @@ func (o *PutMmdsDefault) Code() int { } func (o *PutMmdsDefault) Error() string { - return fmt.Sprintf("[PUT /mmds][%d] PutMmds default %+v", o._statusCode, o.Payload) + return fmt.Sprintf("[PUT /mmds][%d] putMmds default %+v", o._statusCode, o.Payload) } func (o *PutMmdsDefault) GetPayload() *models.Error { diff --git a/client/swagger.yaml b/client/swagger.yaml index 00aae606..930017e8 100644 --- a/client/swagger.yaml +++ b/client/swagger.yaml @@ -5,7 +5,7 @@ info: The API is accessible through HTTP calls on specific URLs carrying JSON modeled data. The transport medium is a Unix Domain Socket. - version: 0.24.3 + version: 1.0.0 termsOfService: "" contact: email: "compute-capsule@amazon.com" @@ -285,7 +285,7 @@ paths: description: Gets the machine configuration of the VM. When called before the PUT operation, it will return the default values for the vCPU count (=1), memory size (=128 MiB). - By default Hyperthreading is disabled and there is no CPU Template. + By default SMT is disabled and there is no CPU Template. operationId: getMachineConfiguration responses: 200: @@ -302,7 +302,7 @@ paths: description: Updates the Virtual Machine Configuration with the specified input. Firecracker starts with default values for vCPU count (=1) and memory size (=128 MiB). - With Hyperthreading enabled, the vCPU count is restricted to be 1 or an even number, + With SMT enabled, the vCPU count is restricted to be 1 or an even number, otherwise there are no restrictions regarding the vCPU count. If any of the parameters has an incorrect value, the whole update fails. operationId: putMachineConfiguration @@ -374,12 +374,13 @@ paths: /mmds: put: summary: Creates a MMDS (Microvm Metadata Service) data store. + operationId: putMmds parameters: - name: body in: body description: The MMDS data store as JSON. schema: - type: object + $ref: "#/definitions/MmdsContentsObject" responses: 204: description: MMDS data store created/updated. @@ -393,12 +394,13 @@ paths: $ref: "#/definitions/Error" patch: summary: Updates the MMDS data store. + operationId: patchMmds parameters: - name: body in: body description: The MMDS data store patch JSON. schema: - type: object + $ref: "#/definitions/MmdsContentsObject" responses: 204: description: MMDS data store updated. @@ -412,6 +414,7 @@ paths: $ref: "#/definitions/Error" get: summary: Get the MMDS data store. + operationId: getMmds responses: 200: description: The MMDS data store JSON. @@ -429,8 +432,10 @@ paths: /mmds/config: put: summary: Set MMDS configuration. Pre-boot only. + operationId: putMmdsConfig description: - Creates MMDS configuration to be used by the MMDS network stack. + Configures MMDS version, IPv4 address used by the MMDS network stack + and interfaces that allow MMDS requests. parameters: - name: body in: body @@ -561,6 +566,20 @@ paths: schema: $ref: "#/definitions/Error" + /version: + get: + summary: Gets the Firecracker version. + operationId: getFirecrackerVersion + responses: + 200: + description: OK + schema: + $ref: "#/definitions/FirecrackerVersion" + default: + description: Internal server error + schema: + $ref: "#/definitions/Error" + /vm: patch: summary: Updates the microVM state. @@ -586,6 +605,22 @@ paths: schema: $ref: "#/definitions/Error" + /vm/config: + get: + summary: Gets the full VM configuration. + description: + Gets configuration for all VM resources. + operationId: getExportVmConfig + responses: + 200: + description: OK + schema: + $ref: "#/definitions/FullVmConfiguration" + default: + description: Internal server error + schema: + $ref: "#/definitions/Error" + /vsock: put: summary: Creates/updates a vsock device. Pre-boot only. @@ -711,7 +746,7 @@ definitions: required: - stats_polling_interval_s description: - Update the statistics polling interval. Statistics cannot be turned on/off after boot. + Update the statistics polling interval, with the first statistics update scheduled immediately. Statistics cannot be turned on/off after boot. properties: stats_polling_interval_s: type: integer @@ -739,6 +774,7 @@ definitions: description: The CPU Template defines a set of flags to be disabled from the microvm so that the features exposed to the guest are the same as in the selected instance type. + Works only on Intel. enum: - C3 - T2 @@ -753,6 +789,12 @@ definitions: properties: drive_id: type: string + cache_type: + type: string + description: + Represents the caching strategy for the block device. + enum: ["Unsafe", "Writeback"] + default: "Unsafe" is_read_only: type: boolean is_root_device: @@ -768,6 +810,13 @@ definitions: description: Host level path for the guest drive rate_limiter: $ref: "#/definitions/RateLimiter" + io_engine: + type: string + description: + Type of the IO engine used by the device. "Async" is supported on + host kernels newer than 5.10.51. + enum: ["Sync", "Async"] + default: "Sync" Error: type: object @@ -777,6 +826,34 @@ definitions: description: A description of the error condition readOnly: true + FullVmConfiguration: + type: object + properties: + balloon_device: + $ref: "#/definitions/Balloon" + block_devices: + type: array + description: Configurations for all block devices. + items: + $ref: "#/definitions/Drive" + boot_source: + $ref: "#/definitions/BootSource" + logger: + $ref: "#/definitions/Logger" + machine_config: + $ref: "#/definitions/MachineConfiguration" + metrics: + $ref: "#/definitions/Metrics" + mmds_config: + $ref: "#/definitions/MmdsConfig" + net_devices: + type: array + description: Configurations for all net devices. + items: + $ref: "#/definitions/NetworkInterface" + vsock_device: + $ref: "#/definitions/Vsock" + InstanceActionInfo: type: object description: @@ -848,18 +925,18 @@ definitions: MachineConfiguration: type: object description: - Describes the number of vCPUs, memory size, Hyperthreading capabilities and + Describes the number of vCPUs, memory size, SMT capabilities and the CPU template. required: - - ht_enabled - mem_size_mib - vcpu_count properties: cpu_template: $ref: "#/definitions/CpuTemplate" - ht_enabled: + smt: type: boolean - description: Flag for enabling/disabling Hyperthreading + description: Flag for enabling/disabling simultaneous multithreading. Can be enabled only on x86. + default: false mem_size_mib: type: integer description: Memory size of VM @@ -891,13 +968,39 @@ definitions: type: object description: Defines the MMDS configuration. + required: + - network_interfaces properties: + version: + description: Enumeration indicating the MMDS version to be configured. + type: string + enum: + - V1 + - V2 + default: V1 + network_interfaces: + description: + List of the network interface IDs capable of forwarding packets to + the MMDS. Network interface IDs mentioned must be valid at the time + of this request. The net device model will reply to HTTP GET requests + sent to the MMDS address via the interfaces mentioned. In this + case, both ARP requests and TCP segments heading to `ipv4_address` + are intercepted by the device model, and do not reach the associated + TAP device. + type: array + items: + type: string ipv4_address: type: string format: "169.254.([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4]).([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" default: "169.254.169.254" description: A valid IPv4 link-local address. + MmdsContentsObject: + type: object + description: + Describes the contents of MMDS in JSON format. + NetworkInterface: type: object description: @@ -906,14 +1009,6 @@ definitions: - host_dev_name - iface_id properties: - allow_mmds_requests: - type: boolean - description: - If this field is set, the device model will reply to HTTP GET - requests sent to the MMDS address via this interface. In this case, - both ARP requests for 169.254.169.254 and TCP segments heading to the - same address are intercepted by the device model, and do not reach - the associated TAP device. guest_mac: type: string host_dev_name: @@ -1058,6 +1153,17 @@ definitions: - Paused - Resumed + FirecrackerVersion: + type: object + description: + Describes the Firecracker version. + required: + - firecracker_version + properties: + firecracker_version: + description: Firecracker build version. + type: string + Vsock: type: object description: @@ -1073,7 +1179,6 @@ definitions: required: - guest_cid - uds_path - - vsock_id properties: guest_cid: type: integer @@ -1084,4 +1189,4 @@ definitions: description: Path to UNIX domain socket, used to proxy vsock connections. vsock_id: type: string - + description: This parameter has been deprecated since v1.0.0. diff --git a/example_test.go b/example_test.go index ccfd9739..5f4d9c93 100644 --- a/example_test.go +++ b/example_test.go @@ -248,7 +248,7 @@ func ExampleJailerConfig_enablingJailer() { LogLevel: "Debug", MachineCfg: models.MachineConfiguration{ VcpuCount: firecracker.Int64(1), - HtEnabled: firecracker.Bool(false), + Smt: firecracker.Bool(false), MemSizeMib: firecracker.Int64(256), }, JailerCfg: &firecracker.JailerConfig{ diff --git a/fctesting/firecracker_mock_client.go b/fctesting/firecracker_mock_client.go index 4f68b274..868a3858 100644 --- a/fctesting/firecracker_mock_client.go +++ b/fctesting/firecracker_mock_client.go @@ -20,22 +20,22 @@ import ( ) type MockClient struct { - GetMmdsFn func(params *ops.GetMmdsParams) (*ops.GetMmdsOK, error) - PatchMmdsFn func(params *ops.PatchMmdsParams) (*ops.PatchMmdsNoContent, error) - PutMmdsFn func(params *ops.PutMmdsParams) (*ops.PutMmdsNoContent, error) - PutMmdsConfigFn func(params *ops.PutMmdsConfigParams) (*ops.PutMmdsConfigNoContent, error) CreateSnapshotFn func(params *ops.CreateSnapshotParams) (*ops.CreateSnapshotNoContent, error) CreateSyncActionFn func(params *ops.CreateSyncActionParams) (*ops.CreateSyncActionNoContent, error) DescribeBalloonConfigFn func(params *ops.DescribeBalloonConfigParams) (*ops.DescribeBalloonConfigOK, error) DescribeBalloonStatsFn func(params *ops.DescribeBalloonStatsParams) (*ops.DescribeBalloonStatsOK, error) DescribeInstanceFn func(params *ops.DescribeInstanceParams) (*ops.DescribeInstanceOK, error) + GetExportVMConfigFn func(params *ops.GetExportVMConfigParams) (*ops.GetExportVMConfigOK, error) + GetFirecrackerVersionFn func(params *ops.GetFirecrackerVersionParams) (*ops.GetFirecrackerVersionOK, error) GetMachineConfigurationFn func(params *ops.GetMachineConfigurationParams) (*ops.GetMachineConfigurationOK, error) + GetMmdsFn func(params *ops.GetMmdsParams) (*ops.GetMmdsOK, error) LoadSnapshotFn func(params *ops.LoadSnapshotParams) (*ops.LoadSnapshotNoContent, error) PatchBalloonFn func(params *ops.PatchBalloonParams) (*ops.PatchBalloonNoContent, error) PatchBalloonStatsIntervalFn func(params *ops.PatchBalloonStatsIntervalParams) (*ops.PatchBalloonStatsIntervalNoContent, error) PatchGuestDriveByIDFn func(params *ops.PatchGuestDriveByIDParams) (*ops.PatchGuestDriveByIDNoContent, error) PatchGuestNetworkInterfaceByIDFn func(params *ops.PatchGuestNetworkInterfaceByIDParams) (*ops.PatchGuestNetworkInterfaceByIDNoContent, error) PatchMachineConfigurationFn func(params *ops.PatchMachineConfigurationParams) (*ops.PatchMachineConfigurationNoContent, error) + PatchMmdsFn func(params *ops.PatchMmdsParams) (*ops.PatchMmdsNoContent, error) PatchVMFn func(params *ops.PatchVMParams) (*ops.PatchVMNoContent, error) PutBalloonFn func(params *ops.PutBalloonParams) (*ops.PutBalloonNoContent, error) PutGuestBootSourceFn func(params *ops.PutGuestBootSourceParams) (*ops.PutGuestBootSourceNoContent, error) @@ -45,38 +45,8 @@ type MockClient struct { PutLoggerFn func(params *ops.PutLoggerParams) (*ops.PutLoggerNoContent, error) PutMachineConfigurationFn func(params *ops.PutMachineConfigurationParams) (*ops.PutMachineConfigurationNoContent, error) PutMetricsFn func(params *ops.PutMetricsParams) (*ops.PutMetricsNoContent, error) -} - -func (c *MockClient) GetMmds(params *ops.GetMmdsParams) (*ops.GetMmdsOK, error) { - if c.GetMmdsFn != nil { - return c.GetMmdsFn(params) - } - - return nil, nil -} - -func (c *MockClient) PatchMmds(params *ops.PatchMmdsParams) (*ops.PatchMmdsNoContent, error) { - if c.PatchMmdsFn != nil { - return c.PatchMmdsFn(params) - } - - return nil, nil -} - -func (c *MockClient) PutMmds(params *ops.PutMmdsParams) (*ops.PutMmdsNoContent, error) { - if c.PutMmdsFn != nil { - return c.PutMmdsFn(params) - } - - return nil, nil -} - -func (c *MockClient) PutMmdsConfig(params *ops.PutMmdsConfigParams) (*ops.PutMmdsConfigNoContent, error) { - if c.PutMmdsConfigFn != nil { - return c.PutMmdsConfigFn(params) - } - - return nil, nil + PutMmdsFn func(params *ops.PutMmdsParams) (*ops.PutMmdsNoContent, error) + PutMmdsConfigFn func(params *ops.PutMmdsConfigParams) (*ops.PutMmdsConfigNoContent, error) } func (c *MockClient) CreateSnapshot(params *ops.CreateSnapshotParams) (*ops.CreateSnapshotNoContent, error) { @@ -119,6 +89,22 @@ func (c *MockClient) DescribeInstance(params *ops.DescribeInstanceParams) (*ops. return nil, nil } +func (c *MockClient) GetExportVMConfig(params *ops.GetExportVMConfigParams) (*ops.GetExportVMConfigOK, error) { + if c.GetExportVMConfigFn != nil { + return c.GetExportVMConfigFn(params) + } + + return nil, nil +} + +func (c *MockClient) GetFirecrackerVersion(params *ops.GetFirecrackerVersionParams) (*ops.GetFirecrackerVersionOK, error) { + if c.GetFirecrackerVersionFn != nil { + return c.GetFirecrackerVersionFn(params) + } + + return nil, nil +} + func (c *MockClient) GetMachineConfiguration(params *ops.GetMachineConfigurationParams) (*ops.GetMachineConfigurationOK, error) { if c.GetMachineConfigurationFn != nil { return c.GetMachineConfigurationFn(params) @@ -127,6 +113,14 @@ func (c *MockClient) GetMachineConfiguration(params *ops.GetMachineConfiguration return nil, nil } +func (c *MockClient) GetMmds(params *ops.GetMmdsParams) (*ops.GetMmdsOK, error) { + if c.GetMmdsFn != nil { + return c.GetMmdsFn(params) + } + + return nil, nil +} + func (c *MockClient) LoadSnapshot(params *ops.LoadSnapshotParams) (*ops.LoadSnapshotNoContent, error) { if c.LoadSnapshotFn != nil { return c.LoadSnapshotFn(params) @@ -175,6 +169,14 @@ func (c *MockClient) PatchMachineConfiguration(params *ops.PatchMachineConfigura return nil, nil } +func (c *MockClient) PatchMmds(params *ops.PatchMmdsParams) (*ops.PatchMmdsNoContent, error) { + if c.PatchMmdsFn != nil { + return c.PatchMmdsFn(params) + } + + return nil, nil +} + func (c *MockClient) PatchVM(params *ops.PatchVMParams) (*ops.PatchVMNoContent, error) { if c.PatchVMFn != nil { return c.PatchVMFn(params) @@ -246,3 +248,19 @@ func (c *MockClient) PutMetrics(params *ops.PutMetricsParams) (*ops.PutMetricsNo return nil, nil } + +func (c *MockClient) PutMmds(params *ops.PutMmdsParams) (*ops.PutMmdsNoContent, error) { + if c.PutMmdsFn != nil { + return c.PutMmdsFn(params) + } + + return nil, nil +} + +func (c *MockClient) PutMmdsConfig(params *ops.PutMmdsConfigParams) (*ops.PutMmdsConfigNoContent, error) { + if c.PutMmdsConfigFn != nil { + return c.PutMmdsConfigFn(params) + } + + return nil, nil +} diff --git a/handlers.go b/handlers.go index 214d57f6..24013836 100644 --- a/handlers.go +++ b/handlers.go @@ -265,7 +265,7 @@ func NewSetMetadataHandler(metadata interface{}) Handler { var ConfigMmdsHandler = Handler{ Name: ConfigMmdsHandlerName, Fn: func(ctx context.Context, m *Machine) error { - return m.setMmdsConfig(ctx, m.Cfg.MmdsAddress) + return m.setMmdsConfig(ctx, m.Cfg.MmdsAddress, m.Cfg.NetworkInterfaces) }, } @@ -291,6 +291,7 @@ var defaultFcInitHandlerList = HandlerList{}.Append( AttachDrivesHandler, CreateNetworkInterfacesHandler, AddVsocksHandler, + ConfigMmdsHandler, ) var defaultValidationHandlerList = HandlerList{}.Append( diff --git a/handlers_test.go b/handlers_test.go index d8a05d4f..0801d677 100644 --- a/handlers_test.go +++ b/handlers_test.go @@ -529,7 +529,10 @@ func TestHandlers(t *testing.T) { "baz": "qux", } mmdsAddress := net.IPv4(169, 254, 169, 254) - mmdsConfig := &models.MmdsConfig{IPV4Address: String(mmdsAddress.String())} + mmdsConfig := &models.MmdsConfig{ + IPV4Address: String(mmdsAddress.String()), + NetworkInterfaces: []string{"1"}, + } cases := []struct { Handler Handler @@ -647,6 +650,13 @@ func TestHandlers(t *testing.T) { }, Config: Config{ MmdsAddress: mmdsAddress, + NetworkInterfaces: []NetworkInterface{{ + StaticConfiguration: &StaticNetworkConfiguration{ + MacAddress: "macaddress", + HostDevName: "host", + }, + AllowMMDS: true, + }}, }, }, } diff --git a/jailer.go b/jailer.go index dda2bb4f..910c7827 100644 --- a/jailer.go +++ b/jailer.go @@ -17,10 +17,12 @@ import ( "context" "fmt" "io" + "io/ioutil" "os" "os/exec" "path/filepath" "strconv" + "strings" ) const ( @@ -116,6 +118,14 @@ func NewJailerCommandBuilder() JailerCommandBuilder { return JailerCommandBuilder{}.WithBin(defaultJailerBin) } +// getNumaCpuset returns the CPU list assigned to a NUMA node +func getNumaCpuset(node int) string { + if cpus, err := ioutil.ReadFile(fmt.Sprintf("/sys/devices/system/node/node%d/cpulist", node)); err == nil { + return strings.TrimSuffix(string(cpus), "\n") + } + return "" +} + // Args returns the specified set of args to be used // in command construction. func (b JailerCommandBuilder) Args() []string { @@ -124,7 +134,11 @@ func (b JailerCommandBuilder) Args() []string { args = append(args, "--uid", strconv.Itoa(b.uid)) args = append(args, "--gid", strconv.Itoa(b.gid)) args = append(args, "--exec-file", b.execFile) - args = append(args, "--node", strconv.Itoa(b.node)) + + if cpulist := getNumaCpuset(b.node); len(cpulist) > 0 { + args = append(args, "--cgroup", fmt.Sprintf("cpuset.mems=%d", b.node)) + args = append(args, "--cgroup", fmt.Sprintf("cpuset.cpus=%s", cpulist)) + } if len(b.chrootBaseDir) > 0 { args = append(args, "--chroot-base-dir", b.chrootBaseDir) @@ -309,6 +323,9 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error { stderr = os.Stderr } + fcArgs := seccompArgs(cfg) + fcArgs = append(fcArgs, "--api-sock", machineSocketPath) + builder := NewJailerCommandBuilder(). WithID(cfg.JailerCfg.ID). WithUID(*cfg.JailerCfg.UID). @@ -317,10 +334,7 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error { WithExecFile(cfg.JailerCfg.ExecFile). WithChrootBaseDir(cfg.JailerCfg.ChrootBaseDir). WithDaemonize(cfg.JailerCfg.Daemonize). - WithFirecrackerArgs( - "--seccomp-level", cfg.SeccompLevel.String(), - "--api-sock", machineSocketPath, - ). + WithFirecrackerArgs(fcArgs...). WithStdout(stdout). WithStderr(stderr) diff --git a/jailer_test.go b/jailer_test.go index 9a13e3b3..ed9a7a97 100644 --- a/jailer_test.go +++ b/jailer_test.go @@ -14,6 +14,7 @@ package firecracker import ( "context" + "fmt" "path/filepath" "reflect" "testing" @@ -47,8 +48,10 @@ func TestJailerBuilder(t *testing.T) { "100", "--exec-file", "/path/to/firecracker", - "--node", - "0", + "--cgroup", + "cpuset.mems=0", + "--cgroup", + fmt.Sprintf("cpuset.cpus=%s", getNumaCpuset(0)), }, expectedSockPath: filepath.Join( defaultJailerPath, @@ -79,8 +82,10 @@ func TestJailerBuilder(t *testing.T) { "100", "--exec-file", "/path/to/firecracker", - "--node", - "0", + "--cgroup", + "cpuset.mems=0", + "--cgroup", + fmt.Sprintf("cpuset.cpus=%s", getNumaCpuset(0)), }, expectedSockPath: filepath.Join( defaultJailerPath, @@ -97,7 +102,7 @@ func TestJailerBuilder(t *testing.T) { ID: "my-test-id", UID: Int(123), GID: Int(100), - NumaNode: Int(1), + NumaNode: Int(0), ChrootStrategy: NewNaiveChrootStrategy("kernel-image-path"), ExecFile: "/path/to/firecracker", ChrootBaseDir: "/tmp", @@ -113,8 +118,10 @@ func TestJailerBuilder(t *testing.T) { "100", "--exec-file", "/path/to/firecracker", - "--node", - "1", + "--cgroup", + "cpuset.mems=0", + "--cgroup", + fmt.Sprintf("cpuset.cpus=%s", getNumaCpuset(0)), "--chroot-base-dir", "/tmp", "--netns", @@ -191,11 +198,12 @@ func TestJail(t *testing.T) { "100", "--exec-file", "/path/to/firecracker", - "--node", - "0", + "--cgroup", + "cpuset.mems=0", + "--cgroup", + fmt.Sprintf("cpuset.cpus=%s", getNumaCpuset(0)), "--", - "--seccomp-level", - "0", + "--no-seccomp", "--api-sock", "/run/firecracker.socket", }, @@ -228,11 +236,12 @@ func TestJail(t *testing.T) { "100", "--exec-file", "/path/to/firecracker", - "--node", - "0", + "--cgroup", + "cpuset.mems=0", + "--cgroup", + fmt.Sprintf("cpuset.cpus=%s", getNumaCpuset(0)), "--", - "--seccomp-level", - "0", + "--no-seccomp", "--api-sock", "/run/firecracker.socket", }, @@ -251,7 +260,7 @@ func TestJail(t *testing.T) { ID: "my-test-id", UID: Int(123), GID: Int(100), - NumaNode: Int(1), + NumaNode: Int(0), ChrootStrategy: NewNaiveChrootStrategy("kernel-image-path"), ExecFile: "/path/to/firecracker", ChrootBaseDir: "/tmp", @@ -267,15 +276,16 @@ func TestJail(t *testing.T) { "100", "--exec-file", "/path/to/firecracker", - "--node", - "1", + "--cgroup", + "cpuset.mems=0", + "--cgroup", + fmt.Sprintf("cpuset.cpus=%s", getNumaCpuset(0)), "--chroot-base-dir", "/tmp", "--netns", "/path/to/netns", "--", - "--seccomp-level", - "0", + "--no-seccomp", "--api-sock", "/run/firecracker.socket", }, @@ -308,11 +318,12 @@ func TestJail(t *testing.T) { "100", "--exec-file", "/path/to/firecracker", - "--node", - "0", + "--cgroup", + "cpuset.mems=0", + "--cgroup", + fmt.Sprintf("cpuset.cpus=%s", getNumaCpuset(0)), "--", - "--seccomp-level", - "0", + "--no-seccomp", "--api-sock", "api.sock", }, diff --git a/machine.go b/machine.go index 506cf09d..5bdadc92 100644 --- a/machine.go +++ b/machine.go @@ -51,22 +51,13 @@ const ( defaultFirecrackerInitTimeoutSeconds = 3 ) -// SeccompLevelValue represents a secure computing level type. -type SeccompLevelValue int +// SeccompConfig contains seccomp settings for firecracker vmm +type SeccompConfig struct { + // Enabled turns on/off the seccomp filters + Enabled bool -// secure computing levels -const ( - // SeccompLevelDisable is the default value. - SeccompLevelDisable SeccompLevelValue = iota - // SeccompLevelBasic prohibits syscalls not whitelisted by Firecracker. - SeccompLevelBasic - // SeccompLevelAdvanced adds further checks on some of the parameters of the - // allowed syscalls. - SeccompLevelAdvanced -) - -func (level SeccompLevelValue) String() string { - return strconv.Itoa(int(level)) + // Filter is a file path that contains user-provided custom filter + Filter string } // ErrAlreadyStarted signifies that the Machine has already started and cannot @@ -151,14 +142,9 @@ type Config struct { // firecracker. If not provided, the default signals will be used. ForwardSignals []os.Signal - // SeccompLevel specifies whether seccomp filters should be installed and how - // restrictive they should be. Possible values are: - // - // 0 : (default): disabled. - // 1 : basic filtering. This prohibits syscalls not whitelisted by Firecracker. - // 2 : advanced filtering. This adds further checks on some of the - // parameters of the allowed syscalls. - SeccompLevel SeccompLevelValue + // Seccomp specifies whether seccomp filters should be installed and how + // restrictive they should be. + Seccomp SeccompConfig // MmdsAddress is IPv4 address used by guest applications when issuing requests to MMDS. // It is possible to use a valid IPv4 link-local address (169.254.0.0/16). @@ -207,9 +193,6 @@ func (cfg *Config) Validate() error { Int64Value(cfg.MachineCfg.MemSizeMib) < 1 { return fmt.Errorf("machine needs a nonzero amount of memory") } - if cfg.MachineCfg.HtEnabled == nil { - return fmt.Errorf("machine needs a setting for ht_enabled") - } return nil } @@ -309,10 +292,22 @@ func (m *Machine) LogLevel() string { return m.Cfg.LogLevel } +// seccompArgs constructs the seccomp related command line arguments +func seccompArgs(cfg *Config) []string { + var args []string + if !cfg.Seccomp.Enabled { + args = append(args, "--no-seccomp") + } else if len(cfg.Seccomp.Filter) > 0 { + args = append(args, "--seccomp-filter", cfg.Seccomp.Filter) + } + return args +} + func configureBuilder(builder VMCommandBuilder, cfg Config) VMCommandBuilder { return builder. WithSocketPath(cfg.SocketPath). - AddArgs("--seccomp-level", cfg.SeccompLevel.String(), "--id", cfg.VMID) + AddArgs("--id", cfg.VMID). + AddArgs(seccompArgs(&cfg)...) } // NewMachine initializes a new Machine instance and performs validation of the @@ -766,10 +761,9 @@ func (m *Machine) createNetworkInterface(ctx context.Context, iface NetworkInter iface.StaticConfiguration.HostDevName, iface.StaticConfiguration.MacAddress, ifaceID) ifaceCfg := models.NetworkInterface{ - IfaceID: &ifaceID, - GuestMac: iface.StaticConfiguration.MacAddress, - HostDevName: String(iface.StaticConfiguration.HostDevName), - AllowMmdsRequests: iface.AllowMMDS, + IfaceID: &ifaceID, + GuestMac: iface.StaticConfiguration.MacAddress, + HostDevName: String(iface.StaticConfiguration.HostDevName), } if iface.InRateLimiter != nil { @@ -835,7 +829,7 @@ func (m *Machine) addVsock(ctx context.Context, dev VsockDevice) error { vsockCfg := models.Vsock{ GuestCid: Int64(int64(dev.CID)), UdsPath: &dev.Path, - VsockID: &dev.ID, + VsockID: dev.ID, } resp, err := m.client.PutGuestVsock(ctx, &vsockCfg) @@ -876,9 +870,22 @@ func (m *Machine) sendCtrlAltDel(ctx context.Context) error { return err } -func (m *Machine) setMmdsConfig(ctx context.Context, address net.IP) error { - mmdsCfg := models.MmdsConfig{ - IPV4Address: String(address.String()), +func (m *Machine) setMmdsConfig(ctx context.Context, address net.IP, ifaces NetworkInterfaces) error { + var mmdsCfg models.MmdsConfig + if address != nil { + mmdsCfg.IPV4Address = String(address.String()) + } + for id, iface := range ifaces { + if iface.AllowMMDS { + mmdsCfg.NetworkInterfaces = append(mmdsCfg.NetworkInterfaces, strconv.Itoa(id+1)) + } + } + // MMDS is tightly coupled with a network interface, which allows MMDS requests. + // When configuring the microVM, if MMDS needs to be activated, a network interface + // has to be configured to allow MMDS requests. + if len(mmdsCfg.NetworkInterfaces) == 0 { + m.logger.Infof("No interfaces are allowed to access MMDS, skipping MMDS config") + return nil } if _, err := m.client.PutMmdsConfig(ctx, &mmdsCfg); err != nil { m.logger.Errorf("Setting mmds configuration failed: %s: %v", address, err) @@ -1088,7 +1095,7 @@ func (m *Machine) CreateSnapshot(ctx context.Context, memFilePath, snapshotPath // CreateBalloon creates a balloon device if one does not exist func (m *Machine) CreateBalloon(ctx context.Context, amountMib int64, deflateOnOom bool, statsPollingIntervals int64, opts ...PutBalloonOpt) error { balloon := models.Balloon{ - AmountMib: &amountMib, + AmountMib: &amountMib, DeflateOnOom: &deflateOnOom, StatsPollingIntervals: statsPollingIntervals, } diff --git a/machine_test.go b/machine_test.go index 52bfdf4d..50accff7 100644 --- a/machine_test.go +++ b/machine_test.go @@ -112,7 +112,7 @@ func TestNewMachine(t *testing.T) { VcpuCount: Int64(1), MemSizeMib: Int64(100), CPUTemplate: models.CPUTemplate(models.CPUTemplateT2), - HtEnabled: Bool(false), + Smt: Bool(false), }, }, WithLogger(fctesting.NewLogEntry(t))) @@ -208,7 +208,7 @@ func TestJailerMicroVMExecution(t *testing.T) { VcpuCount: Int64(nCpus), CPUTemplate: cpuTemplate, MemSizeMib: Int64(memSz), - HtEnabled: Bool(false), + Smt: Bool(false), }, Drives: []models.Drive{ { @@ -324,7 +324,7 @@ func TestMicroVMExecution(t *testing.T) { VcpuCount: Int64(nCpus), CPUTemplate: cpuTemplate, MemSizeMib: Int64(memSz), - HtEnabled: Bool(false), + Smt: Bool(false), }, DisableValidation: true, NetworkInterfaces: networkIfaces, @@ -495,7 +495,7 @@ func testLogAndMetrics(t *testing.T, logLevel string) string { VcpuCount: Int64(1), MemSizeMib: Int64(64), CPUTemplate: models.CPUTemplate(models.CPUTemplateT2), - HtEnabled: Bool(false), + Smt: Bool(false), }, MetricsPath: filepath.Join(dir, "fc-metrics.out"), LogPath: filepath.Join(dir, "fc.log"), @@ -550,7 +550,7 @@ func TestStartVMMOnce(t *testing.T) { VcpuCount: Int64(1), MemSizeMib: Int64(64), CPUTemplate: models.CPUTemplate(models.CPUTemplateT2), - HtEnabled: Bool(false), + Smt: Bool(false), }, } ctx := context.Background() @@ -1158,7 +1158,7 @@ func TestPID(t *testing.T) { VcpuCount: Int64(nCpus), CPUTemplate: cpuTemplate, MemSizeMib: Int64(memSz), - HtEnabled: Bool(false), + Smt: Bool(false), }, Drives: []models.Drive{ { @@ -1432,7 +1432,7 @@ func createValidConfig(t *testing.T, socketPath string) Config { VcpuCount: Int64(2), CPUTemplate: models.CPUTemplate(models.CPUTemplateT2), MemSizeMib: Int64(256), - HtEnabled: Bool(false), + Smt: Bool(false), }, Drives: []models.Drive{ { @@ -1737,7 +1737,7 @@ func testCreateBalloon(ctx context.Context, t *testing.T, m *Machine) { func testGetBalloonConfig(ctx context.Context, t *testing.T, m *Machine) { expectedBalloonConfig := models.Balloon{ - AmountMib: &testBalloonMemory, + AmountMib: &testBalloonMemory, DeflateOnOom: &testBalloonDeflateOnOom, StatsPollingIntervals: testStatsPollingIntervals, } diff --git a/network_test.go b/network_test.go index cdff014a..e13f7993 100644 --- a/network_test.go +++ b/network_test.go @@ -405,7 +405,7 @@ func newCNIMachine(t *testing.T, MachineCfg: models.MachineConfiguration{ VcpuCount: Int64(2), MemSizeMib: Int64(256), - HtEnabled: Bool(true), + Smt: Bool(true), }, Drives: []models.Drive{ {