]> xenbits.xensource.com Git - libvirt.git/commitdiff
Added setvcpus, setmem, setmaxme commands to virsh
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 16 Aug 2006 17:30:33 +0000 (17:30 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 16 Aug 2006 17:30:33 +0000 (17:30 +0000)
ChangeLog
src/virsh.c

index c30842b868ea2aeab39b9d08018043b74762e73f..dc581bc27801342f47971ace9a719273136e1214 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Aug 16 12:33:02 EDT 2006 Daniel Berrange <berrange@redhat.com>
+
+       * src/virsh.c: Added 'setvcpus', 'setmem', 'setmaxmem'
+       commands to virsh shell. Allow full read-write connection
+       to non-Xen test hypervisor.
+
 Wed Aug 16 11:38:02 EDT 2006 Daniel Berrange <berrange@redhat.com>
 
        * src/test.c, src/test.h: Allow a hypervisor config to be
index a5f72ac0a05e54062b87a8ed584eb3882ae7e247..75651d2b9e8b7514c36eb73e99bebb27ebe37fd1 100644 (file)
@@ -963,6 +963,135 @@ cmdVcpupin(vshControl * ctl, vshCmd * cmd)
     return ret;
 }
 
+/*
+ * "setvcpus" command
+ */
+static vshCmdInfo info_setvcpus[] = {
+    {"syntax", "setvcpus <domain> <count>"},
+    {"help", "change number of virtual CPUs"},
+    {"desc", "Change the number of virtual CPUs active in the guest domain"},
+    {NULL, NULL}
+};
+
+static vshCmdOptDef opts_setvcpus[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name, id or uuid"},
+    {"count", VSH_OT_DATA, VSH_OFLAG_REQ, "number of virtual CPUs"},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdSetvcpus(vshControl * ctl, vshCmd * cmd)
+{
+    virDomainPtr dom;
+    int count;
+    int ret = TRUE;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+        return FALSE;
+
+    count = vshCommandOptInt(cmd, "count", &count);
+    if (!count) {
+        virDomainFree(dom);
+        return FALSE;
+    }
+
+    if (virDomainSetVcpus(dom, count) != 0) {
+        ret = FALSE;
+    }
+
+    virDomainFree(dom);
+    return ret;
+}
+
+/*
+ * "setmemory" command
+ */
+static vshCmdInfo info_setmem[] = {
+    {"syntax", "setmem <domain> <bytes>"},
+    {"help", "change memory allocation"},
+    {"desc", "Change the current memory allocation in the guest domain"},
+    {NULL, NULL}
+};
+
+static vshCmdOptDef opts_setmem[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name, id or uuid"},
+    {"bytes", VSH_OT_DATA, VSH_OFLAG_REQ, "number of bytes of memory"},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdSetmem(vshControl * ctl, vshCmd * cmd)
+{
+    virDomainPtr dom;
+    int bytes;
+    int ret = TRUE;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+        return FALSE;
+
+    bytes = vshCommandOptInt(cmd, "bytes", &bytes);
+    if (!bytes) {
+        virDomainFree(dom);
+        return FALSE;
+    }
+
+    if (virDomainSetMemory(dom, bytes) != 0) {
+        ret = FALSE;
+    }
+
+    virDomainFree(dom);
+    return ret;
+}
+
+/*
+ * "setmaxmem" command
+ */
+static vshCmdInfo info_setmaxmem[] = {
+    {"syntax", "setmaxmem <domain> <bytes>"},
+    {"help", "change maximum memory limit"},
+    {"desc", "Change the maximum memory allocation limit in the guest domain"},
+    {NULL, NULL}
+};
+
+static vshCmdOptDef opts_setmaxmem[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name, id or uuid"},
+    {"bytes", VSH_OT_DATA, VSH_OFLAG_REQ, "maxmimum memory limit in bytes"},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdSetmaxmem(vshControl * ctl, vshCmd * cmd)
+{
+    virDomainPtr dom;
+    int bytes;
+    int ret = TRUE;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+        return FALSE;
+
+    bytes = vshCommandOptInt(cmd, "bytes", &bytes);
+    if (!bytes) {
+        virDomainFree(dom);
+        return FALSE;
+    }
+
+    if (virDomainSetMaxMemory(dom, bytes) != 0) {
+        ret = FALSE;
+    }
+
+    virDomainFree(dom);
+    return ret;
+}
+
 /*
  * "nodeinfo" command
  */
@@ -1250,6 +1379,9 @@ static vshCmdDef commands[] = {
     {"resume", cmdResume, opts_resume, info_resume},
     {"save", cmdSave, opts_save, info_save},
     {"shutdown", cmdShutdown, opts_shutdown, info_shutdown},
+    {"setmem", cmdSetmem, opts_setmem, info_setmem},
+    {"setmaxmem", cmdSetmaxmem, opts_setmaxmem, info_setmaxmem},
+    {"setvcpus", cmdSetvcpus, opts_setvcpus, info_setvcpus},
     {"suspend", cmdSuspend, opts_suspend, info_suspend},
     {"vcpuinfo", cmdVcpuinfo, opts_vcpuinfo, info_vcpuinfo},
     {"vcpupin", cmdVcpupin, opts_vcpupin, info_vcpupin},
@@ -1945,8 +2077,10 @@ vshInit(vshControl * ctl)
     /* set up the library error handler */
     virSetErrorFunc(NULL, virshErrorHandler);
 
-    /* basic connection to hypervisor */
-    if (ctl->uid == 0)
+    /* basic connection to hypervisor, for Xen connections unless
+       we're root open a read only connections. Allow 'test' HV
+       to be RW all the time though */
+    if (ctl->uid == 0 || (ctl->name && !strncmp(ctl->name, "test", 4)))
         ctl->conn = virConnectOpen(ctl->name);
     else
         ctl->conn = virConnectOpenReadOnly(ctl->name);