diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2012-08-16 09:58:07 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2012-08-16 09:58:07 +0200 |
commit | fe94f363725052b4157cf595a12e75f64e1289df (patch) | |
tree | 31734a9408f5955c021df867f9599aeef40b73dc | |
parent | e2add4678330ac78666ab572f6cf21705aec9300 (diff) | |
download | vconsole-fe94f363725052b4157cf595a12e75f64e1289df.tar.gz |
more guest actions
-rw-r--r-- | domain.c | 51 | ||||
-rw-r--r-- | vconsole.c | 50 | ||||
-rw-r--r-- | vconsole.h | 3 |
3 files changed, 102 insertions, 2 deletions
@@ -186,6 +186,9 @@ void domain_start(struct vconsole_domain *dom) case VIR_DOMAIN_PAUSED: virDomainResume(d); break; + default: + fprintf(stderr, "%s: invalid guest state: %s\n", + __func__, domain_state_name(dom)); } } @@ -198,6 +201,54 @@ void domain_pause(struct vconsole_domain *dom) case VIR_DOMAIN_RUNNING: virDomainSuspend(d); break; + default: + fprintf(stderr, "%s: invalid guest state: %s\n", + __func__, domain_state_name(dom)); + } +} + +void domain_reboot(struct vconsole_domain *dom) +{ + virDomainPtr d = virDomainLookupByUUIDString(dom->conn->ptr, dom->uuid); + + virDomainGetInfo(d, &dom->info); + switch (dom->info.state) { + case VIR_DOMAIN_RUNNING: + virDomainReboot(d, 0); + break; + default: + fprintf(stderr, "%s: invalid guest state: %s\n", + __func__, domain_state_name(dom)); + } +} + +void domain_shutdown(struct vconsole_domain *dom) +{ + virDomainPtr d = virDomainLookupByUUIDString(dom->conn->ptr, dom->uuid); + + virDomainGetInfo(d, &dom->info); + switch (dom->info.state) { + case VIR_DOMAIN_RUNNING: + virDomainShutdown(d); + break; + default: + fprintf(stderr, "%s: invalid guest state: %s\n", + __func__, domain_state_name(dom)); + } +} + +void domain_kill(struct vconsole_domain *dom) +{ + virDomainPtr d = virDomainLookupByUUIDString(dom->conn->ptr, dom->uuid); + + virDomainGetInfo(d, &dom->info); + switch (dom->info.state) { + case VIR_DOMAIN_RUNNING: + virDomainDestroy(d); + break; + default: + fprintf(stderr, "%s: invalid guest state: %s\n", + __func__, domain_state_name(dom)); } } @@ -247,6 +247,33 @@ static void menu_cb_vm_pause(GtkAction *action, void *data) domain_pause(dom); } +static void menu_cb_vm_reboot(GtkAction *action, void *data) +{ + struct vconsole_window *win = data; + struct vconsole_domain *dom = find_guest(win); + + if (dom) + domain_reboot(dom); +} + +static void menu_cb_vm_shutdown(GtkAction *action, void *data) +{ + struct vconsole_window *win = data; + struct vconsole_domain *dom = find_guest(win); + + if (dom) + domain_shutdown(dom); +} + +static void menu_cb_vm_kill(GtkAction *action, void *data) +{ + struct vconsole_window *win = data; + struct vconsole_domain *dom = find_guest(win); + + if (dom) + domain_kill(dom); +} + static void menu_cb_about(GtkAction *action, gpointer userdata) { static char *comments = "virtual machine console"; @@ -336,8 +363,8 @@ static const GtkActionEntry entries[] = { /* --- guest menu --- */ .name = "GuestRun", .stock_id = GTK_STOCK_MEDIA_PLAY, - .label = "Start", - .tooltip = "Start Guest", + .label = "Run", + .tooltip = "Run Guest", .callback = G_CALLBACK(menu_cb_vm_run), },{ .name = "GuestPause", @@ -345,6 +372,21 @@ static const GtkActionEntry entries[] = { .label = "Pause", .tooltip = "Pause Guest", .callback = G_CALLBACK(menu_cb_vm_pause), + },{ + .name = "GuestReboot", + .label = "Reboot", + .tooltip = "Reboot Guest", + .callback = G_CALLBACK(menu_cb_vm_reboot), + },{ + .name = "GuestShutdown", + .label = "Shutdown", + .tooltip = "Shutdown Guest", + .callback = G_CALLBACK(menu_cb_vm_shutdown), + },{ + .name = "GuestKill", + .label = "Destroy", + .tooltip = "Destroy Guest", + .callback = G_CALLBACK(menu_cb_vm_kill), },{ /* --- help menu --- */ @@ -391,6 +433,10 @@ static char ui_xml[] = " <menu action='GuestMenu'>\n" " <menuitem action='GuestRun'/>\n" " <menuitem action='GuestPause'/>\n" +" <menuitem action='GuestReboot'/>\n" +" <menuitem action='GuestShutdown'/>\n" +" <separator/>\n" +" <menuitem action='GuestKill'/>\n" " </menu>\n" " <menu action='HelpMenu'>\n" " <menuitem action='About'/>\n" @@ -77,6 +77,9 @@ struct vconsole_domain { void domain_start(struct vconsole_domain *dom); void domain_pause(struct vconsole_domain *dom); +void domain_reboot(struct vconsole_domain *dom); +void domain_shutdown(struct vconsole_domain *dom); +void domain_kill(struct vconsole_domain *dom); void domain_update(struct vconsole_connect *conn, virDomainPtr d, virDomainEventType event); |