added a guest.mconsole() method to script mconsole (e.g. add additional conX=)
This commit is contained in:
@@ -204,6 +204,22 @@ static VALUE guest_exec(VALUE self, VALUE cmd)
|
|||||||
bool block;
|
bool block;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
block = rb_block_given_p();
|
||||||
|
Data_Get_Struct(self, guest_t, guest);
|
||||||
|
if ((ret = guest->exec_str(guest, block ? (void*)exec_cb : NULL, TRUE, NULL,
|
||||||
|
"exec %s", StringValuePtr(cmd))) != 0)
|
||||||
|
{
|
||||||
|
rb_raise(rb_eRuntimeError, "executing command failed (%d)", ret);
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE guest_mconsole(VALUE self, VALUE cmd)
|
||||||
|
{
|
||||||
|
guest_t *guest;
|
||||||
|
bool block;
|
||||||
|
int ret;
|
||||||
|
|
||||||
block = rb_block_given_p();
|
block = rb_block_given_p();
|
||||||
Data_Get_Struct(self, guest_t, guest);
|
Data_Get_Struct(self, guest_t, guest);
|
||||||
if ((ret = guest->exec_str(guest, block ? (void*)exec_cb : NULL, TRUE, NULL,
|
if ((ret = guest->exec_str(guest, block ? (void*)exec_cb : NULL, TRUE, NULL,
|
||||||
@@ -310,6 +326,7 @@ static void guest_init()
|
|||||||
rb_define_method(rbc_guest, "stop", guest_stop, 0);
|
rb_define_method(rbc_guest, "stop", guest_stop, 0);
|
||||||
rb_define_method(rbc_guest, "running?", guest_running, 0);
|
rb_define_method(rbc_guest, "running?", guest_running, 0);
|
||||||
rb_define_method(rbc_guest, "exec", guest_exec, 1);
|
rb_define_method(rbc_guest, "exec", guest_exec, 1);
|
||||||
|
rb_define_method(rbc_guest, "mconsole", guest_mconsole, 1);
|
||||||
rb_define_method(rbc_guest, "add", guest_add_iface, 1);
|
rb_define_method(rbc_guest, "add", guest_add_iface, 1);
|
||||||
rb_define_method(rbc_guest, "[]", guest_get_iface, 1);
|
rb_define_method(rbc_guest, "[]", guest_get_iface, 1);
|
||||||
rb_define_method(rbc_guest, "each", guest_each_iface, -1);
|
rb_define_method(rbc_guest, "each", guest_each_iface, -1);
|
||||||
|
|||||||
+8
-6
@@ -142,7 +142,7 @@ struct guest_t {
|
|||||||
bool (*load_template)(guest_t *this, char *parent);
|
bool (*load_template)(guest_t *this, char *parent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a command in the guest.
|
* Execute a command on the guests mconsole.
|
||||||
*
|
*
|
||||||
* @param cb callback to call for each read block
|
* @param cb callback to call for each read block
|
||||||
* @param data data to pass to callback
|
* @param data data to pass to callback
|
||||||
@@ -154,20 +154,22 @@ struct guest_t {
|
|||||||
char *cmd, ...);
|
char *cmd, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a command in the guest and return the output by lines or as combined
|
* Execute a command on the guests mconsole, with output formatter.
|
||||||
* string.
|
|
||||||
*
|
*
|
||||||
* @note This function does not work with binary output (i.e. containing 0 bytes).
|
* If lines is TRUE, callback is invoked for each output line. Otherwise
|
||||||
|
* the full result is returned in one callback invocation.
|
||||||
|
*
|
||||||
|
* @note This function does not work with binary output.
|
||||||
*
|
*
|
||||||
* @param cb callback to call for each line or for the complete output
|
* @param cb callback to call for each line or for the complete output
|
||||||
* @param lines TRUE if the callback should be called for each line (instead of for the combined output)
|
* @param lines TRUE if the callback should be called for each line
|
||||||
* @param data data to pass to callback
|
* @param data data to pass to callback
|
||||||
* @param cmd command to execute
|
* @param cmd command to execute
|
||||||
* @param ... printf style argument list for cmd
|
* @param ... printf style argument list for cmd
|
||||||
* @return return value
|
* @return return value
|
||||||
*/
|
*/
|
||||||
int (*exec_str)(guest_t *this, void(*cb)(void*,char*), bool lines,
|
int (*exec_str)(guest_t *this, void(*cb)(void*,char*), bool lines,
|
||||||
void *data, char *cmd, ...);
|
void *data, char *cmd, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called whenever a SIGCHILD for the guests PID is received.
|
* @brief Called whenever a SIGCHILD for the guests PID is received.
|
||||||
|
|||||||
+6
-6
@@ -104,8 +104,8 @@ static char* get_hostif(private_iface_t *this)
|
|||||||
*/
|
*/
|
||||||
static bool add_address(private_iface_t *this, host_t *addr)
|
static bool add_address(private_iface_t *this, host_t *addr)
|
||||||
{
|
{
|
||||||
return (this->guest->exec(this->guest, NULL, NULL, "ip addr add %H dev %s",
|
return (this->guest->exec(this->guest, NULL, NULL,
|
||||||
addr, this->guestif) == 0);
|
"exec ip addr add %H dev %s", addr, this->guestif) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,7 +136,7 @@ static enumerator_t* create_address_enumerator(private_iface_t *this)
|
|||||||
linked_list_t *addresses = linked_list_create();
|
linked_list_t *addresses = linked_list_create();
|
||||||
this->guest->exec_str(this->guest, (void(*)(void*,char*))compile_address_list,
|
this->guest->exec_str(this->guest, (void(*)(void*,char*))compile_address_list,
|
||||||
TRUE, addresses,
|
TRUE, addresses,
|
||||||
"ip addr list dev %s scope global | "
|
"exec ip addr list dev %s scope global | "
|
||||||
"grep '^ \\+\\(inet6\\? \\)' | "
|
"grep '^ \\+\\(inet6\\? \\)' | "
|
||||||
"awk -F '( +|/)' '{ print $3 }'", this->guestif);
|
"awk -F '( +|/)' '{ print $3 }'", this->guestif);
|
||||||
return enumerator_create_cleaner(addresses->create_enumerator(addresses),
|
return enumerator_create_cleaner(addresses->create_enumerator(addresses),
|
||||||
@@ -149,7 +149,7 @@ static enumerator_t* create_address_enumerator(private_iface_t *this)
|
|||||||
static bool delete_address(private_iface_t *this, host_t *addr)
|
static bool delete_address(private_iface_t *this, host_t *addr)
|
||||||
{
|
{
|
||||||
return (this->guest->exec(this->guest, NULL, NULL,
|
return (this->guest->exec(this->guest, NULL, NULL,
|
||||||
"ip addr del %H dev %s", addr, this->guestif) == 0);
|
"exec ip addr del %H dev %s", addr, this->guestif) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -160,12 +160,12 @@ static void set_bridge(private_iface_t *this, bridge_t *bridge)
|
|||||||
if (this->bridge == NULL && bridge)
|
if (this->bridge == NULL && bridge)
|
||||||
{
|
{
|
||||||
this->guest->exec(this->guest, NULL, NULL,
|
this->guest->exec(this->guest, NULL, NULL,
|
||||||
"ip link set %s up", this->guestif);
|
"exec ip link set %s up", this->guestif);
|
||||||
}
|
}
|
||||||
else if (this->bridge && bridge == NULL)
|
else if (this->bridge && bridge == NULL)
|
||||||
{
|
{
|
||||||
this->guest->exec(this->guest, NULL, NULL,
|
this->guest->exec(this->guest, NULL, NULL,
|
||||||
"ip link set %s down", this->guestif);
|
"exec ip link set %s down", this->guestif);
|
||||||
}
|
}
|
||||||
this->bridge = bridge;
|
this->bridge = bridge;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -201,7 +201,7 @@ static bool del_iface(private_mconsole_t *this, char *guest)
|
|||||||
static int exec(private_mconsole_t *this, void(*cb)(void*,char*,size_t),
|
static int exec(private_mconsole_t *this, void(*cb)(void*,char*,size_t),
|
||||||
void *data, char *cmd)
|
void *data, char *cmd)
|
||||||
{
|
{
|
||||||
return request(this, cb, data, "exec %s", cmd);
|
return request(this, cb, data, "%s", cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ struct mconsole_t {
|
|||||||
bool (*del_iface)(mconsole_t *this, char *guest);
|
bool (*del_iface)(mconsole_t *this, char *guest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a command in the UML host.
|
* Execute a command on the mconsole.
|
||||||
*
|
*
|
||||||
* @param cb callback function to invoke for each line
|
* @param cb callback function to invoke for each line
|
||||||
* @param data data to pass to callback
|
* @param data data to pass to callback
|
||||||
|
|||||||
Reference in New Issue
Block a user