~ubuntu-branches/ubuntu/maverick/libvirt/maverick

« back to all changes in this revision

Viewing changes to src/virsh.c

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2009-02-11 01:01:42 UTC
  • mto: (3.4.1 sid) (1.2.1 upstream) (0.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20090211010142-wk9mgtbw8bmp3zcb
Tags: upstream-0.6.0
ImportĀ upstreamĀ versionĀ 0.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * virsh.c: a Xen shell used to exercise the libvirt API
3
3
 *
4
 
 * Copyright (C) 2005, 2007-2008 Red Hat, Inc.
 
4
 * Copyright (C) 2005, 2007-2009 Red Hat, Inc.
5
5
 *
6
6
 * See COPYING.LIB for the License of this software
7
7
 *
8
8
 * Daniel Veillard <veillard@redhat.com>
9
9
 * Karel Zak <kzak@redhat.com>
10
10
 * Daniel P. Berrange <berrange@redhat.com>
11
 
 *
12
 
 *
13
 
 * $Id: virsh.c,v 1.176 2008/12/04 14:51:58 crobinso Exp $
14
11
 */
15
12
 
16
13
#include <config.h>
224
221
    ATTRIBUTE_FORMAT(printf, 3, 4);
225
222
static int vshInit(vshControl *ctl);
226
223
static int vshDeinit(vshControl *ctl);
227
 
static void vshUsage(vshControl *ctl, const char *cmdname);
 
224
static void vshUsage(void);
228
225
static void vshOpenLogFile(vshControl *ctl);
229
226
static void vshOutputLogFile(vshControl *ctl, int log_level, const char *format, va_list ap);
230
227
static void vshCloseLogFile(vshControl *ctl);
233
230
 
234
231
static const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info);
235
232
static const vshCmdDef *vshCmddefSearch(const char *cmdname);
236
 
static int vshCmddefHelp(vshControl *ctl, const char *name, int withprog);
 
233
static int vshCmddefHelp(vshControl *ctl, const char *name);
237
234
 
238
235
static vshCmdOpt *vshCommandOpt(const vshCmd *cmd, const char *name);
239
236
static int vshCommandOptInt(const vshCmd *cmd, const char *name, int *found);
249
246
#define VSH_BYNAME   (1 << 3)
250
247
 
251
248
static virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
252
 
                                          const char *optname, char **name, int flag);
 
249
                                          char **name, int flag);
253
250
 
254
251
/* default is lookup by Id, Name and UUID */
255
 
#define vshCommandOptDomain(_ctl, _cmd, _optname, _name)            \
256
 
    vshCommandOptDomainBy(_ctl, _cmd, _optname, _name,              \
257
 
                          VSH_BYID|VSH_BYUUID|VSH_BYNAME)
 
252
#define vshCommandOptDomain(_ctl, _cmd, _name)                      \
 
253
    vshCommandOptDomainBy(_ctl, _cmd, _name, VSH_BYID|VSH_BYUUID|VSH_BYNAME)
258
254
 
259
255
static virNetworkPtr vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
260
 
                            const char *optname, char **name, int flag);
 
256
                                            char **name, int flag);
261
257
 
262
258
/* default is lookup by Name and UUID */
263
 
#define vshCommandOptNetwork(_ctl, _cmd, _optname, _name)           \
264
 
    vshCommandOptNetworkBy(_ctl, _cmd, _optname, _name,             \
 
259
#define vshCommandOptNetwork(_ctl, _cmd, _name)                    \
 
260
    vshCommandOptNetworkBy(_ctl, _cmd, _name,                      \
265
261
                           VSH_BYUUID|VSH_BYNAME)
266
262
 
267
263
static virStoragePoolPtr vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd,
335
331
 * "help" command
336
332
 */
337
333
static const vshCmdInfo info_help[] = {
338
 
    {"syntax", "help [<command>]"},
339
334
    {"help", gettext_noop("print help")},
340
335
    {"desc", gettext_noop("Prints global help or command specific help.")},
341
336
 
361
356
                     N_(vshCmddefGetInfo(def, "help")));
362
357
        return TRUE;
363
358
    }
364
 
    return vshCmddefHelp(ctl, cmdname, FALSE);
 
359
    return vshCmddefHelp(ctl, cmdname);
365
360
}
366
361
 
367
362
/*
368
363
 * "autostart" command
369
364
 */
