[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libvir] 4/4 virsh



This adds four new subcommands to virsh allowing you to control the
new functionality.

Rich.

-- 
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.132
diff -u -r1.132 virsh.c
--- src/virsh.c	20 Feb 2008 15:29:13 -0000	1.132
+++ src/virsh.c	21 Feb 2008 20:44:28 -0000
@@ -2437,6 +2437,168 @@
 
 
 /*
+ * "net-dhcp-host-list" command
+ */
+static vshCmdInfo info_network_dhcp_host_list[] = {
+    {"syntax", "net-dhcp-host-list <network>"},
+    {"help", gettext_noop("list DHCP host mappings on a network")},
+    {"desc", gettext_noop("Returns list of DHCP host mappings on a network.")},
+    {NULL, NULL}
+};
+
+static vshCmdOptDef opts_network_dhcp_host_list[] = {
+    {"network", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("network name, id or uuid")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNetworkDHCPHostList (vshControl *ctl, vshCmd *cmd)
+{
+    virNetworkPtr network;
+    int i, ret;
+    char *name;
+    virNetworkDHCPHostMappingPtr *mappings;
+    int nr_mappings;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+
+    if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
+        return FALSE;
+
+    nr_mappings = virNetworkNumOfDHCPHostMappings (network);
+    if (nr_mappings == -1) {
+        virNetworkFree (network);
+        return FALSE;
+    }
+
+    mappings =
+        vshMalloc (ctl,
+                   nr_mappings * sizeof (virNetworkDHCPHostMappingPtr));
+    ret = virNetworkListDHCPHostMappings (network, mappings, nr_mappings);
+
+    if (ret == -1) {
+        virNetworkFree (network);
+        return FALSE;
+    }
+
+    for (i = 0; i < ret; ++i) {
+        printf ("%-20s %-20s ", mappings[i]->hwaddr, mappings[i]->ipaddr);
+        if (mappings[i]->hostname) printf ("%s", mappings[i]->hostname);
+        printf ("\n");
+    }
+
+    virNetworkFreeDHCPHostMappings (mappings, nr_mappings);
+    free (mappings);
+    virNetworkFree(network);
+
+    return TRUE;
+}
+
+
+/*
+ * "net-dhcp-host-add" command
+ */
+static vshCmdInfo info_network_dhcp_host_add[] = {
+    {"syntax", "net-dhcp-host-list <network> <hwaddr> <ipaddr> [<hostname>]"},
+    {"help", gettext_noop("add a DHCP host mappings")},
+    {"desc", gettext_noop("Adds a DHCP host mapping to the given network.")},
+    {NULL, NULL}
+};
+
+static vshCmdOptDef opts_network_dhcp_host_add[] = {
+    {"network", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("network name, id or uuid")},
+    {"hwaddr", VSH_OT_STRING, VSH_OFLAG_REQ, gettext_noop("hardware (MAC) address")},
+    {"ipaddr", VSH_OT_STRING, VSH_OFLAG_REQ, gettext_noop("IP address")},
+    {"hostname", VSH_OT_STRING, VSH_OFLAG_NONE, gettext_noop("optional hostname to assign over DHCP")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNetworkDHCPHostAdd (vshControl *ctl, vshCmd *cmd)
+{
+    virNetworkPtr network;
+    int ret;
+    char *name;
+    char *hwaddr, *ipaddr, *hostname;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+
+    if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
+        return FALSE;
+
+    if (!(hwaddr = vshCommandOptString (cmd, "hwaddr", NULL))) {
+        virNetworkFree (network);
+        return FALSE;
+    }
+    if (!(ipaddr = vshCommandOptString (cmd, "ipaddr", NULL))) {
+        virNetworkFree (network);
+        return FALSE;
+    }
+
+    hostname = vshCommandOptString (cmd, "hostname", NULL);
+
+    ret = virNetworkAddDHCPHostMapping (network, hwaddr, ipaddr, hostname, 0);
+    if (ret == -1) {
+        virNetworkFree (network);
+        return FALSE;
+    }
+
+    virNetworkFree(network);
+
+    return TRUE;
+}
+
+
+/*
+ * "net-dhcp-host-delete" command
+ */
+static vshCmdInfo info_network_dhcp_host_delete[] = {
+    {"syntax", "net-dhcp-host-list <network> <hwaddr>"},
+    {"help", gettext_noop("delete a DHCP host mappings")},
+    {"desc", gettext_noop("Deletes a DHCP host mapping from the given network.")},
+    {NULL, NULL}
+};
+
+static vshCmdOptDef opts_network_dhcp_host_delete[] = {
+    {"network", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("network name, id or uuid")},
+    {"hwaddr", VSH_OT_STRING, VSH_OFLAG_REQ, gettext_noop("hardware (MAC) address")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNetworkDHCPHostDelete (vshControl *ctl, vshCmd *cmd)
+{
+    virNetworkPtr network;
+    int ret;
+    char *name;
+    char *hwaddr;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+
+    if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
+        return FALSE;
+
+    if (!(hwaddr = vshCommandOptString (cmd, "hwaddr", NULL))) {
+        virNetworkFree (network);
+        return FALSE;
+    }
+
+    ret = virNetworkDeleteDHCPHostMapping (network, hwaddr);
+    if (ret == -1) {
+        virNetworkFree (network);
+        return FALSE;
+    }
+
+    virNetworkFree(network);
+
+    return TRUE;
+}
+
+
+/*
  * "net-dumpxml" command
  */
 static vshCmdInfo info_network_dumpxml[] = {
@@ -5109,6 +5271,9 @@
     {"net-create", cmdNetworkCreate, opts_network_create, info_network_create},
     {"net-define", cmdNetworkDefine, opts_network_define, info_network_define},
     {"net-destroy", cmdNetworkDestroy, opts_network_destroy, info_network_destroy},
+    {"net-dhcp-host-add", cmdNetworkDHCPHostAdd, opts_network_dhcp_host_add, info_network_dhcp_host_add},
+    {"net-dhcp-host-delete", cmdNetworkDHCPHostDelete, opts_network_dhcp_host_delete, info_network_dhcp_host_delete},
+    {"net-dhcp-host-list", cmdNetworkDHCPHostList, opts_network_dhcp_host_list, info_network_dhcp_host_list},
     {"net-dumpxml", cmdNetworkDumpXML, opts_network_dumpxml, info_network_dumpxml},
     {"net-list", cmdNetworkList, opts_network_list, info_network_list},
     {"net-name", cmdNetworkName, opts_network_name, info_network_name},

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]