mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-07-07 10:15:45 +00:00
api-client: Refactor to removed hard-coded prefix
The existing API client only allows access to "VM" operations, so added a new `simple_api_full_command_with_fds()` that allows access to "VMM" operations too. Also added a `simple_api_full_command()` to avoid having to specify the file descriptors, in a similar manner to `simple_api_command()`. Fixes: #4701. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
45fa8be97a
commit
eea9bcea38
@ -141,18 +141,20 @@ fn parse_http_response(socket: &mut dyn Read) -> Result<Option<String>, Error> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn simple_api_command_with_fds<T: Read + Write + ScmSocket>(
|
/// Make an API request using the fully qualified command name.
|
||||||
|
/// For example, full_command could be "vm.create" or "vmm.ping".
|
||||||
|
pub fn simple_api_full_command_with_fds<T: Read + Write + ScmSocket>(
|
||||||
socket: &mut T,
|
socket: &mut T,
|
||||||
method: &str,
|
method: &str,
|
||||||
c: &str,
|
full_command: &str,
|
||||||
request_body: Option<&str>,
|
request_body: Option<&str>,
|
||||||
request_fds: Vec<RawFd>,
|
request_fds: Vec<RawFd>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
socket
|
socket
|
||||||
.send_with_fds(
|
.send_with_fds(
|
||||||
&[format!(
|
&[format!(
|
||||||
"{} /api/v1/vm.{} HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n",
|
"{} /api/v1/{} HTTP/1.1\r\nHost: localhost\r\nAccept: */*\r\n",
|
||||||
method, c
|
method, full_command
|
||||||
)
|
)
|
||||||
.as_bytes()],
|
.as_bytes()],
|
||||||
&request_fds,
|
&request_fds,
|
||||||
@ -181,6 +183,29 @@ pub fn simple_api_command_with_fds<T: Read + Write + ScmSocket>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn simple_api_full_command<T: Read + Write + ScmSocket>(
|
||||||
|
socket: &mut T,
|
||||||
|
method: &str,
|
||||||
|
full_command: &str,
|
||||||
|
request_body: Option<&str>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
simple_api_full_command_with_fds(socket, method, full_command, request_body, Vec::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn simple_api_command_with_fds<T: Read + Write + ScmSocket>(
|
||||||
|
socket: &mut T,
|
||||||
|
method: &str,
|
||||||
|
c: &str,
|
||||||
|
request_body: Option<&str>,
|
||||||
|
request_fds: Vec<RawFd>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
// Create the full VM command. For VMM commands, use
|
||||||
|
// simple_api_full_command().
|
||||||
|
let full_command = format!("vm.{}", c);
|
||||||
|
|
||||||
|
simple_api_full_command_with_fds(socket, method, &full_command, request_body, request_fds)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn simple_api_command<T: Read + Write + ScmSocket>(
|
pub fn simple_api_command<T: Read + Write + ScmSocket>(
|
||||||
socket: &mut T,
|
socket: &mut T,
|
||||||
method: &str,
|
method: &str,
|
||||||
|
Loading…
Reference in New Issue
Block a user