370
365
static const vshCmdInfo info_autostart[] = {
371
 
    {"syntax", "autostart [--disable] <domain>"},
372
366
    {"help", gettext_noop("autostart a domain")},
373
367
    {"desc",
374
368
     gettext_noop("Configure a domain to be automatically started at boot.")},
391
385
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
392
386
        return FALSE;
393
387
 
394
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
 
388
    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
395
389
        return FALSE;
396
390
 
397
391
    autostart = !vshCommandOptBool(cmd, "disable");
420
414
 * "connect" command
421
415
 */
422
416
static const vshCmdInfo info_connect[] = {
423
 
    {"syntax", "connect [name] [--readonly]"},
424
417
    {"help", gettext_noop("(re)connect to hypervisor")},
425
418
    {"desc",
426
419
     gettext_noop("Connect to local hypervisor. This is built-in command after shell start up.")},
468
461
 * "console" command
469
462
 */
470
463
static const vshCmdInfo info_console[] = {
471
 
    {"syntax", "console <domain>"},
472
464
    {"help", gettext_noop("connect to the guest console")},
473
465
    {"desc",
474
466
     gettext_noop("Connect the virtual serial console for the guest")},
495
487
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
496
488
        return FALSE;
497
489
 
498
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
490
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
499
491
        return FALSE;
500
492
 
501
493
    doc = virDomainGetXMLDesc(dom, 0);
545
537
 * "list" command
546
538
 */
547
539
static const vshCmdInfo info_list[] = {
548
 
    {"syntax", "list [--inactive | --all]"},
549
540
    {"help", gettext_noop("list domains")},
550
541
    {"desc", gettext_noop("Returns list of domains.")},
551
542
    {NULL, NULL}
663
654
 * "domstate" command
664
655
 */
665
656
static const vshCmdInfo info_domstate[] = {
666
 
    {"syntax", "domstate <domain>"},
667
657
    {"help", gettext_noop("domain state")},
668
658
    {"desc", gettext_noop("Returns state about a domain.")},
669
659
    {NULL, NULL}
684
674
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
685
675
        return FALSE;
686
676
 
687
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
677
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
688
678
        return FALSE;
689
679
 
690
680
    if (virDomainGetInfo(dom, &info) == 0)
700
690
/* "domblkstat" command
701
691
 */
702
692
static const vshCmdInfo info_domblkstat[] = {
703
 
    {"syntax", "domblkstat <domain> <dev>"},
704
693
    {"help", gettext_noop("get device block stats for a domain")},
705
694
    {"desc", gettext_noop("Get device block stats for a running domain.")},
706
695
    {NULL,NULL}
722
711
    if (!vshConnectionUsability (ctl, ctl->conn, TRUE))
723
712
        return FALSE;
724
713
 
725
 
    if (!(dom = vshCommandOptDomain (ctl, cmd, "domain", &name)))
 
714
    if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
726
715
        return FALSE;
727
716
 
728
717
    if (!(device = vshCommandOptString (cmd, "device", NULL)))
757
746
/* "domifstat" command
758
747
 */
759
748
static const vshCmdInfo info_domifstat[] = {
760
 
    {"syntax", "domifstat <domain> <dev>"},
761
749
    {"help", gettext_noop("get network interface stats for a domain")},
762
750
    {"desc", gettext_noop("Get network interface stats for a running domain.")},
763
751
    {NULL,NULL}
779
767
    if (!vshConnectionUsability (ctl, ctl->conn, TRUE))
780
768
        return FALSE;
781
769
 
782
 
    if (!(dom = vshCommandOptDomain (ctl, cmd, "domain", &name)))
 
770
    if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
783
771
        return FALSE;
784
772
 
785
773
    if (!(device = vshCommandOptString (cmd, "interface", NULL)))
824
812
 * "suspend" command
825
813
 */
826
814
static const vshCmdInfo info_suspend[] = {
827
 
    {"syntax", "suspend <domain>"},
828
815
    {"help", gettext_noop("suspend a domain")},
829
816
    {"desc", gettext_noop("Suspend a running domain.")},
830
817
    {NULL, NULL}
845
832
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
846
833
        return FALSE;
847
834
 
848
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
 
835
    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
849
836
        return FALSE;
850
837
 
851
838
    if (virDomainSuspend(dom) == 0) {
863
850
 * "create" command
864
851
 */
865
852
static const vshCmdInfo info_create[] = {
866
 
    {"syntax", "create a domain from an XML <file>"},
867
853
    {"help", gettext_noop("create a domain from an XML file")},
868
854
    {"desc", gettext_noop("Create a domain.")},
869
855
    {NULL, NULL}
911
897
 * "define" command
912
898
 */
913
899
static const vshCmdInfo info_define[] = {
914
 
    {"syntax", "define a domain from an XML <file>"},
915
900
    {"help", gettext_noop("define (but don't start) a domain from an XML file")},
916
901
    {"desc", gettext_noop("Define a domain.")},
917
902
    {NULL, NULL}
959
944
 * "undefine" command
960
945
 */
961
946
static const vshCmdInfo info_undefine[] = {
962
 
    {"syntax", "undefine <domain>"},
963
947
    {"help", gettext_noop("undefine an inactive domain")},
964
948
    {"desc", gettext_noop("Undefine the configuration for an inactive domain.")},
965
949
    {NULL, NULL}
994
978
        virDomainFree(dom);
995
979
        return FALSE;
996
980
    }
997
 
    if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", &name,
 
981
    if (!(dom = vshCommandOptDomainBy(ctl, cmd, &name,
998
982
                                      VSH_BYNAME|VSH_BYUUID)))
999
983
        return FALSE;
1000
984
 
1014
998
 * "start" command
1015
999
 */
1016
1000
static const vshCmdInfo info_start[] = {
1017
 
    {"syntax", "start <domain>"},
1018
1001
    {"help", gettext_noop("start a (previously defined) inactive domain")},
1019
1002
    {"desc", gettext_noop("Start a domain.")},
1020
1003
    {NULL, NULL}
1021
1004
};
1022
1005
 
1023
1006
static const vshCmdOptDef opts_start[] = {
1024
 
    {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive domain")},
 
1007
    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive domain")},
1025
1008
    {NULL, 0, 0, NULL}
1026
1009
};
1027
1010
 
1034
1017
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
1035
1018
        return FALSE;
1036
1019
 
1037
 
    if (!(dom = vshCommandOptDomainBy(ctl, cmd, "name", NULL, VSH_BYNAME)))
 
1020
    if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL, VSH_BYNAME)))
1038
1021
        return FALSE;
1039
1022
 
1040
1023
    if (virDomainGetID(dom) != (unsigned int)-1) {
1059
1042
 * "save" command
1060
1043
 */
1061
1044
static const vshCmdInfo info_save[] = {
1062
 
    {"syntax", "save <domain> <file>"},
1063
1045
    {"help", gettext_noop("save a domain state to a file")},
1064
1046
    {"desc", gettext_noop("Save a running domain.")},
1065
1047
    {NULL, NULL}
1085
1067
    if (!(to = vshCommandOptString(cmd, "file", NULL)))
1086
1068
        return FALSE;
1087
1069
 
1088
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
 
1070
    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
1089
1071
        return FALSE;
1090
1072
 
1091
1073
    if (virDomainSave(dom, to) == 0) {
1103
1085
 * "schedinfo" command
1104
1086
 */
1105
1087
static const vshCmdInfo info_schedinfo[] = {
1106
 
    {"syntax", "schedinfo <domain>"},
1107
1088
    {"help", gettext_noop("show/set scheduler parameters")},
1108
1089
    {"desc", gettext_noop("Show/Set scheduler parameters.")},
1109
1090
    {NULL, NULL}
1142
1123
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
1143
1124
        return FALSE;
1144
1125
 
1145
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
1126
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
1146
1127
        return FALSE;
1147
1128
 
1148
1129
    /* Deprecated Xen-only options */
1286
1267
 * "restore" command
1287
1268
 */
1288
1269
static const vshCmdInfo info_restore[] = {
1289
 
    {"syntax", "restore a domain from <file>"},
1290
1270
    {"help", gettext_noop("restore a domain from a saved state in a file")},
1291
1271
    {"desc", gettext_noop("Restore a domain.")},
1292
1272
    {NULL, NULL}
1324
1304
 * "dump" command
1325
1305
 */
1326
1306
static const vshCmdInfo info_dump[] = {
1327
 
    {"syntax", "dump <domain> <file>"},
1328
1307
    {"help", gettext_noop("dump the core of a domain to a file for analysis")},
1329
1308
    {"desc", gettext_noop("Core dump a domain.")},
1330
1309
    {NULL, NULL}
1350
1329
    if (!(to = vshCommandOptString(cmd, "file", NULL)))
1351
1330
        return FALSE;
1352
1331
 
1353
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
 
1332
    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
1354
1333
        return FALSE;
1355
1334
 
1356
1335
    if (virDomainCoreDump(dom, to, 0) == 0) {
1369
1348
 * "resume" command
1370
1349
 */
1371
1350
static const vshCmdInfo info_resume[] = {
1372
 
    {"syntax", "resume <domain>"},
1373
1351
    {"help", gettext_noop("resume a domain")},
1374
1352
    {"desc", gettext_noop("Resume a previously suspended domain.")},
1375
1353
    {NULL, NULL}
1390
1368
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
1391
1369
        return FALSE;
1392
1370
 
1393
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
 
1371
    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
1394
1372
        return FALSE;
1395
1373
 
1396
1374
    if (virDomainResume(dom) == 0) {
1408
1386
 * "shutdown" command
1409
1387
 */
1410
1388
static const vshCmdInfo info_shutdown[] = {
1411
 
    {"syntax", "shutdown <domain>"},
1412
1389
    {"help", gettext_noop("gracefully shutdown a domain")},
1413
1390
    {"desc", gettext_noop("Run shutdown in the target domain.")},
1414
1391
    {NULL, NULL}
1429
1406
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
1430
1407
        return FALSE;
1431
1408
 
1432
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
 
1409
    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
1433
1410
        return FALSE;
1434
1411
 
1435
1412
    if (virDomainShutdown(dom) == 0) {
1447
1424
 * "reboot" command
1448
1425
 */
1449
1426
static const vshCmdInfo info_reboot[] = {
1450
 
    {"syntax", "reboot <domain>"},
1451
1427
    {"help", gettext_noop("reboot a domain")},
1452
1428
    {"desc", gettext_noop("Run a reboot command in the target domain.")},
1453
1429
    {NULL, NULL}
1468
1444
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
1469
1445
        return FALSE;
1470
1446
 
1471
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
 
1447
    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
1472
1448
        return FALSE;
1473
1449
 
1474
1450
    if (virDomainReboot(dom, 0) == 0) {
1486
1462
 * "destroy" command
1487
1463
 */
1488
1464
static const vshCmdInfo info_destroy[] = {
1489
 
    {"syntax", "destroy <domain>"},
1490
1465
    {"help", gettext_noop("destroy a domain")},
1491
1466
    {"desc", gettext_noop("Destroy a given domain.")},
1492
1467
    {NULL, NULL}
1507
1482
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
1508
1483
        return FALSE;
1509
1484
 
1510
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
 
1485
    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
1511
1486
        return FALSE;
1512
1487
 
1513
1488
    if (virDomainDestroy(dom) == 0) {
1525
1500
 * "dominfo" command
1526
1501
 */
1527
1502
static const vshCmdInfo info_dominfo[] = {
1528
 
    {"syntax", "dominfo <domain>"},
1529
1503
    {"help", gettext_noop("domain information")},
1530
1504
    {"desc", gettext_noop("Returns basic information about the domain.")},
1531
1505
    {NULL, NULL}
1548
1522
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
1549
1523
        return FALSE;
1550
1524
 
1551
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
1525
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
1552
1526
        return FALSE;
1553
1527
 
1554
1528
    id = virDomainGetID(dom);
1607
1581
 * "freecell" command
1608
1582
 */
1609
1583
static const vshCmdInfo info_freecell[] = {
1610
 
    {"syntax", "freecell [<cellno>]"},
1611
1584
    {"help", gettext_noop("NUMA free memory")},
1612
1585
    {"desc", gettext_noop("display available free memory for the NUMA cell.")},
1613
1586
    {NULL, NULL}
1649
1622
 * "vcpuinfo" command
1650
1623
 */
1651
1624
static const vshCmdInfo info_vcpuinfo[] = {
1652
 
    {"syntax", "vcpuinfo <domain>"},
1653
1625
    {"help", gettext_noop("domain vcpu information")},
1654
1626
    {"desc", gettext_noop("Returns basic information about the domain virtual CPUs.")},
1655
1627
    {NULL, NULL}
1675
1647
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
1676
1648
        return FALSE;
1677
1649
 
1678
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
1650
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
1679
1651
        return FALSE;
1680
1652
 
1681
1653
    if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
1736
1708
 * "vcpupin" command
1737
1709
 */
1738
1710
static const vshCmdInfo info_vcpupin[] = {
1739
 
    {"syntax", "vcpupin <domain> <vcpu> <cpulist>"},
1740
1711
    {"help", gettext_noop("control domain vcpu affinity")},
1741
1712
    {"desc", gettext_noop("Pin domain VCPUs to host physical CPUs.")},
1742
1713
    {NULL, NULL}
1767
1738
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
1768
1739
        return FALSE;
1769
1740
 
1770
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
1741
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
1771
1742
        return FALSE;
1772
1743
 
1773
1744
    vcpu = vshCommandOptInt(cmd, "vcpu", &vcpufound);
1870
1841
 * "setvcpus" command
1871
1842
 */
1872
1843
static const vshCmdInfo info_setvcpus[] = {
1873
 
    {"syntax", "setvcpus <domain> <count>"},
1874
1844
    {"help", gettext_noop("change number of virtual CPUs")},
1875
1845
    {"desc", gettext_noop("Change the number of virtual CPUs in the guest domain.")},
1876
1846
    {NULL, NULL}
1893
1863
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
1894
1864
        return FALSE;
1895
1865
 
1896
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
1866
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
1897
1867
        return FALSE;
1898
1868
 
1899
1869
    count = vshCommandOptInt(cmd, "count", &count);
1927
1897
 * "setmemory" command
1928
1898
 */
1929
1899
static const vshCmdInfo info_setmem[] = {
1930
 
    {"syntax", "setmem <domain> <kilobytes>"},
1931
1900
    {"help", gettext_noop("change memory allocation")},
1932
1901
    {"desc", gettext_noop("Change the current memory allocation in the guest domain.")},
1933
1902
    {NULL, NULL}
1950
1919
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
1951
1920
        return FALSE;
1952
1921
 
1953
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
1922
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
1954
1923
        return FALSE;
1955
1924
 
1956
1925
    kilobytes = vshCommandOptInt(cmd, "kilobytes", &kilobytes);
1984
1953
 * "setmaxmem" command
1985
1954
 */
1986
1955
static const vshCmdInfo info_setmaxmem[] = {
1987
 
    {"syntax", "setmaxmem <domain> <kilobytes>"},
1988
1956
    {"help", gettext_noop("change maximum memory limit")},
1989
1957
    {"desc", gettext_noop("Change the maximum memory allocation limit in the guest domain.")},
1990
1958
    {NULL, NULL}
2007
1975
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2008
1976
        return FALSE;
2009
1977
 
2010
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
1978
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
2011
1979
        return FALSE;
2012
1980
 
2013
1981
    kilobytes = vshCommandOptInt(cmd, "kilobytes", &kilobytes);
2044
2012
 * "nodeinfo" command
2045
2013
 */
2046
2014
static const vshCmdInfo info_nodeinfo[] = {
2047
 
    {"syntax", "nodeinfo"},
2048
2015
    {"help", gettext_noop("node information")},
2049
2016
    {"desc", gettext_noop("Returns basic information about the node.")},
2050
2017
    {NULL, NULL}
2078
2045
 * "capabilities" command
2079
2046
 */
2080
2047
static const vshCmdInfo info_capabilities[] = {
2081
 
    {"syntax", "capabilities"},
2082
2048
    {"help", gettext_noop("capabilities")},
2083
2049
    {"desc", gettext_noop("Returns capabilities of hypervisor/driver.")},
2084
2050
    {NULL, NULL}
2106
2072
 * "dumpxml" command
2107
2073
 */
2108
2074
static const vshCmdInfo info_dumpxml[] = {
2109
 
    {"syntax", "dumpxml <domain>"},
2110
2075
    {"help", gettext_noop("domain information in XML")},
2111
2076
    {"desc", gettext_noop("Output the domain information as an XML dump to stdout.")},
2112
2077
    {NULL, NULL}
2114
2079
 
2115
2080
static const vshCmdOptDef opts_dumpxml[] = {
2116
2081
    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
 
2082
    {"inactive", VSH_OT_BOOL, 0, gettext_noop("show inactive defined XML")},
 
2083
    {"security-info", VSH_OT_BOOL, 0, gettext_noop("include security sensitive information in XML dump")},
2117
2084
    {NULL, 0, 0, NULL}
2118
2085
};
2119
2086
 
2123
2090
    virDomainPtr dom;
2124
2091
    int ret = TRUE;
2125
2092
    char *dump;
 
2093
    int flags = 0;
 
2094
    int inactive = vshCommandOptBool(cmd, "inactive");
 
2095
    int secure = vshCommandOptBool(cmd, "security-info");
 
2096
 
 
2097
    if (inactive)
 
2098
        flags |= VIR_DOMAIN_XML_INACTIVE;
 
2099
    if (secure)
 
2100
        flags |= VIR_DOMAIN_XML_SECURE;
2126
2101
 
2127
2102
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2128
2103
        return FALSE;
2129
2104
 
2130
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
2105
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
2131
2106
        return FALSE;
2132
2107
 
2133
 
    dump = virDomainGetXMLDesc(dom, 0);
 
2108
    dump = virDomainGetXMLDesc(dom, flags);
2134
2109
    if (dump != NULL) {
2135
2110
        printf("%s", dump);
2136
2111
        free(dump);
2146
2121
 * "domname" command
2147
2122
 */
2148
2123
static const vshCmdInfo info_domname[] = {
2149
 
    {"syntax", "domname <domain>"},
2150
2124
    {"help", gettext_noop("convert a domain id or UUID to domain name")},
 
2125
    {"desc", ""},
2151
2126
    {NULL, NULL}
2152
2127
};
2153
2128
 
2163
2138
 
2164
2139
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2165
2140
        return FALSE;
2166
 
    if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
 
2141
    if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
2167
2142
                                      VSH_BYID|VSH_BYUUID)))
2168
2143
        return FALSE;
2169
2144
 
2176
2151
 * "domid" command
2177
2152
 */
2178
2153
static const vshCmdInfo info_domid[] = {
2179
 
    {"syntax", "domid <domain>"},
2180
2154
    {"help", gettext_noop("convert a domain name or UUID to domain id")},
 
2155
    {"desc", ""},
2181
2156
    {NULL, NULL}
2182
2157
};
2183
2158
 
2194
2169
 
2195
2170
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2196
2171
        return FALSE;
2197
 
    if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
 
2172
    if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
2198
2173
                                      VSH_BYNAME|VSH_BYUUID)))
2199
2174
        return FALSE;
2200
2175
 
2211
2186
 * "domuuid" command
2212
2187
 */
2213
2188
static const vshCmdInfo info_domuuid[] = {
2214
 
    {"syntax", "domuuid <domain>"},
2215
2189
    {"help", gettext_noop("convert a domain name or id to domain UUID")},
 
2190
    {"desc", ""},
2216
2191
    {NULL, NULL}
2217
2192
};
2218
2193
 
2229
2204
 
2230
2205
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2231
2206
        return FALSE;
2232
 
    if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
 
2207
    if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
2233
2208
                                      VSH_BYNAME|VSH_BYID)))
2234
2209
        return FALSE;
2235
2210
 
2246
2221
 * "migrate" command
2247
2222
 */
2248
2223
static const vshCmdInfo info_migrate[] = {
2249
 
    {"syntax", "migrate [--live] <domain> <desturi> [<migrateuri>]"},
2250
2224
    {"help", gettext_noop("migrate domain to another host")},
2251
2225
    {"desc", gettext_noop("Migrate domain to another host.  Add --live for live migration.")},
2252
2226
    {NULL, NULL}
2275
2249
    if (!vshConnectionUsability (ctl, ctl->conn, TRUE))
2276
2250
        return FALSE;
2277
2251
 
2278
 
    if (!(dom = vshCommandOptDomain (ctl, cmd, "domain", NULL)))
 
2252
    if (!(dom = vshCommandOptDomain (ctl, cmd, NULL)))
2279
2253
        return FALSE;
2280
2254
 
2281
2255
    desturi = vshCommandOptString (cmd, "desturi", &found);
2284
2258
        goto done;
2285
2259
    }
2286
2260
 
2287
 
    migrateuri = vshCommandOptString (cmd, "migrateuri", &found);
2288
 
    if (!found) migrateuri = NULL;
 
2261
    migrateuri = vshCommandOptString (cmd, "migrateuri", NULL);
2289
2262
 
2290
 
    dname = vshCommandOptString (cmd, "dname", &found);
2291
 
    if (!found) migrateuri = dname;
 
2263
    dname = vshCommandOptString (cmd, "dname", NULL);
2292
2264
 
2293
2265
    if (vshCommandOptBool (cmd, "live"))
2294
2266
        flags |= VIR_MIGRATE_LIVE;
2314
2286
 * "net-autostart" command
2315
2287
 */
2316
2288
static const vshCmdInfo info_network_autostart[] = {
2317
 
    {"syntax", "net-autostart [--disable] <network>"},
2318
2289
    {"help", gettext_noop("autostart a network")},
2319
2290
    {"desc",
2320
2291
     gettext_noop("Configure a network to be automatically started at boot.")},
2337
2308
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2338
2309
        return FALSE;
2339
2310
 
2340
 
    if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
 
2311
    if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
2341
2312
        return FALSE;
2342
2313
 
2343
2314
    autostart = !vshCommandOptBool(cmd, "disable");
2365
2336
 * "net-create" command
2366
2337
 */
2367
2338
static const vshCmdInfo info_network_create[] = {
2368
 
    {"syntax", "net-create <file>"},
2369
2339
    {"help", gettext_noop("create a network from an XML file")},
2370
2340
    {"desc", gettext_noop("Create a network.")},
2371
2341
    {NULL, NULL}
2413
2383
 * "net-define" command
2414
2384
 */
2415
2385
static const vshCmdInfo info_network_define[] = {
2416
 
    {"syntax", "net-define <file>"},
2417
2386
    {"help", gettext_noop("define (but don't start) a network from an XML file")},
2418
2387
    {"desc", gettext_noop("Define a network.")},
2419
2388
    {NULL, NULL}
2461
2430
 * "net-destroy" command
2462
2431
 */
2463
2432
static const vshCmdInfo info_network_destroy[] = {
2464
 
    {"syntax", "net-destroy <network>"},
2465
2433
    {"help", gettext_noop("destroy a network")},
2466
2434
    {"desc", gettext_noop("Destroy a given network.")},
2467
2435
    {NULL, NULL}
2482
2450
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2483
2451
        return FALSE;
2484
2452
 
2485
 
    if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
 
2453
    if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
2486
2454
        return FALSE;
2487
2455
 
2488
2456
    if (virNetworkDestroy(network) == 0) {
2501
2469
 * "net-dumpxml" command
2502
2470
 */
2503
2471
static const vshCmdInfo info_network_dumpxml[] = {
2504
 
    {"syntax", "net-dumpxml <network>"},
2505
2472
    {"help", gettext_noop("network information in XML")},
2506
2473
    {"desc", gettext_noop("Output the network information as an XML dump to stdout.")},
2507
2474
    {NULL, NULL}
2522
2489
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2523
2490
        return FALSE;
2524
2491
 
2525
 
    if (!(network = vshCommandOptNetwork(ctl, cmd, "network", NULL)))
 
2492
    if (!(network = vshCommandOptNetwork(ctl, cmd, NULL)))
2526
2493
        return FALSE;
2527
2494
 
2528
2495
    dump = virNetworkGetXMLDesc(network, 0);
2542
2509
 * "net-list" command
2543
2510
 */
2544
2511
static const vshCmdInfo info_network_list[] = {
2545
 
    {"syntax", "net-list [ --inactive | --all ]"},
2546
2512
    {"help", gettext_noop("list networks")},
2547
2513
    {"desc", gettext_noop("Returns list of networks.")},
2548
2514
    {NULL, NULL}
2666
2632
 * "net-name" command
2667
2633
 */
2668
2634
static const vshCmdInfo info_network_name[] = {
2669
 
    {"syntax", "net-name <network>"},
2670
2635
    {"help", gettext_noop("convert a network UUID to network name")},
 
2636
    {"desc", ""},
2671
2637
    {NULL, NULL}
2672
2638
};
2673
2639
 
2683
2649
 
2684
2650
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2685
2651
        return FALSE;
2686
 
    if (!(network = vshCommandOptNetworkBy(ctl, cmd, "network", NULL,
 
2652
    if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
2687
2653
                                           VSH_BYUUID)))
2688
2654
        return FALSE;
2689
2655
 
2697
2663
 * "net-start" command
2698
2664
 */
2699
2665
static const vshCmdInfo info_network_start[] = {
2700
 
    {"syntax", "net-start <network>"},
2701
2666
    {"help", gettext_noop("start a (previously defined) inactive network")},
2702
2667
    {"desc", gettext_noop("Start a network.")},
2703
2668
    {NULL, NULL}
2704
2669
};
2705
2670
 
2706
2671
static const vshCmdOptDef opts_network_start[] = {
2707
 
    {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive network")},
 
2672
    {"network", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive network")},
2708
2673
    {NULL, 0, 0, NULL}
2709
2674
};
2710
2675
 
2717
2682
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2718
2683
        return FALSE;
2719
2684
 
2720
 
    if (!(network = vshCommandOptNetworkBy(ctl, cmd, "name", NULL, VSH_BYNAME)))
 
2685
    if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL, VSH_BYNAME)))
2721
2686
         return FALSE;
2722
2687
 
2723
2688
    if (virNetworkCreate(network) == 0) {
2736
2701
 * "net-undefine" command
2737
2702
 */
2738
2703
static const vshCmdInfo info_network_undefine[] = {
2739
 
    {"syntax", "net-undefine <network>"},
2740
2704
    {"help", gettext_noop("undefine an inactive network")},
2741
2705
    {"desc", gettext_noop("Undefine the configuration for an inactive network.")},
2742
2706
    {NULL, NULL}
2757
2721
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2758
2722
        return FALSE;
2759
2723
 
2760
 
    if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
 
2724
    if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
2761
2725
        return FALSE;
2762
2726
 
2763
2727
    if (virNetworkUndefine(network) == 0) {
2775
2739
 * "net-uuid" command
2776
2740
 */
2777
2741
static const vshCmdInfo info_network_uuid[] = {
2778
 
    {"syntax", "net-uuid <network>"},
2779
2742
    {"help", gettext_noop("convert a network name to network UUID")},
 
2743
    {"desc", ""},
2780
2744
    {NULL, NULL}
2781
2745
};
2782
2746
 
2794
2758
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2795
2759
        return FALSE;
2796
2760
 
2797
 
    if (!(network = vshCommandOptNetworkBy(ctl, cmd, "network", NULL,
 
2761
    if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
2798
2762
                                           VSH_BYNAME)))
2799
2763
        return FALSE;
2800
2764
 
2811
2775
 * "pool-autostart" command
2812
2776
 */
2813
2777
static const vshCmdInfo info_pool_autostart[] = {
2814
 
    {"syntax", "pool-autostart [--disable] <pool>"},
2815
2778
    {"help", gettext_noop("autostart a pool")},
2816
2779
    {"desc",
2817
2780
     gettext_noop("Configure a pool to be automatically started at boot.")},
2862
2825
 * "pool-create" command
2863
2826
 */
2864
2827
static const vshCmdInfo info_pool_create[] = {
2865
 
    {"syntax", "pool-create <file>"},
2866
2828
    {"help", gettext_noop("create a pool from an XML file")},
2867
2829
    {"desc", gettext_noop("Create a pool.")},
2868
2830
    {NULL, NULL}
2906
2868
    return ret;
2907
2869
}
2908
2870
 
 
2871
 
 
2872
/*
 
2873
 * XML Building helper for pool-define-as and pool-create-as
 
2874
 */
 
2875
static const vshCmdOptDef opts_pool_X_as[] = {
 
2876
    {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the pool")},
 
2877
    {"type", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("type of the pool")},
 
2878
    {"source-host", VSH_OT_DATA, 0, gettext_noop("source-host for underlying storage")},
 
2879
    {"source-path", VSH_OT_DATA, 0, gettext_noop("source path for underlying storage")},
 
2880
    {"source-dev", VSH_OT_DATA, 0, gettext_noop("source device for underlying storage")},
 
2881
    {"source-name", VSH_OT_DATA, 0, gettext_noop("source name for underlying storage")},
 
2882
    {"target", VSH_OT_DATA, 0, gettext_noop("target for underlying storage")},
 
2883
    {NULL, 0, 0, NULL}
 
2884
};
 
2885
 
 
2886
static int buildPoolXML(const vshCmd *cmd, char **retname, char **xml) {
 
2887
 
 
2888
    int found;
 
2889
    char *name, *type, *srcHost, *srcPath, *srcDev, *srcName, *target;
 
2890
    virBuffer buf = VIR_BUFFER_INITIALIZER;
 
2891
 
 
2892
    name = vshCommandOptString(cmd, "name", &found);
 
2893
    if (!found)
 
2894
        goto cleanup;
 
2895
    type = vshCommandOptString(cmd, "type", &found);
 
2896
    if (!found)
 
2897
        goto cleanup;
 
2898
 
 
2899
    srcHost = vshCommandOptString(cmd, "source-host", &found);
 
2900
    srcPath = vshCommandOptString(cmd, "source-path", &found);
 
2901
    srcDev = vshCommandOptString(cmd, "source-dev", &found);
 
2902
    srcName = vshCommandOptString(cmd, "source-name", &found);
 
2903
    target = vshCommandOptString(cmd, "target", &found);
 
2904
 
 
2905
    virBufferVSprintf(&buf, "<pool type='%s'>\n", type);
 
2906
    virBufferVSprintf(&buf, "  <name>%s</name>\n", name);
 
2907
    if (srcHost || srcPath || srcDev) {
 
2908
        virBufferAddLit(&buf, "  <source>\n");
 
2909
 
 
2910
        if (srcHost)
 
2911
            virBufferVSprintf(&buf, "    <host name='%s'/>\n", srcHost);
 
2912
        if (srcPath)
 
2913
            virBufferVSprintf(&buf, "    <dir path='%s'/>\n", srcPath);
 
2914
        if (srcDev)
 
2915
            virBufferVSprintf(&buf, "    <device path='%s'/>\n", srcDev);
 
2916
        if (srcName)
 
2917
            virBufferVSprintf(&buf, "    <name>%s</name>\n", srcName);
 
2918
 
 
2919
        virBufferAddLit(&buf, "  </source>\n");
 
2920
    }
 
2921
    if (target) {
 
2922
        virBufferAddLit(&buf, "  <target>\n");
 
2923
        virBufferVSprintf(&buf, "    <path>%s</path>\n", target);
 
2924
        virBufferAddLit(&buf, "  </target>\n");
 
2925
    }
 
2926
    virBufferAddLit(&buf, "</pool>\n");
 
2927
 
 
2928
    if (virBufferError(&buf)) {
 
2929
        vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
 
2930
        return FALSE;
 
2931
    }
 
2932
 
 
2933
    *xml = virBufferContentAndReset(&buf);
 
2934
    *retname = name;
 
2935
    return TRUE;
 
2936
 
 
2937
cleanup:
 
2938
    free(virBufferContentAndReset(&buf));
 
2939
    return FALSE;
 
2940
}
 
2941
 
2909
2942
/*
2910
2943
 * "pool-create-as" command
2911
2944
 */
2912
2945
static const vshCmdInfo info_pool_create_as[] = {
2913
 
    {"syntax", "pool-create-as <name> <type>"},
2914
2946
    {"help", gettext_noop("create a pool from a set of args")},
2915
2947
    {"desc", gettext_noop("Create a pool.")},
2916
2948
    {NULL, NULL}
2917
2949
};
2918
2950
 
2919
 
static const vshCmdOptDef opts_pool_create_as[] = {
2920
 
    {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the pool")},
2921
 
    {"type", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("type of the pool")},
2922
 
    {"source-host", VSH_OT_DATA, 0, gettext_noop("source-host for underlying storage")},
2923
 
    {"source-path", VSH_OT_DATA, 0, gettext_noop("source path for underlying storage")},
2924
 
    {"source-dev", VSH_OT_DATA, 0, gettext_noop("source device for underlying storage")},
2925
 
    {"target", VSH_OT_DATA, 0, gettext_noop("target for underlying storage")},
2926
 
    {NULL, 0, 0, NULL}
2927
 
};
2928
 
 
2929
 
 
2930
2951
static int
2931
2952
cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
2932
2953
{
2933
2954
    virStoragePoolPtr pool;
2934
 
    int found;
2935
 
    char *xml;
2936
 
    char *name, *type, *srcHost, *srcPath, *srcDev, *target;
2937
 
    virBuffer buf = VIR_BUFFER_INITIALIZER;
 
2955
    char *xml, *name;
2938
2956
 
2939
2957
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
2940
2958
        return FALSE;
2941
2959
 
2942
 
    name = vshCommandOptString(cmd, "name", &found);
2943
 
    if (!found)
2944
 
        goto cleanup;
2945
 
    type = vshCommandOptString(cmd, "type", &found);
2946
 
    if (!found)
2947
 
        goto cleanup;
2948
 
 
2949
 
    srcHost = vshCommandOptString(cmd, "source-host", &found);
2950
 
    srcPath = vshCommandOptString(cmd, "source-path", &found);
2951
 
    srcDev = vshCommandOptString(cmd, "source-dev", &found);
2952
 
    target = vshCommandOptString(cmd, "target", &found);
2953
 
 
2954
 
    virBufferVSprintf(&buf, "<pool type='%s'>\n", type);
2955
 
    virBufferVSprintf(&buf, "  <name>%s</name>\n", name);
2956
 
    if (srcHost || srcPath || srcDev) {
2957
 
        virBufferAddLit(&buf, "  <source>\n");
2958
 
        if (srcHost)
2959
 
            virBufferVSprintf(&buf, "    <host name='%s'>\n", srcHost);
2960
 
 
2961
 
        if (srcPath)
2962
 
            virBufferVSprintf(&buf, "    <dir path='%s'/>\n", srcPath);
2963
 
 
2964
 
        if (srcDev)
2965
 
            virBufferVSprintf(&buf, "    <device path='%s'/>\n", srcDev);
2966
 
 
2967
 
        virBufferAddLit(&buf, "  </source>\n");
2968
 
    }
2969
 
    if (target) {
2970
 
        virBufferAddLit(&buf, "  <target>\n");
2971
 
        virBufferVSprintf(&buf, "    <path>%s</path>\n", target);
2972
 
        virBufferAddLit(&buf, "  </target>\n");
2973
 
    }
2974
 
    virBufferAddLit(&buf, "</pool>\n");
2975
 
 
2976
 
    if (virBufferError(&buf)) {
2977
 
        vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
 
2960
    if (!buildPoolXML(cmd, &name, &xml))
2978
2961
        return FALSE;
2979
 
    }
2980
 
    xml = virBufferContentAndReset(&buf);
2981
2962
 
2982
2963
    pool = virStoragePoolCreateXML(ctl->conn, xml, 0);
2983
2964
    free (xml);
2988
2969
        return TRUE;
2989
2970
    } else {
2990
2971
        vshError(ctl, FALSE, _("Failed to create pool %s"), name);
2991
 
        return FALSE;
2992
2972
    }
2993
2973
 
2994
 
 cleanup:
2995
 
    free(virBufferContentAndReset(&buf));
2996
2974
    return FALSE;
2997
2975
}
2998
2976
 
3001
2979
 * "pool-define" command
3002
2980
 */
3003
2981
static const vshCmdInfo info_pool_define[] = {
3004
 
    {"syntax", "pool-define <file>"},
3005
2982
    {"help", gettext_noop("define (but don't start) a pool from an XML file")},
3006
2983
    {"desc", gettext_noop("Define a pool.")},
3007
2984
    {NULL, NULL}
3049
3026
 * "pool-define-as" command
3050
3027
 */
3051
3028
static const vshCmdInfo info_pool_define_as[] = {
3052
 
    {"syntax", "pool-define-as <name> <type>"},
3053
3029
    {"help", gettext_noop("define a pool from a set of args")},
3054
3030
    {"desc", gettext_noop("Define a pool.")},
3055
3031
    {NULL, NULL}
3056
3032
};
3057
3033
 
3058
 
static const vshCmdOptDef opts_pool_define_as[] = {
3059
 
    {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the pool")},
3060
 
    {"type", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("type of the pool")},
3061
 
    {"source-host", VSH_OT_DATA, 0, gettext_noop("source-host for underlying storage")},
3062
 
    {"source-path", VSH_OT_DATA, 0, gettext_noop("source path for underlying storage")},
3063
 
    {"source-dev", VSH_OT_DATA, 0, gettext_noop("source device for underlying storage")},
3064
 
    {"source-name", VSH_OT_DATA, 0, gettext_noop("source name for underlying storage")},
3065
 
    {"target", VSH_OT_DATA, 0, gettext_noop("target for underlying storage")},
3066
 
    {NULL, 0, 0, NULL}
3067
 
};
3068
 
 
3069
 
 
3070
3034
static int
3071
3035
cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
3072
3036
{
3073
3037
    virStoragePoolPtr pool;
3074
 
    int found;
3075
 
    char *xml;
3076
 
    char *name, *type, *srcHost, *srcPath, *srcDev, *srcName, *target;
3077
 
    virBuffer buf = VIR_BUFFER_INITIALIZER;
 
3038
    char *xml, *name;
3078
3039
 
3079
3040
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
3080
3041
        return FALSE;
3081
3042
 
3082
 
    name = vshCommandOptString(cmd, "name", &found);
3083
 
    if (!found)
3084
 
        goto cleanup;
3085
 
    type = vshCommandOptString(cmd, "type", &found);
3086
 
    if (!found)
3087
 
        goto cleanup;
3088
 
 
3089
 
    srcHost = vshCommandOptString(cmd, "source-host", &found);
3090
 
    srcPath = vshCommandOptString(cmd, "source-path", &found);
3091
 
    srcDev = vshCommandOptString(cmd, "source-dev", &found);
3092
 
    srcName = vshCommandOptString(cmd, "source-name", &found);
3093
 
    target = vshCommandOptString(cmd, "target", &found);
3094
 
 
3095
 
    virBufferVSprintf(&buf, "<pool type='%s'>\n", type);
3096
 
    virBufferVSprintf(&buf, "  <name>%s</name>\n", name);
3097
 
    if (srcHost || srcPath || srcDev || srcName) {
3098
 
        virBufferAddLit(&buf, "  <source>\n");
3099
 
        if (srcHost)
3100
 
            virBufferVSprintf(&buf, "    <host>%s</host>\n", srcHost);
3101
 
        if (srcPath)
3102
 
            virBufferVSprintf(&buf, "    <path>%s</path>\n", srcPath);
3103
 
        if (srcDev)
3104
 
            virBufferVSprintf(&buf, "    <device>%s</device>\n", srcDev);
3105
 
        if (srcName)
3106
 
            virBufferVSprintf(&buf, "    <name>%s</name>\n", srcName);
3107
 
 
3108
 
        virBufferAddLit(&buf, "  </source>\n");
3109
 
    }
3110
 
    if (target) {
3111
 
        virBufferAddLit(&buf, "  <target>\n");
3112
 
        virBufferVSprintf(&buf, "    <path>%s</path>\n", target);
3113
 
        virBufferAddLit(&buf, "  </target>\n");
3114
 
    }
3115
 
    virBufferAddLit(&buf, "</pool>\n");
3116
 
 
3117
 
 
3118
 
    if (virBufferError(&buf)) {
3119
 
        vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
 
3043
    if (!buildPoolXML(cmd, &name, &xml))
3120
3044
        return FALSE;
3121
 
    }
3122
 
    xml = virBufferContentAndReset(&buf);
3123
3045
 
3124
3046
    pool = virStoragePoolDefineXML(ctl->conn, xml, 0);
3125
3047
    free (xml);
3130
3052
        return TRUE;
3131
3053
    } else {
3132
3054
        vshError(ctl, FALSE, _("Failed to define pool %s"), name);
3133
 
        return FALSE;
3134
3055
    }
3135
3056
 
3136
 
 cleanup:
3137
 
    free(virBufferContentAndReset(&buf));
3138
3057
    return FALSE;
3139
3058
}
3140
3059
 
3143
3062
 * "pool-build" command
3144
3063
 */
3145
3064
static const vshCmdInfo info_pool_build[] = {
3146
 
    {"syntax", "pool-build <pool>"},
3147
3065
    {"help", gettext_noop("build a pool")},
3148
3066
    {"desc", gettext_noop("Build a given pool.")},
3149
3067
    {NULL, NULL}
3183
3101
 * "pool-destroy" command
3184
3102
 */
3185
3103
static const vshCmdInfo info_pool_destroy[] = {
3186
 
    {"syntax", "pool-destroy <pool>"},
3187
3104
    {"help", gettext_noop("destroy a pool")},
3188
3105
    {"desc", gettext_noop("Destroy a given pool.")},
3189
3106
    {NULL, NULL}
3223
3140
 * "pool-delete" command
3224
3141
 */
3225
3142
static const vshCmdInfo info_pool_delete[] = {
3226
 
    {"syntax", "pool-delete <pool>"},
3227
3143
    {"help", gettext_noop("delete a pool")},
3228
3144
    {"desc", gettext_noop("Delete a given pool.")},
3229
3145
    {NULL, NULL}
3263
3179
 * "pool-refresh" command
3264
3180
 */
3265
3181
static const vshCmdInfo info_pool_refresh[] = {
3266
 
    {"syntax", "pool-refresh <pool>"},
3267
3182
    {"help", gettext_noop("refresh a pool")},
3268
3183
    {"desc", gettext_noop("Refresh a given pool.")},
3269
3184
    {NULL, NULL}
3303
3218
 * "pool-dumpxml" command
3304
3219
 */
3305
3220
static const vshCmdInfo info_pool_dumpxml[] = {
3306
 
    {"syntax", "pool-dumpxml <pool>"},
3307
3221
    {"help", gettext_noop("pool information in XML")},
3308
3222
    {"desc", gettext_noop("Output the pool information as an XML dump to stdout.")},
3309
3223
    {NULL, NULL}
3344
3258
 * "pool-list" command
3345
3259
 */
3346
3260
static const vshCmdInfo info_pool_list[] = {
3347
 
    {"syntax", "pool-list [ --inactive | --all ]"},
3348
3261
    {"help", gettext_noop("list pools")},
3349
3262
    {"desc", gettext_noop("Returns list of pools.")},
3350
3263
    {NULL, NULL}
3467
3380
 * "find-storage-pool-sources-as" command
3468
3381
 */
3469
3382
static const vshCmdInfo info_find_storage_pool_sources_as[] = {
3470
 
    {"syntax", "find-storage-pool-sources-as <type> [options]"},
3471
3383
    {"help", gettext_noop("find potential storage pool sources")},
3472
3384
    {"desc", gettext_noop("Returns XML <sources> document.")},
3473
3385
    {NULL, NULL}
3513
3425
            }
3514
3426
        }
3515
3427
        ret = port ?
3516
 
            asprintf(&srcSpec,
3517
 
                     "<source><host name='%.*s' port='%s'/></source>",
3518
 
                     (int)hostlen, host, port) :
3519
 
            asprintf(&srcSpec,
3520
 
                     "<source><host name='%.*s'/></source>",
3521
 
                     (int)hostlen, host);
 
3428
            virAsprintf(&srcSpec,
 
3429
                        "<source><host name='%.*s' port='%s'/></source>",
 
3430
                        (int)hostlen, host, port) :
 
3431
            virAsprintf(&srcSpec,
 
3432
                        "<source><host name='%.*s'/></source>",
 
3433
                        (int)hostlen, host);
3522
3434
        if (ret < 0) {
3523
3435
            switch (errno) {
3524
3436
            case ENOMEM:
3525
3437
                vshError(ctl, FALSE, "%s", _("Out of memory"));
3526
3438
                break;
3527
3439
            default:
3528
 
                vshError(ctl, FALSE, _("asprintf failed (errno %d)"), errno);
 
3440
                vshError(ctl, FALSE, _("virAsprintf failed (errno %d)"), errno);
3529
3441
            }
3530
3442
            return FALSE;
3531
3443
        }
3548
3460
 * "find-storage-pool-sources" command
3549
3461
 */
3550
3462
static const vshCmdInfo info_find_storage_pool_sources[] = {
3551
 
    {"syntax", "find-storage-pool-sources <type> [srcSpec]"},
3552
3463
    {"help", gettext_noop("discover potential storage pool sources")},
3553
3464
    {"desc", gettext_noop("Returns XML <sources> document.")},
3554
3465
    {NULL, NULL}
3621
3532
 * "pool-info" command
3622
3533
 */
3623
3534
static const vshCmdInfo info_pool_info[] = {
3624
 
    {"syntax", "pool-info <pool>"},
3625
3535
    {"help", gettext_noop("storage pool information")},
3626
3536
    {"desc", gettext_noop("Returns basic information about the storage pool.")},
3627
3537
    {NULL, NULL}
3697
3607
 * "pool-name" command
3698
3608
 */
3699
3609
static const vshCmdInfo info_pool_name[] = {
3700
 
    {"syntax", "pool-name <pool>"},
3701
3610
    {"help", gettext_noop("convert a pool UUID to pool name")},
 
3611
    {"desc", ""},
3702
3612
    {NULL, NULL}
3703
3613
};
3704
3614
 
3728
3638
 * "pool-start" command
3729
3639
 */
3730
3640
static const vshCmdInfo info_pool_start[] = {
3731
 
    {"syntax", "pool-start <pool>"},
3732
3641
    {"help", gettext_noop("start a (previously defined) inactive pool")},
3733
3642
    {"desc", gettext_noop("Start a pool.")},
3734
3643
    {NULL, NULL}
3735
3644
};
3736
3645
 
3737
3646
static const vshCmdOptDef opts_pool_start[] = {
3738
 
    {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive pool")},
 
3647
    {"pool", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive pool")},
3739
3648
    {NULL, 0, 0, NULL}
3740
3649
};
3741
3650
 
3748
3657
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
3749
3658
        return FALSE;
3750
3659
 
3751
 
    if (!(pool = vshCommandOptPoolBy(ctl, cmd, "name", NULL, VSH_BYNAME)))
 
3660
    if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL, VSH_BYNAME)))
3752
3661
         return FALSE;
3753
3662
 
3754
3663
    if (virStoragePoolCreate(pool, 0) == 0) {
3767
3676
 * "vol-create-as" command
3768
3677
 */
3769
3678
static const vshCmdInfo info_vol_create_as[] = {
3770
 
    {"syntax", "vol-create-as <pool> <name> <capacity>"},
3771
3679
    {"help", gettext_noop("create a volume from a set of args")},
3772
3680
    {"desc", gettext_noop("Create a vol.")},
3773
3681
    {NULL, NULL}
3777
3685
    {"pool", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("pool name")},
3778
3686
    {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the volume")},
3779
3687
    {"capacity", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("size of the vol with optional k,M,G,T suffix")},
3780
 
    {"allocation", VSH_OT_DATA, 0, gettext_noop("initial allocation size with optional k,M,G,T suffix")},
3781
 
    {"format", VSH_OT_DATA, 0, gettext_noop("file format type raw,bochs,qcow,qcow2,vmdk")},
 
3688
    {"allocation", VSH_OT_STRING, 0, gettext_noop("initial allocation size with optional k,M,G,T suffix")},
 
3689
    {"format", VSH_OT_STRING, 0, gettext_noop("file format type raw,bochs,qcow,qcow2,vmdk")},
3782
3690
    {NULL, 0, 0, NULL}
3783
3691
};
3784
3692
 
3889
3797
 * "pool-undefine" command
3890
3798
 */
3891
3799
static const vshCmdInfo info_pool_undefine[] = {
3892
 
    {"syntax", "pool-undefine <pool>"},
3893
3800
    {"help", gettext_noop("undefine an inactive pool")},
3894
3801
    {"desc", gettext_noop("Undefine the configuration for an inactive pool.")},
3895
3802
    {NULL, NULL}
3928
3835
 * "pool-uuid" command
3929
3836
 */
3930
3837
static const vshCmdInfo info_pool_uuid[] = {
3931
 
    {"syntax", "pool-uuid <pool>"},
3932
3838
    {"help", gettext_noop("convert a pool name to pool UUID")},
 
3839
    {"desc", ""},
3933
3840
    {NULL, NULL}
3934
3841
};
3935
3842
 
3966
3873
 * "vol-create" command
3967
3874
 */
3968
3875
static const vshCmdInfo info_vol_create[] = {
3969
 
    {"syntax", "vol-create <file>"},
3970
3876
    {"help", gettext_noop("create a vol from an XML file")},
3971
3877
    {"desc", gettext_noop("Create a vol.")},
3972
3878
    {NULL, NULL}
4025
3931
 * "vol-delete" command
4026
3932
 */
4027
3933
static const vshCmdInfo info_vol_delete[] = {
4028
 
    {"syntax", "vol-delete <vol>"},
4029
3934
    {"help", gettext_noop("delete a vol")},
4030
3935
    {"desc", gettext_noop("Delete a given vol.")},
4031
3936
    {NULL, NULL}
4067
3972
 * "vol-info" command
4068
3973
 */
4069
3974
static const vshCmdInfo info_vol_info[] = {
4070
 
    {"syntax", "vol-info <vol>"},
4071
3975
    {"help", gettext_noop("storage vol information")},
4072
3976
    {"desc", gettext_noop("Returns basic information about the storage vol.")},
4073
3977
    {NULL, NULL}
4119
4023
 * "vol-dumpxml" command
4120
4024
 */
4121
4025
static const vshCmdInfo info_vol_dumpxml[] = {
4122
 
    {"syntax", "vol-dumpxml <vol>"},
4123
4026
    {"help", gettext_noop("vol information in XML")},
4124
4027
    {"desc", gettext_noop("Output the vol information as an XML dump to stdout.")},
4125
4028
    {NULL, NULL}
4161
4064
 * "vol-list" command
4162
4065
 */
4163
4066
static const vshCmdInfo info_vol_list[] = {
4164
 
    {"syntax", "vol-list <pool>"},
4165
4067
    {"help", gettext_noop("list vols")},
4166
4068
    {"desc", gettext_noop("Returns list of vols by pool.")},
4167
4069
    {NULL, NULL}
4240
4142
 * "vol-name" command
4241
4143
 */
4242
4144
static const vshCmdInfo info_vol_name[] = {
4243
 
    {"syntax", "vol-name <vol>"},
4244
4145
    {"help", gettext_noop("convert a vol UUID to vol name")},
 
4146
    {"desc", ""},
4245
4147
    {NULL, NULL}
4246
4148
};
4247
4149
 
4273
4175
 * "vol-key" command
4274
4176
 */
4275
4177
static const vshCmdInfo info_vol_key[] = {
4276
 
    {"syntax", "vol-key <vol>"},
4277
4178
    {"help", gettext_noop("convert a vol UUID to vol key")},
 
4179
    {"desc", ""},
4278
4180
    {NULL, NULL}
4279
4181
};
4280
4182
 
4306
4208
 * "vol-path" command
4307
4209
 */
4308
4210
static const vshCmdInfo info_vol_path[] = {
4309
 
    {"syntax", "vol-path <pool> <vol>"},
4310
4211
    {"help", gettext_noop("convert a vol UUID to vol path")},
 
4212
    {"desc", ""},
4311
4213
    {NULL, NULL}
4312
4214
};
4313
4215
 
4343
4245
 * "version" command
4344
4246
 */
4345
4247
static const vshCmdInfo info_version[] = {
4346
 
    {"syntax", "version"},
4347
4248
    {"help", gettext_noop("show version")},
4348
4249
    {"desc", gettext_noop("Display the system version information.")},
4349
4250
    {NULL, NULL}
4423
4324
 * "nodedev-list" command
4424
4325
 */
4425
4326
static const vshCmdInfo info_node_list_devices[] = {
4426
 
    {"syntax", "nodedev-list [--cap <capability>]"},
4427
4327
    {"help", gettext_noop("enumerate devices on this host")},
 
4328
    {"desc", ""},
4428
4329
    {NULL, NULL}
4429
4330
};
4430
4331
 
4476
4377
 * "nodedev-dumpxml" command
4477
4378
 */
4478
4379
static const vshCmdInfo info_node_device_dumpxml[] = {
4479
 
    {"syntax", "nodedev-dumpxml <device>"},
4480
4380
    {"help", gettext_noop("node device details in XML")},
4481
4381
    {"desc", gettext_noop("Output the node device details as an XML dump to stdout.")},
4482
4382
    {NULL, NULL}
4512
4412
 * "hostkey" command
4513
4413
 */
4514
4414
static const vshCmdInfo info_hostname[] = {
4515
 
    {"syntax", "hostname"},
4516
4415
    {"help", gettext_noop("print the hypervisor hostname")},
 
4416
    {"desc", ""},
4517
4417
    {NULL, NULL}
4518
4418
};
4519
4419
 
4541
4441
 * "uri" command
4542
4442
 */
4543
4443
static const vshCmdInfo info_uri[] = {
4544
 
    {"syntax", "uri"},
4545
4444
    {"help", gettext_noop("print the hypervisor canonical URI")},
 
4445
    {"desc", ""},
4546
4446
    {NULL, NULL}
4547
4447
};
4548
4448
 
4570
4470
 * "vncdisplay" command
4571
4471
 */
4572
4472
static const vshCmdInfo info_vncdisplay[] = {
4573
 
    {"syntax", "vncdisplay <domain>"},
4574
4473
    {"help", gettext_noop("vnc display")},
4575
4474
    {"desc", gettext_noop("Output the IP address and port number for the VNC display.")},
4576
4475
    {NULL, NULL}
4595
4494
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
4596
4495
        return FALSE;
4597
4496
 
4598
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
4497
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
4599
4498
        return FALSE;
4600
4499
 
4601
4500
    doc = virDomainGetXMLDesc(dom, 0);
4646
4545
 * "ttyconsole" command
4647
4546
 */
4648
4547
static const vshCmdInfo info_ttyconsole[] = {
4649
 
    {"syntax", "ttyconsole <domain>"},
4650
4548
    {"help", gettext_noop("tty console")},
4651
4549
    {"desc", gettext_noop("Output the device for the TTY console.")},
4652
4550
    {NULL, NULL}
4670
4568
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
4671
4569
        return FALSE;
4672
4570
 
4673
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
4571
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
4674
4572
        return FALSE;
4675
4573
 
4676
4574
    doc = virDomainGetXMLDesc(dom, 0);
4707
4605
 * "attach-device" command
4708
4606
 */
4709
4607
static const vshCmdInfo info_attach_device[] = {
4710
 
    {"syntax", "attach-device <domain> <file> "},
4711
4608
    {"help", gettext_noop("attach device from an XML file")},
4712
4609
    {"desc", gettext_noop("Attach device from an XML <file>.")},
4713
4610
    {NULL, NULL}
4731
4628
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
4732
4629
        return FALSE;
4733
4630
 
4734
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
4631
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
4735
4632
        return FALSE;
4736
4633
 
4737
4634
    from = vshCommandOptString(cmd, "file", &found);
4766
4663
 * "detach-device" command
4767
4664
 */
4768
4665
static const vshCmdInfo info_detach_device[] = {
4769
 
    {"syntax", "detach-device <domain> <file> "},
4770
4666
    {"help", gettext_noop("detach device from an XML file")},
4771
4667
    {"desc", gettext_noop("Detach device from an XML <file>")},
4772
4668
    {NULL, NULL}
4790
4686
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
4791
4687
        return FALSE;
4792
4688
 
4793
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
4689
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
4794
4690
        return FALSE;
4795
4691
 
4796
4692
    from = vshCommandOptString(cmd, "file", &found);
4825
4721
 * "attach-interface" command
4826
4722
 */
4827
4723
static const vshCmdInfo info_attach_interface[] = {
4828
 
    {"syntax", "attach-interface <domain> <type> <source> [--target <target>] [--mac <mac>] [--script <script>] "},
4829
4724
    {"help", gettext_noop("attach network interface")},
4830
4725
    {"desc", gettext_noop("Attach new network interface.")},
4831
4726
    {NULL, NULL}
4852
4747
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
4853
4748
        goto cleanup;
4854
4749
 
4855
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
4750
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
4856
4751
        goto cleanup;
4857
4752
 
4858
4753
    if (!(type = vshCommandOptString(cmd, "type", NULL)))
4942
4837
 * "detach-interface" command
4943
4838
 */
4944
4839
static const vshCmdInfo info_detach_interface[] = {
4945
 
    {"syntax", "detach-interface <domain> <type> [--mac <mac>] "},
4946
4840
    {"help", gettext_noop("detach network interface")},
4947
4841
    {"desc", gettext_noop("Detach network interface.")},
4948
4842
    {NULL, NULL}
4951
4845
static const vshCmdOptDef opts_detach_interface[] = {
4952
4846
    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
4953
4847
    {"type",   VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("network interface type")},
4954
 
    {"mac",    VSH_OT_DATA, 0, gettext_noop("MAC address")},
 
4848
    {"mac",    VSH_OT_STRING, 0, gettext_noop("MAC address")},
4955
4849
    {NULL, 0, 0, NULL}
4956
4850
};
4957
4851
 
4972
4866
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
4973
4867
        goto cleanup;
4974
4868
 
4975
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
4869
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
4976
4870
        goto cleanup;
4977
4871
 
4978
4872
    if (!(type = vshCommandOptString(cmd, "type", NULL)))
5063
4957
 * "attach-disk" command
5064
4958
 */
5065
4959
static const vshCmdInfo info_attach_disk[] = {
5066
 
    {"syntax", "attach-disk <domain> <source> <target> [--driver <driver>] [--subdriver <subdriver>] [--type <type>] [--mode <mode>] "},
5067
4960
    {"help", gettext_noop("attach disk device")},
5068
4961
    {"desc", gettext_noop("Attach new disk device.")},
5069
4962
    {NULL, NULL}
5073
4966
    {"domain",  VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
5074
4967
    {"source",  VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("source of disk device")},
5075
4968
    {"target",  VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("target of disk device")},
5076
 
    {"driver",    VSH_OT_DATA, 0, gettext_noop("driver of disk device")},
5077
 
    {"subdriver", VSH_OT_DATA, 0, gettext_noop("subdriver of disk device")},
5078
 
    {"type",    VSH_OT_DATA, 0, gettext_noop("target device type")},
5079
 
    {"mode",    VSH_OT_DATA, 0, gettext_noop("mode of device reading and writing")},
 
4969
    {"driver",    VSH_OT_STRING, 0, gettext_noop("driver of disk device")},
 
4970
    {"subdriver", VSH_OT_STRING, 0, gettext_noop("subdriver of disk device")},
 
4971
    {"type",    VSH_OT_STRING, 0, gettext_noop("target device type")},
 
4972
    {"mode",    VSH_OT_STRING, 0, gettext_noop("mode of device reading and writing")},
5080
4973
    {NULL, 0, 0, NULL}
5081
4974
};
5082
4975
 
5091
4984
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
5092
4985
        goto cleanup;
5093
4986
 
5094
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
4987
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
5095
4988
        goto cleanup;
5096
4989
 
5097
4990
    if (!(source = vshCommandOptString(cmd, "source", NULL)))
5228
5121
 * "detach-disk" command
5229
5122
 */
5230
5123
static const vshCmdInfo info_detach_disk[] = {
5231
 
    {"syntax", "detach-disk <domain> <target> "},
5232
5124
    {"help", gettext_noop("detach disk device")},
5233
5125
    {"desc", gettext_noop("Detach disk device.")},
5234
5126
    {NULL, NULL}
5256
5148
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
5257
5149
        goto cleanup;
5258
5150
 
5259
 
    if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
 
5151
    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
5260
5152
        goto cleanup;
5261
5153
 
5262
5154
    if (!(target = vshCommandOptString(cmd, "target", NULL)))
5417
5309
        return -1;
5418
5310
    }
5419
5311
 
5420
 
    if (asprintf (&command, "%s %s", editor, filename) == -1) {
 
5312
    if (virAsprintf(&command, "%s %s", editor, filename) == -1) {
5421
5313
        vshError(ctl, FALSE,
5422
 
                 _("asprintf: could not create editing command: %s"),
 
5314
                 _("virAsprintf: could not create editing command: %s"),
5423
5315
                 strerror (errno));
5424
5316
        return -1;
5425
5317
    }
5459
5351
 * "edit" command
5460
5352
 */
5461
5353
static const vshCmdInfo info_edit[] = {
5462
 
    {"syntax", "edit <domain>"},
5463
5354
    {"help", gettext_noop("edit XML configuration for a domain")},
5464
5355
    {"desc", gettext_noop("Edit the XML configuration for a domain.")},
5465
5356
    {NULL, NULL}
5486
5377
    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
5487
5378
        goto cleanup;
5488
5379
 
5489
 
    dom = vshCommandOptDomain (ctl, cmd, "domain", NULL);
 
5380
    dom = vshCommandOptDomain (ctl, cmd, NULL);
5490
5381
    if (dom == NULL)
5491
5382
        goto cleanup;
5492
5383
 
5493
5384
    /* Get the XML configuration of the domain. */
5494
 
    doc = virDomainGetXMLDesc (dom, 0);
 
5385
    doc = virDomainGetXMLDesc (dom, VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_INACTIVE);
5495
5386
    if (!doc)
5496
5387
        goto cleanup;
5497
5388
 
5521
5412
     * it was being edited?  This also catches problems such as us
5522
5413
     * losing a connection or the domain going away.
5523
5414
     */
5524
 
    doc_reread = virDomainGetXMLDesc (dom, 0);
 
5415
    doc_reread = virDomainGetXMLDesc (dom, VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_INACTIVE);
5525
5416
    if (!doc_reread)
5526
5417
        goto cleanup;
5527
5418
 
5562
5453
 * "net-edit" command
5563
5454
 */
5564
5455
static const vshCmdInfo info_network_edit[] = {
5565
 
    {"syntax", "net-edit <network>"},
5566
5456
    {"help", gettext_noop("edit XML configuration for a network")},
5567
5457
    {"desc", gettext_noop("Edit the XML configuration for a network.")},
5568
5458
    {NULL, NULL}
5580
5470
 * "pool-edit" command
5581
5471
 */
5582
5472
static const vshCmdInfo info_pool_edit[] = {
5583
 
    {"syntax", "pool-edit <domain>"},
5584
5473
    {"help", gettext_noop("edit XML configuration for a storage pool")},
5585
5474
    {"desc", gettext_noop("Edit the XML configuration for a storage pool.")},
5586
5475
    {NULL, NULL}
5598
5487
 * "quit" command
5599
5488
 */
5600
5489
static const vshCmdInfo info_quit[] = {
5601
 
    {"syntax", "quit"},
5602
5490
    {"help", gettext_noop("quit this interactive terminal")},
 
5491
    {"desc", ""},
5603
5492
    {NULL, NULL}
5604
5493
};
5605
5494
 
5666
5555
    {"pool-autostart", cmdPoolAutostart, opts_pool_autostart, info_pool_autostart},
5667
5556
    {"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build},
5668
5557
    {"pool-create", cmdPoolCreate, opts_pool_create, info_pool_create},
5669
 
    {"pool-create-as", cmdPoolCreateAs, opts_pool_create_as, info_pool_create_as},
 
5558
    {"pool-create-as", cmdPoolCreateAs, opts_pool_X_as, info_pool_create_as},
5670
5559
    {"pool-define", cmdPoolDefine, opts_pool_define, info_pool_define},
5671
 
    {"pool-define-as", cmdPoolDefineAs, opts_pool_define_as, info_pool_define_as},
 
5560
    {"pool-define-as", cmdPoolDefineAs, opts_pool_X_as, info_pool_define_as},
5672
5561
    {"pool-destroy", cmdPoolDestroy, opts_pool_destroy, info_pool_destroy},
5673
5562
    {"pool-delete", cmdPoolDelete, opts_pool_delete, info_pool_delete},
5674
5563
    {"pool-dumpxml", cmdPoolDumpXML, opts_pool_dumpxml, info_pool_dumpxml},
5803
5692
}
5804
5693
 
5805
5694
static int
5806
 
vshCmddefHelp(vshControl *ctl, const char *cmdname, int withprog)
 
5695
vshCmddefHelp(vshControl *ctl, const char *cmdname)
5807
5696
{
5808
5697
    const vshCmdDef *def = vshCmddefSearch(cmdname);
5809
5698
 
5811
5700
        vshError(ctl, FALSE, _("command '%s' doesn't exist"), cmdname);
5812
5701
        return FALSE;
5813
5702
    } else {
5814
 
        const vshCmdOptDef *opt;
5815
5703
        const char *desc = N_(vshCmddefGetInfo(def, "desc"));
5816
5704
        const char *help = N_(vshCmddefGetInfo(def, "help"));
5817
 
        const char *syntax = vshCmddefGetInfo(def, "syntax");
 
5705
        char buf[256];
5818
5706
 
5819
5707
        fputs(_("  NAME\n"), stdout);
5820
5708
        fprintf(stdout, "    %s - %s\n", def->name, help);
5821
5709
 
5822
 
        if (syntax) {
5823
 
            fputs(_("\n  SYNOPSIS\n"), stdout);
5824
 
            if (!withprog)
5825
 
                fprintf(stdout, "    %s\n", syntax);
5826
 
            else
5827
 
                fprintf(stdout, "    %s %s\n", progname, syntax);
 
5710
        fputs(_("\n  SYNOPSIS\n"), stdout);
 
5711
        fprintf(stdout, "    %s", def->name);
 
5712
        if (def->opts) {
 
5713
            const vshCmdOptDef *opt;
 
5714
            for (opt = def->opts; opt->name; opt++) {
 
5715
                const char *fmt;
 
5716
                if (opt->type == VSH_OT_BOOL)
 
5717
                    fmt = "[--%s]";
 
5718
                else if (opt->type == VSH_OT_INT)
 
5719
                    fmt = N_("[--%s <number>]");
 
5720
                else if (opt->type == VSH_OT_STRING)
 
5721
                    fmt = N_("[--%s <string>]");
 
5722
                else if (opt->type == VSH_OT_DATA)
 
5723
                    fmt = ((opt->flag & VSH_OFLAG_REQ) ? "<%s>" : "[<%s>]");
 
5724
                else
 
5725
                    assert(0);
 
5726
                fputc(' ', stdout);
 
5727
                fprintf(stdout, _(fmt), opt->name);
 
5728
            }
5828
5729
        }
5829
 
        if (desc) {
 
5730
        fputc('\n', stdout);
 
5731
 
 
5732
        if (desc[0]) {
 
5733
            /* Print the description only if it's not empty.  */
5830
5734
            fputs(_("\n  DESCRIPTION\n"), stdout);
5831
5735
            fprintf(stdout, "    %s\n", desc);
5832
5736
        }
 
5737
 
5833
5738
        if (def->opts) {
 
5739
            const vshCmdOptDef *opt;
5834
5740
            fputs(_("\n  OPTIONS\n"), stdout);
5835
5741
            for (opt = def->opts; opt->name; opt++) {
5836
 
                char buf[256];
5837
 
 
5838
5742
                if (opt->type == VSH_OT_BOOL)
5839
5743
                    snprintf(buf, sizeof(buf), "--%s", opt->name);
5840
5744
                else if (opt->type == VSH_OT_INT)
5974
5878
    return vshCommandOpt(cmd, name) ? TRUE : FALSE;
5975
5879
}
5976
5880
 
 
5881
/* Determine whether CMD->opts includes an option with name OPTNAME.
 
5882
   If not, give a diagnostic and return false.
 
5883
   If so, return true.  */
 
5884
static bool
 
5885
cmd_has_option (vshControl *ctl, const vshCmd *cmd, const char *optname)
 
5886
{
 
5887
    /* Iterate through cmd->opts, to ensure that there is an entry
 
5888
       with name OPTNAME and type VSH_OT_DATA. */
 
5889
    bool found = false;
 
5890
    const vshCmdOpt *opt;
 
5891
    for (opt = cmd->opts; opt; opt = opt->next) {
 
5892
        if (STREQ (opt->def->name, optname) && opt->def->type == VSH_OT_DATA) {
 
5893
            found = true;
 
5894
            break;
 
5895
        }
 
5896
    }
 
5897
 
 
5898
    if (!found)
 
5899
        vshError(ctl, FALSE,
 
5900
                 _("internal error: virsh %s: no %s VSH_OT_DATA option"),
 
5901
                 cmd->def->name, optname);
 
5902
    return found;
 
5903
}
5977
5904
 
5978
5905
static virDomainPtr
5979
 
vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
 
5906
vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
5980
5907
                      char **name, int flag)
5981
5908
{
5982
5909
    virDomainPtr dom = NULL;
5983
5910
    char *n;
5984
5911
    int id;
 
5912
    const char *optname = "domain";
 
5913
    if (!cmd_has_option (ctl, cmd, optname))
 
5914
        return NULL;
5985
5915
 
5986
5916
    if (!(n = vshCommandOptString(cmd, optname, NULL))) {
5987
5917
        vshError(ctl, FALSE, "%s", _("undefined domain name or id"));
6022
5952
}
6023
5953
 
6024
5954
static virNetworkPtr
6025
 
vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
 
5955
vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
6026
5956
                       char **name, int flag)
6027
5957
{
6028
5958
    virNetworkPtr network = NULL;
6029
5959
    char *n;
 
5960
    const char *optname = "network";
 
5961
    if (!cmd_has_option (ctl, cmd, optname))
 
5962
        return NULL;
6030
5963
 
6031
5964
    if (!(n = vshCommandOptString(cmd, optname, NULL))) {
6032
5965
        vshError(ctl, FALSE, "%s", _("undefined network name"));
6912
6845
 * Print usage
6913
6846
 */
6914
6847
static void
6915
 
vshUsage(vshControl *ctl, const char *cmdname)
 
6848
vshUsage(void)
6916
6849
{
6917
6850
    const vshCmdDef *cmd;
6918
 
 
6919
 
    /* global help */
6920
 
    if (!cmdname) {
6921
 
        fprintf(stdout, _("\n%s [options] [commands]\n\n"
6922
 
                          "  options:\n"
6923
 
                          "    -c | --connect <uri>    hypervisor connection URI\n"
6924
 
                          "    -r | --readonly         connect readonly\n"
6925
 
                          "    -d | --debug <num>      debug level [0-5]\n"
6926
 
                          "    -h | --help             this help\n"
6927
 
                          "    -q | --quiet            quiet mode\n"
6928
 
                          "    -t | --timing           print timing information\n"
6929
 
                          "    -l | --log <file>       output logging to file\n"
6930
 
                          "    -v | --version          program version\n\n"
6931
 
                          "  commands (non interactive mode):\n"), progname);
6932
 
 
6933
 
        for (cmd = commands; cmd->name; cmd++)
6934
 
            fprintf(stdout,
6935
 
                    "    %-15s %s\n", cmd->name, N_(vshCmddefGetInfo(cmd,
6936
 
                                                                     "help")));
6937
 
 
6938
 
        fprintf(stdout, "%s",
6939
 
                _("\n  (specify help <command> for details about the command)\n\n"));
6940
 
        return;
6941
 
    }
6942
 
    if (!vshCmddefHelp(ctl, cmdname, TRUE))
6943
 
        exit(EXIT_FAILURE);
 
6851
    fprintf(stdout, _("\n%s [options] [commands]\n\n"
 
6852
                      "  options:\n"
 
6853
                      "    -c | --connect <uri>    hypervisor connection URI\n"
 
6854
                      "    -r | --readonly         connect readonly\n"
 
6855
                      "    -d | --debug <num>      debug level [0-5]\n"
 
6856
                      "    -h | --help             this help\n"
 
6857
                      "    -q | --quiet            quiet mode\n"
 
6858
                      "    -t | --timing           print timing information\n"
 
6859
                      "    -l | --log <file>       output logging to file\n"
 
6860
                      "    -v | --version          program version\n\n"
 
6861
                      "  commands (non interactive mode):\n"), progname);
 
6862
 
 
6863
    for (cmd = commands; cmd->name; cmd++)
 
6864
        fprintf(stdout,
 
6865
                "    %-15s %s\n", cmd->name, N_(vshCmddefGetInfo(cmd,
 
6866
                                                                 "help")));
 
6867
 
 
6868
    fprintf(stdout, "%s",
 
6869
            _("\n  (specify help <command> for details about the command)\n\n"));
 
6870
    return;
6944
6871
}
6945
6872
 
6946
6873
/*
7038
6965
    }
7039
6966
 
7040
6967
    if (help) {
7041
 
        /* global or command specific help */
7042
 
        vshUsage(ctl, argc > end ? argv[end] : NULL);
 
6968
        if (end < argc)
 
6969
            vshError(ctl, TRUE,
 
6970
                     _("extra argument '%s'. See --help."), argv[end]);
 
6971
 
 
6972
        /* list all command */
 
6973
        vshUsage();
7043
6974
        exit(EXIT_SUCCESS);
7044
6975
    }
7045
6976
 
7078
7009
 
7079
7010
    if (!setlocale(LC_ALL, "")) {
7080
7011
        perror("setlocale");
7081
 
        return -1;
 
7012
        /* failure to setup locale is not fatal */
7082
7013
    }
7083
7014
    if (!bindtextdomain(GETTEXT_PACKAGE, LOCALEBASEDIR)) {
7084
7015
        perror("bindtextdomain");