-
Notifications
You must be signed in to change notification settings - Fork 1.9k
api: Added GET method for machine-config #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ version = "0.1.0" | |
authors = ["Amazon firecracker team <[email protected]>"] | ||
|
||
[dependencies] | ||
hyper = "=0.11.16" | ||
libc = ">=0.2.39" | ||
epoll = "=2.1.0" | ||
scopeguard = "=0.3.3" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
extern crate epoll; | ||
extern crate hyper; | ||
extern crate libc; | ||
|
||
extern crate api_server; | ||
|
@@ -27,6 +28,7 @@ use std::sync::{Arc, Barrier, RwLock}; | |
use std::thread; | ||
|
||
use api_server::ApiRequest; | ||
use api_server::http_service::json_response; | ||
use api_server::request::async::{AsyncOutcome, AsyncRequest}; | ||
use api_server::request::instance_info::{InstanceInfo, InstanceState}; | ||
use api_server::request::sync::{DriveError, Error as SyncError, GenerateResponse, | ||
|
@@ -283,8 +285,7 @@ pub struct KernelConfig { | |
pub cmdline_addr: GuestAddress, | ||
} | ||
|
||
// This structure should replace MachineCfg; For now it is safer to duplicate the work as the | ||
// net support is not fuully integrated. | ||
#[derive(Clone)] | ||
pub struct VirtualMachineConfig { | ||
vcpu_count: u8, | ||
mem_size_mib: usize, | ||
|
@@ -299,6 +300,18 @@ impl Default for VirtualMachineConfig { | |
} | ||
} | ||
|
||
impl GenerateResponse for VirtualMachineConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I vote for having this block of code in "api_server/" rather than "vmm/". It's common to implement a trait for an object in a different place/crate than the object definition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a shared crate so this code is not in the VMM any more: #248 |
||
fn generate_response(&self) -> hyper::Response { | ||
json_response( | ||
hyper::StatusCode::Ok, | ||
format!( | ||
"{{ \"vcpu_count\": {:?}, \"mem_size_mib\": {:?} }}", | ||
self.vcpu_count, self.mem_size_mib | ||
), | ||
) | ||
} | ||
} | ||
|
||
pub struct Vmm { | ||
_kvm_fd: Kvm, | ||
|
||
|
@@ -911,6 +924,12 @@ impl Vmm { | |
} | ||
ApiRequest::Sync(req) => { | ||
match req { | ||
SyncRequest::GetMachineConfiguration(sender) => { | ||
sender | ||
.send(Box::new(self.vm_config.clone())) | ||
.map_err(|_| ()) | ||
.expect("one-shot channel closed"); | ||
} | ||
SyncRequest::PutDrive(drive_description, sender) => { | ||
match self.put_block_device(BlockDeviceConfig::from(drive_description)) { | ||
Ok(_) => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a body on the GET request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted it, check the new PR: #248